Moved rename functionality to class a new glade file

This commit is contained in:
itdominator 2022-12-03 17:00:54 -06:00
parent d91266886f
commit ba0cf50ad5
9 changed files with 348 additions and 282 deletions

View File

@ -13,7 +13,6 @@ from gi.repository import GLib
from .controller_data import Controller_Data
from .mixins.signals_mixins import SignalsMixins
from .ui import UI
from widgets.context_menu_widget import ContextMenuWidget
@ -25,8 +24,6 @@ class Controller(UI, SignalsMixins, Controller_Data):
self.setup_controller_data()
self.generate_windows(self.fm_controller_data)
ContextMenuWidget().build_context_menu()
if args.no_plugins == "false":
self.plugins.launch_plugins()
@ -109,7 +106,7 @@ class Controller(UI, SignalsMixins, Controller_Data):
self.hide_context_menu()
self.hide_new_file_menu()
self.hide_edit_file_menu()
event_system.emit("do_hide_edit_file_menu")
if action == "open":
self.open_files()
@ -135,23 +132,6 @@ class Controller(UI, SignalsMixins, Controller_Data):
self.save_load_session(action)
def set_to_title_case(self, widget, eve=None):
rename_widget = self.builder.get_object("new_rename_fname")
rename_widget.set_text( rename_widget.get_text().title() )
def set_to_upper_case(self, widget, eve=None):
rename_widget = self.builder.get_object("new_rename_fname")
rename_widget.set_text( rename_widget.get_text().upper() )
def set_to_lower_case(self, widget, eve=None):
rename_widget = self.builder.get_object("new_rename_fname")
rename_widget.set_text( rename_widget.get_text().lower() )
def set_to_invert_case(self, widget, eve=None):
rename_widget = self.builder.get_object("new_rename_fname")
rename_widget.set_text( rename_widget.get_text().swapcase() )
@endpoint_registry.register(rule="go_home")
def go_home(self, widget=None, eve=None):
self.builder.get_object("go_home").released()

View File

@ -12,6 +12,8 @@ from gi.repository import Gtk
from gi.repository import GLib
# Application imports
from widgets.context_menu_widget import ContextMenuWidget
from widgets.rename_widget import RenameWidget
from shellfm.windows.controller import WindowController
from plugins.plugins_controller import PluginsController
@ -37,6 +39,9 @@ class Controller_Data:
self.builder = settings.get_builder()
self.keybindings = settings.get_keybindings()
RenameWidget()
ContextMenuWidget()
self.fm_controller = WindowController()
self.plugins = PluginsController()
self.fm_controller_data = self.fm_controller.get_state_from_file()

View File

@ -119,14 +119,6 @@ class ShowHideMixin:
def show_io_popup(self, widget=None, eve=None):
self.builder.get_object("io_popup").popup()
def hide_edit_file_menu(self, widget=None, eve=None):
self.builder.get_object("edit_file_menu").hide()
def hide_edit_file_menu_enter_key(self, widget=None, eve=None):
keyname = Gdk.keyval_name(eve.keyval).lower()
if keyname in ["return", "enter"]:
self.builder.get_object("edit_file_menu").hide()
def hide_edit_file_menu_skip(self, widget=None, eve=None):
self.edit_file_menu.response(Gtk.ResponseType.CLOSE)

View File

@ -179,7 +179,7 @@ class FileActionSignalsMixin:
self.skip_edit = False
self.cancel_edit = False
self.hide_edit_file_menu()
event_system.emit("do_hide_edit_file_menu")
self.selected_files.clear()
def cut_files(self):

View File

@ -19,20 +19,21 @@ from .keybindings import Keybindings
class Settings:
def __init__(self):
self._SCRIPT_PTH = os.path.dirname(os.path.realpath(__file__))
self._USER_HOME = path.expanduser('~')
self._CONFIG_PATH = f"{self._USER_HOME}/.config/{app_name.lower()}"
self._PLUGINS_PATH = f"{self._CONFIG_PATH}/plugins"
self._USR_SOLARFM = f"/usr/share/{app_name.lower()}"
self._SCRIPT_PTH = os.path.dirname(os.path.realpath(__file__))
self._USER_HOME = path.expanduser('~')
self._CONFIG_PATH = f"{self._USER_HOME}/.config/{app_name.lower()}"
self._UI_WIDEGTS_PATH = f"{self._CONFIG_PATH}/ui_widgets"
self._PLUGINS_PATH = f"{self._CONFIG_PATH}/plugins"
self._USR_SOLARFM = f"/usr/share/{app_name.lower()}"
self._CSS_FILE = f"{self._CONFIG_PATH}/stylesheet.css"
self._GLADE_FILE = f"{self._CONFIG_PATH}/Main_Window.glade"
self._KEY_BINDINGS = f"{self._CONFIG_PATH}/key-bindings.json"
self._DEFAULT_ICONS = f"{self._CONFIG_PATH}/icons"
self._WINDOW_ICON = f"{self._DEFAULT_ICONS}/{app_name.lower()}.png"
self._CONTEXT_MENU = f"{self._CONFIG_PATH}/contexct_menu.json"
self._PID_FILE = f"{self._CONFIG_PATH}/{app_name.lower()}.pid"
self._ICON_THEME = Gtk.IconTheme.get_default()
self._CSS_FILE = f"{self._CONFIG_PATH}/stylesheet.css"
self._GLADE_FILE = f"{self._CONFIG_PATH}/Main_Window.glade"
self._KEY_BINDINGS = f"{self._CONFIG_PATH}/key-bindings.json"
self._DEFAULT_ICONS = f"{self._CONFIG_PATH}/icons"
self._WINDOW_ICON = f"{self._DEFAULT_ICONS}/{app_name.lower()}.png"
self._CONTEXT_MENU = f"{self._CONFIG_PATH}/contexct_menu.json"
self._PID_FILE = f"{self._CONFIG_PATH}/{app_name.lower()}.pid"
self._ICON_THEME = Gtk.IconTheme.get_default()
if not os.path.exists(self._CONFIG_PATH):
os.mkdir(self._CONFIG_PATH)
@ -149,8 +150,9 @@ class Settings:
def get_context_menu_data(self) -> Gtk.Builder: return self._context_menu_data
def get_main_window(self) -> Gtk.ApplicationWindow: return self._main_window
def get_builder(self) -> Gtk.Builder: return self._builder
def get_main_window(self) -> Gtk.ApplicationWindow: return self._main_window
def get_builder(self) -> Gtk.Builder: return self._builder
def get_ui_widgets_path(self) -> Gtk.Builder: return self._UI_WIDEGTS_PATH
def get_logger(self) -> Logger: return self._logger
def get_keybindings(self) -> Keybindings: return self._keybindings
def get_plugins_path(self) -> str: return self._PLUGINS_PATH

View File

@ -18,6 +18,8 @@ class ContextMenuWidget(Gtk.Menu):
self._context_menu_data = settings.get_context_menu_data()
self._window = settings.get_main_window()
self.build_context_menu()
def make_submenu(self, name, data, keys):
menu = Gtk.Menu()

View File

@ -0,0 +1,81 @@
# Python imports
# Lib imports
import inspect
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
# Application imports
class RenameWidget:
"""docstring for RenameWidget."""
def __init__(self):
super(RenameWidget, self).__init__()
_GLADE_FILE = f"{settings.get_ui_widgets_path()}/rename_ui.glade"
builder = settings.get_builder()
self._builder = Gtk.Builder()
self._builder.add_from_file(_GLADE_FILE)
edit_file_menu = self._builder.get_object("edit_file_menu")
new_rename_fname = self._builder.get_object("new_rename_fname")
file_to_rename_label = self._builder.get_object("file_to_rename_label")
builder.expose_object(f"edit_file_menu", edit_file_menu)
builder.expose_object(f"new_rename_fname", new_rename_fname)
builder.expose_object(f"file_to_rename_label", file_to_rename_label)
self._setup_styling()
self._setup_signals()
self._load_widgets()
def _setup_styling(self):
...
def _setup_signals(self):
event_system.subscribe("do_hide_edit_file_menu", self.hide_edit_file_menu)
classes = [self]
handlers = {}
for c in classes:
methods = None
try:
methods = inspect.getmembers(c, predicate=inspect.ismethod)
handlers.update(methods)
except Exception as e:
print(repr(e))
self._builder.connect_signals(handlers)
def _load_widgets(self):
...
def set_to_title_case(self, widget, eve=None):
rename_widget = self._builder.get_object("new_rename_fname")
rename_widget.set_text( rename_widget.get_text().title() )
def set_to_upper_case(self, widget, eve=None):
rename_widget = self._builder.get_object("new_rename_fname")
rename_widget.set_text( rename_widget.get_text().upper() )
def set_to_lower_case(self, widget, eve=None):
rename_widget = self._builder.get_object("new_rename_fname")
rename_widget.set_text( rename_widget.get_text().lower() )
def set_to_invert_case(self, widget, eve=None):
rename_widget = self._builder.get_object("new_rename_fname")
rename_widget.set_text( rename_widget.get_text().swapcase() )
def hide_edit_file_menu(self, widget=None, eve=None):
self._builder.get_object("edit_file_menu").hide()
def hide_edit_file_menu_enter_key(self, widget=None, eve=None):
keyname = Gdk.keyval_name(eve.keyval).lower()
if keyname in ["return", "enter"]:
self._builder.get_object("edit_file_menu").hide()

View File

@ -488,12 +488,6 @@ SolarFM is developed on Atom, git, and using Python 3+ with Gtk GObject introspe
<property name="stock">gtk-stop</property>
</object>
<object class="GtkTextBuffer" id="message_buffer"/>
<object class="GtkImage" id="rename_img">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="stock">gtk-edit</property>
<property name="icon_size">3</property>
</object>
<object class="GtkFileChooserDialog" id="save_load_dialog">
<property name="can-focus">False</property>
<property name="type-hint">dialog</property>
@ -554,11 +548,6 @@ SolarFM is developed on Atom, git, and using Python 3+ with Gtk GObject introspe
<action-widget response="-5">button12</action-widget>
</action-widgets>
</object>
<object class="GtkImage" id="skip_img">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="stock">gtk-media-forward</property>
</object>
<object class="GtkImage" id="tggl_notebook_1_img">
<property name="visible">True</property>
<property name="can-focus">False</property>
@ -1363,232 +1352,6 @@ SolarFM is developed on Atom, git, and using Python 3+ with Gtk GObject introspe
</object>
</child>
</object>
<object class="GtkDialog" id="edit_file_menu">
<property name="can-focus">False</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="window-position">center-always</property>
<property name="destroy-with-parent">True</property>
<property name="type-hint">dialog</property>
<property name="skip-taskbar-hint">True</property>
<property name="skip-pager-hint">True</property>
<property name="decorated">False</property>
<property name="deletable">False</property>
<property name="gravity">center</property>
<property name="attached-to">main_window</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="margin-left">5</property>
<property name="margin-right">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="layout-style">end</property>
<child>
<object class="GtkButton" id="button2">
<property name="label">gtk-cancel</property>
<property name="name">cancel_renames</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-stock">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">Skip</property>
<property name="name">skip_renames</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">skip_img</property>
<property name="always-show-image">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Rename:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="file_to_rename_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="new_rename_fname">
<property name="width-request">500</property>
<property name="height-request">26</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="has-focus">True</property>
<property name="tooltip-text" translatable="yes">Rename To:</property>
<property name="activates-default">True</property>
<property name="primary-icon-stock">gtk-edit</property>
<property name="primary-icon-activatable">False</property>
<property name="secondary-icon-activatable">False</property>
<property name="primary-icon-sensitive">False</property>
<property name="secondary-icon-sensitive">False</property>
<property name="placeholder-text" translatable="yes">To:</property>
<signal name="key-release-event" handler="hide_edit_file_menu_enter_key" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButtonBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="homogeneous">True</property>
<property name="layout-style">expand</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Title Case</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="released" handler="set_to_title_case" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Upper Case</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="released" handler="set_to_upper_case" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Lower Case</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="released" handler="set_to_lower_case" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Invert Case</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="released" handler="set_to_invert_case" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Rename</property>
<property name="name">rename</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">rename_img</property>
<property name="always-show-image">True</property>
<signal name="button-release-event" handler="hide_edit_file_menu" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-6">button2</action-widget>
<action-widget response="-7">button1</action-widget>
</action-widgets>
</object>
<object class="GtkDialog" id="file_exists_dialog">
<property name="height-request">120</property>
<property name="can-focus">False</property>

View File

@ -0,0 +1,241 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<object class="GtkImage" id="rename_img">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="stock">gtk-edit</property>
<property name="icon_size">3</property>
</object>
<object class="GtkImage" id="skip_img">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="stock">gtk-media-forward</property>
</object>
<object class="GtkDialog" id="edit_file_menu">
<property name="can-focus">False</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="window-position">center-always</property>
<property name="destroy-with-parent">True</property>
<property name="type-hint">dialog</property>
<property name="skip-taskbar-hint">True</property>
<property name="skip-pager-hint">True</property>
<property name="decorated">False</property>
<property name="deletable">False</property>
<property name="gravity">center</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="margin-left">5</property>
<property name="margin-right">5</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="layout-style">end</property>
<child>
<object class="GtkButton" id="button2">
<property name="label">gtk-cancel</property>
<property name="name">cancel_renames</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-stock">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">Skip</property>
<property name="name">skip_renames</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">skip_img</property>
<property name="always-show-image">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Rename:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="file_to_rename_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="new_rename_fname">
<property name="width-request">500</property>
<property name="height-request">26</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="has-focus">True</property>
<property name="tooltip-text" translatable="yes">Rename To:</property>
<property name="activates-default">True</property>
<property name="primary-icon-stock">gtk-edit</property>
<property name="primary-icon-activatable">False</property>
<property name="secondary-icon-activatable">False</property>
<property name="primary-icon-sensitive">False</property>
<property name="secondary-icon-sensitive">False</property>
<property name="placeholder-text" translatable="yes">To:</property>
<signal name="key-release-event" handler="hide_edit_file_menu_enter_key" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButtonBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="homogeneous">True</property>
<property name="layout-style">expand</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Title Case</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="released" handler="set_to_title_case" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Upper Case</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="released" handler="set_to_upper_case" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Lower Case</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="released" handler="set_to_lower_case" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Invert Case</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="released" handler="set_to_invert_case" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Rename</property>
<property name="name">rename</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">rename_img</property>
<property name="always-show-image">True</property>
<signal name="button-release-event" handler="hide_edit_file_menu" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-6">button2</action-widget>
<action-widget response="-7">button1</action-widget>
</action-widgets>
</object>
</interface>