aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mime_editor.py33
-rw-r--r--src/ui_main_window.glade76
2 files changed, 99 insertions, 10 deletions
diff --git a/src/mime_editor.py b/src/mime_editor.py
index ffccb4c..ac30c9a 100644
--- a/src/mime_editor.py
+++ b/src/mime_editor.py
@@ -33,11 +33,13 @@ import mime_editor_cat_mode
APP = os.path.join(DIR, "python-mime-editor-gui")
GLADE_FILE = "ui_main_window.glade"
-editor_modes = { "by_apps" : mime_editor_app_mode.MainWidget,
- "by_categories" : mime_editor_cat_mode.MainWidget }
+editor_modes = { "app_mode" : mime_editor_app_mode.MainWidget,
+ "cat_mode" : mime_editor_cat_mode.MainWidget }
class MainWindow:
def __init__(self, mode):
+ self.current_mode = mode
+
self.builder = Gtk.Builder()
self.builder.set_translation_domain(APP)
self.builder.add_from_file(GLADE_FILE)
@@ -52,6 +54,21 @@ class MainWindow:
self.viewport.pack_start(editor.get_widget(), True, True, 0)
+ self._init_menu()
+
+ def _init_menu(self):
+ quit_menuitem = self.builder.get_object("quit_menuitem")
+ quit_menuitem.connect("activate", self.on_close)
+
+ #change mode
+ cat_mode_menuitem = self.builder.get_object("cat_mode_menuitem")
+ app_mode_menuitem = self.builder.get_object("app_mode_menuitem")
+ if self.current_mode == "cat_mode":
+ cat_mode_menuitem.set_active(True)
+ elif self.current_mode == "app_mode":
+ app_mode_menuitem.set_active(True)
+ cat_mode_menuitem.connect("activate", self.switch_mode, "cat_mode")
+ app_mode_menuitem.connect("activate", self.switch_mode, "app_mode")
def run(self):
self.window.show()
@@ -60,9 +77,15 @@ class MainWindow:
def on_close(self, *args):
Gtk.main_quit()
+ def switch_mode(self, widget, new_mode):
+ if new_mode != self.current_mode:
+ os.execl(sys.executable, sys.executable, sys.argv[0], new_mode)
+
if __name__ == "__main__":
- #main(sys.argv)
- #window = MainWindow("by_categories")
- window = MainWindow("by_apps")
+ mode = "cat_mode"
+ if len(sys.argv) > 1 and sys.argv[1] in editor_modes:
+ mode = sys.argv[1]
+
+ window = MainWindow(mode)
window.run()
diff --git a/src/ui_main_window.glade b/src/ui_main_window.glade
index b3b650e..9afd5da 100644
--- a/src/ui_main_window.glade
+++ b/src/ui_main_window.glade
@@ -2,6 +2,7 @@
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.12"/>
+ <object class="GtkAccelGroup" id="accelgroup"/>
<object class="GtkApplicationWindow" id="main_window">
<property name="width_request">640</property>
<property name="height_request">400</property>
@@ -19,13 +20,13 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
- <object class="GtkMenuItem" id="menuitem1">
+ <object class="GtkMenuItem" id="file_menuitem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Файл</property>
<property name="use_underline">True</property>
<child type="submenu">
- <object class="GtkMenu" id="menu1">
+ <object class="GtkMenu" id="file_menu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
@@ -71,12 +72,14 @@
</object>
</child>
<child>
- <object class="GtkImageMenuItem" id="imagemenuitem5">
+ <object class="GtkImageMenuItem" id="quit_menuitem">
<property name="label">gtk-quit</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
+ <property name="accel_group">accelgroup</property>
+ <accelerator key="q" signal="activate" modifiers="GDK_CONTROL_MASK"/>
</object>
</child>
</object>
@@ -84,7 +87,7 @@
</object>
</child>
<child>
- <object class="GtkMenuItem" id="menuitem2">
+ <object class="GtkMenuItem" id="edit_menuitem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Правка</property>
@@ -134,11 +137,34 @@
</object>
</child>
<child>
- <object class="GtkMenuItem" id="menuitem3">
+ <object class="GtkMenuItem" id="view_menuitem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Вид</property>
<property name="use_underline">True</property>
+ <child type="submenu">
+ <object class="GtkMenu" id="menu4">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkRadioMenuItem" id="cat_mode_menuitem">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Group by categories</property>
+ <property name="draw_as_radio">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkRadioMenuItem" id="app_mode_menuitem">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Group by applications</property>
+ <property name="draw_as_radio">True</property>
+ <property name="group">cat_mode_menuitem</property>
+ </object>
+ </child>
+ </object>
+ </child>
</object>
</child>
<child>
@@ -177,4 +203,44 @@
</object>
</child>
</object>
+ <object class="GtkMenu" id="menu1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkImageMenuItem" id="imagemenuitem5">
+ <property name="label">gtk-cut</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="imagemenuitem11">
+ <property name="label">gtk-copy</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="imagemenuitem12">
+ <property name="label">gtk-paste</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImageMenuItem" id="imagemenuitem13">
+ <property name="label">gtk-delete</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_underline">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ </child>
+ </object>
</interface>
bgstack15