Moved appchooser dialogue to class and new glade file
This commit is contained in:
parent
59adbe58da
commit
0e0802a375
@ -18,6 +18,7 @@ from widgets.new_file_widget import NewFileWidget
|
||||
from widgets.rename_widget import RenameWidget
|
||||
from widgets.file_exists_widget import FileExistsWidget
|
||||
from widgets.about_widget import AboutWidget
|
||||
from widgets.appchooser_widget import AppchooserWidget
|
||||
|
||||
from .ui import UI
|
||||
|
||||
@ -49,15 +50,15 @@ class Controller(UI, SignalsMixins, Controller_Data):
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
# NOTE: Really we will move these to the UI/(New) Window
|
||||
# 'base' controller after we're done cleaning and refactoring
|
||||
# to use fewer mixins.
|
||||
# NOTE: Really we will move these to the UI/(New) Window 'base' controller
|
||||
# after we're done cleaning and refactoring to use fewer mixins.
|
||||
def _load_widgets(self):
|
||||
ContextMenuWidget()
|
||||
NewFileWidget()
|
||||
RenameWidget()
|
||||
FileExistsWidget()
|
||||
AboutWidget()
|
||||
AppchooserWidget()
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
|
||||
@ -65,6 +66,9 @@ class Controller(UI, SignalsMixins, Controller_Data):
|
||||
event_system.subscribe("display_message", self.display_message)
|
||||
event_system.subscribe("go_to_path", self.go_to_path)
|
||||
event_system.subscribe("do_action_from_menu_controls", self.do_action_from_menu_controls)
|
||||
# NOTE: Needs to be moved (probably just to file actions class) after reducing mixins usage
|
||||
event_system.subscribe("open_with_files", self.open_with_files)
|
||||
|
||||
|
||||
def tear_down(self, widget=None, eve=None):
|
||||
if not settings.is_trace_debug():
|
||||
@ -136,7 +140,7 @@ class Controller(UI, SignalsMixins, Controller_Data):
|
||||
if action == "open":
|
||||
self.open_files()
|
||||
if action == "open_with":
|
||||
self.show_appchooser_menu()
|
||||
event_system.emit("show_appchooser_menu")
|
||||
if action == "execute":
|
||||
self.execute_files()
|
||||
if action == "execute_in_terminal":
|
||||
|
@ -12,30 +12,6 @@ class ShowHideMixin:
|
||||
def show_messages_popup(self, type, text, seconds=None):
|
||||
self.message_popup_widget.popup()
|
||||
|
||||
def stop_file_searching(self, widget=None, eve=None):
|
||||
self.is_searching = False
|
||||
|
||||
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")
|
||||
response = appchooser_menu.run()
|
||||
|
||||
if response == Gtk.ResponseType.OK:
|
||||
self.open_with_files(appchooser_widget)
|
||||
self.hide_appchooser_menu()
|
||||
|
||||
if response == Gtk.ResponseType.CANCEL:
|
||||
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):
|
||||
dialog = widget.get_parent().get_parent()
|
||||
dialog.response(Gtk.ResponseType.OK)
|
||||
|
||||
|
||||
def show_plugins_popup(self, widget=None, eve=None):
|
||||
self.builder.get_object("plugin_controls").popup()
|
||||
|
||||
|
@ -130,9 +130,8 @@ class FileActionSignalsMixin:
|
||||
for file in uris:
|
||||
state.tab.open_file_locally(file)
|
||||
|
||||
def open_with_files(self, appchooser_widget):
|
||||
def open_with_files(self, app_info):
|
||||
state = self.get_current_state()
|
||||
app_info = appchooser_widget.get_app_info()
|
||||
uris = self.format_to_uris(state.store, state.wid, state.tid, self.selected_files)
|
||||
state.tab.app_chooser_exec(app_info, uris)
|
||||
|
||||
|
@ -0,0 +1,72 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import inspect
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('Gdk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gdk
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
class AppchooserWidget:
|
||||
"""docstring for AppchooserWidget."""
|
||||
|
||||
def __init__(self):
|
||||
super(AppchooserWidget, self).__init__()
|
||||
_GLADE_FILE = f"{settings.get_ui_widgets_path()}/appchooser_ui.glade"
|
||||
builder = settings.get_builder()
|
||||
self._builder = Gtk.Builder()
|
||||
|
||||
self._builder.add_from_file(_GLADE_FILE)
|
||||
self._appchooser_menu = self._builder.get_object("appchooser_menu")
|
||||
self._appchooser_widget = self._builder.get_object("appchooser_widget")
|
||||
|
||||
builder.expose_object(f"appchooser_menu", self._appchooser_menu)
|
||||
builder.expose_object(f"appchooser_widget", self._appchooser_widget)
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._load_widgets()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
...
|
||||
|
||||
def _setup_signals(self):
|
||||
event_system.subscribe("show_appchooser_menu", self.show_appchooser_menu)
|
||||
event_system.subscribe("hide_appchooser_menu", self.hide_appchooser_menu)
|
||||
event_system.subscribe("run_appchooser_launch", self.run_appchooser_launch)
|
||||
|
||||
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 show_appchooser_menu(self, widget=None, eve=None):
|
||||
response = self._appchooser_menu.run()
|
||||
if response == Gtk.ResponseType.OK:
|
||||
app_info = self._appchooser_widget.get_app_info()
|
||||
event_system.emit("open_with_files", app_info)
|
||||
self.hide_appchooser_menu()
|
||||
if response == Gtk.ResponseType.CANCEL:
|
||||
self.hide_appchooser_menu()
|
||||
|
||||
|
||||
def hide_appchooser_menu(self, widget=None, eve=None):
|
||||
self._appchooser_menu.hide()
|
||||
|
||||
def run_appchooser_launch(self, widget=None, eve=None):
|
||||
self._appchooser_menu.response(Gtk.ResponseType.OK)
|
@ -2,76 +2,6 @@
|
||||
<!-- Generated with glade 3.40.0 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.22"/>
|
||||
<object class="GtkDialog" id="appchooser_menu">
|
||||
<property name="can-focus">False</property>
|
||||
<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>
|
||||
<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="button31">
|
||||
<property name="label">gtk-cancel</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="appchooser_select_btn">
|
||||
<property name="label" translatable="yes">Select</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">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="GtkAppChooserWidget" id="appchooser_widget">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="show-recommended">False</property>
|
||||
<property name="show-all">True</property>
|
||||
<signal name="application-activated" handler="run_appchooser_launch" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<action-widgets>
|
||||
<action-widget response="-6">button31</action-widget>
|
||||
<action-widget response="-5">appchooser_select_btn</action-widget>
|
||||
</action-widgets>
|
||||
</object>
|
||||
<object class="GtkImage" id="image1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
|
75
user_config/usr/share/solarfm/ui_widgets/appchooser_ui.glade
Normal file
75
user_config/usr/share/solarfm/ui_widgets/appchooser_ui.glade
Normal file
@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.40.0 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.22"/>
|
||||
<object class="GtkDialog" id="appchooser_menu">
|
||||
<property name="can-focus">False</property>
|
||||
<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>
|
||||
<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="button31">
|
||||
<property name="label">gtk-cancel</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="appchooser_select_btn">
|
||||
<property name="label" translatable="yes">Select</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="receives-default">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="GtkAppChooserWidget" id="appchooser_widget">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="show-recommended">False</property>
|
||||
<property name="show-all">True</property>
|
||||
<signal name="application-activated" handler="run_appchooser_launch" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<action-widgets>
|
||||
<action-widget response="-6">button31</action-widget>
|
||||
<action-widget response="-5">appchooser_select_btn</action-widget>
|
||||
</action-widgets>
|
||||
</object>
|
||||
</interface>
|
Loading…
Reference in New Issue
Block a user