Merge pull request #153 from MightyCreak/dont-use-new

Don't use new() in GTK classes
This commit is contained in:
Creak 2022-04-04 14:47:20 -04:00 committed by GitHub
commit 8d27125f08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 90 additions and 62 deletions

View File

@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Documentation: added release process instructions - Documentation: added release process instructions
- Translation: added French translation - Translation: added French translation
### Fixed
- Cleanups: use constructors instead of `new()` whenever possible in GTK
classes
## 0.7.4 - 2022-04-03 ## 0.7.4 - 2022-04-03
### Added ### Added

View File

@ -78,9 +78,8 @@ class FileChooserDialog(Gtk.FileChooserDialog):
self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL) self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
self.add_button(accept, Gtk.ResponseType.OK) self.add_button(accept, Gtk.ResponseType.OK)
self.prefs = prefs self.prefs = prefs
hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0) hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0, border_width=5)
hbox.set_border_width(5) label = Gtk.Label(label=_('Encoding: '))
label = Gtk.Label.new(_('Encoding: '))
hbox.pack_start(label, False, False, 0) hbox.pack_start(label, False, False, 0)
label.show() label.show()
self.encoding = entry = utils.EncodingMenu( self.encoding = entry = utils.EncodingMenu(
@ -89,10 +88,10 @@ class FileChooserDialog(Gtk.FileChooserDialog):
hbox.pack_start(entry, False, False, 5) hbox.pack_start(entry, False, False, 5)
entry.show() entry.show()
if rev: if rev:
self.revision = entry = Gtk.Entry.new() self.revision = entry = Gtk.Entry()
hbox.pack_end(entry, False, False, 0) hbox.pack_end(entry, False, False, 0)
entry.show() entry.show()
label = Gtk.Label.new(_('Revision: ')) label = Gtk.Label(label=_('Revision: '))
hbox.pack_end(label, False, False, 0) hbox.pack_end(label, False, False, 0)
label.show() label.show()
@ -122,15 +121,21 @@ class NumericDialog(Gtk.Dialog):
self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT) self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT)
self.add_button(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT) self.add_button(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)
vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
vbox.set_border_width(10) vbox.set_border_width(10)
hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0) hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
label = Gtk.Label.new(text) label = Gtk.Label(label=text)
hbox.pack_start(label, False, False, 0) hbox.pack_start(label, False, False, 0)
label.show() label.show()
adj = Gtk.Adjustment.new(val, lower, upper, step, page, 0) adj = Gtk.Adjustment(
self.button = button = Gtk.SpinButton.new(adj, 1.0, 0) value=val,
lower=lower,
upper=upper,
step_increment=step,
page_increment=page,
page_size=0)
self.button = button = Gtk.SpinButton(adjustment=adj, climb_rate=1.0, digits=0)
button.connect('activate', self.button_cb) button.connect('activate', self.button_cb)
hbox.pack_start(button, True, True, 0) hbox.pack_start(button, True, True, 0)
button.show() button.show()
@ -152,11 +157,11 @@ class SearchDialog(Gtk.Dialog):
self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT) self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT)
self.add_button(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT) self.add_button(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)
vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
vbox.set_border_width(10) vbox.set_border_width(10)
hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0) hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
label = Gtk.Label.new(_('Search For: ')) label = Gtk.Label(label=_('Search For: '))
hbox.pack_start(label, False, False, 0) hbox.pack_start(label, False, False, 0)
label.show() label.show()
combo = Gtk.ComboBoxText.new_with_entry() combo = Gtk.ComboBoxText.new_with_entry()
@ -167,7 +172,7 @@ class SearchDialog(Gtk.Dialog):
self.entry.set_text(pattern) self.entry.set_text(pattern)
if history is not None: if history is not None:
completion = Gtk.EntryCompletion.new() completion = Gtk.EntryCompletion()
liststore = Gtk.ListStore(GObject.TYPE_STRING) liststore = Gtk.ListStore(GObject.TYPE_STRING)
completion.set_model(liststore) completion.set_model(liststore)
completion.set_text_column(0) completion.set_text_column(0)

View File

@ -61,14 +61,14 @@ class NotebookTab(Gtk.EventBox):
def __init__(self, name: str, stock: str) -> None: def __init__(self, name: str, stock: str) -> None:
Gtk.EventBox.__init__(self) Gtk.EventBox.__init__(self)
self.set_visible_window(False) self.set_visible_window(False)
hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0) hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
if stock is not None: if stock is not None:
image = Gtk.Image.new() image = Gtk.Image()
image.set_from_stock(stock, Gtk.IconSize.MENU) image.set_from_stock(stock, Gtk.IconSize.MENU)
hbox.pack_start(image, False, False, 5) hbox.pack_start(image, False, False, 5)
image.show() image.show()
label = Gtk.Label.new(name) label = Gtk.Label(label=name)
# left justify the widget # left justify the widget
label.set_xalign(0.0) label.set_xalign(0.0)
label.set_yalign(0.5) label.set_yalign(0.5)
@ -76,9 +76,9 @@ class NotebookTab(Gtk.EventBox):
label.show() label.show()
self.label = label self.label = label
button = Gtk.Button.new() button = Gtk.Button()
button.set_relief(Gtk.ReliefStyle.NONE) button.set_relief(Gtk.ReliefStyle.NONE)
image = Gtk.Image.new() image = Gtk.Image()
image.set_from_stock(Gtk.STOCK_CLOSE, Gtk.IconSize.MENU) image.set_from_stock(Gtk.STOCK_CLOSE, Gtk.IconSize.MENU)
button.add(image) button.add(image)
image.show() image.show()
@ -134,7 +134,7 @@ class Diffuse(Gtk.Window):
[Gtk.STOCK_SAVE, self.button_cb, 'save', _('Save File')], [Gtk.STOCK_SAVE, self.button_cb, 'save', _('Save File')],
[Gtk.STOCK_SAVE_AS, self.button_cb, 'save_as', _('Save File As...')]]) [Gtk.STOCK_SAVE_AS, self.button_cb, 'save_as', _('Save File As...')]])
self.label = label = Gtk.Label.new() self.label = label = Gtk.Label()
label.set_selectable(True) label.set_selectable(True)
label.set_ellipsize(Pango.EllipsizeMode.START) label.set_ellipsize(Pango.EllipsizeMode.START)
label.set_max_width_chars(1) label.set_max_width_chars(1)
@ -181,23 +181,23 @@ class Diffuse(Gtk.Window):
class PaneFooter(Gtk.Box): class PaneFooter(Gtk.Box):
def __init__(self) -> None: def __init__(self) -> None:
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=0) Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
self.cursor = label = Gtk.Label.new() self.cursor = label = Gtk.Label()
self.cursor.set_size_request(-1, -1) self.cursor.set_size_request(-1, -1)
self.pack_start(label, False, False, 0) self.pack_start(label, False, False, 0)
separator = Gtk.Separator.new(Gtk.Orientation.VERTICAL) separator = Gtk.Separator(orientation=Gtk.Orientation.VERTICAL)
self.pack_end(separator, False, False, 10) self.pack_end(separator, False, False, 10)
self.encoding = label = Gtk.Label.new() self.encoding = label = Gtk.Label()
self.pack_end(label, False, False, 0) self.pack_end(label, False, False, 0)
separator = Gtk.Separator.new(Gtk.Orientation.VERTICAL) separator = Gtk.Separator(orientation=Gtk.Orientation.VERTICAL)
self.pack_end(separator, False, False, 10) self.pack_end(separator, False, False, 10)
self.format = label = Gtk.Label.new() self.format = label = Gtk.Label()
self.pack_end(label, False, False, 0) self.pack_end(label, False, False, 0)
separator = Gtk.Separator.new(Gtk.Orientation.VERTICAL) separator = Gtk.Separator(orientation=Gtk.Orientation.VERTICAL)
self.pack_end(separator, False, False, 10) self.pack_end(separator, False, False, 10)
self.set_size_request(0, self.get_size_request()[1]) self.set_size_request(0, self.get_size_request()[1])
@ -905,7 +905,7 @@ class Diffuse(Gtk.Window):
menu_bar.show() menu_bar.show()
# create button bar # create button bar
hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0) hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
_append_buttons(hbox, Gtk.IconSize.LARGE_TOOLBAR, [ _append_buttons(hbox, Gtk.IconSize.LARGE_TOOLBAR, [
[DIFFUSE_STOCK_NEW_2WAY_MERGE, self.new_2_way_file_merge_cb, None, _('New 2-Way File Merge')], # noqa: E501 [DIFFUSE_STOCK_NEW_2WAY_MERGE, self.new_2_way_file_merge_cb, None, _('New 2-Way File Merge')], # noqa: E501
[DIFFUSE_STOCK_NEW_3WAY_MERGE, self.new_3_way_file_merge_cb, None, _('New 3-Way File Merge')], # noqa: E501 [DIFFUSE_STOCK_NEW_3WAY_MERGE, self.new_3_way_file_merge_cb, None, _('New 3-Way File Merge')], # noqa: E501
@ -936,14 +936,14 @@ class Diffuse(Gtk.Window):
hbox.show() hbox.show()
self.closed_tabs = [] self.closed_tabs = []
self.notebook = notebook = Gtk.Notebook.new() self.notebook = notebook = Gtk.Notebook()
notebook.set_scrollable(True) notebook.set_scrollable(True)
notebook.connect('switch-page', self.switch_page_cb) notebook.connect('switch-page', self.switch_page_cb)
vbox.pack_start(notebook, True, True, 0) vbox.pack_start(notebook, True, True, 0)
notebook.show() notebook.show()
# Add a status bar to the bottom # Add a status bar to the bottom
self.statusbar = statusbar = Gtk.Statusbar.new() self.statusbar = statusbar = Gtk.Statusbar()
vbox.pack_start(statusbar, False, False, 0) vbox.pack_start(statusbar, False, False, 0)
statusbar.show() statusbar.show()
@ -1056,15 +1056,15 @@ class Diffuse(Gtk.Window):
dialog.set_resizable(True) dialog.set_resizable(True)
dialog.set_title(constants.APP_NAME) dialog.set_title(constants.APP_NAME)
# add list of files with unsaved changes # add list of files with unsaved changes
sw = Gtk.ScrolledWindow.new() sw = Gtk.ScrolledWindow()
sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
treeview = Gtk.TreeView.new_with_model(model) treeview = Gtk.TreeView.new_with_model(model)
r = Gtk.CellRendererToggle.new() r = Gtk.CellRendererToggle()
r.connect('toggled', self._confirmClose_toggle_cb, model) r.connect('toggled', self._confirmClose_toggle_cb, model)
column = Gtk.TreeViewColumn(None, r) column = Gtk.TreeViewColumn(None, r)
column.add_attribute(r, 'active', 0) column.add_attribute(r, 'active', 0)
treeview.append_column(column) treeview.append_column(column)
r = Gtk.CellRendererText.new() r = Gtk.CellRendererText()
column = Gtk.TreeViewColumn(_('Tab'), r, text=1) column = Gtk.TreeViewColumn(_('Tab'), r, text=1)
column.set_resizable(True) column.set_resizable(True)
column.set_expand(True) column.set_expand(True)
@ -1137,7 +1137,7 @@ class Diffuse(Gtk.Window):
self.remove_tab_cb(widget, data) self.remove_tab_cb(widget, data)
elif event.button == 3: elif event.button == 3:
# create a popup to pick a tab for focus on RMB # create a popup to pick a tab for focus on RMB
menu = Gtk.Menu.new() menu = Gtk.Menu()
nb = self.notebook nb = self.notebook
for i in range(nb.get_n_pages()): for i in range(nb.get_n_pages()):
viewer = nb.get_nth_page(i) viewer = nb.get_nth_page(i)
@ -1685,7 +1685,7 @@ class Diffuse(Gtk.Window):
# convenience method for creating a menu bar according to a template # convenience method for creating a menu bar according to a template
def _create_menu_bar(specs, radio, accel_group): def _create_menu_bar(specs, radio, accel_group):
menu_bar = Gtk.MenuBar.new() menu_bar = Gtk.MenuBar()
for label, spec in specs: for label, spec in specs:
menu = Gtk.MenuItem.new_with_mnemonic(label) menu = Gtk.MenuItem.new_with_mnemonic(label)
menu.set_submenu(createMenu(spec, radio, accel_group)) menu.set_submenu(createMenu(spec, radio, accel_group))
@ -1700,10 +1700,10 @@ def _create_menu_bar(specs, radio, accel_group):
def _append_buttons(box, size, specs): def _append_buttons(box, size, specs):
for spec in specs: for spec in specs:
if len(spec) > 0: if len(spec) > 0:
button = Gtk.Button.new() button = Gtk.Button()
button.set_relief(Gtk.ReliefStyle.NONE) button.set_relief(Gtk.ReliefStyle.NONE)
button.set_can_focus(False) button.set_can_focus(False)
image = Gtk.Image.new() image = Gtk.Image()
image.set_from_stock(spec[0], size) image.set_from_stock(spec[0], size)
button.add(image) button.add(image)
image.show() image.show()
@ -1714,7 +1714,7 @@ def _append_buttons(box, size, specs):
box.pack_start(button, False, False, 0) box.pack_start(button, False, False, 0)
button.show() button.show()
else: else:
separator = Gtk.Separator.new(Gtk.Orientation.VERTICAL) separator = Gtk.Separator(orientation=Gtk.Orientation.VERTICAL)
box.pack_start(separator, False, False, 5) box.pack_start(separator, False, False, 5)
separator.show() separator.show()

View File

@ -306,11 +306,11 @@ class Preferences:
def _buildPrefsDialog(self, parent, widgets, template): def _buildPrefsDialog(self, parent, widgets, template):
tpl_section = template[0] tpl_section = template[0]
if tpl_section == 'FolderSet': if tpl_section == 'FolderSet':
notebook = Gtk.Notebook.new() notebook = Gtk.Notebook()
notebook.set_border_width(10) notebook.set_border_width(10)
i = 1 i = 1
while i < len(template): while i < len(template):
label = Gtk.Label.new(template[i]) label = Gtk.Label(label=template[i])
i += 1 i += 1
w = self._buildPrefsDialog(parent, widgets, template[i]) w = self._buildPrefsDialog(parent, widgets, template[i])
i += 1 i += 1
@ -319,7 +319,7 @@ class Preferences:
label.show() label.show()
return notebook return notebook
table = Gtk.Grid.new() table = Gtk.Grid()
table.set_border_width(10) table.set_border_width(10)
for i, tpl in enumerate(template[1:]): for i, tpl in enumerate(template[1:]):
tpl_section = tpl[0] tpl_section = tpl[0]
@ -335,21 +335,28 @@ class Preferences:
button.connect('toggled', self._toggled_cb, widgets, tpl[1]) button.connect('toggled', self._toggled_cb, widgets, tpl[1])
button.show() button.show()
else: else:
label = Gtk.Label.new(tpl[3] + ': ') label = Gtk.Label(label=tpl[3] + ': ')
label.set_xalign(1.0) label.set_xalign(1.0)
label.set_yalign(0.5) label.set_yalign(0.5)
table.attach(label, 0, i, 1, 1) table.attach(label, 0, i, 1, 1)
label.show() label.show()
if tpl[0] in ['Font', 'Integer']: if tpl[0] in ['Font', 'Integer']:
entry = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0) entry = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
if tpl[0] == 'Font': if tpl[0] == 'Font':
button = Gtk.FontButton() button = Gtk.FontButton()
button.set_font(self.string_prefs[tpl[1]]) button.set_font(self.string_prefs[tpl[1]])
else: else:
button = Gtk.SpinButton.new( adj = Gtk.Adjustment(
Gtk.Adjustment.new(self.int_prefs[tpl[1]], tpl[4], tpl[5], 1, 0, 0), value=self.int_prefs[tpl[1]],
1.0, lower=tpl[4],
0) upper=tpl[5],
step_increment=1,
page_increment=0,
page_size=0)
button = Gtk.SpinButton(
adjustment=adj,
climb_rate=1.0,
digits=0)
widgets[tpl[1]] = button widgets[tpl[1]] = button
entry.pack_start(button, False, False, 0) entry.pack_start(button, False, False, 0)
button.show() button.show()
@ -360,7 +367,7 @@ class Preferences:
elif tpl[0] == 'File': elif tpl[0] == 'File':
entry = _FileEntry(parent, tpl[3]) entry = _FileEntry(parent, tpl[3])
else: else:
entry = Gtk.Entry.new() entry = Gtk.Entry()
widgets[tpl[1]] = entry widgets[tpl[1]] = entry
entry.set_text(self.string_prefs[tpl[1]]) entry.set_text(self.string_prefs[tpl[1]])
table.attach(entry, 1, i, 1, 1) table.attach(entry, 1, i, 1, 1)
@ -443,11 +450,11 @@ class _FileEntry(Gtk.Box):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL) Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
self.toplevel = parent self.toplevel = parent
self.title = title self.title = title
self.entry = entry = Gtk.Entry.new() self.entry = entry = Gtk.Entry()
self.pack_start(entry, True, True, 0) self.pack_start(entry, True, True, 0)
entry.show() entry.show()
button = Gtk.Button.new() button = Gtk.Button()
image = Gtk.Image.new() image = Gtk.Image()
image.set_from_stock(Gtk.STOCK_OPEN, Gtk.IconSize.MENU) image.set_from_stock(Gtk.STOCK_OPEN, Gtk.IconSize.MENU)
button.add(image) button.add(image)
image.show() image.show()

View File

@ -57,7 +57,7 @@ class MessageDialog(Gtk.MessageDialog):
class EncodingMenu(Gtk.Box): class EncodingMenu(Gtk.Box):
def __init__(self, prefs: Preferences, autodetect: bool = False) -> None: def __init__(self, prefs: Preferences, autodetect: bool = False) -> None:
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL) Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
self.combobox = combobox = Gtk.ComboBoxText.new() self.combobox = combobox = Gtk.ComboBoxText()
self.encodings = prefs.getEncodings()[:] self.encodings = prefs.getEncodings()[:]
for e in self.encodings: for e in self.encodings:
combobox.append_text(e) combobox.append_text(e)

View File

@ -63,8 +63,8 @@ class ScrolledWindow(Gtk.Grid):
self.partial_redraw = False self.partial_redraw = False
self.hadj, self.vadj = hadj, vadj self.hadj, self.vadj = hadj, vadj
vport = Gtk.Viewport.new() vport = Gtk.Viewport()
darea = Gtk.DrawingArea.new() darea = Gtk.DrawingArea()
darea.add_events(Gdk.EventMask.SCROLL_MASK) darea.add_events(Gdk.EventMask.SCROLL_MASK)
self.darea = darea self.darea = darea
# replace darea's queue_draw_area with our own so we can tell when # replace darea's queue_draw_area with our own so we can tell when
@ -78,11 +78,11 @@ class ScrolledWindow(Gtk.Grid):
vport.set_hexpand(True) vport.set_hexpand(True)
vport.show() vport.show()
self.vbar = Gtk.Scrollbar.new(Gtk.Orientation.VERTICAL, vadj) self.vbar = Gtk.Scrollbar(orientation=Gtk.Orientation.VERTICAL, adjustment=vadj)
self.attach(self.vbar, 1, 0, 1, 1) self.attach(self.vbar, 1, 0, 1, 1)
self.vbar.show() self.vbar.show()
self.hbar = Gtk.Scrollbar.new(Gtk.Orientation.HORIZONTAL, hadj) self.hbar = Gtk.Scrollbar(orientation=Gtk.Orientation.HORIZONTAL, adjustment=hadj)
self.attach(self.hbar, 0, 1, 1, 1) self.attach(self.hbar, 0, 1, 1, 1)
self.hbar.show() self.hbar.show()
@ -319,8 +319,20 @@ class FileDiffViewerBase(Gtk.Grid):
# create panes # create panes
self.dareas: List[Gtk.DrawingArea] = [] self.dareas: List[Gtk.DrawingArea] = []
self.panes: List[FileDiffViewerBase.Pane] = [] self.panes: List[FileDiffViewerBase.Pane] = []
self.hadj = Gtk.Adjustment.new(0, 0, 0, 0, 0, 0) self.hadj = Gtk.Adjustment(
self.vadj = Gtk.Adjustment.new(0, 0, 0, 0, 0, 0) value=0,
lower=0,
upper=0,
step_increment=0,
page_increment=0,
page_size=0)
self.vadj = Gtk.Adjustment(
value=0,
lower=0,
upper=0,
step_increment=0,
page_increment=0,
page_size=0)
for i in range(n): for i in range(n):
pane = FileDiffViewerBase.Pane() pane = FileDiffViewerBase.Pane()
self.panes.append(pane) self.panes.append(pane)
@ -343,7 +355,7 @@ class FileDiffViewerBase(Gtk.Grid):
self.vadj.connect('value-changed', self.vadj_changed_cb) self.vadj.connect('value-changed', self.vadj_changed_cb)
# add diff map # add diff map
self.diffmap = diffmap = Gtk.DrawingArea.new() self.diffmap = diffmap = Gtk.DrawingArea()
diffmap.add_events(Gdk.EventMask.BUTTON_PRESS_MASK | diffmap.add_events(Gdk.EventMask.BUTTON_PRESS_MASK |
Gdk.EventMask.BUTTON1_MOTION_MASK | Gdk.EventMask.BUTTON1_MOTION_MASK |
Gdk.EventMask.SCROLL_MASK) Gdk.EventMask.SCROLL_MASK)
@ -361,7 +373,7 @@ class FileDiffViewerBase(Gtk.Grid):
self.connect('key-press-event', self.key_press_cb) self.connect('key-press-event', self.key_press_cb)
# input method # input method
self.im_context = im = Gtk.IMMulticontext.new() self.im_context = im = Gtk.IMMulticontext()
im.connect('commit', self.im_commit_cb) im.connect('commit', self.im_commit_cb)
im.connect('preedit-changed', self.im_preedit_changed_cb) im.connect('preedit-changed', self.im_preedit_changed_cb)
im.connect('retrieve-surrounding', self.im_retrieve_surrounding_cb) im.connect('retrieve-surrounding', self.im_retrieve_surrounding_cb)
@ -3698,7 +3710,7 @@ class FileDiffViewerBase(Gtk.Grid):
# convenience method for creating a menu according to a template # convenience method for creating a menu according to a template
def createMenu(specs, radio=None, accel_group=None): def createMenu(specs, radio=None, accel_group=None):
menu = Gtk.Menu.new() menu = Gtk.Menu()
for spec in specs: for spec in specs:
if len(spec) > 0: if len(spec) > 0:
if len(spec) > 7 and spec[7] is not None: if len(spec) > 7 and spec[7] is not None:
@ -3716,7 +3728,7 @@ def createMenu(specs, radio=None, accel_group=None):
data = spec[2] data = spec[2]
item.connect('activate', cb, data) item.connect('activate', cb, data)
if len(spec) > 3 and spec[3] is not None: if len(spec) > 3 and spec[3] is not None:
image = Gtk.Image.new() image = Gtk.Image()
image.set_from_stock(spec[3], Gtk.IconSize.MENU) image.set_from_stock(spec[3], Gtk.IconSize.MENU)
item.set_image(image) item.set_image(image)
if accel_group is not None and len(spec) > 4: if accel_group is not None and len(spec) > 4:
@ -3735,7 +3747,7 @@ def createMenu(specs, radio=None, accel_group=None):
item.set_submenu(createMenu(spec[6], radio, accel_group)) item.set_submenu(createMenu(spec[6], radio, accel_group))
item.set_use_underline(True) item.set_use_underline(True)
else: else:
item = Gtk.SeparatorMenuItem.new() item = Gtk.SeparatorMenuItem()
item.show() item.show()
menu.append(item) menu.append(item)
return menu return menu