Cleaning up message widgets

This commit is contained in:
itdominator 2023-03-04 23:13:17 -06:00
parent 3c72ad2801
commit 66cfe8caec
9 changed files with 52 additions and 43 deletions

View File

@ -17,7 +17,6 @@ from .widgets.dialogs.about_widget import AboutWidget
from .widgets.dialogs.appchooser_widget import AppchooserWidget from .widgets.dialogs.appchooser_widget import AppchooserWidget
from .widgets.dialogs.file_exists_widget import FileExistsWidget from .widgets.dialogs.file_exists_widget import FileExistsWidget
from .widgets.dialogs.new_file_widget import NewFileWidget from .widgets.dialogs.new_file_widget import NewFileWidget
from .widgets.dialogs.message_widget import MessageWidget
from .widgets.dialogs.rename_widget import RenameWidget from .widgets.dialogs.rename_widget import RenameWidget
from .widgets.dialogs.save_load_widget import SaveLoadWidget from .widgets.dialogs.save_load_widget import SaveLoadWidget
@ -92,6 +91,7 @@ class Controller(UIMixin, SignalsMixins, Controller_Data):
# after we're done cleaning and refactoring to use fewer mixins. # after we're done cleaning and refactoring to use fewer mixins.
def _load_widgets(self): def _load_widgets(self):
BottomStatusInfoWidget() BottomStatusInfoWidget()
IOPopupWidget() IOPopupWidget()
MessagePopupWidget() MessagePopupWidget()
PathMenuPopupWidget() PathMenuPopupWidget()
@ -104,7 +104,6 @@ class Controller(UIMixin, SignalsMixins, Controller_Data):
RenameWidget() RenameWidget()
FileExistsWidget() FileExistsWidget()
SaveLoadWidget() SaveLoadWidget()
self.message_dialog = MessageWidget()
def reload_plugins(self, widget=None, eve=None): def reload_plugins(self, widget=None, eve=None):
@ -187,4 +186,4 @@ class Controller(UIMixin, SignalsMixins, Controller_Data):
tab.execute([f"{tab.terminal_app}"], start_dir=tab.get_current_directory()) tab.execute([f"{tab.terminal_app}"], start_dir=tab.get_current_directory())
def go_to_path(self, path: str): def go_to_path(self, path: str):
self.path_entry.set_text(path) self.builder.get_object("path_entry").set_text(path)

View File

@ -1,5 +1,4 @@
# Python imports # Python imports
import sys
import os import os
import subprocess import subprocess
from dataclasses import dataclass from dataclasses import dataclass
@ -10,12 +9,13 @@ gi.require_version('Gtk', '3.0')
from gi.repository import Gtk from gi.repository import Gtk
# Application imports # Application imports
from .widgets.dialogs.message_widget import MessageWidget
from shellfm.windows.controller import WindowController from shellfm.windows.controller import WindowController
from plugins.plugins_controller import PluginsController from plugins.plugins_controller import PluginsController
@dataclass(slots=True) @dataclass(slots=True)
class State: class State:
fm_controller: any = None fm_controller: any = None
@ -52,11 +52,6 @@ class Controller_Data:
self.window3 = self.builder.get_object("window_3") self.window3 = self.builder.get_object("window_3")
self.window4 = self.builder.get_object("window_4") self.window4 = self.builder.get_object("window_4")
self.path_entry = self.builder.get_object("path_entry")
# self.bottom_size_label = self.builder.get_object("bottom_size_label")
# self.bottom_file_count_label = self.builder.get_object("bottom_file_count_label")
# self.bottom_path_label = self.builder.get_object("bottom_path_label")
self.notebooks = [self.window1, self.window2, self.window3, self.window4] self.notebooks = [self.window1, self.window2, self.window3, self.window4]
self.selected_files = [] self.selected_files = []
self.to_copy_files = [] self.to_copy_files = []
@ -75,19 +70,6 @@ class Controller_Data:
self.shift_down = False self.shift_down = False
self.alt_down = False self.alt_down = False
# sys.excepthook = self.custom_except_hook
if settings.is_debug():
self.window.set_interactive_debugging(True)
def custom_except_hook(self, exc_type, exc_value, exc_traceback):
if issubclass(exc_type, KeyboardInterrupt):
sys.__excepthook__(exc_type, exc_value, exc_traceback)
return
logger.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
def get_current_state(self) -> State: def get_current_state(self) -> State:
''' '''
@ -106,7 +88,7 @@ class Controller_Data:
state.tab = self.get_fm_window(state.wid).get_tab_by_id(state.tid) state.tab = self.get_fm_window(state.wid).get_tab_by_id(state.tid)
state.icon_grid = self.builder.get_object(f"{state.wid}|{state.tid}|icon_grid") state.icon_grid = self.builder.get_object(f"{state.wid}|{state.tid}|icon_grid")
state.store = state.icon_grid.get_model() state.store = state.icon_grid.get_model()
state.message_dialog = self.message_dialog state.message_dialog = MessageWidget()
selected_files = state.icon_grid.get_selected_items() selected_files = state.icon_grid.get_selected_items()
if selected_files: if selected_files:

View File

@ -15,6 +15,7 @@ class FileSystemActions(HandlerMixin, CRUDMixin):
def __init__(self): def __init__(self):
super(FileSystemActions, self).__init__() super(FileSystemActions, self).__init__()
self._setup_styling() self._setup_styling()
self._setup_signals() self._setup_signals()
self._subscribe_to_events() self._subscribe_to_events()

View File

@ -12,6 +12,9 @@ from gi.repository import Gio
from ..widgets.io_widget import IOWidget from ..widgets.io_widget import IOWidget
class HandlerMixinException(Exception):
...
class HandlerMixin: class HandlerMixin:
@ -35,7 +38,7 @@ class HandlerMixin:
file = Gio.File.new_for_path(path) file = Gio.File.new_for_path(path)
if _target_path: if _target_path:
if file.get_parent().get_path() == _target_path: if file.get_parent().get_path() == _target_path:
raise Exception("Parent dir of target and file locations are the same! Won't copy or move!") raise HandlerMixinException("Parent dir of target and file locations are the same! Won't copy or move!")
if os.path.isdir(_target_path): if os.path.isdir(_target_path):
info = file.query_info("standard::display-name", 0, cancellable=None) info = file.query_info("standard::display-name", 0, cancellable=None)
@ -153,7 +156,7 @@ class HandlerMixin:
value = file_name[(file_name.find(start)+len(start)):] value = file_name[(file_name.find(start)+len(start)):]
int(value) int(value)
file_name = file_name.split(start)[0] file_name = file_name.split(start)[0]
except Exception as e: except HandlerMixinException as e:
pass pass
target = Gio.File.new_for_path(f"{base_path}/{file_name}-copy{i}{extension}") target = Gio.File.new_for_path(f"{base_path}/{file_name}-copy{i}{extension}")

View File

@ -45,16 +45,14 @@ class PaneMixin:
state = self.run_flag_toggle(pane_index) state = self.run_flag_toggle(pane_index)
if self.is_pane1_hidden and self.is_pane2_hidden and self.is_pane3_hidden and self.is_pane4_hidden: if self.is_pane1_hidden and self.is_pane2_hidden and self.is_pane3_hidden and self.is_pane4_hidden:
state = self.run_flag_toggle(pane_index) state = self.run_flag_toggle(pane_index)
self._save_state(state, pane_index) self._set_fm_state(state, pane_index)
return return
child = pane.get_child1() if pane_index in [1, 3] else pane.get_child2() child = pane.get_child1() if pane_index in [1, 3] else pane.get_child2()
self.toggle_pane(child) self.toggle_pane(child)
self._save_state(state, pane_index) self._set_fm_state(state, pane_index)
def _save_state(self, state, pane_index): def _set_fm_state(self, state, pane_index):
window = self.fm_controller.get_window_by_index(pane_index - 1) window = self.fm_controller.get_window_by_index(pane_index - 1)
window.set_is_hidden(state) window.set_is_hidden(state)
if not settings.is_trace_debug():
self.fm_controller.save_state()

View File

@ -18,6 +18,7 @@ class MessageWidget(Gtk.MessageDialog):
self._setup_styling() self._setup_styling()
self._setup_signals() self._setup_signals()
self._subscribe_to_events()
self._load_widgets() self._load_widgets()
@ -27,6 +28,9 @@ class MessageWidget(Gtk.MessageDialog):
def _setup_signals(self): def _setup_signals(self):
... ...
def _subscribe_to_events(self):
...
def _load_widgets(self): def _load_widgets(self):
message_area = self.get_message_area() message_area = self.get_message_area()
message_area.get_children()[0].set_label("Alert!") message_area.get_children()[0].set_label("Alert!")

View File

@ -9,6 +9,9 @@ from gi.repository import Gtk
# Application imports # Application imports
class SaveLoadWidgetException(Exception):
...
class SaveLoadWidget: class SaveLoadWidget:
@ -52,7 +55,7 @@ class SaveLoadWidget:
elif action == "load_session": elif action == "load_session":
self.save_load_dialog.set_action(Gtk.FileChooserAction.OPEN) self.save_load_dialog.set_action(Gtk.FileChooserAction.OPEN)
else: else:
raise Exception(f"Unknown action given: {action}") raise SaveLoadWidgetException(f"Unknown action given: {action}")
self.save_load_dialog.set_current_folder(state.tab.get_current_directory()) self.save_load_dialog.set_current_folder(state.tab.get_current_directory())
self.save_load_dialog.set_current_name("session.json") self.save_load_dialog.set_current_name("session.json")

View File

@ -1,7 +1,9 @@
# Python imports # Python imports
import datetime
import inspect import inspect
import traceback import sys
import time import time
import traceback
# Lib imports # Lib imports
import gi import gi
@ -26,6 +28,8 @@ class MessagePopupWidget(Gtk.Popover):
self._message_buffer = None self._message_buffer = None
sys.excepthook = self.custom_except_hook
self._setup_styling() self._setup_styling()
self._setup_signals() self._setup_signals()
self._load_widgets() self._load_widgets()
@ -35,7 +39,8 @@ class MessagePopupWidget(Gtk.Popover):
self.set_relative_to( self.builder.get_object(f"main_menu_bar") ) self.set_relative_to( self.builder.get_object(f"main_menu_bar") )
self.set_modal(True) self.set_modal(True)
self.set_position(Gtk.PositionType.BOTTOM) self.set_position(Gtk.PositionType.BOTTOM)
self.set_size_request(620, 580) self.set_hexpand(True)
self.set_vexpand(True)
def _setup_signals(self): def _setup_signals(self):
event_system.subscribe("show_messages_popup", self.show_messages_popup) event_system.subscribe("show_messages_popup", self.show_messages_popup)
@ -52,8 +57,6 @@ class MessagePopupWidget(Gtk.Popover):
button.connect("released", self.save_debug_alerts) button.connect("released", self.save_debug_alerts)
button.set_always_show_image(True) button.set_always_show_image(True)
vbox.set_vexpand(True)
vbox.set_hexpand(True)
scroll_window.set_vexpand(True) scroll_window.set_vexpand(True)
scroll_window.set_hexpand(True) scroll_window.set_hexpand(True)
vbox.set_orientation(Gtk.Orientation.VERTICAL) vbox.set_orientation(Gtk.Orientation.VERTICAL)
@ -61,9 +64,10 @@ class MessagePopupWidget(Gtk.Popover):
self.builder.expose_object(f"message_popup_widget", self) self.builder.expose_object(f"message_popup_widget", self)
self.builder.expose_object(f"message_text_view", message_text_view) self.builder.expose_object(f"message_text_view", message_text_view)
vbox.add(button)
scroll_window.add(message_text_view) scroll_window.add(message_text_view)
vbox.add(button)
vbox.add(scroll_window) vbox.add(scroll_window)
vbox.show_all()
self.add(vbox) self.add(vbox)
@ -73,18 +77,30 @@ class MessagePopupWidget(Gtk.Popover):
def hide_messages_popup(self): def hide_messages_popup(self):
self.popup() self.popup()
def custom_except_hook(self, exc_type, exc_value, exc_traceback):
if issubclass(exc_type, KeyboardInterrupt):
sys.__excepthook__(exc_type, exc_value, exc_traceback)
return
logger.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
self._exception_to_ui(exc_type, exc_value, exc_traceback)
def _exception_to_ui(self, exc_type, exc_value, exc_traceback):
trace = ''.join(traceback.format_tb(exc_traceback))
current_time = datetime.datetime.now()
data = f"{current_time}\nExec Type: {exc_type} <--> Value: {exc_value}\n\n{trace}\n\n"
def custom_except_hook(self, exec_type, value, _traceback):
trace = ''.join(traceback.format_tb(_traceback))
data = f"Exec Type: {exec_type} <--> Value: {value}\n\n{trace}\n\n\n\n"
start_itr = self._message_buffer.get_start_iter()
self._message_buffer.place_cursor(start_itr)
self.display_message(settings.get_error_color(), data) self.display_message(settings.get_error_color(), data)
def display_message(self, type, text, seconds=None): def display_message(self, type, text, seconds=None):
# start_itr = self._message_buffer.get_start_iter()
start_itr = self._message_buffer.get_iter_at_line(0)
self._message_buffer.place_cursor(start_itr)
self._message_buffer.insert_at_cursor(text) self._message_buffer.insert_at_cursor(text)
self.popup()
if seconds: if seconds:
self.popup()
self.hide_message_timeout(seconds) self.hide_message_timeout(seconds)
@threaded @threaded

View File

@ -52,6 +52,9 @@ class Window(Gtk.ApplicationWindow):
event_system.subscribe("tear_down", self._tear_down) event_system.subscribe("tear_down", self._tear_down)
def _load_widgets(self, args, unknownargs): def _load_widgets(self, args, unknownargs):
if settings.is_debug():
self.set_interactive_debugging(True)
self._controller = Controller(args, unknownargs) self._controller = Controller(args, unknownargs)
if not self._controller: if not self._controller: