Skip to content

Commit

Permalink
[002_private_public_attributes], issue #2, Cleaned the icon setup and…
Browse files Browse the repository at this point in the history
… added traceback support
  • Loading branch information
lelaus committed Sep 10, 2024
1 parent 865337d commit b0b3206
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
38 changes: 25 additions & 13 deletions tugui/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import tkinter as tk
import os
import re
import sys
import traceback

from tkinter import PhotoImage, ttk
from tkinter import filedialog
Expand All @@ -13,7 +15,7 @@
from tu_interface import DatGenerator, InpHandler, MicReader, PliReader, StaReader, TuInp, MacReader
from gui_configuration import GuiPlotFieldsConfigurator
from gui_widgets import CustomNotebook, EntryVariable, StatusBar, provide_label_image
from support import IANT, ERROR_LEVEL, OS_PLATFORM, SUPPORTED_OS_PLATFORMS
from support import IANT, ERROR_LEVEL, OS_PLATFORM, SUPPORTED_OS_PLATFORMS, ICON_PATH
from shutil import copyfile
from typing import Union

Expand All @@ -34,10 +36,7 @@ class TuPostProcessingGui(ThemedTk):
"""
def __init__(self, window_title: str, width: int, height: int) -> None:
# Check whether the OS platform is supported
if OS_PLATFORM not in SUPPORTED_OS_PLATFORMS:
error_message = f"The {OS_PLATFORM} OS is not yet supported!"
messagebox.showerror("Error", error_message)
raise RuntimeError(error_message)
self.__check_OS_platform()

# Call the superclass constructor
super().__init__()
Expand All @@ -49,13 +48,7 @@ def __init__(self, window_title: str, width: int, height: int) -> None:
self.__set_working_dir()

# Set the titlebar icon
if OS_PLATFORM == "Linux":
self.iconphoto(False, PhotoImage(file = os.path.join(
os.getcwd(),"../resources/icons/tuoutgui.gif")))
else:
# FIXME: to add the file "tuoutgui.ico" in the right location
self.iconphoto(True, PhotoImage(file = os.path.join(
os.getcwd(), "../resources/icons/tuoutgui.ico")))
self.__set_icon()

# Instantiate and configure the 'GuiPlotFieldsConfigurator' class in a try-except
try:
Expand Down Expand Up @@ -165,6 +158,16 @@ def __init__(self, window_title: str, width: int, height: int) -> None:
# Bind the <<DatPltLoaded>> virtual event to the plot creation
self.bind('<<DatPltLoaded>>', func=lambda event: self.display_plot())

def __check_OS_platform(self) -> None:
"""
Method that checks whether the OS platform is supported:
for the time being, only Windows and Linux OSs are supported.
"""
if OS_PLATFORM not in SUPPORTED_OS_PLATFORMS:
error_message = f"The {OS_PLATFORM} OS is not yet supported!"
messagebox.showerror("Error", error_message)
raise RuntimeError(error_message)

def __initialize_gui_window(self, title: str, width: int, height: int) -> None:
"""
Method that sets the GUI window title, as well as its dimensions, in terms
Expand All @@ -181,6 +184,15 @@ def __initialize_gui_window(self, title: str, width: int, height: int) -> None:
# Set the window geometry
self.geometry(f"{width}x{height}+{left}+{top}")

def __set_icon(self) -> None:
"""
Set the titlebar icon
"""
try:
self.iconphoto(False,
PhotoImage(file = os.path.join(os.getcwd(), ICON_PATH)))
except Exception:
raise

def __set_working_dir(self) -> None:
"""
Expand Down Expand Up @@ -1012,6 +1024,6 @@ def new_postprocessing(event: Union[tk.Event, None] = None) -> None:
try:
new_postprocessing()
except Exception as e:
print(e)
traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr)
# If any exception is caught, exit
exit()
10 changes: 9 additions & 1 deletion tugui/support.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import platform
from enum import Enum
from typing import List, Tuple
from typing import List, Tuple, Union

# Flag defining the level of error management
ERROR_LEVEL: bool = 0
Expand All @@ -11,6 +11,14 @@
# Variable storing the OS platform tugui is running on
OS_PLATFORM: str = platform.system()

# Variable storing the relative path of the icon file
ICON_PATH: Union[str, None] = None
if OS_PLATFORM == "Linux":
ICON_PATH = "../resources/icons/tuoutgui.gif"
elif OS_PLATFORM == "Windows":
# FIXME: to add the file "tuoutgui.ico" in the right location
ICON_PATH = "../resources/icons/tuoutgui.ico"

class IDGA(Enum):
"""
Enumeration storing the different types of plots (field "Type").
Expand Down

0 comments on commit b0b3206

Please sign in to comment.