Renamed Signals to Controller; Moved show/hides to mixin file

This commit is contained in:
itdominator 2021-11-27 18:54:33 -06:00
parent a25b500773
commit 489288204c
6 changed files with 81 additions and 69 deletions

View File

@ -5,7 +5,7 @@ import os, inspect, time
# Application imports
from utils import Settings
from signal_classes import Signals
from signal_classes import Controller
from __builtins__ import Builtins
@ -30,13 +30,13 @@ class Main(Builtins):
settings = Settings()
settings.createWindow()
signals = Signals(args, unknownargs, settings)
if not signals:
raise Exception("Signals exited...")
controller = Controller(args, unknownargs, settings)
if not controller:
raise Exception("Controller exited and doesn't exist...")
# Gets the methods from the classes and sets to handler.
# Then, builder connects to any signals it needs.
classes = [signals]
classes = [controller]
handlers = {}
for c in classes:
methods = None

View File

@ -388,6 +388,7 @@ PyFM is developed on Atom, git, and using Python 3+ with Gtk GObject introspecti
<property name="window-position">mouse</property>
<property name="type-hint">splashscreen</property>
<property name="gravity">south</property>
<signal name="focus-out-event" handler="hide_appchooser_menu" swapped="no"/>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can-focus">False</property>

View File

@ -4,15 +4,13 @@ import threading, subprocess, signal, inspect, os, time
# Gtk imports
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GLib
# Application imports
from .mixins import *
from shellfm import WindowController
from . import KeyboardSignalsMixin
from . import ShowHideMixin, KeyboardSignalsMixin
def threaded(fn):
@ -21,7 +19,7 @@ def threaded(fn):
return wrapper
class Signals(KeyboardSignalsMixin, WidgetFileActionMixin, PaneMixin, WindowMixin):
class Controller(ShowHideMixin, KeyboardSignalsMixin, WidgetFileActionMixin, PaneMixin, WindowMixin):
def __init__(self, args, unknownargs, settings):
self.settings = settings
self.builder = self.settings.builder
@ -95,15 +93,7 @@ class Signals(KeyboardSignalsMixin, WidgetFileActionMixin, PaneMixin, WindowMixi
return callable(getattr(o, name, None))
def refresh_tab(data=None):
self, ids = data
wid, tid = ids.split("|")
notebook = self.builder.get_object(f"window_{wid}")
store, tab_label = self.get_store_and_label_from_notebook(notebook, f"{wid}|{tid}")
view = self.get_fm_window(wid).get_view_by_id(tid)
view.load_directory()
self.load_store(view, store)
def do_edit_files(self, widget=None, eve=None):
self.to_rename_files = self.selected_files
@ -147,57 +137,6 @@ class Signals(KeyboardSignalsMixin, WidgetFileActionMixin, PaneMixin, WindowMixi
self.ctrlDown = False
def show_about_page(self, widget, eve):
about_page = self.builder.get_object("about_page")
response = about_page.run()
if response == -4:
self.hide_about_page()
def hide_about_page(self, widget=None, eve=None):
about_page = self.builder.get_object("about_page").hide()
def show_appchooser_menu(self, widget=None, eve=None):
appchooser_menu = self.builder.get_object("appchooser_menu")
appchooser_widget = self.builder.get_object("appchooser_widget")
resp = appchooser_menu.run()
if resp == Gtk.ResponseType.CANCEL:
self.hide_appchooser_menu()
if resp == Gtk.ResponseType.OK:
self.open_with_files(appchooser_widget)
self.hide_appchooser_menu()
def hide_appchooser_menu(self, widget=None, eve=None):
self.builder.get_object("appchooser_menu").hide()
def run_appchooser_launch(self, widget=None, eve=None):
self.builder.get_object("appchooser_select_btn").pressed()
def show_context_menu(self, widget=None, eve=None):
self.builder.get_object("context_menu").run()
def hide_context_menu(self, widget=None, eve=None):
self.builder.get_object("context_menu").hide()
def show_new_file_menu(self, widget=None, eve=None):
self.builder.get_object("new_file_menu").run()
def hide_new_file_menu(self, widget=None, eve=None):
self.builder.get_object("new_file_menu").hide()
def show_edit_file_menu(self, widget=None, eve=None):
self.builder.get_object("edit_file_menu").run()
def hide_edit_file_menu(self, widget=None, eve=None):
self.builder.get_object("edit_file_menu").hide()
def hide_edit_file_menu_skip(self, widget=None, eve=None):
self.skip_edit = True
self.builder.get_object("edit_file_menu").hide()
def hide_edit_file_menu_cancel(self, widget=None, eve=None):
self.cancel_edit = True
self.builder.get_object("edit_file_menu").hide()
def generate_windows(self, data = None):

View File

@ -0,0 +1,62 @@
# Python imports
# Gtk imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
class ShowHideMixin:
def show_about_page(self, widget, eve):
about_page = self.builder.get_object("about_page")
response = about_page.run()
if response == -4:
self.hide_about_page()
def hide_about_page(self, widget=None, eve=None):
about_page = self.builder.get_object("about_page").hide()
def show_appchooser_menu(self, widget=None, eve=None):
appchooser_menu = self.builder.get_object("appchooser_menu")
appchooser_widget = self.builder.get_object("appchooser_widget")
resp = appchooser_menu.run()
if resp == Gtk.ResponseType.CANCEL:
self.hide_appchooser_menu()
if resp == Gtk.ResponseType.OK:
self.open_with_files(appchooser_widget)
self.hide_appchooser_menu()
def hide_appchooser_menu(self, widget=None, eve=None):
self.builder.get_object("appchooser_menu").hide()
def run_appchooser_launch(self, widget=None, eve=None):
self.builder.get_object("appchooser_select_btn").pressed()
def show_context_menu(self, widget=None, eve=None):
self.builder.get_object("context_menu").run()
def hide_context_menu(self, widget=None, eve=None):
self.builder.get_object("context_menu").hide()
def show_new_file_menu(self, widget=None, eve=None):
self.builder.get_object("new_file_menu").run()
def hide_new_file_menu(self, widget=None, eve=None):
self.builder.get_object("new_file_menu").hide()
def show_edit_file_menu(self, widget=None, eve=None):
self.builder.get_object("edit_file_menu").run()
def hide_edit_file_menu(self, widget=None, eve=None):
self.builder.get_object("edit_file_menu").hide()
def hide_edit_file_menu_skip(self, widget=None, eve=None):
self.skip_edit = True
self.builder.get_object("edit_file_menu").hide()
def hide_edit_file_menu_cancel(self, widget=None, eve=None):
self.cancel_edit = True
self.builder.get_object("edit_file_menu").hide()

View File

@ -4,4 +4,5 @@
from .mixins import *
from .DBusControllerMixin import DBusControllerMixin
from .KeyboardSignalsMixin import KeyboardSignalsMixin
from .Signals import Signals
from .ShowHideMixin import ShowHideMixin
from .Controller import Controller

View File

@ -105,6 +105,15 @@ class TabMixin(WidgetMixin):
def get_tab_iconview_from_notebook(self, notebook):
return notebook.get_children()[1].get_children()[0]
def refresh_tab(data=None):
self, ids = data
wid, tid = ids.split("|")
notebook = self.builder.get_object(f"window_{wid}")
store, tab_label = self.get_store_and_label_from_notebook(notebook, f"{wid}|{tid}")
view = self.get_fm_window(wid).get_view_by_id(tid)
view.load_directory()
self.load_store(view, store)
def do_action_from_bar_controls(self, widget, eve=None):
action = widget.get_name()