Skip to content

Commit da06235

Browse files
committed
Use kwargs when instantiating GTK objects
Due to API changes, positional arguments for Gtk.Label/Button etc instantiation is deprecated. Instead, kwargs are to be used. Ref.: #233
1 parent f73d4ac commit da06235

File tree

14 files changed

+58
-52
lines changed

14 files changed

+58
-52
lines changed

hamster_gtk/hamster_gtk.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def __init__(self, app, *args, **kwargs):
7070

7171
def _get_overview_button(self):
7272
"""Return a button to open the ``Overview`` dialog."""
73-
button = Gtk.Button(_("Overview"))
73+
button = Gtk.Button(label=_("Overview"))
7474
button.connect('clicked', self._on_overview_button)
7575
return button
7676

hamster_gtk/misc/dialogs/date_range_select_dialog.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def daterange(self, daterange):
8787

8888
# Widgets
8989
def _get_apply_button(self):
90-
button = Gtk.Button(_('_Apply'), use_underline=True)
90+
button = Gtk.Button(label=_('_Apply'), use_underline=True)
9191
return button
9292

9393
def _get_today_widget(self):
@@ -128,11 +128,11 @@ def _get_end_calendar(self):
128128

129129
def _get_custom_range_label(self):
130130
"""Return a 'heading' label for the widget."""
131-
return Gtk.Label(_("Custom Range"))
131+
return Gtk.Label(label=_("Custom Range"))
132132

133133
def _get_custom_range_connection_label(self):
134134
"""Return the label to be displayed between the two calendars."""
135-
return Gtk.Label(_("to"))
135+
return Gtk.Label(label=_("to"))
136136

137137
# Helper
138138
def _get_double_label_button(self, left_label, right_label):
@@ -145,11 +145,11 @@ def _get_double_label_button(self, left_label, right_label):
145145
grid = Gtk.Grid()
146146
button.add(grid)
147147

148-
left_label = Gtk.Label(left_label)
148+
left_label = Gtk.Label(label=left_label)
149149
left_label.set_hexpand(True)
150150
left_label.set_halign(Gtk.Align.START)
151151

152-
right_label = Gtk.Label(right_label)
152+
right_label = Gtk.Label(label=right_label)
153153
right_label.set_hexpand(True)
154154
right_label.set_halign(Gtk.Align.END)
155155

hamster_gtk/misc/dialogs/edit_fact_dialog.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def _get_main_box(self):
108108

109109
def _get_old_fact_widget(self):
110110
"""Return a widget representing the fact to be edited."""
111-
label = Gtk.Label(text_type(self._fact))
111+
label = Gtk.Label(label=text_type(self._fact))
112112
label.set_hexpand(True)
113113
label.set_name('EditDialogOldFactLabel')
114114
return label
@@ -156,12 +156,12 @@ def _get_description_widget(self):
156156

157157
def _get_delete_button(self):
158158
"""Return a *delete* button."""
159-
return Gtk.Button(_('_Delete'), use_underline=True)
159+
return Gtk.Button(label=_('_Delete'), use_underline=True)
160160

161161
def _get_apply_button(self):
162162
"""Return a *apply* button."""
163-
return Gtk.Button(_('_Apply'), use_underline=True)
163+
return Gtk.Button(label=_('_Apply'), use_underline=True)
164164

165165
def _get_cancel_button(self):
166166
"""Return a *cancel* button."""
167-
return Gtk.Button(_('_Cancel'), use_underline=True)
167+
return Gtk.Button(label=_('_Cancel'), use_underline=True)

hamster_gtk/misc/widgets/labelled_widgets_grid.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self, fields=None):
4444

4545
row = 0
4646
for key, (label, widget) in self._fields.items():
47-
label_widget = Gtk.Label(label)
47+
label_widget = Gtk.Label(label=label)
4848
label_widget.set_use_underline(True)
4949
label_widget.set_mnemonic_widget(widget)
5050
self.attach(label_widget, 0, row, 1, 1)

hamster_gtk/overview/dialogs/overview_dialog.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def refresh(self):
124124
self.totals_panel = widgets.Summary(self._get_highest_totals(self._totals.category, 3))
125125
self.main_box.pack_start(self.totals_panel, False, False, 0)
126126

127-
charts_button = Gtk.Button('click to show more details ...')
127+
charts_button = Gtk.Button(label='click to show more details ...')
128128
if not self._facts:
129129
charts_button.set_sensitive(False)
130130
charts_button.connect('clicked', self._on_charts_button)

hamster_gtk/overview/widgets/charts.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import operator
2323

24-
from gi.repository import GObject, Gtk
24+
from gi.repository import GObject, Gtk, GLib
2525

2626
from hamster_gtk import helpers
2727

@@ -39,11 +39,11 @@ def __init__(self, totals):
3939
"""Initialize widget."""
4040
super(Charts, self).__init__()
4141
self.set_column_spacing(20)
42-
self.attach(Gtk.Label('Categories'), 0, 0, 1, 1)
42+
self.attach(Gtk.Label(label='Categories'), 0, 0, 1, 1)
4343
self.attach(self._get_barcharts(totals.category), 0, 1, 1, 1)
44-
self.attach(Gtk.Label('Activities'), 1, 0, 1, 1)
44+
self.attach(Gtk.Label(label='Activities'), 1, 0, 1, 1)
4545
self.attach(self._get_barcharts(totals.activity), 1, 1, 1, 1)
46-
self.attach(Gtk.Label('Dates'), 2, 0, 1, 1)
46+
self.attach(Gtk.Label(label='Dates'), 2, 0, 1, 1)
4747
self.attach(self._get_barcharts(totals.date), 2, 1, 1, 1)
4848

4949
def _get_barcharts(self, totals):
@@ -87,7 +87,7 @@ def _get_barcharts(self, totals):
8787
delta_label = Gtk.Label()
8888
delta_label.set_selectable(True)
8989
delta_label.set_halign(Gtk.Align.START)
90-
delta_label.set_markup("<small>{}</small>".format(GObject.markup_escape_text(
90+
delta_label.set_markup("<small>{}</small>".format(GLib.markup_escape_text(
9191
helpers.get_delta_string(delta))))
9292
grid.attach(category_label, 0, row, 1, 1)
9393
grid.attach(bar_chart, 1, row, 1, 1)

hamster_gtk/overview/widgets/fact_grid.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import operator
2626

27-
from gi.repository import GObject, Gtk
27+
from gi.repository import GObject, Gtk, GLib
2828

2929
from hamster_gtk import helpers
3030
from hamster_gtk.misc.dialogs import EditFactDialog
@@ -65,7 +65,7 @@ def _get_date_widget(self, date):
6565
date_box.set_name('DayRowDateBox')
6666
date_label = Gtk.Label()
6767
date_label.set_name('OverviewDateLabel')
68-
date_label.set_markup("<b>{}</b>".format(GObject.markup_escape_text(date_string)))
68+
date_label.set_markup("<b>{}</b>".format(GLib.markup_escape_text(date_string)))
6969
date_label.set_valign(Gtk.Align.START)
7070
date_label.set_justify(Gtk.Justification.RIGHT)
7171
date_box.add(date_label)
@@ -165,14 +165,14 @@ def _get_time_widget(self, fact):
165165
""""Return widget to represent ``Fact.start`` and ``Fact.end``."""
166166
start_time = fact.start.strftime('%H:%M')
167167
end_time = fact.end.strftime('%H:%M')
168-
time_label = Gtk.Label('{start} - {end}'.format(start=start_time, end=end_time))
168+
time_label = Gtk.Label(label='{start} - {end}'.format(start=start_time, end=end_time))
169169
time_label.props.valign = Gtk.Align.START
170170
time_label.props.halign = Gtk.Align.START
171171
return time_label
172172

173173
def _get_delta_widget(self, fact):
174174
""""Return widget to represent ``Fact.delta``."""
175-
label = Gtk.Label('{} Minutes'.format(fact.get_string_delta()))
175+
label = Gtk.Label(label='{} Minutes'.format(fact.get_string_delta()))
176176
label.props.valign = Gtk.Align.START
177177
label.props.halign = Gtk.Align.END
178178
box = Gtk.EventBox()
@@ -211,16 +211,16 @@ def _get_activity_widget(self, fact):
211211
category = str(fact.category)
212212
activity_label = Gtk.Label()
213213
activity_label.set_markup("{activity} - {category}".format(
214-
activity=GObject.markup_escape_text(fact.activity.name),
215-
category=GObject.markup_escape_text(category)))
214+
activity=GLib.markup_escape_text(fact.activity.name),
215+
category=GLib.markup_escape_text(category)))
216216
activity_label.props.halign = Gtk.Align.START
217217
return activity_label
218218

219219
def _get_tags_widget(self, fact):
220220
"""Return widget to represent ``Fact.tags``."""
221221
def get_tag_widget(name):
222222
tag_label = Gtk.Label()
223-
tag_label.set_markup("<small>{}</small>".format(GObject.markup_escape_text(name)))
223+
tag_label.set_markup("<small>{}</small>".format(GLib.markup_escape_text(name)))
224224
tag_label.set_name('OverviewTagLabel')
225225
tag_box = Gtk.EventBox()
226226
tag_box.set_name('OverviewTagBox')
@@ -240,6 +240,6 @@ def _get_description_widget(self, fact):
240240
description_label.set_name('OverviewDescriptionLabel')
241241
description_label.set_line_wrap(True)
242242
description_label.set_markup("<small><i>{}</i></small>".format(
243-
GObject.markup_escape_text(fact.description)))
243+
GLib.markup_escape_text(fact.description)))
244244
description_label.props.halign = Gtk.Align.START
245245
return description_label

hamster_gtk/overview/widgets/misc.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from gettext import gettext as _
2323

24-
from gi.repository import GObject, Gtk
24+
from gi.repository import GObject, Gtk, GLib
2525
from six import text_type
2626

2727
from hamster_gtk.helpers import get_parent_window
@@ -48,27 +48,27 @@ def __init__(self, controller, *args, **kwargs):
4848
# Widgets
4949
def _get_export_button(self):
5050
"""Return a button to export facts."""
51-
button = Gtk.Button(_("Export"))
51+
button = Gtk.Button(label=_("Export"))
5252
button.connect('clicked', self._on_export_button_clicked)
5353
return button
5454

5555
def _get_daterange_button(self):
5656
"""Return a button that opens the *select daterange* dialog."""
5757
# We add a dummy label which will be set properly once a daterange is
5858
# set.
59-
button = Gtk.Button('')
59+
button = Gtk.Button(label='')
6060
button.connect('clicked', self._on_daterange_button_clicked)
6161
return button
6262

6363
def _get_prev_daterange_button(self):
6464
"""Return a 'previous dateframe' widget."""
65-
button = Gtk.Button(_("Earlier"))
65+
button = Gtk.Button(label=_("Earlier"))
6666
button.connect('clicked', self._on_previous_daterange_button_clicked)
6767
return button
6868

6969
def _get_next_daterange_button(self):
7070
"""Return a 'next dateframe' widget."""
71-
button = Gtk.Button(_("Later"))
71+
button = Gtk.Button(label=_("Later"))
7272
button.connect('clicked', self._on_next_daterange_button_clicked)
7373
return button
7474

@@ -128,6 +128,6 @@ def __init__(self, category_totals):
128128
for category, total in category_totals:
129129
label = Gtk.Label()
130130
label.set_markup("<b>{}:</b> {} minutes".format(
131-
GObject.markup_escape_text(text_type(category)),
131+
GLib.markup_escape_text(text_type(category)),
132132
int(total.total_seconds() / 60)))
133133
self.pack_start(label, False, False, 10)

hamster_gtk/preferences/preferences_dialog.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from gettext import gettext as _
2727

2828
import hamster_lib
29-
from gi.repository import GObject, Gtk
29+
from gi.repository import GObject, Gtk, GLib
3030

3131
from hamster_gtk.misc.widgets import LabelledWidgetsGrid
3232
from hamster_gtk.preferences.widgets import (ComboFileChooser,
@@ -66,7 +66,7 @@ def __init__(self, parent, app, initial, *args, **kwargs):
6666
(_('Tracking'), LabelledWidgetsGrid(collections.OrderedDict([
6767
('day_start', (_('_Day Start (HH:MM:SS)'), TimeEntry())),
6868
('fact_min_delta', (_('_Minimal Fact Duration'),
69-
HamsterSpinButton(SimpleAdjustment(0, GObject.G_MAXDOUBLE, 1)))),
69+
HamsterSpinButton(SimpleAdjustment(0, GLib.MAXDOUBLE, 1)))),
7070
]))),
7171
(_('Storage'), LabelledWidgetsGrid(collections.OrderedDict([
7272
('store', (_('_Store'), HamsterComboBoxText(stores))),
@@ -76,7 +76,7 @@ def __init__(self, parent, app, initial, *args, **kwargs):
7676
]))),
7777
(_('Miscellaneous'), LabelledWidgetsGrid(collections.OrderedDict([
7878
('autocomplete_activities_range', (_("Autocomplete Activities Range"),
79-
HamsterSpinButton(SimpleAdjustment(0, GObject.G_MAXDOUBLE, 1)))),
79+
HamsterSpinButton(SimpleAdjustment(0, GLib.MAXDOUBLE, 1)))),
8080
('autocomplete_split_activity',
8181
(_("Autocomplete activities and categories separately"),
8282
HamsterSwitch())),
@@ -87,7 +87,7 @@ def __init__(self, parent, app, initial, *args, **kwargs):
8787
notebook.set_name('PreferencesNotebook')
8888

8989
for title, page in self._pages:
90-
notebook.append_page(page, Gtk.Label(title))
90+
notebook.append_page(page, Gtk.Label(label=title))
9191

9292
if initial:
9393
self._set_config(initial)

hamster_gtk/preferences/widgets/combo_file_chooser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(self):
4747
self._entry = Gtk.Entry()
4848
self._entry.set_hexpand(True)
4949

50-
self._button = Gtk.Button(_("Choose"))
50+
self._button = Gtk.Button(label=_("Choose"))
5151
self._button.connect('clicked', self._on_choose_clicked)
5252

5353
self.attach(self._entry, 0, 0, 1, 1)

hamster_gtk/preferences/widgets/hamster_spin_button.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ def __init__(self, adjustment=None, climb_rate=0, digits=0):
6262
if adjustment is not None:
6363
if isinstance(adjustment, SimpleAdjustment):
6464
self._validate_simple_adjustment(adjustment)
65-
adjustment = Gtk.Adjustment(adjustment.min, adjustment.min, adjustment.max,
66-
adjustment.step, 10 * adjustment.step, 0)
65+
adjustment = Gtk.Adjustment(
66+
value=adjustment.min,
67+
lower=adjustment.min,
68+
upper=adjustment.max,
69+
step_increment=adjustment.step, page_increment=(10 * adjustment.step),
70+
page_size=0
71+
)
6772
elif not isinstance(adjustment, Gtk.Adjustment):
6873
raise ValueError('Instance of SimpleAdjustment or Gtk.Adjustment is expected.')
6974

hamster_gtk/tracking/screens.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,21 @@ def update(self, fact=None):
107107

108108
def _get_fact_label(self, fact):
109109
text = '{fact}'.format(fact=fact)
110-
return Gtk.Label(text)
110+
return Gtk.Label(label=text)
111111

112112
def _get_cancel_button(self):
113-
cancel_button = Gtk.Button(_('Cancel'))
113+
cancel_button = Gtk.Button(label=_('Cancel'))
114114
cancel_button.connect('clicked', self._on_cancel_button)
115115
return cancel_button
116116

117117
def _get_save_button(self):
118-
save_button = Gtk.Button(_('Stop & Save'))
118+
save_button = Gtk.Button(label=_('Stop & Save'))
119119
save_button.connect('clicked', self._on_save_button)
120120
return save_button
121121

122122
def _get_invalid_label(self):
123123
"""Return placeholder in case there is no current ongoing fact present."""
124-
return Gtk.Label(_("There currently is no ongoing fact that could be displayed."))
124+
return Gtk.Label(label=_("There currently is no ongoing fact that could be displayed."))
125125

126126
# Callbacks
127127
def _on_cancel_button(self, button):
@@ -174,7 +174,7 @@ def __init__(self, app, *args, **kwargs):
174174
# Refactor to call separate 'get_widget' methods instead.
175175
# Introduction text
176176
text = _('Currently no tracked activity. Want to start one?')
177-
self.current_fact_label = Gtk.Label(text)
177+
self.current_fact_label = Gtk.Label(label=text)
178178
self.pack_start(self.current_fact_label, False, False, 0)
179179

180180
# Fact entry field

tests/preferences/widgets/conftest.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ def paths(request, faker):
6161
@pytest.fixture
6262
def adjustment(request, numbers):
6363
"""Return a list of random numbers."""
64-
value = sorted(numbers)[len(numbers) // 2]
65-
lower = min(numbers)
66-
upper = max(numbers)
67-
step_increment = 1
68-
page_increment = 5
69-
page_size = 0
70-
return Gtk.Adjustment(value, lower, upper, step_increment, page_increment, page_size)
64+
return Gtk.Adjustment(
65+
value=sorted(numbers)[len(numbers) // 2],
66+
lower=min(numbers),
67+
upper=max(numbers),
68+
step_increment=1,
69+
page_increment=5,
70+
page_size=0
71+
)
7172

7273

7374
@pytest.fixture

tests/test_helpers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
def test_get_parent_window_standalone(request):
1313
"""Make sure the parent window of a windowless widget is None."""
14-
label = Gtk.Label('foo')
14+
label = Gtk.Label(label='foo')
1515
assert helpers.get_parent_window(label) is None
1616

1717

1818
def test_get_parent_window(request):
1919
"""Make sure the parent window of a widget placed in the window is determined correctly."""
2020
window = Gtk.Window()
21-
label = Gtk.Label('foo')
21+
label = Gtk.Label(label='foo')
2222
window.add(label)
2323
assert helpers.get_parent_window(label) == window
2424

0 commit comments

Comments
 (0)