Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidation & Unit Tests - Custom Widgets #936

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/navigate/view/custom_widgets/LabelInputWidgetFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@

# Local Imports
from navigate.view.custom_widgets.validation import ValidatedCombobox, ValidatedSpinbox
from navigate.view.custom_widgets.hovermixin import (
from navigate.view.custom_widgets.hover import (
HoverButton,
HoverCheckButton,
HoverRadioButton,
HoverTkButton,
HoverRadioButton,
HoverCheckButton,
)

# Logger Setup
Expand Down
106 changes: 105 additions & 1 deletion src/navigate/view/custom_widgets/hover.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2021-2022 The University of Texas Southwestern Medical Center.
# Copyright (c) 2021-2024 The University of Texas Southwestern Medical Center.
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -33,6 +33,7 @@
# Standard Library Imports
import tkinter as tk
import logging
from tkinter import ttk

# Third Party Imports

Expand Down Expand Up @@ -82,17 +83,23 @@ def __init__(self, widget=None, text=None, type="free"):
"""
#: tk.Widget: The widget to which the hover instance is bound
self.widget = widget

#: tk.Toplevel: The hover window
self.tipwindow = None

#: int: The id of the widget
self.id = None

#: int: The x position of the widget
#: int: The y position of the widget
self.x = self.y = 0

#: str: The text to be displayed when the hover is shown
self.text = text

#: str: The current state of the hover
self.description = None

#: str: The current state of the hover
self.type = type

Expand Down Expand Up @@ -227,3 +234,100 @@ def hidetip(self):
self.tipwindow = None
if tw:
tw.destroy()


class HoverMixin:
"""Adds hover attribute to widget

This class is meant to be mixed in with other widgets to add a hover attribute.
Hover provides contextual information about the widget when the mouse is over it.
"""

def __init__(self, *args, **kwargs):
"""Initializes HoverMixin

Parameters
----------
*args
Additional arguments to pass to the ttk.Frame constructor.
**kwargs
Additional keyword arguments to pass to the ttk.Frame constructor.
"""
super().__init__(*args, **kwargs)
self.hover = Hover(self, text=None, type="free")


class HoverButton(HoverMixin, ttk.Button):
"""Adds hover attribute to ttk.Button

This class is meant to be mixed in with other widgets to add a hover attribute
"""

def __init__(self, *args, **kwargs):
"""Initializes HoverButton

Parameters
----------
*args
Additional arguments to pass to the ttk.Frame constructor.
**kwargs
Additional keyword arguments to pass to the ttk.Frame constructor.
"""
super().__init__(*args, **kwargs)


class HoverTkButton(HoverMixin, tk.Button):
"""Adds hover attribute to tk.Button

This class is meant to be mixed in with other widgets to add a hover attribute
"""

def __init__(self, *args, **kwargs):
"""Initializes HoverTkButton

Parameters
----------
*args
Additional arguments to pass to the ttk.Frame constructor.
**kwargs
Additional keyword arguments to pass to the ttk.Frame constructor.
"""
super().__init__(*args, **kwargs)


class HoverRadioButton(HoverMixin, ttk.Radiobutton):
"""Adds hover attribute to ttk.Radiobutton

This class is meant to be mixed in with other widgets to add a hover attribute
"""

def __init__(self, *args, **kwargs):
"""Initializes HoverRadioButton

Parameters
----------
*args
Additional arguments to pass to the ttk.Frame constructor.
**kwargs
Additional keyword arguments to pass to the ttk.Frame constructor.
"""
super().__init__(*args, **kwargs)


class HoverCheckButton(HoverMixin, ttk.Checkbutton):
"""Adds hover attribute to ttk.Checkbutton

This class is meant to be mixed in with other widgets to add a hover attribute.
"""

def __init__(self, *args, **kwargs):
"""Initializes HoverCheckButton

Parameters
----------
*args
Additional arguments to pass to the ttk.Frame constructor.
**kwargs
Additional keyword arguments to pass to the ttk.Frame constructor.
"""
super().__init__(*args, **kwargs)
Loading
Loading