Merge pull request #153 from MightyCreak/dont-use-new
Don't use new() in GTK classes
This commit is contained in:
commit
8d27125f08
|
@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Documentation: added release process instructions
|
||||
- Translation: added French translation
|
||||
|
||||
### Fixed
|
||||
- Cleanups: use constructors instead of `new()` whenever possible in GTK
|
||||
classes
|
||||
|
||||
## 0.7.4 - 2022-04-03
|
||||
|
||||
### Added
|
||||
|
|
|
@ -78,9 +78,8 @@ class FileChooserDialog(Gtk.FileChooserDialog):
|
|||
self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
|
||||
self.add_button(accept, Gtk.ResponseType.OK)
|
||||
self.prefs = prefs
|
||||
hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
|
||||
hbox.set_border_width(5)
|
||||
label = Gtk.Label.new(_('Encoding: '))
|
||||
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0, border_width=5)
|
||||
label = Gtk.Label(label=_('Encoding: '))
|
||||
hbox.pack_start(label, False, False, 0)
|
||||
label.show()
|
||||
self.encoding = entry = utils.EncodingMenu(
|
||||
|
@ -89,10 +88,10 @@ class FileChooserDialog(Gtk.FileChooserDialog):
|
|||
hbox.pack_start(entry, False, False, 5)
|
||||
entry.show()
|
||||
if rev:
|
||||
self.revision = entry = Gtk.Entry.new()
|
||||
self.revision = entry = Gtk.Entry()
|
||||
hbox.pack_end(entry, False, False, 0)
|
||||
entry.show()
|
||||
label = Gtk.Label.new(_('Revision: '))
|
||||
label = Gtk.Label(label=_('Revision: '))
|
||||
hbox.pack_end(label, False, False, 0)
|
||||
label.show()
|
||||
|
||||
|
@ -122,15 +121,21 @@ class NumericDialog(Gtk.Dialog):
|
|||
self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT)
|
||||
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)
|
||||
|
||||
hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
|
||||
label = Gtk.Label.new(text)
|
||||
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
|
||||
label = Gtk.Label(label=text)
|
||||
hbox.pack_start(label, False, False, 0)
|
||||
label.show()
|
||||
adj = Gtk.Adjustment.new(val, lower, upper, step, page, 0)
|
||||
self.button = button = Gtk.SpinButton.new(adj, 1.0, 0)
|
||||
adj = Gtk.Adjustment(
|
||||
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)
|
||||
hbox.pack_start(button, True, True, 0)
|
||||
button.show()
|
||||
|
@ -152,11 +157,11 @@ class SearchDialog(Gtk.Dialog):
|
|||
self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT)
|
||||
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)
|
||||
|
||||
hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
|
||||
label = Gtk.Label.new(_('Search For: '))
|
||||
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
|
||||
label = Gtk.Label(label=_('Search For: '))
|
||||
hbox.pack_start(label, False, False, 0)
|
||||
label.show()
|
||||
combo = Gtk.ComboBoxText.new_with_entry()
|
||||
|
@ -167,7 +172,7 @@ class SearchDialog(Gtk.Dialog):
|
|||
self.entry.set_text(pattern)
|
||||
|
||||
if history is not None:
|
||||
completion = Gtk.EntryCompletion.new()
|
||||
completion = Gtk.EntryCompletion()
|
||||
liststore = Gtk.ListStore(GObject.TYPE_STRING)
|
||||
completion.set_model(liststore)
|
||||
completion.set_text_column(0)
|
||||
|
|
|
@ -61,14 +61,14 @@ class NotebookTab(Gtk.EventBox):
|
|||
def __init__(self, name: str, stock: str) -> None:
|
||||
Gtk.EventBox.__init__(self)
|
||||
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:
|
||||
image = Gtk.Image.new()
|
||||
image = Gtk.Image()
|
||||
image.set_from_stock(stock, Gtk.IconSize.MENU)
|
||||
hbox.pack_start(image, False, False, 5)
|
||||
image.show()
|
||||
|
||||
label = Gtk.Label.new(name)
|
||||
label = Gtk.Label(label=name)
|
||||
# left justify the widget
|
||||
label.set_xalign(0.0)
|
||||
label.set_yalign(0.5)
|
||||
|
@ -76,9 +76,9 @@ class NotebookTab(Gtk.EventBox):
|
|||
label.show()
|
||||
self.label = label
|
||||
|
||||
button = Gtk.Button.new()
|
||||
button = Gtk.Button()
|
||||
button.set_relief(Gtk.ReliefStyle.NONE)
|
||||
image = Gtk.Image.new()
|
||||
image = Gtk.Image()
|
||||
image.set_from_stock(Gtk.STOCK_CLOSE, Gtk.IconSize.MENU)
|
||||
button.add(image)
|
||||
image.show()
|
||||
|
@ -134,7 +134,7 @@ class Diffuse(Gtk.Window):
|
|||
[Gtk.STOCK_SAVE, self.button_cb, 'save', _('Save File')],
|
||||
[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_ellipsize(Pango.EllipsizeMode.START)
|
||||
label.set_max_width_chars(1)
|
||||
|
@ -181,23 +181,23 @@ class Diffuse(Gtk.Window):
|
|||
class PaneFooter(Gtk.Box):
|
||||
def __init__(self) -> None:
|
||||
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.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.encoding = label = Gtk.Label.new()
|
||||
self.encoding = label = Gtk.Label()
|
||||
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.format = label = Gtk.Label.new()
|
||||
self.format = label = Gtk.Label()
|
||||
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.set_size_request(0, self.get_size_request()[1])
|
||||
|
@ -905,7 +905,7 @@ class Diffuse(Gtk.Window):
|
|||
menu_bar.show()
|
||||
|
||||
# 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, [
|
||||
[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
|
||||
|
@ -936,14 +936,14 @@ class Diffuse(Gtk.Window):
|
|||
hbox.show()
|
||||
|
||||
self.closed_tabs = []
|
||||
self.notebook = notebook = Gtk.Notebook.new()
|
||||
self.notebook = notebook = Gtk.Notebook()
|
||||
notebook.set_scrollable(True)
|
||||
notebook.connect('switch-page', self.switch_page_cb)
|
||||
vbox.pack_start(notebook, True, True, 0)
|
||||
notebook.show()
|
||||
|
||||
# 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)
|
||||
statusbar.show()
|
||||
|
||||
|
@ -1056,15 +1056,15 @@ class Diffuse(Gtk.Window):
|
|||
dialog.set_resizable(True)
|
||||
dialog.set_title(constants.APP_NAME)
|
||||
# add list of files with unsaved changes
|
||||
sw = Gtk.ScrolledWindow.new()
|
||||
sw = Gtk.ScrolledWindow()
|
||||
sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
|
||||
treeview = Gtk.TreeView.new_with_model(model)
|
||||
r = Gtk.CellRendererToggle.new()
|
||||
r = Gtk.CellRendererToggle()
|
||||
r.connect('toggled', self._confirmClose_toggle_cb, model)
|
||||
column = Gtk.TreeViewColumn(None, r)
|
||||
column.add_attribute(r, 'active', 0)
|
||||
treeview.append_column(column)
|
||||
r = Gtk.CellRendererText.new()
|
||||
r = Gtk.CellRendererText()
|
||||
column = Gtk.TreeViewColumn(_('Tab'), r, text=1)
|
||||
column.set_resizable(True)
|
||||
column.set_expand(True)
|
||||
|
@ -1137,7 +1137,7 @@ class Diffuse(Gtk.Window):
|
|||
self.remove_tab_cb(widget, data)
|
||||
elif event.button == 3:
|
||||
# create a popup to pick a tab for focus on RMB
|
||||
menu = Gtk.Menu.new()
|
||||
menu = Gtk.Menu()
|
||||
nb = self.notebook
|
||||
for i in range(nb.get_n_pages()):
|
||||
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
|
||||
def _create_menu_bar(specs, radio, accel_group):
|
||||
menu_bar = Gtk.MenuBar.new()
|
||||
menu_bar = Gtk.MenuBar()
|
||||
for label, spec in specs:
|
||||
menu = Gtk.MenuItem.new_with_mnemonic(label)
|
||||
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):
|
||||
for spec in specs:
|
||||
if len(spec) > 0:
|
||||
button = Gtk.Button.new()
|
||||
button = Gtk.Button()
|
||||
button.set_relief(Gtk.ReliefStyle.NONE)
|
||||
button.set_can_focus(False)
|
||||
image = Gtk.Image.new()
|
||||
image = Gtk.Image()
|
||||
image.set_from_stock(spec[0], size)
|
||||
button.add(image)
|
||||
image.show()
|
||||
|
@ -1714,7 +1714,7 @@ def _append_buttons(box, size, specs):
|
|||
box.pack_start(button, False, False, 0)
|
||||
button.show()
|
||||
else:
|
||||
separator = Gtk.Separator.new(Gtk.Orientation.VERTICAL)
|
||||
separator = Gtk.Separator(orientation=Gtk.Orientation.VERTICAL)
|
||||
box.pack_start(separator, False, False, 5)
|
||||
separator.show()
|
||||
|
||||
|
|
|
@ -306,11 +306,11 @@ class Preferences:
|
|||
def _buildPrefsDialog(self, parent, widgets, template):
|
||||
tpl_section = template[0]
|
||||
if tpl_section == 'FolderSet':
|
||||
notebook = Gtk.Notebook.new()
|
||||
notebook = Gtk.Notebook()
|
||||
notebook.set_border_width(10)
|
||||
i = 1
|
||||
while i < len(template):
|
||||
label = Gtk.Label.new(template[i])
|
||||
label = Gtk.Label(label=template[i])
|
||||
i += 1
|
||||
w = self._buildPrefsDialog(parent, widgets, template[i])
|
||||
i += 1
|
||||
|
@ -319,7 +319,7 @@ class Preferences:
|
|||
label.show()
|
||||
return notebook
|
||||
|
||||
table = Gtk.Grid.new()
|
||||
table = Gtk.Grid()
|
||||
table.set_border_width(10)
|
||||
for i, tpl in enumerate(template[1:]):
|
||||
tpl_section = tpl[0]
|
||||
|
@ -335,21 +335,28 @@ class Preferences:
|
|||
button.connect('toggled', self._toggled_cb, widgets, tpl[1])
|
||||
button.show()
|
||||
else:
|
||||
label = Gtk.Label.new(tpl[3] + ': ')
|
||||
label = Gtk.Label(label=tpl[3] + ': ')
|
||||
label.set_xalign(1.0)
|
||||
label.set_yalign(0.5)
|
||||
table.attach(label, 0, i, 1, 1)
|
||||
label.show()
|
||||
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':
|
||||
button = Gtk.FontButton()
|
||||
button.set_font(self.string_prefs[tpl[1]])
|
||||
else:
|
||||
button = Gtk.SpinButton.new(
|
||||
Gtk.Adjustment.new(self.int_prefs[tpl[1]], tpl[4], tpl[5], 1, 0, 0),
|
||||
1.0,
|
||||
0)
|
||||
adj = Gtk.Adjustment(
|
||||
value=self.int_prefs[tpl[1]],
|
||||
lower=tpl[4],
|
||||
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
|
||||
entry.pack_start(button, False, False, 0)
|
||||
button.show()
|
||||
|
@ -360,7 +367,7 @@ class Preferences:
|
|||
elif tpl[0] == 'File':
|
||||
entry = _FileEntry(parent, tpl[3])
|
||||
else:
|
||||
entry = Gtk.Entry.new()
|
||||
entry = Gtk.Entry()
|
||||
widgets[tpl[1]] = entry
|
||||
entry.set_text(self.string_prefs[tpl[1]])
|
||||
table.attach(entry, 1, i, 1, 1)
|
||||
|
@ -443,11 +450,11 @@ class _FileEntry(Gtk.Box):
|
|||
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
|
||||
self.toplevel = parent
|
||||
self.title = title
|
||||
self.entry = entry = Gtk.Entry.new()
|
||||
self.entry = entry = Gtk.Entry()
|
||||
self.pack_start(entry, True, True, 0)
|
||||
entry.show()
|
||||
button = Gtk.Button.new()
|
||||
image = Gtk.Image.new()
|
||||
button = Gtk.Button()
|
||||
image = Gtk.Image()
|
||||
image.set_from_stock(Gtk.STOCK_OPEN, Gtk.IconSize.MENU)
|
||||
button.add(image)
|
||||
image.show()
|
||||
|
|
|
@ -57,7 +57,7 @@ class MessageDialog(Gtk.MessageDialog):
|
|||
class EncodingMenu(Gtk.Box):
|
||||
def __init__(self, prefs: Preferences, autodetect: bool = False) -> None:
|
||||
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL)
|
||||
self.combobox = combobox = Gtk.ComboBoxText.new()
|
||||
self.combobox = combobox = Gtk.ComboBoxText()
|
||||
self.encodings = prefs.getEncodings()[:]
|
||||
for e in self.encodings:
|
||||
combobox.append_text(e)
|
||||
|
|
|
@ -63,8 +63,8 @@ class ScrolledWindow(Gtk.Grid):
|
|||
self.partial_redraw = False
|
||||
|
||||
self.hadj, self.vadj = hadj, vadj
|
||||
vport = Gtk.Viewport.new()
|
||||
darea = Gtk.DrawingArea.new()
|
||||
vport = Gtk.Viewport()
|
||||
darea = Gtk.DrawingArea()
|
||||
darea.add_events(Gdk.EventMask.SCROLL_MASK)
|
||||
self.darea = darea
|
||||
# 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.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.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.hbar.show()
|
||||
|
||||
|
@ -319,8 +319,20 @@ class FileDiffViewerBase(Gtk.Grid):
|
|||
# create panes
|
||||
self.dareas: List[Gtk.DrawingArea] = []
|
||||
self.panes: List[FileDiffViewerBase.Pane] = []
|
||||
self.hadj = Gtk.Adjustment.new(0, 0, 0, 0, 0, 0)
|
||||
self.vadj = Gtk.Adjustment.new(0, 0, 0, 0, 0, 0)
|
||||
self.hadj = Gtk.Adjustment(
|
||||
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):
|
||||
pane = FileDiffViewerBase.Pane()
|
||||
self.panes.append(pane)
|
||||
|
@ -343,7 +355,7 @@ class FileDiffViewerBase(Gtk.Grid):
|
|||
self.vadj.connect('value-changed', self.vadj_changed_cb)
|
||||
|
||||
# add diff map
|
||||
self.diffmap = diffmap = Gtk.DrawingArea.new()
|
||||
self.diffmap = diffmap = Gtk.DrawingArea()
|
||||
diffmap.add_events(Gdk.EventMask.BUTTON_PRESS_MASK |
|
||||
Gdk.EventMask.BUTTON1_MOTION_MASK |
|
||||
Gdk.EventMask.SCROLL_MASK)
|
||||
|
@ -361,7 +373,7 @@ class FileDiffViewerBase(Gtk.Grid):
|
|||
self.connect('key-press-event', self.key_press_cb)
|
||||
|
||||
# input method
|
||||
self.im_context = im = Gtk.IMMulticontext.new()
|
||||
self.im_context = im = Gtk.IMMulticontext()
|
||||
im.connect('commit', self.im_commit_cb)
|
||||
im.connect('preedit-changed', self.im_preedit_changed_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
|
||||
def createMenu(specs, radio=None, accel_group=None):
|
||||
menu = Gtk.Menu.new()
|
||||
menu = Gtk.Menu()
|
||||
for spec in specs:
|
||||
if len(spec) > 0:
|
||||
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]
|
||||
item.connect('activate', cb, data)
|
||||
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)
|
||||
item.set_image(image)
|
||||
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_use_underline(True)
|
||||
else:
|
||||
item = Gtk.SeparatorMenuItem.new()
|
||||
item = Gtk.SeparatorMenuItem()
|
||||
item.show()
|
||||
menu.append(item)
|
||||
return menu
|
||||
|
|
Loading…
Reference in New Issue