Пример #1
0
 def test_showtip(self):
     tooltip = Hovertip(self.button, 'ToolTip text')
     self.addCleanup(tooltip.hidetip)
     self.assertFalse(tooltip.tipwindow
                      and tooltip.tipwindow.winfo_viewable())
     tooltip.showtip()
     self.assertTrue(tooltip.tipwindow
                     and tooltip.tipwindow.winfo_viewable())
Пример #2
0
 def test_hidetip_on_mouse_leave(self):
     tooltip = Hovertip(self.button, 'ToolTip text', hover_delay=None)
     self.addCleanup(tooltip.hidetip)
     tooltip.showtip = add_call_counting(tooltip.showtip)
     root_update()
     self.button.event_generate('<Enter>', x=0, y=0)
     root_update()
     self.button.event_generate('<Leave>', x=0, y=0)
     root_update()
     self.assertFalse(tooltip.tipwindow
                      and tooltip.tipwindow.winfo_viewable())
     self.assertGreater(len(tooltip.showtip.call_args_list), 0)
Пример #3
0
 def test_dont_show_on_mouse_leave_before_delay(self):
     tooltip = Hovertip(self.button, 'ToolTip text', hover_delay=50)
     self.addCleanup(tooltip.hidetip)
     tooltip.showtip = add_call_counting(tooltip.showtip)
     root_update()
     self.button.event_generate('<Enter>', x=0, y=0)
     root_update()
     self.button.event_generate('<Leave>', x=0, y=0)
     root_update()
     time.sleep(0.1)
     root_update()
     self.assertFalse(tooltip.tipwindow
                      and tooltip.tipwindow.winfo_viewable())
     self.assertEqual(tooltip.showtip.call_args_list, [])
Пример #4
0
    def __init__(self, s, tags, numoflines, squeezer):
        self.s = s
        self.tags = tags
        self.numoflines = numoflines
        self.squeezer = squeezer
        self.editwin = editwin = squeezer.editwin
        self.text = text = editwin.text
        # The base Text widget is needed to change text before iomark.
        self.base_text = editwin.per.bottom

        line_plurality = "lines" if numoflines != 1 else "line"
        button_text = f"Squeezed text ({numoflines} {line_plurality})."
        tk.Button.__init__(self,
                           text,
                           text=button_text,
                           background="#FFFFC0",
                           activebackground="#FFFFE0")

        button_tooltip_text = (
            "Double-click to expand, right-click for more options.")
        Hovertip(self, button_tooltip_text, hover_delay=80)

        self.bind("<Double-Button-1>", self.expand)
        if macosx.isAquaTk():
            # AquaTk defines <2> as the right button, not <3>.
            self.bind("<Button-2>", self.context_menu_event)
        else:
            self.bind("<Button-3>", self.context_menu_event)
        self.selection_handle(  # X windows only.
            lambda offset, length: s[int(offset):int(offset) + int(length)])

        self.is_dangerous = None
        self.after_idle(self.set_is_dangerous)