diff options
Diffstat (limited to 'Mozo')
-rw-r--r-- | Mozo/MainWindow.py | 102 | ||||
-rw-r--r-- | Mozo/util.py | 11 |
2 files changed, 63 insertions, 50 deletions
diff --git a/Mozo/MainWindow.py b/Mozo/MainWindow.py index 0239044..35c3cf2 100644 --- a/Mozo/MainWindow.py +++ b/Mozo/MainWindow.py @@ -16,7 +16,14 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -import gtk, matemenu, gobject, gio +import matemenu +import gi +gi.require_version('Gtk', "3.0") +from gi.repository import Gtk +from gi.repository import Gdk +from gi.repository import GdkPixbuf +from gi.repository import GObject +from gi.repository import Gio import cgi, os import gettext import subprocess @@ -25,8 +32,9 @@ try: from Mozo import config gettext.bindtextdomain(config.GETTEXT_PACKAGE,config.localedir) gettext.textdomain(config.GETTEXT_PACKAGE) + GETTEXT_PACKAGE = config.GETTEXT_PACKAGE except: - pass + GETTEXT_PACKAGE = "mozo" _ = gettext.gettext from Mozo.MenuEditor import MenuEditor from Mozo import util @@ -36,8 +44,8 @@ class MainWindow: #hack to make editing menu properties work allow_update = True #drag-and-drop stuff - dnd_items = [('MOZO_ITEM_ROW', gtk.TARGET_SAME_APP, 0), ('text/plain', 0, 1)] - dnd_menus = [('MOZO_MENU_ROW', gtk.TARGET_SAME_APP, 0)] + dnd_items = [('MOZO_ITEM_ROW', Gtk.TargetFlags.SAME_APP, 0), ('text/plain', 0, 1)] + dnd_menus = [('MOZO_MENU_ROW', Gtk.TargetFlags.SAME_APP, 0)] dnd_both = [dnd_items[0],] + dnd_menus drag_data = None edit_pool = [] @@ -46,9 +54,9 @@ class MainWindow: self.file_path = datadir self.version = version self.editor = MenuEditor() - gtk.window_set_default_icon_name('mozo') - self.tree = gtk.Builder() - self.tree.set_translation_domain(config.GETTEXT_PACKAGE) + Gtk.Window.set_default_icon_name('mozo') + self.tree = Gtk.Builder() + self.tree.set_translation_domain(GETTEXT_PACKAGE) self.tree.add_from_file(os.path.join(self.file_path, 'mozo.ui')) self.tree.connect_signals(self) self.setupMenuTree() @@ -59,13 +67,13 @@ class MainWindow: self.tree.get_object('move_up_button').set_sensitive(False) self.tree.get_object('move_down_button').set_sensitive(False) self.tree.get_object('new_separator_button').set_sensitive(False) - accelgroup = gtk.AccelGroup() - keyval, modifier = gtk.accelerator_parse('<Ctrl>Z') - accelgroup.connect_group(keyval, modifier, gtk.ACCEL_VISIBLE, self.on_mainwindow_undo) - keyval, modifier = gtk.accelerator_parse('<Ctrl><Shift>Z') - accelgroup.connect_group(keyval, modifier, gtk.ACCEL_VISIBLE, self.on_mainwindow_redo) - keyval, modifier = gtk.accelerator_parse('F1') - accelgroup.connect_group(keyval, modifier, gtk.ACCEL_VISIBLE, self.on_help_button_clicked) + accelgroup = Gtk.AccelGroup() + keyval, modifier = Gtk.accelerator_parse('<Ctrl>Z') + accelgroup.connect(keyval, modifier, Gtk.AccelFlags.VISIBLE, self.on_mainwindow_undo) + keyval, modifier = Gtk.accelerator_parse('<Ctrl><Shift>Z') + accelgroup.connect(keyval, modifier, Gtk.AccelFlags.VISIBLE, self.on_mainwindow_redo) + keyval, modifier = Gtk.accelerator_parse('F1') + accelgroup.connect(keyval, modifier, Gtk.AccelFlags.VISIBLE, self.on_help_button_clicked) self.tree.get_object('mainwindow').add_accel_group(accelgroup) def run(self): @@ -73,13 +81,13 @@ class MainWindow: self.editor.applications.tree.add_monitor(self.menuChanged, None) self.editor.settings.tree.add_monitor(self.menuChanged, None) self.tree.get_object('mainwindow').show_all() - gtk.main() + Gtk.main() def menuChanged(self, *a): if self.timer: - gobject.source_remove(self.timer) + GObject.source_remove(self.timer) self.timer = None - self.timer = gobject.timeout_add(3, self.loadUpdates) + self.timer = GObject.timeout_add(3, self.loadUpdates) def loadUpdates(self): if not self.allow_update: @@ -161,48 +169,48 @@ class MainWindow: return True def setupMenuTree(self): - self.menu_store = gtk.TreeStore(gtk.gdk.Pixbuf, str, object) + self.menu_store = Gtk.TreeStore(GdkPixbuf.Pixbuf, str, object) menus = self.tree.get_object('menu_tree') - column = gtk.TreeViewColumn(_('Name')) + column = Gtk.TreeViewColumn(_('Name')) column.set_spacing(4) - cell = gtk.CellRendererPixbuf() + cell = Gtk.CellRendererPixbuf() column.pack_start(cell, False) column.set_attributes(cell, pixbuf=0) - cell = gtk.CellRendererText() + cell = Gtk.CellRendererText() cell.set_fixed_size(-1, 25) column.pack_start(cell, True) column.set_attributes(cell, markup=1) - column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) + column.set_sizing(Gtk.TreeViewColumnSizing.FIXED) menus.append_column(column) - menus.enable_model_drag_source(gtk.gdk.BUTTON1_MASK, self.dnd_menus, gtk.gdk.ACTION_COPY) - menus.enable_model_drag_dest(self.dnd_both, gtk.gdk.ACTION_PRIVATE) + menus.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK, self.dnd_menus, Gdk.DragAction.COPY) + menus.enable_model_drag_dest(self.dnd_both, Gdk.DragAction.PRIVATE) def setupItemTree(self): items = self.tree.get_object('item_tree') - column = gtk.TreeViewColumn(_('Show')) - cell = gtk.CellRendererToggle() + column = Gtk.TreeViewColumn(_('Show')) + cell = Gtk.CellRendererToggle() cell.connect('toggled', self.on_item_tree_show_toggled) column.pack_start(cell, True) column.set_attributes(cell, active=0) #hide toggle for separators column.set_cell_data_func(cell, self._cell_data_toggle_func) items.append_column(column) - column = gtk.TreeViewColumn(_('Item')) + column = Gtk.TreeViewColumn(_('Item')) column.set_spacing(4) - cell = gtk.CellRendererPixbuf() + cell = Gtk.CellRendererPixbuf() column.pack_start(cell, False) column.set_attributes(cell, pixbuf=1) - cell = gtk.CellRendererText() + cell = Gtk.CellRendererText() cell.set_fixed_size(-1, 25) column.pack_start(cell, True) column.set_attributes(cell, markup=2) items.append_column(column) - self.item_store = gtk.ListStore(bool, gtk.gdk.Pixbuf, str, object) + self.item_store = Gtk.ListStore(bool, GdkPixbuf.Pixbuf, str, object) items.set_model(self.item_store) - items.enable_model_drag_source(gtk.gdk.BUTTON1_MASK, self.dnd_items, gtk.gdk.ACTION_COPY) - items.enable_model_drag_dest(self.dnd_items, gtk.gdk.ACTION_PRIVATE) + items.enable_model_drag_source(Gdk.ModifierType.BUTTON1_MASK, self.dnd_items, Gdk.DragAction.COPY) + items.enable_model_drag_dest(self.dnd_items, Gdk.DragAction.PRIVATE) - def _cell_data_toggle_func(self, tree_column, renderer, model, treeiter): + def _cell_data_toggle_func(self, tree_column, renderer, model, treeiter, data=None): if model[treeiter][3].get_type() == matemenu.TYPE_SEPARATOR: renderer.set_property('visible', False) else: @@ -298,7 +306,7 @@ class MainWindow: parent = menus[iter][2] file_path = os.path.join(util.getUserDirectoryPath(), util.getUniqueFileId('mozo-made', '.directory')) process = subprocess.Popen(['mate-desktop-item-edit', file_path], env=os.environ) - gobject.timeout_add(100, self.waitForNewMenuProcess, process, parent.menu_id, file_path) + GObject.timeout_add(100, self.waitForNewMenuProcess, process, parent.menu_id, file_path) def on_new_item_button_clicked(self, button): menu_tree = self.tree.get_object('menu_tree') @@ -311,7 +319,7 @@ class MainWindow: parent = menus[iter][2] file_path = os.path.join(util.getUserItemPath(), util.getUniqueFileId('mozo-made', '.desktop')) process = subprocess.Popen(['mate-desktop-item-edit', file_path], env=os.environ) - gobject.timeout_add(100, self.waitForNewItemProcess, process, parent.menu_id, file_path) + GObject.timeout_add(100, self.waitForNewItemProcess, process, parent.menu_id, file_path) def on_new_separator_button_clicked(self, button): item_tree = self.tree.get_object('item_tree') @@ -382,10 +390,12 @@ class MainWindow: if file_path not in self.edit_pool: self.edit_pool.append(file_path) process = subprocess.Popen(['mate-desktop-item-edit', file_path], env=os.environ) - gobject.timeout_add(100, self.waitForEditProcess, process, file_path) + GObject.timeout_add(100, self.waitForEditProcess, process, file_path) def on_menu_tree_cursor_changed(self, treeview): menus, iter = treeview.get_selection().get_selected() + if iter is None: + return menu_path = menus.get_path(iter) item_tree = self.tree.get_object('item_tree') item_tree.get_selection().unselect_all() @@ -406,7 +416,7 @@ class MainWindow: drop_info = treeview.get_dest_row_at_pos(x, y) if drop_info: path, position = drop_info - types = (gtk.TREE_VIEW_DROP_INTO_OR_BEFORE, gtk.TREE_VIEW_DROP_INTO_OR_AFTER) + types = (Gtk.TreeViewDropPosition.INTO_OR_BEFORE, Gtk.TreeViewDropPosition.INTO_OR_AFTER) if position not in types: context.finish(False, False, etime) return False @@ -487,7 +497,7 @@ class MainWindow: item_tree.grab_focus() item_tree.set_cursor(path, item_tree.get_columns()[0], 0) popup = self.tree.get_object('edit_menu') - popup.popup(None, None, None, button, event_time) + popup.popup(None, None, None, None, button, event_time) #without this shift-f10 won't work return True @@ -497,7 +507,7 @@ class MainWindow: def on_item_tree_drag_data_received(self, treeview, context, x, y, selection, info, etime): items = treeview.get_model() - types = (gtk.TREE_VIEW_DROP_BEFORE, gtk.TREE_VIEW_DROP_INTO_OR_BEFORE) + types = (Gtk.TreeViewDropPosition.BEFORE, Gtk.TreeViewDropPosition.INTO_OR_BEFORE) if selection.target == 'MOZO_ITEM_ROW': drop_info = treeview.get_dest_row_at_pos(x, y) before = None @@ -542,8 +552,8 @@ class MainWindow: file_path = urllib.unquote(selection.data).strip() if not file_path.startswith('file:'): return - myfile = gio.File(uri=file_path) - file_info = myfile.query_info(gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE) + myfile = Gio.File(uri=file_path) + file_info = myfile.query_info(Gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE) content_type = file_info.get_content_type() if content_type == 'application/x-desktop': input_stream = myfile.read() @@ -557,7 +567,7 @@ class MainWindow: self.drag_data = None def on_item_tree_key_press_event(self, item_tree, event): - if event.keyval == gtk.keysyms.Delete: + if event.keyval == Gdk.KEY_Delete: self.on_edit_delete_activate(item_tree) def on_move_up_button_clicked(self, button): @@ -603,13 +613,13 @@ class MainWindow: self.editor.redo() def on_help_button_clicked(self, *args): - gtk.show_uri(gtk.gdk.screen_get_default(), "help:mate-user-guide/menu-editor", gtk.get_current_event_time()) + Gtk.show_uri(Gdk.screen_get_default(), "help:mate-user-guide/menu-editor", Gtk.get_current_event_time()) def on_revert_button_clicked(self, button): dialog = self.tree.get_object('revertdialog') dialog.set_transient_for(self.tree.get_object('mainwindow')) dialog.show_all() - if dialog.run() == gtk.RESPONSE_YES: + if dialog.run() == Gtk.ResponseType.YES: self.editor.revert() dialog.hide() @@ -618,11 +628,11 @@ class MainWindow: self.tree.get_object('mainwindow').hide() except: pass - gobject.timeout_add(10, self.quit) + GObject.timeout_add(10, self.quit) def on_style_set(self, *args): self.loadUpdates() def quit(self): self.editor.quit() - gtk.main_quit() + Gtk.main_quit() diff --git a/Mozo/util.py b/Mozo/util.py index 0a6da20..edc654d 100644 --- a/Mozo/util.py +++ b/Mozo/util.py @@ -17,7 +17,10 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import os -import gtk, matemenu +import matemenu +import gi +from gi.repository import Gtk +from gi.repository import GdkPixbuf from ConfigParser import ConfigParser class DesktopParser(ConfigParser): @@ -212,14 +215,14 @@ def getIcon(item, for_properties=False): iconName = item.get_icon() if iconName and not '/' in iconName and iconName[-3:] in ('png', 'svg', 'xpm'): iconName = iconName[:-4] - icon_theme = gtk.icon_theme_get_default() + icon_theme = Gtk.IconTheme.get_default() try: pixbuf = icon_theme.load_icon(iconName, 24, 0) path = icon_theme.lookup_icon(iconName, 24, 0).get_filename() except: if iconName and '/' in iconName: try: - pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(iconName, 24, 24) + pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(iconName, 24, 24) path = iconName except: pass @@ -238,7 +241,7 @@ def getIcon(item, for_properties=False): if pixbuf == None: return None if pixbuf.get_width() != 24 or pixbuf.get_height() != 24: - pixbuf = pixbuf.scale_simple(24, 24, gtk.gdk.INTERP_HYPER) + pixbuf = pixbuf.scale_simple(24, 24, GdkPixbuf.InterpType.HYPER) if for_properties: return pixbuf, path return pixbuf |