Module ui.window

Generic Window base classes

Expand source code
"""
Generic Window base classes
"""
import tkinter
from tkinter import messagebox, Toplevel
from tkinter.filedialog import askopenfilename, asksaveasfilename

from ttkthemes import ThemedStyle

import ui


class UsesDialog:
    """
    A helper class for use inside of the views
    """

    @classmethod
    def show_error(cls, title, message, **options):
        """
        Helper method for showing an error dialog
        Calls tkinter.messagebox.showerror
        :param title: Title
        :param message: Message
        :param options: Options
        :return: None
        """
        messagebox.showerror(title=title, message=message, **options)

    @classmethod
    def show_info(cls, title, message, **options):
        """
        Helper method for showing an info dialog
        Calls tkinter.messagebox.showinfo
        :param title: Title
        :param message: Message
        :param options: Options
        :return: None
        """
        messagebox.showinfo(title=title, message=message, **options)

    @classmethod
    def show_confirm(cls, title, message, **options):
        """
        Helper method for showing a confirmation dialog
        Calls tkinter.messagebox.askyesno
        :param title: Title
        :param message: Message
        :param options: Options.
        :return: bool True if "yes" was clicked
        """
        return messagebox.askyesno(title=title, message=message, **options)

    @classmethod
    def show_warning(cls, title, message, **options):
        """
        Helper method for showing an warning dialog
        Calls tkinter.messagebox.showwarning
        :param title: Title
        :param message: Message
        :param options: Options
        :return: None
        """
        messagebox.showwarning(title=title, message=message, **options)

    @classmethod
    def show_file_picker(cls, title=None, filetypes=None, **options):
        """
        Helper method for a file picker dialog
        :param title: Title
        :param filetypes: valid file types
        :return: filepath selected
        """
        return askopenfilename(title=title, filetypes=filetypes, **options)

    @classmethod
    def show_save_picker(cls, title=None, filetypes=None, **options):
        """
        Helper method for a save picker dialog
        :param title: Title
        :param filetypes: valid file types
        :return: filepath selected
        """
        return asksaveasfilename(title=title, filetypes=filetypes, **options)


class TkinterWindow(UsesDialog):
    """
    Easily creates windows and exposes event handlers for controllers
    """

    def __init__(self, event_handlers):
        """
        Creates a new Tkinter instance

        :param event_handlers: Received by the controller.
                                This contains hooks back to the controller for actions
        """
        self.master = tkinter.Tk()
        # self.master.configure(bg='white')
        style = ThemedStyle(self.master)
        style.theme_use('arc')

        try:
            self.master.iconphoto(True, ui.load_image("ui/icons/EmpDat.gif"))
        except tkinter.TclError:
            pass

        self.event_handlers = event_handlers

    def mainloop(self):
        """
        Forwards mainloop call to the Tkinter instance

        :return: None
        """
        self.master.mainloop()

    def destroy(self):
        """
        Destroys tkinter instance

        :return: None
        """
        self.master.destroy()


class TkinterDialog(Toplevel, UsesDialog):
    """
    Easily creates windows and exposes event handlers for controllers
    """

    def __init__(self, event_handlers):
        """
        A TkinterDialog is different as it uses a pre-existing Tkinter instance.

        :param event_handlers: Received by the controller.
                                This contains hooks back to the controller for actions
        """
        super().__init__()

        self.event_handlers = event_handlers

Sub-modules

ui.window.change_requests

Change Requests view

ui.window.database

Main View of the Application

ui.window.dialogs
ui.window.login

Login GUI Window implemented with Tkinter w/ built-in tester

Classes

class TkinterDialog (event_handlers)

Easily creates windows and exposes event handlers for controllers

A TkinterDialog is different as it uses a pre-existing Tkinter instance.

:param event_handlers: Received by the controller. This contains hooks back to the controller for actions

Expand source code
class TkinterDialog(Toplevel, UsesDialog):
    """
    Easily creates windows and exposes event handlers for controllers
    """

    def __init__(self, event_handlers):
        """
        A TkinterDialog is different as it uses a pre-existing Tkinter instance.

        :param event_handlers: Received by the controller.
                                This contains hooks back to the controller for actions
        """
        super().__init__()

        self.event_handlers = event_handlers

Ancestors

  • tkinter.Toplevel
  • tkinter.BaseWidget
  • tkinter.Misc
  • tkinter.Wm
  • UsesDialog

Subclasses

Inherited members

class TkinterWindow (event_handlers)

Easily creates windows and exposes event handlers for controllers

Creates a new Tkinter instance

:param event_handlers: Received by the controller. This contains hooks back to the controller for actions

Expand source code
class TkinterWindow(UsesDialog):
    """
    Easily creates windows and exposes event handlers for controllers
    """

    def __init__(self, event_handlers):
        """
        Creates a new Tkinter instance

        :param event_handlers: Received by the controller.
                                This contains hooks back to the controller for actions
        """
        self.master = tkinter.Tk()
        # self.master.configure(bg='white')
        style = ThemedStyle(self.master)
        style.theme_use('arc')

        try:
            self.master.iconphoto(True, ui.load_image("ui/icons/EmpDat.gif"))
        except tkinter.TclError:
            pass

        self.event_handlers = event_handlers

    def mainloop(self):
        """
        Forwards mainloop call to the Tkinter instance

        :return: None
        """
        self.master.mainloop()

    def destroy(self):
        """
        Destroys tkinter instance

        :return: None
        """
        self.master.destroy()

Ancestors

Subclasses

Methods

def destroy(self)

Destroys tkinter instance

:return: None

Expand source code
def destroy(self):
    """
    Destroys tkinter instance

    :return: None
    """
    self.master.destroy()
def mainloop(self)

Forwards mainloop call to the Tkinter instance

:return: None

Expand source code
def mainloop(self):
    """
    Forwards mainloop call to the Tkinter instance

    :return: None
    """
    self.master.mainloop()

Inherited members

class UsesDialog

A helper class for use inside of the views

Expand source code
class UsesDialog:
    """
    A helper class for use inside of the views
    """

    @classmethod
    def show_error(cls, title, message, **options):
        """
        Helper method for showing an error dialog
        Calls tkinter.messagebox.showerror
        :param title: Title
        :param message: Message
        :param options: Options
        :return: None
        """
        messagebox.showerror(title=title, message=message, **options)

    @classmethod
    def show_info(cls, title, message, **options):
        """
        Helper method for showing an info dialog
        Calls tkinter.messagebox.showinfo
        :param title: Title
        :param message: Message
        :param options: Options
        :return: None
        """
        messagebox.showinfo(title=title, message=message, **options)

    @classmethod
    def show_confirm(cls, title, message, **options):
        """
        Helper method for showing a confirmation dialog
        Calls tkinter.messagebox.askyesno
        :param title: Title
        :param message: Message
        :param options: Options.
        :return: bool True if "yes" was clicked
        """
        return messagebox.askyesno(title=title, message=message, **options)

    @classmethod
    def show_warning(cls, title, message, **options):
        """
        Helper method for showing an warning dialog
        Calls tkinter.messagebox.showwarning
        :param title: Title
        :param message: Message
        :param options: Options
        :return: None
        """
        messagebox.showwarning(title=title, message=message, **options)

    @classmethod
    def show_file_picker(cls, title=None, filetypes=None, **options):
        """
        Helper method for a file picker dialog
        :param title: Title
        :param filetypes: valid file types
        :return: filepath selected
        """
        return askopenfilename(title=title, filetypes=filetypes, **options)

    @classmethod
    def show_save_picker(cls, title=None, filetypes=None, **options):
        """
        Helper method for a save picker dialog
        :param title: Title
        :param filetypes: valid file types
        :return: filepath selected
        """
        return asksaveasfilename(title=title, filetypes=filetypes, **options)

Subclasses

Static methods

def show_confirm(title, message, **options)

Helper method for showing a confirmation dialog Calls tkinter.messagebox.askyesno :param title: Title :param message: Message :param options: Options. :return: bool True if "yes" was clicked

Expand source code
@classmethod
def show_confirm(cls, title, message, **options):
    """
    Helper method for showing a confirmation dialog
    Calls tkinter.messagebox.askyesno
    :param title: Title
    :param message: Message
    :param options: Options.
    :return: bool True if "yes" was clicked
    """
    return messagebox.askyesno(title=title, message=message, **options)
def show_error(title, message, **options)

Helper method for showing an error dialog Calls tkinter.messagebox.showerror :param title: Title :param message: Message :param options: Options :return: None

Expand source code
@classmethod
def show_error(cls, title, message, **options):
    """
    Helper method for showing an error dialog
    Calls tkinter.messagebox.showerror
    :param title: Title
    :param message: Message
    :param options: Options
    :return: None
    """
    messagebox.showerror(title=title, message=message, **options)
def show_file_picker(title=None, filetypes=None, **options)

Helper method for a file picker dialog :param title: Title :param filetypes: valid file types :return: filepath selected

Expand source code
@classmethod
def show_file_picker(cls, title=None, filetypes=None, **options):
    """
    Helper method for a file picker dialog
    :param title: Title
    :param filetypes: valid file types
    :return: filepath selected
    """
    return askopenfilename(title=title, filetypes=filetypes, **options)
def show_info(title, message, **options)

Helper method for showing an info dialog Calls tkinter.messagebox.showinfo :param title: Title :param message: Message :param options: Options :return: None

Expand source code
@classmethod
def show_info(cls, title, message, **options):
    """
    Helper method for showing an info dialog
    Calls tkinter.messagebox.showinfo
    :param title: Title
    :param message: Message
    :param options: Options
    :return: None
    """
    messagebox.showinfo(title=title, message=message, **options)
def show_save_picker(title=None, filetypes=None, **options)

Helper method for a save picker dialog :param title: Title :param filetypes: valid file types :return: filepath selected

Expand source code
@classmethod
def show_save_picker(cls, title=None, filetypes=None, **options):
    """
    Helper method for a save picker dialog
    :param title: Title
    :param filetypes: valid file types
    :return: filepath selected
    """
    return asksaveasfilename(title=title, filetypes=filetypes, **options)
def show_warning(title, message, **options)

Helper method for showing an warning dialog Calls tkinter.messagebox.showwarning :param title: Title :param message: Message :param options: Options :return: None

Expand source code
@classmethod
def show_warning(cls, title, message, **options):
    """
    Helper method for showing an warning dialog
    Calls tkinter.messagebox.showwarning
    :param title: Title
    :param message: Message
    :param options: Options
    :return: None
    """
    messagebox.showwarning(title=title, message=message, **options)