Skip to content

Commit 92bb5b8

Browse files
Consolidation & Unit Tests - Custom Widgets
Consolidated hovermixin and hover into a single file. Removed hoverbar, was unused and didn't appear functional. Added tests.
1 parent 9302ce3 commit 92bb5b8

File tree

7 files changed

+293
-420
lines changed

7 files changed

+293
-420
lines changed

src/navigate/view/custom_widgets/LabelInputWidgetFactory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939

4040
# Local Imports
4141
from navigate.view.custom_widgets.validation import ValidatedCombobox, ValidatedSpinbox
42-
from navigate.view.custom_widgets.hovermixin import (
42+
from navigate.view.custom_widgets.hover import (
4343
HoverButton,
44-
HoverCheckButton,
45-
HoverRadioButton,
4644
HoverTkButton,
45+
HoverRadioButton,
46+
HoverCheckButton,
4747
)
4848

4949
# Logger Setup

src/navigate/view/custom_widgets/hover.py

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2021-2022 The University of Texas Southwestern Medical Center.
1+
# Copyright (c) 2021-2024 The University of Texas Southwestern Medical Center.
22
# All rights reserved.
33

44
# Redistribution and use in source and binary forms, with or without
@@ -33,6 +33,7 @@
3333
# Standard Library Imports
3434
import tkinter as tk
3535
import logging
36+
from tkinter import ttk
3637

3738
# Third Party Imports
3839

@@ -82,17 +83,23 @@ def __init__(self, widget=None, text=None, type="free"):
8283
"""
8384
#: tk.Widget: The widget to which the hover instance is bound
8485
self.widget = widget
86+
8587
#: tk.Toplevel: The hover window
8688
self.tipwindow = None
89+
8790
#: int: The id of the widget
8891
self.id = None
92+
8993
#: int: The x position of the widget
9094
#: int: The y position of the widget
9195
self.x = self.y = 0
96+
9297
#: str: The text to be displayed when the hover is shown
9398
self.text = text
99+
94100
#: str: The current state of the hover
95101
self.description = None
102+
96103
#: str: The current state of the hover
97104
self.type = type
98105

@@ -227,3 +234,100 @@ def hidetip(self):
227234
self.tipwindow = None
228235
if tw:
229236
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

Comments
 (0)