Skip to content

Commit

Permalink
Feature/tooltips offscreen (#1412)
Browse files Browse the repository at this point in the history
  • Loading branch information
lawson89 authored Oct 14, 2023
1 parent 4808c6e commit 5cb0a87
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion porcupine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ def show(self) -> None:
if self.got_mouse:
self.destroy_tipwindow()
tipwindow = type(self).tipwindow = tkinter.Toplevel()
tipwindow.geometry(f"+{self.mousex + 10}+{self.mousey - 10}")
tipwindow.bind("<Motion>", self.destroy_tipwindow, add=True)
tipwindow.overrideredirect(True)

Expand All @@ -176,6 +175,15 @@ def show(self) -> None:
# the label will have light text on a light background or
# dark text on a dark background on some systems.
tkinter.Label(tipwindow, text=self.text, border=3, fg="black", bg="white").pack()
tipwindow.update_idletasks()
screen_width = tipwindow.winfo_screenwidth()
to_end = screen_width - self.mousex
tip_width = tipwindow.winfo_width()
if to_end >= tip_width / 2:
offset = int(tip_width / 2)
else:
offset = int(tip_width - to_end)
tipwindow.geometry(f"+{self.mousex - offset}+{self.mousey - 30}")


def set_tooltip(widget: tkinter.Widget, text: str) -> None:
Expand Down

0 comments on commit 5cb0a87

Please sign in to comment.