From 81e87eb16161b107e17d38e829c33f7eac1c66ca Mon Sep 17 00:00:00 2001 From: Romain Failliot Date: Sun, 21 Nov 2021 13:29:17 -0500 Subject: [PATCH] Fix cyclic import between utils and resources --- .pylintrc | 1 + src/main.py | 4 ++-- src/utils.py | 45 --------------------------------------------- src/widgets.py | 46 +++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 48 insertions(+), 48 deletions(-) diff --git a/.pylintrc b/.pylintrc index 1e8baea..f407186 100644 --- a/.pylintrc +++ b/.pylintrc @@ -95,6 +95,7 @@ disable=raw-checker-failed, missing-class-docstring, missing-function-docstring, missing-module-docstring, + no-name-in-module, no-self-use, too-few-public-methods, too-many-arguments, diff --git a/src/main.py b/src/main.py index 702a4c9..a2aefdb 100644 --- a/src/main.py +++ b/src/main.py @@ -45,7 +45,7 @@ from diffuse.preferences import Preferences from diffuse.resources import theResources from diffuse.vcs.vcs_registry import VcsRegistry from diffuse.widgets import FileDiffViewer -from diffuse.widgets import LINE_MODE, CHAR_MODE, ALIGN_MODE +from diffuse.widgets import createMenu, LINE_MODE, CHAR_MODE, ALIGN_MODE theVCSs = VcsRegistry() @@ -1550,7 +1550,7 @@ def _create_menu_bar(specs, radio, accel_group): menu_bar = Gtk.MenuBar.new() for label, spec in specs: menu = Gtk.MenuItem.new_with_mnemonic(label) - menu.set_submenu(utils.createMenu(spec, radio, accel_group)) + menu.set_submenu(createMenu(spec, radio, accel_group)) menu.set_use_underline(True) menu.show() menu_bar.append(menu) diff --git a/src/utils.py b/src/utils.py index 322cdb2..cbd10bd 100644 --- a/src/utils.py +++ b/src/utils.py @@ -30,7 +30,6 @@ from gi.repository import Gtk # pylint: enable=wrong-import-position from diffuse import constants -from diffuse.resources import theResources # convenience class for displaying a message dialogue class MessageDialog(Gtk.MessageDialog): @@ -272,50 +271,6 @@ def step_adjustment(adj, delta): v = min(v, int(adj.get_upper() - adj.get_page_size())) adj.set_value(v) -# convenience method for creating a menu according to a template -def createMenu(specs, radio=None, accel_group=None): - menu = Gtk.Menu.new() - for spec in specs: - if len(spec) > 0: - if len(spec) > 7 and spec[7] is not None: - g, k = spec[7] - if g not in radio: - item = Gtk.RadioMenuItem.new_with_mnemonic_from_widget(None, spec[0]) - radio[g] = (item, {}) - else: - item = Gtk.RadioMenuItem.new_with_mnemonic_from_widget(radio[g][0], spec[0]) - radio[g][1][k] = item - else: - item = Gtk.ImageMenuItem.new_with_mnemonic(spec[0]) - cb = spec[1] - if cb is not None: - data = spec[2] - item.connect('activate', cb, data) - if len(spec) > 3 and spec[3] is not None: - image = Gtk.Image.new() - image.set_from_stock(spec[3], Gtk.IconSize.MENU) # pylint: disable=no-member - item.set_image(image) - if accel_group is not None and len(spec) > 4: - a = theResources.getKeyBindings('menu', spec[4]) - if len(a) > 0: - key, modifier = a[0] - item.add_accelerator( - 'activate', - accel_group, - key, - modifier, - Gtk.AccelFlags.VISIBLE) - if len(spec) > 5: - item.set_sensitive(spec[5]) - if len(spec) > 6 and spec[6] is not None: - item.set_submenu(createMenu(spec[6], radio, accel_group)) - item.set_use_underline(True) - else: - item = Gtk.SeparatorMenuItem.new() - item.show() - menu.append(item) - return menu - # masks used to indicate the presence of particular line endings DOS_FORMAT = 1 diff --git a/src/widgets.py b/src/widgets.py index f6c625c..a655ef4 100644 --- a/src/widgets.py +++ b/src/widgets.py @@ -1833,7 +1833,7 @@ class FileDiffViewer(Gtk.Grid): can_swap = (f != self.current_pane) # pylint: disable=line-too-long - menu = utils.createMenu( + menu = createMenu( [ [_('Align with Selection'), self.align_with_selection_cb, [f, i], Gtk.STOCK_EXECUTE, None, can_align], [_('Isolate'), self.button_cb, 'isolate', None, None, can_isolate ], [_('Merge Selection'), self.merge_lines_cb, f, None, None, can_merge], @@ -3685,6 +3685,50 @@ class FileDiffViewer(Gtk.Grid): def merge_from_right_then_left(self): self._mergeBoth(True) +# convenience method for creating a menu according to a template +def createMenu(specs, radio=None, accel_group=None): + menu = Gtk.Menu.new() + for spec in specs: + if len(spec) > 0: + if len(spec) > 7 and spec[7] is not None: + g, k = spec[7] + if g not in radio: + item = Gtk.RadioMenuItem.new_with_mnemonic_from_widget(None, spec[0]) + radio[g] = (item, {}) + else: + item = Gtk.RadioMenuItem.new_with_mnemonic_from_widget(radio[g][0], spec[0]) + radio[g][1][k] = item + else: + item = Gtk.ImageMenuItem.new_with_mnemonic(spec[0]) + cb = spec[1] + if cb is not None: + data = spec[2] + item.connect('activate', cb, data) + if len(spec) > 3 and spec[3] is not None: + image = Gtk.Image.new() + image.set_from_stock(spec[3], Gtk.IconSize.MENU) # pylint: disable=no-member + item.set_image(image) + if accel_group is not None and len(spec) > 4: + a = theResources.getKeyBindings('menu', spec[4]) + if len(a) > 0: + key, modifier = a[0] + item.add_accelerator( + 'activate', + accel_group, + key, + modifier, + Gtk.AccelFlags.VISIBLE) + if len(spec) > 5: + item.set_sensitive(spec[5]) + if len(spec) > 6 and spec[6] is not None: + item.set_submenu(createMenu(spec[6], radio, accel_group)) + item.set_use_underline(True) + else: + item = Gtk.SeparatorMenuItem.new() + item.show() + menu.append(item) + return menu + ALPHANUMERIC_CLASS = 0 WHITESPACE_CLASS = 1 OTHER_CLASS = 2