Skip to content

Commit ee813f2

Browse files
committed
Remove deprecated STOCK constant
1 parent 47a02d7 commit ee813f2

File tree

4 files changed

+56
-53
lines changed

4 files changed

+56
-53
lines changed

src/diffuse/dialogs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _current_folder_changed_cb(widget):
7777

7878
def __init__(self, title, parent, prefs, action, accept, rev=False):
7979
Gtk.FileChooserDialog.__init__(self, title=title, transient_for=parent, action=action)
80-
self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
80+
self.add_button(_('_Cancel'), Gtk.ResponseType.CANCEL)
8181
self.add_button(accept, Gtk.ResponseType.OK)
8282
self.prefs = prefs
8383
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0, border_width=5)
@@ -120,8 +120,8 @@ def get_filename(self) -> str:
120120
class NumericDialog(Gtk.Dialog):
121121
def __init__(self, parent, title, text, val, lower, upper, step=1, page=0):
122122
Gtk.Dialog.__init__(self, title=title, transient_for=parent, destroy_with_parent=True)
123-
self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT)
124-
self.add_button(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)
123+
self.add_button(_('_Cancel'), Gtk.ResponseType.REJECT)
124+
self.add_button(_('_OK'), Gtk.ResponseType.ACCEPT)
125125

126126
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
127127
vbox.set_border_width(10)
@@ -164,8 +164,8 @@ def __init__(self, parent, pattern=None, history=None):
164164
title=_('Find...'),
165165
transient_for=parent,
166166
destroy_with_parent=True)
167-
self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT)
168-
self.add_button(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)
167+
self.add_button(_('_Cancel'), Gtk.ResponseType.REJECT)
168+
self.add_button(_('_OK'), Gtk.ResponseType.ACCEPT)
169169

170170
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
171171
vbox.set_border_width(10)

src/diffuse/preferences.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ def _toggled_cb(self, widget, widgets, name):
257257
# button was pressed
258258
def runDialog(self, parent: Gtk.Widget) -> None:
259259
dialog = Gtk.Dialog(_('Preferences'), parent=parent, destroy_with_parent=True)
260-
dialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT)
261-
dialog.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK)
260+
dialog.add_button(_('_Cancel'), Gtk.ResponseType.REJECT)
261+
dialog.add_button(_('_OK'), Gtk.ResponseType.OK)
262262

263263
widgets: Dict[str, Gtk.Widget] = {}
264264
w = self._buildPrefsDialog(parent, widgets, self.template)
@@ -473,7 +473,7 @@ def __init__(self, parent: Gtk.Widget, title: str) -> None:
473473
entry.show()
474474
button = Gtk.Button()
475475
image = Gtk.Image()
476-
image.set_from_stock(Gtk.STOCK_OPEN, Gtk.IconSize.MENU)
476+
image.set_from_icon_name('document-open-symbolic', Gtk.IconSize.MENU)
477477
button.add(image)
478478
image.show()
479479
button.connect('clicked', self.chooseFile)
@@ -486,7 +486,7 @@ def chooseFile(self, widget: Gtk.Widget) -> None:
486486
self.title,
487487
self.toplevel,
488488
Gtk.FileChooserAction.OPEN,
489-
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
489+
(_('_Cancel'), Gtk.ResponseType.CANCEL, _('_Open'), Gtk.ResponseType.OK))
490490
dialog.set_current_folder(os.path.realpath(os.curdir))
491491
if dialog.run() == Gtk.ResponseType.OK:
492492
self.entry.set_text(dialog.get_filename())

src/diffuse/widgets.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,16 +1854,16 @@ def darea_button_press_cb(self, widget, event, f):
18541854
can_swap = (f != self.current_pane)
18551855

18561856
menu = self._create_menu([
1857-
[_('Align with Selection'), self.align_with_selection_cb, [f, i], Gtk.STOCK_EXECUTE, can_align], # noqa: E501
1857+
[_('Align with Selection'), self.align_with_selection_cb, [f, i], 'system-run-symbolic', can_align], # noqa: E501
18581858
[_('Isolate'), self.button_cb, 'isolate', None, can_isolate],
18591859
[_('Merge Selection'), self.merge_lines_cb, f, None, can_merge],
18601860
[],
1861-
[_('Cut'), self.button_cb, 'cut', Gtk.STOCK_CUT, can_select],
1862-
[_('Copy'), self.button_cb, 'copy', Gtk.STOCK_COPY, can_select],
1863-
[_('Paste'), self.button_cb, 'paste', Gtk.STOCK_PASTE, can_select],
1861+
[_('Cut'), self.button_cb, 'cut', 'edit-cut-symbolic', can_select],
1862+
[_('Copy'), self.button_cb, 'copy', 'edit-copy-symbolic', can_select],
1863+
[_('Paste'), self.button_cb, 'paste', 'edit-paste-symbolic', can_select],
18641864
[],
18651865
[_('Select All'), self.button_cb, 'select-all', None, can_select],
1866-
[_('Clear Edits'), self.button_cb, 'clear-edits', Gtk.STOCK_CLEAR, can_isolate], # noqa: E501
1866+
[_('Clear Edits'), self.button_cb, 'clear-edits', 'edit-clear-symbolic', can_isolate], # noqa: E501
18671867
[],
18681868
[_('Swap with Selected Pane'), self.swap_panes_cb, f, None, can_swap]
18691869
])
@@ -1875,13 +1875,13 @@ def _create_menu(specs):
18751875
menu = Gtk.Menu()
18761876
for spec in specs:
18771877
if len(spec) > 0:
1878-
(label, cb, cb_data, image_stock_name, sensitive) = spec
1878+
(label, cb, cb_data, image_icon_name, sensitive) = spec
18791879
item = Gtk.ImageMenuItem.new_with_mnemonic(label)
18801880
item.set_use_underline(True)
18811881
item.set_sensitive(sensitive)
1882-
if image_stock_name is not None:
1882+
if image_icon_name is not None:
18831883
image = Gtk.Image()
1884-
image.set_from_stock(image_stock_name, Gtk.IconSize.MENU)
1884+
image.set_from_icon_name(image_icon_name, Gtk.IconSize.MENU)
18851885
item.set_image(image)
18861886
if cb is not None:
18871887
item.connect('activate', cb, cb_data)

src/diffuse/window.py

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ class NotebookTab(Gtk.EventBox):
5757
signals can be connected for MMB and RMB button presses.
5858
"""
5959

60-
def __init__(self, name: str, stock: str) -> None:
60+
def __init__(self, name: str, icon_name: str) -> None:
6161
Gtk.EventBox.__init__(self)
6262
self.set_visible_window(False)
6363
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
64-
if stock is not None:
64+
if icon_name is not None:
6565
image = Gtk.Image()
66-
image.set_from_stock(stock, Gtk.IconSize.MENU)
66+
image.set_from_icon_name(icon_name, Gtk.IconSize.MENU)
6767
hbox.pack_start(image, False, False, 5)
6868
image.show()
6969

@@ -78,7 +78,7 @@ def __init__(self, name: str, stock: str) -> None:
7878
button = Gtk.Button()
7979
button.set_relief(Gtk.ReliefStyle.NONE)
8080
image = Gtk.Image()
81-
image.set_from_stock(Gtk.STOCK_CLOSE, Gtk.IconSize.MENU)
81+
image.set_from_icon_name('window-close-symbolic', Gtk.IconSize.MENU)
8282
button.add(image)
8383
image.show()
8484
button.set_tooltip_text(_('Close Tab'))
@@ -124,10 +124,10 @@ class PaneHeader(Gtk.Box):
124124
def __init__(self) -> None:
125125
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
126126
button_specs = [
127-
[Gtk.STOCK_OPEN, self.button_cb, 'open', _('Open File...')],
128-
[Gtk.STOCK_REFRESH, self.button_cb, 'reload', _('Reload File')],
129-
[Gtk.STOCK_SAVE, self.button_cb, 'save', _('Save File')],
130-
[Gtk.STOCK_SAVE_AS, self.button_cb, 'save_as', _('Save File As...')]
127+
['document-open-symbolic', self.button_cb, 'open', _('Open File...')],
128+
['view-refresh-symbolic', self.button_cb, 'reload', _('Reload File')],
129+
['document-save-symbolic', self.button_cb, 'save', _('Save File')],
130+
['document-save-as-symbolic', self.button_cb, 'save_as', _('Save File As...')]
131131
]
132132
_append_buttons(self, Gtk.IconSize.MENU, button_specs)
133133

@@ -307,9 +307,9 @@ def loadFromInfo(self, f: int, info: FileInfo) -> None:
307307
Gtk.ButtonsType.NONE, _('Save changes before loading the new file?')
308308
)
309309
dialog.set_title(constants.APP_NAME)
310-
dialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
311-
dialog.add_button(Gtk.STOCK_NO, Gtk.ResponseType.REJECT)
312-
dialog.add_button(Gtk.STOCK_YES, Gtk.ResponseType.OK)
310+
dialog.add_button(_('_Cancel'), Gtk.ResponseType.CANCEL)
311+
dialog.add_button(_('_No'), Gtk.ResponseType.REJECT)
312+
dialog.add_button(_('_Yes'), Gtk.ResponseType.OK)
313313
dialog.set_default_response(Gtk.ResponseType.CANCEL)
314314
response = dialog.run()
315315
dialog.destroy()
@@ -444,7 +444,7 @@ def open_file(self, f: int, reload: bool = False) -> None:
444444
self.get_toplevel(),
445445
self.prefs,
446446
Gtk.FileChooserAction.OPEN,
447-
Gtk.STOCK_OPEN,
447+
_('_Open'),
448448
True
449449
)
450450
if info.name is not None:
@@ -497,7 +497,7 @@ def save_file(self, f: int, save_as: bool = False) -> bool:
497497
self.get_toplevel(),
498498
self.prefs,
499499
Gtk.FileChooserAction.SAVE,
500-
Gtk.STOCK_SAVE
500+
_('_Save')
501501
)
502502
if name is not None:
503503
dialog.set_filename(os.path.abspath(name))
@@ -917,25 +917,25 @@ def __init__(self, rc_dir, **kwargs):
917917
[DIFFUSE_STOCK_NEW_2WAY_MERGE, self.new_2_way_file_merge_cb, None, _('New 2-Way File Merge')], # noqa: E501
918918
[DIFFUSE_STOCK_NEW_3WAY_MERGE, self.new_3_way_file_merge_cb, None, _('New 3-Way File Merge')], # noqa: E501
919919
[],
920-
[Gtk.STOCK_EXECUTE, self.button_cb, 'realign-all', _('Realign All')],
921-
[Gtk.STOCK_GOTO_TOP, self.button_cb, 'first-difference', _('First Difference')],
922-
[Gtk.STOCK_GO_UP, self.button_cb, 'previous-difference', _('Previous Difference')],
923-
[Gtk.STOCK_GO_DOWN, self.button_cb, 'next-difference', _('Next Difference')],
924-
[Gtk.STOCK_GOTO_BOTTOM, self.button_cb, 'last-difference', _('Last Difference')],
920+
['system-run-symbolic', self.button_cb, 'realign-all', _('Realign All')],
921+
['go-top-symbolic', self.button_cb, 'first-difference', _('First Difference')],
922+
['go-up-symbolic', self.button_cb, 'previous-difference', _('Previous Difference')],
923+
['go-down-symbolic', self.button_cb, 'next-difference', _('Next Difference')],
924+
['go-bottom-symbolic', self.button_cb, 'last-difference', _('Last Difference')],
925925
[],
926-
[Gtk.STOCK_GOTO_LAST, self.button_cb, 'copy-selection-right', _('Copy Selection Right')], # noqa: E501
927-
[Gtk.STOCK_GOTO_FIRST, self.button_cb, 'copy-selection-left', _('Copy Selection Left')],
928-
[Gtk.STOCK_GO_FORWARD, self.button_cb, 'copy-left-into-selection', _('Copy Left Into Selection')], # noqa: E501
929-
[Gtk.STOCK_GO_BACK, self.button_cb, 'copy-right-into-selection', _('Copy Right Into Selection')], # noqa: E501
926+
['go-last-symbolic', self.button_cb, 'copy-selection-right', _('Copy Selection Right')], # noqa: E501
927+
['go-first-symbolic', self.button_cb, 'copy-selection-left', _('Copy Selection Left')],
928+
['go-next-symbolic', self.button_cb, 'copy-left-into-selection', _('Copy Left Into Selection')], # noqa: E501
929+
['go-previous-symbolic', self.button_cb, 'copy-right-into-selection', _('Copy Right Into Selection')], # noqa: E501
930930
[DIFFUSE_STOCK_LEFT_RIGHT, self.button_cb, 'merge-from-left-then-right', _('Merge From Left Then Right')], # noqa: E501
931931
[DIFFUSE_STOCK_RIGHT_LEFT, self.button_cb, 'merge-from-right-then-left', _('Merge From Right Then Left')], # noqa: E501
932932
[],
933-
[Gtk.STOCK_UNDO, self.button_cb, 'undo', _('Undo')],
934-
[Gtk.STOCK_REDO, self.button_cb, 'redo', _('Redo')],
935-
[Gtk.STOCK_CUT, self.button_cb, 'cut', _('Cut')],
936-
[Gtk.STOCK_COPY, self.button_cb, 'copy', _('Copy')],
937-
[Gtk.STOCK_PASTE, self.button_cb, 'paste', _('Paste')],
938-
[Gtk.STOCK_CLEAR, self.button_cb, 'clear-edits', _('Clear Edits')]
933+
['edit-undo-symbolic', self.button_cb, 'undo', _('Undo')],
934+
['edit-redo-symbolic', self.button_cb, 'redo', _('Redo')],
935+
['edit-cut-symbolic', self.button_cb, 'cut', _('Cut')],
936+
['edit-copy-symbolic', self.button_cb, 'copy', _('Copy')],
937+
['edit-paste-symbolic', self.button_cb, 'paste', _('Paste')],
938+
['edit-clear-symbolic', self.button_cb, 'clear-edits', _('Clear Edits')]
939939
]
940940
_append_buttons(hbox, Gtk.IconSize.LARGE_TOOLBAR, button_specs)
941941
# avoid the button bar from dictating the minimum window size
@@ -1170,11 +1170,11 @@ def confirmCloseViewers(self, viewers: List[FileDiffViewer]) -> bool:
11701170
dialog.vbox.pack_start(sw, True, True, 0)
11711171
sw.show()
11721172
# add custom set of action buttons
1173-
dialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
1173+
dialog.add_button(_('_Cancel'), Gtk.ResponseType.CANCEL)
11741174
button = Gtk.Button.new_with_mnemonic(_('Close _Without Saving'))
11751175
dialog.add_action_widget(button, Gtk.ResponseType.REJECT)
11761176
button.show()
1177-
dialog.add_button(Gtk.STOCK_SAVE, Gtk.ResponseType.OK)
1177+
dialog.add_button(_('_Save'), Gtk.ResponseType.OK)
11781178
dialog.set_default_response(Gtk.ResponseType.CANCEL)
11791179
response = dialog.run()
11801180
dialog.destroy()
@@ -1288,7 +1288,7 @@ def syntax_changed_cb(self, widget, s):
12881288
def newFileDiffViewer(self, n: int) -> FileDiffViewer:
12891289
self.viewer_count += 1
12901290
tabname = _('File Merge %d') % (self.viewer_count, )
1291-
tab = NotebookTab(tabname, Gtk.STOCK_FILE)
1291+
tab = NotebookTab(tabname, 'text-x-generic-symbolic')
12921292
viewer = FileDiffViewer(n, self.prefs, tabname)
12931293
tab.button.connect('clicked', self.remove_tab_cb, viewer)
12941294
tab.connect('button-press-event', self.notebooktab_button_press_cb, viewer)
@@ -1476,7 +1476,7 @@ def open_file_in_new_tab_cb(self, widget, data):
14761476
self.get_toplevel(),
14771477
self.prefs,
14781478
Gtk.FileChooserAction.OPEN,
1479-
Gtk.STOCK_OPEN,
1479+
_('_Open'),
14801480
True
14811481
)
14821482
dialog.set_default_response(Gtk.ResponseType.OK)
@@ -1499,7 +1499,7 @@ def open_modified_files_cb(self, widget, data):
14991499
parent,
15001500
self.prefs,
15011501
Gtk.FileChooserAction.SELECT_FOLDER,
1502-
Gtk.STOCK_OPEN
1502+
_('_Open')
15031503
)
15041504
dialog.set_default_response(Gtk.ResponseType.OK)
15051505
accept = (dialog.run() == Gtk.ResponseType.OK)
@@ -1522,7 +1522,7 @@ def open_commit_cb(self, widget, data):
15221522
_('Choose Folder With Commit'),
15231523
parent, self.prefs,
15241524
Gtk.FileChooserAction.SELECT_FOLDER,
1525-
Gtk.STOCK_OPEN,
1525+
_('_Open'),
15261526
True
15271527
)
15281528
dialog.set_default_response(Gtk.ResponseType.OK)
@@ -1806,12 +1806,15 @@ def _append_buttons(box, size, specs):
18061806
"""Convenience method for packing buttons into a container."""
18071807
for spec in specs:
18081808
if len(spec) > 0:
1809-
(stock_id, cb, cb_data, label) = spec
1809+
(icon_name, cb, cb_data, label) = spec
18101810
button = Gtk.Button()
18111811
button.set_relief(Gtk.ReliefStyle.NONE)
18121812
button.set_can_focus(False)
18131813
image = Gtk.Image()
1814-
image.set_from_stock(stock_id, size)
1814+
if icon_name.startswith('diffuse'):
1815+
image.set_from_stock(icon_name, size)
1816+
else:
1817+
image.set_from_icon_name(icon_name, size)
18151818
button.add(image)
18161819
image.show()
18171820
button.connect('clicked', cb, cb_data)

0 commit comments

Comments
 (0)