Skip to content

Commit 71418b9

Browse files
author
oskro
committed
tooltip line breaks prettifying
1 parent ff4dbe3 commit 71418b9

File tree

3 files changed

+29
-53
lines changed

3 files changed

+29
-53
lines changed

modules/grail.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ def _make_widgets(self):
3737
bfr1.propagate(False)
3838
bfr1.pack(expand=False, fill=tk.X, padx=1, pady=1)
3939

40-
tkd.Button(bfr1, text='Sync', width=6, command=self.sync_local_grail, relief=tk.RIDGE, borderwidth=1, tooltip='Updates your local grail to include items logged either\nin your profiles or on herokuapp').pack(side=tk.LEFT, padx=[1, 15], pady=1)
40+
tkd.Button(bfr1, text='Sync', width=6, command=self.sync_local_grail, relief=tk.RIDGE, borderwidth=1, tooltip='Updates your local grail to include items logged either in your profiles or on herokuapp').pack(side=tk.LEFT, padx=[1, 15], pady=1)
4141
tkd.Checkbutton(bfr1, text='Profiles', variable=self.sync_drops).pack(side=tk.LEFT)
4242
tkd.Checkbutton(bfr1, text='Herokuapp', variable=self.sync_herokuapp).pack(side=tk.LEFT)
4343

4444
bfr2 = tkd.Frame(self)
4545
bfr2.pack(pady=12, expand=True, fill=tk.X)
46-
tkd.Button(bfr2, text='Upload grail to herokuapp', command=self.upload_to_herokuapp, borderwidth=3, tooltip='This will not delete already found items on herokuapp if they are not\nin your local grail, but only add new items').pack(padx=8, side=tk.LEFT, fill=tk.X, expand=True)
46+
tkd.Button(bfr2, text='Upload grail to herokuapp', command=self.upload_to_herokuapp, borderwidth=3, tooltip='This will not delete already found items on herokuapp if they are not in your local grail, but only add new items').pack(padx=8, side=tk.LEFT, fill=tk.X, expand=True)
4747

4848
bfr3 = tkd.Frame(self)
4949
bfr3.pack(side=tk.BOTTOM, expand=tk.YES, fill=tk.X)

modules/suboptions/general.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(self, main_frame, parent=None, **kw):
1717
self.add_flag(flag_name='Autocompletion unids', comment='Enable autocompletion for unid set/uniques, for tc84/87 items and for circlets, charms and jewels')
1818
self.add_theme_choice(comment='Select which color/style theme to use for the application')
1919
self.add_num_entry(flag_name='Start run delay (seconds)', comment='Add an artificial delay to the "start run" command')
20-
self.add_num_entry(flag_name='Auto archive (hours)', comment='Automatically calls "Archive session" if more than configured number\nof hours have passed since last time the profile was used\nDisabled when equal to zero (0.0)\n\nThis is checked when app is opened and when profile is changed')
20+
self.add_num_entry(flag_name='Auto archive (hours)', comment='Automatically calls "Archive session" if more than configured number of hours have passed since last time the profile was used\n\nDisabled when equal to zero (0.0)\n\nThis is checked when app is opened and when profile is changed')
2121

2222
def add_theme_choice(self, comment=None):
2323
lf = tkd.LabelFrame(self, height=LAB_HEIGHT, width=LAB_WIDTH)

utils/tk_dynamic.py

+26-50
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from init import *
2-
import os, sys
2+
import textwrap
33
import tkinter as tk
44
from tkinter import ttk
55
import webbrowser
@@ -512,67 +512,44 @@ def insert(self, *args, **kwargs):
512512
self.tag_add(tag, "end-1c linestart", "end-1c lineend")
513513

514514

515-
class Tooltip(object):
515+
class Tooltip:
516516
def __init__(self, widget):
517517
self.widget = widget
518518
self.tipwindow = None
519519
self.id = None
520520
self.x = self.y = 0
521+
self.text = None
521522

522-
# @staticmethod
523-
# def get_monitor_from_coord(x, y):
524-
# monitors = screeninfo.get_monitors()
525-
#
526-
# for m in reversed(monitors):
527-
# if m.x <= x <= m.width + m.x and m.y <= y <= m.height + m.y:
528-
# return m
529-
# return monitors[0]
530-
#
531-
# def get_displaced_geom(self, root, window_width, window_height, pos_x, pos_y):
532-
# mon = self.get_monitor_from_coord(root.winfo_rootx(), root.winfo_rooty())
533-
# min_x = mon.x
534-
# min_y = mon.y
535-
# max_x = mon.width + min_x
536-
# max_y = mon.height + min_y
537-
#
538-
# displaced_x = max(min(pos_x, max_x - window_width), min_x - 5)
539-
# displaced_y = max(min(pos_y, max_y - window_height), min_y)
540-
#
541-
# return '%sx%s+%s+%s' % (window_width, window_height, displaced_x, displaced_y)
523+
@staticmethod
524+
def linebreak_text(text):
525+
return '\n'.join(textwrap.fill(line, 50) for line in text.split('\n'))
542526

543527
def showtip(self, text):
544-
"Display text in tooltip window"
545-
self.text = text
528+
""" Display text in tooltip window """
529+
self.text = self.linebreak_text(text)
546530
if self.tipwindow or not self.text:
547531
return
548532
x, y, cx, cy = self.widget.bbox("insert")
549533

550534
x = x + self.widget.winfo_rootx() + 57
551535
y = y + cy + self.widget.winfo_rooty() + 27
552536

553-
self.tipwindow = tw = tk.Toplevel(self.widget)
537+
self.tipwindow = tk.Toplevel(self.widget)
554538
self.tipwindow.wm_attributes('-topmost', True)
555-
tw.wm_overrideredirect(1)
539+
self.tipwindow.wm_overrideredirect(True)
556540

557-
# tw.wm_geometry("+%d+%d" % (x, y))
558-
label = tk.Label(tw, text=self.text, justify=tk.LEFT,
541+
label = tk.Label(self.tipwindow, text=self.text, justify=tk.LEFT,
559542
background="#ffffe0", relief=tk.SOLID, borderwidth=1,
560543
font=("tahoma", "8", "normal"))
561544
label.pack(ipadx=1)
562545

563-
564-
# tw.update()
565-
# geom = self.get_displaced_geom(self.widget, self.tipwindow.winfo_width(), self.tipwindow.winfo_height(), x, y)
566-
# tw.wm_geometry(geom)
567-
568546
geom = "+%d+%d" % (x, y)
569-
tw.wm_geometry(geom)
547+
self.tipwindow.wm_geometry(geom)
570548

571549
def hidetip(self):
572-
tw = self.tipwindow
550+
if self.tipwindow:
551+
self.tipwindow.destroy()
573552
self.tipwindow = None
574-
if tw:
575-
tw.destroy()
576553

577554

578555
def create_tooltip(widget, text):
@@ -590,9 +567,6 @@ def __init__(self, *args, **kwargs):
590567
self.tag_configure('Odd', background='gray95')
591568
self.tag_configure('Even', background='white')
592569

593-
# self.highlighted_item = None
594-
# self.highlighted_prev_tags = ''
595-
596570
self.tag_configure('highlighted_line', background='#1874CD', foreground='white')
597571
self.bind('<Control-c>', lambda _: self.copy_highlighted_to_clipboard())
598572

@@ -620,18 +594,20 @@ def _sort(self, column, reverse, data_type, callback):
620594
self.heading(column, command=partial(callback, column, not reverse))
621595

622596
def _sort_by_num(self, column, reverse):
623-
if reverse:
624-
foo = lambda x: float('-inf') if x == '' else float(x.replace('%', ''))
625-
else:
626-
foo = lambda x: float('inf') if x == '' else float(x.replace('%', ''))
627-
self._sort(column, reverse, foo, self._sort_by_num)
597+
def sort_fnc(x):
598+
if x == '':
599+
return float('-inf') if reverse else float('inf')
600+
return float(x.replace('%', ''))
601+
602+
self._sort(column, reverse, sort_fnc, self._sort_by_num)
628603

629604
def _sort_by_name(self, column, reverse):
630-
if reverse:
631-
foo = lambda x: str(x)
632-
else:
633-
foo = lambda x: '€'*100 if x == '' else str(x)
634-
self._sort(column, reverse, foo, self._sort_by_name)
605+
def sort_fnc(x):
606+
if x == '' and not reverse:
607+
return '€'*100
608+
return str(x)
609+
610+
self._sort(column, reverse, sort_fnc, self._sort_by_name)
635611

636612
def insert(self, *args, **kwargs):
637613
if self.alternate_colour:

0 commit comments

Comments
 (0)