|
1 | | -# Copyright (c) 2021-2022 The University of Texas Southwestern Medical Center. |
| 1 | +# Copyright (c) 2021-2024 The University of Texas Southwestern Medical Center. |
2 | 2 | # All rights reserved. |
3 | 3 |
|
4 | 4 | # Redistribution and use in source and binary forms, with or without |
|
33 | 33 | # Standard Library Imports |
34 | 34 | import tkinter as tk |
35 | 35 | import logging |
| 36 | +from tkinter import ttk |
36 | 37 |
|
37 | 38 | # Third Party Imports |
38 | 39 |
|
@@ -82,17 +83,23 @@ def __init__(self, widget=None, text=None, type="free"): |
82 | 83 | """ |
83 | 84 | #: tk.Widget: The widget to which the hover instance is bound |
84 | 85 | self.widget = widget |
| 86 | + |
85 | 87 | #: tk.Toplevel: The hover window |
86 | 88 | self.tipwindow = None |
| 89 | + |
87 | 90 | #: int: The id of the widget |
88 | 91 | self.id = None |
| 92 | + |
89 | 93 | #: int: The x position of the widget |
90 | 94 | #: int: The y position of the widget |
91 | 95 | self.x = self.y = 0 |
| 96 | + |
92 | 97 | #: str: The text to be displayed when the hover is shown |
93 | 98 | self.text = text |
| 99 | + |
94 | 100 | #: str: The current state of the hover |
95 | 101 | self.description = None |
| 102 | + |
96 | 103 | #: str: The current state of the hover |
97 | 104 | self.type = type |
98 | 105 |
|
@@ -227,3 +234,100 @@ def hidetip(self): |
227 | 234 | self.tipwindow = None |
228 | 235 | if tw: |
229 | 236 | tw.destroy() |
| 237 | + |
| 238 | + |
| 239 | +class HoverMixin: |
| 240 | + """Adds hover attribute to widget |
| 241 | +
|
| 242 | + This class is meant to be mixed in with other widgets to add a hover attribute. |
| 243 | + Hover provides contextual information about the widget when the mouse is over it. |
| 244 | + """ |
| 245 | + |
| 246 | + def __init__(self, *args, **kwargs): |
| 247 | + """Initializes HoverMixin |
| 248 | +
|
| 249 | + Parameters |
| 250 | + ---------- |
| 251 | + *args |
| 252 | + Additional arguments to pass to the ttk.Frame constructor. |
| 253 | + **kwargs |
| 254 | + Additional keyword arguments to pass to the ttk.Frame constructor. |
| 255 | + """ |
| 256 | + super().__init__(*args, **kwargs) |
| 257 | + self.hover = Hover(self, text=None, type="free") |
| 258 | + |
| 259 | + |
| 260 | +class HoverButton(HoverMixin, ttk.Button): |
| 261 | + """Adds hover attribute to ttk.Button |
| 262 | +
|
| 263 | + This class is meant to be mixed in with other widgets to add a hover attribute |
| 264 | + """ |
| 265 | + |
| 266 | + def __init__(self, *args, **kwargs): |
| 267 | + """Initializes HoverButton |
| 268 | +
|
| 269 | + Parameters |
| 270 | + ---------- |
| 271 | + *args |
| 272 | + Additional arguments to pass to the ttk.Frame constructor. |
| 273 | + **kwargs |
| 274 | + Additional keyword arguments to pass to the ttk.Frame constructor. |
| 275 | + """ |
| 276 | + super().__init__(*args, **kwargs) |
| 277 | + |
| 278 | + |
| 279 | +class HoverTkButton(HoverMixin, tk.Button): |
| 280 | + """Adds hover attribute to tk.Button |
| 281 | +
|
| 282 | + This class is meant to be mixed in with other widgets to add a hover attribute |
| 283 | + """ |
| 284 | + |
| 285 | + def __init__(self, *args, **kwargs): |
| 286 | + """Initializes HoverTkButton |
| 287 | +
|
| 288 | + Parameters |
| 289 | + ---------- |
| 290 | + *args |
| 291 | + Additional arguments to pass to the ttk.Frame constructor. |
| 292 | + **kwargs |
| 293 | + Additional keyword arguments to pass to the ttk.Frame constructor. |
| 294 | + """ |
| 295 | + super().__init__(*args, **kwargs) |
| 296 | + |
| 297 | + |
| 298 | +class HoverRadioButton(HoverMixin, ttk.Radiobutton): |
| 299 | + """Adds hover attribute to ttk.Radiobutton |
| 300 | +
|
| 301 | + This class is meant to be mixed in with other widgets to add a hover attribute |
| 302 | + """ |
| 303 | + |
| 304 | + def __init__(self, *args, **kwargs): |
| 305 | + """Initializes HoverRadioButton |
| 306 | +
|
| 307 | + Parameters |
| 308 | + ---------- |
| 309 | + *args |
| 310 | + Additional arguments to pass to the ttk.Frame constructor. |
| 311 | + **kwargs |
| 312 | + Additional keyword arguments to pass to the ttk.Frame constructor. |
| 313 | + """ |
| 314 | + super().__init__(*args, **kwargs) |
| 315 | + |
| 316 | + |
| 317 | +class HoverCheckButton(HoverMixin, ttk.Checkbutton): |
| 318 | + """Adds hover attribute to ttk.Checkbutton |
| 319 | +
|
| 320 | + This class is meant to be mixed in with other widgets to add a hover attribute. |
| 321 | + """ |
| 322 | + |
| 323 | + def __init__(self, *args, **kwargs): |
| 324 | + """Initializes HoverCheckButton |
| 325 | +
|
| 326 | + Parameters |
| 327 | + ---------- |
| 328 | + *args |
| 329 | + Additional arguments to pass to the ttk.Frame constructor. |
| 330 | + **kwargs |
| 331 | + Additional keyword arguments to pass to the ttk.Frame constructor. |
| 332 | + """ |
| 333 | + super().__init__(*args, **kwargs) |
0 commit comments