Skip to content

Commit

Permalink
Fix deprecation warnings
Browse files Browse the repository at this point in the history
Fixes the PyGTKDeprecationWarning outputs in terminal, mostly related
to positional arguments.

Added a `make test` command to quickly check that examples run and view
output in terminal for deprecated warnings.

Fixes: #150
  • Loading branch information
cas-- committed Jun 4, 2019
1 parent f8d443c commit dba418b
Show file tree
Hide file tree
Showing 24 changed files with 155 additions and 113 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ help:

.PHONY: help Makefile

.PHONY: test
test:
cd examples && for file in *.py; do \
echo $$file; \
xvfb-run -a timeout -k 1 0.4 python3 -u $$file; \
done


# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
Expand Down
2 changes: 1 addition & 1 deletion examples/cellrendererspin_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self):
renderer_spin.connect("edited", self.on_amount_edited)
renderer_spin.set_property("editable", True)

adjustment = Gtk.Adjustment(0, 0, 100, 1, 10, 0)
adjustment = Gtk.Adjustment(upper=100, step_increment=1, page_increment=10)
renderer_spin.set_property("adjustment", adjustment)

column_spin = Gtk.TreeViewColumn("Amount", renderer_spin, text=1)
Expand Down
4 changes: 2 additions & 2 deletions examples/checkbutton_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def __init__(self):
hbox = Gtk.Box(spacing=6)
self.add(hbox)

button = Gtk.CheckButton("Button 1")
button = Gtk.CheckButton(label="Button 1")
button.connect("toggled", self.on_button_toggled, "1")
hbox.pack_start(button, False, False, 0)

button = Gtk.CheckButton("B_utton 2", use_underline=True)
button = Gtk.CheckButton(label="B_utton 2", use_underline=True)
button.set_active(True)
button.connect("toggled", self.on_button_toggled, "2")
hbox.pack_start(button, False, False, 0)
Expand Down
25 changes: 12 additions & 13 deletions examples/clipboard_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,29 @@ class ClipboardWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Clipboard Example")

table = Gtk.Table(3, 2)

self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
self.entry = Gtk.Entry()
self.image = Gtk.Image.new_from_icon_name("process-stop", Gtk.IconSize.MENU)

button_copy_text = Gtk.Button("Copy Text")
button_paste_text = Gtk.Button("Paste Text")
button_copy_image = Gtk.Button("Copy Image")
button_paste_image = Gtk.Button("Paste Image")
button_copy_text = Gtk.Button(label="Copy Text")
button_paste_text = Gtk.Button(label="Paste Text")
button_copy_image = Gtk.Button(label="Copy Image")
button_paste_image = Gtk.Button(label="Paste Image")

table.attach(self.entry, 0, 1, 0, 1)
table.attach(self.image, 0, 1, 1, 2)
table.attach(button_copy_text, 1, 2, 0, 1)
table.attach(button_paste_text, 2, 3, 0, 1)
table.attach(button_copy_image, 1, 2, 1, 2)
table.attach(button_paste_image, 2, 3, 1, 2)
grid = Gtk.Grid()
grid.attach(self.entry, 0, 0, 1, 1)
grid.attach(self.image, 0, 1, 1, 1)
grid.attach(button_copy_text, 1, 0, 1, 1)
grid.attach(button_paste_text, 2, 0, 1, 1)
grid.attach(button_copy_image, 1, 1, 1, 1)
grid.attach(button_paste_image, 2, 1, 1, 1)

button_copy_text.connect("clicked", self.copy_text)
button_paste_text.connect("clicked", self.paste_text)
button_copy_image.connect("clicked", self.copy_image)
button_paste_image.connect("clicked", self.paste_image)

self.add(table)
self.add(grid)

def copy_text(self, widget):
self.clipboard.set_text(self.entry.get_text(), -1)
Expand Down
9 changes: 4 additions & 5 deletions examples/dialog_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
class DialogExample(Gtk.Dialog):

def __init__(self, parent):
Gtk.Dialog.__init__(self, "My Dialog", parent, 0,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
super().__init__(title="My Dialog", parent=parent)
self.add_buttons("_OK", Gtk.ResponseType.OK, "_Cancel", Gtk.ResponseType.CANCEL)

self.set_default_size(150, 100)

label = Gtk.Label("This is a dialog to display additional information")
label = Gtk.Label.new("This is a dialog to display additional information")

box = self.get_content_area()
box.add(label)
Expand All @@ -24,7 +23,7 @@ def __init__(self):

self.set_border_width(6)

button = Gtk.Button("Open dialog")
button = Gtk.Button(label="Open dialog")
button.connect("clicked", self.on_button_clicked)

self.add(button)
Expand Down
8 changes: 4 additions & 4 deletions examples/entry_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ def __init__(self):
hbox = Gtk.Box(spacing=6)
vbox.pack_start(hbox, True, True, 0)

self.check_editable = Gtk.CheckButton("Editable")
self.check_editable = Gtk.CheckButton(label="Editable")
self.check_editable.connect("toggled", self.on_editable_toggled)
self.check_editable.set_active(True)
hbox.pack_start(self.check_editable, True, True, 0)

self.check_visible = Gtk.CheckButton("Visible")
self.check_visible = Gtk.CheckButton(label="Visible")
self.check_visible.connect("toggled", self.on_visible_toggled)
self.check_visible.set_active(True)
hbox.pack_start(self.check_visible, True, True, 0)

self.pulse = Gtk.CheckButton("Pulse")
self.pulse = Gtk.CheckButton(label="Pulse")
self.pulse.connect("toggled", self.on_pulse_toggled)
self.pulse.set_active(False)
hbox.pack_start(self.pulse, True, True, 0)

self.icon = Gtk.CheckButton("Icon")
self.icon = Gtk.CheckButton(label="Icon")
self.icon.connect("toggled", self.on_icon_toggled)
self.icon.set_active(False)
hbox.pack_start(self.icon, True, True, 0)
Expand Down
34 changes: 24 additions & 10 deletions examples/filechooserdialog_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,26 @@ def __init__(self):
box = Gtk.Box(spacing=6)
self.add(box)

button1 = Gtk.Button("Choose File")
button1 = Gtk.Button(label="Choose File")
button1.connect("clicked", self.on_file_clicked)
box.add(button1)

button2 = Gtk.Button("Choose Folder")
button2 = Gtk.Button(label="Choose Folder")
button2.connect("clicked", self.on_folder_clicked)
box.add(button2)

def on_file_clicked(self, widget):
dialog = Gtk.FileChooserDialog("Please choose a file", self,
Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
dialog = Gtk.FileChooserDialog(
title="Please choose a file",
parent=self,
action=Gtk.FileChooserAction.OPEN
)
dialog.add_buttons(
"Cancel",
Gtk.ResponseType.CANCEL,
"Open",
Gtk.ResponseType.OK,
)

self.add_filters(dialog)

Expand Down Expand Up @@ -52,10 +59,17 @@ def add_filters(self, dialog):
dialog.add_filter(filter_any)

def on_folder_clicked(self, widget):
dialog = Gtk.FileChooserDialog("Please choose a folder", self,
Gtk.FileChooserAction.SELECT_FOLDER,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
"Select", Gtk.ResponseType.OK))
dialog = Gtk.FileChooserDialog(
title="Please choose a folder",
parent=self,
action=Gtk.FileChooserAction.SELECT_FOLDER
)
dialog.add_buttons(
"Cancel",
Gtk.ResponseType.CANCEL,
"Select",
Gtk.ResponseType.OK,
)
dialog.set_default_size(800, 400)

response = dialog.run()
Expand Down
24 changes: 12 additions & 12 deletions examples/label_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ class LabelWindow(Gtk.Window):

def __init__(self):
Gtk.Window.__init__(self, title="Label Example")

hbox = Gtk.Box(spacing=10)
hbox.set_homogeneous(False)
vbox_left = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
vbox_left.set_homogeneous(False)
vbox_right = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
vbox_right.set_homogeneous(False)

hbox.pack_start(vbox_left, True, True, 0)
hbox.pack_start(vbox_right, True, True, 0)
label = Gtk.Label("This is a normal label")

label = Gtk.Label.new("This is a normal label")
vbox_left.pack_start(label, True, True, 0)

label = Gtk.Label()
label.set_text("This is a left-justified label.\nWith multiple lines.")
label.set_justify(Gtk.Justification.LEFT)
vbox_left.pack_start(label, True, True, 0)
label = Gtk.Label(

label = Gtk.Label.new(
"This is a right-justified label.\nWith multiple lines.")
label.set_justify(Gtk.Justification.RIGHT)
vbox_left.pack_start(label, True, True, 0)
label = Gtk.Label("This is an example of a line-wrapped label. It "

label = Gtk.Label.new("This is an example of a line-wrapped label. It "
"should not be taking up the entire "
"width allocated to it, but automatically "
"wraps the words to fit.\n"
Expand All @@ -39,8 +39,8 @@ def __init__(self):
"many extra spaces. ")
label.set_line_wrap(True)
vbox_right.pack_start(label, True, True, 0)
label = Gtk.Label("This is an example of a line-wrapped, filled label. "

label = Gtk.Label.new("This is an example of a line-wrapped, filled label. "
"It should be taking "
"up the entire width allocated to it. "
"Here is a sentence to prove "
Expand Down Expand Up @@ -73,7 +73,7 @@ def __init__(self):

self.add(hbox)

window = LabelWindow()
window = LabelWindow()
window.connect("destroy", Gtk.main_quit)
window.show_all()
Gtk.main()
9 changes: 4 additions & 5 deletions examples/layout_headerbar_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@ def __init__(self):
image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON)
button.add(image)
hb.pack_end(button)

box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
Gtk.StyleContext.add_class(box.get_style_context(), "linked")

button = Gtk.Button()
button.add(Gtk.Arrow(Gtk.ArrowType.LEFT, Gtk.ShadowType.NONE))
button = Gtk.Button.new_from_icon_name("pan-start-symbolic", Gtk.IconSize.MENU)
box.add(button)

button = Gtk.Button()
button.add(Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE))
button = Gtk.Button.new_from_icon_name("pan-end-symbolic", Gtk.IconSize.MENU)
box.add(button)

hb.pack_start(box)

self.add(Gtk.TextView())

win = HeaderBarWindow()
Expand Down
10 changes: 5 additions & 5 deletions examples/layout_listbox_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ListBoxRowWithData(Gtk.ListBoxRow):
def __init__(self, data):
super(Gtk.ListBoxRow, self).__init__()
self.data = data
self.add(Gtk.Label(data))
self.add(Gtk.Label.new(data))

class ListBoxWindow(Gtk.Window):

Expand All @@ -27,8 +27,8 @@ def __init__(self):
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
hbox.pack_start(vbox, True, True, 0)

label1 = Gtk.Label("Automatic Date & Time", xalign=0)
label2 = Gtk.Label("Requires internet access", xalign=0)
label1 = Gtk.Label(label="Automatic Date & Time", xalign=0)
label2 = Gtk.Label(label="Requires internet access", xalign=0)
vbox.pack_start(label1, True, True, 0)
vbox.pack_start(label2, True, True, 0)

Expand All @@ -41,7 +41,7 @@ def __init__(self):
row = Gtk.ListBoxRow()
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
row.add(hbox)
label = Gtk.Label("Enable Automatic Update", xalign=0)
label = Gtk.Label(label="Enable Automatic Update", xalign=0)
check = Gtk.CheckButton()
hbox.pack_start(label, True, True, 0)
hbox.pack_start(check, False, True, 0)
Expand All @@ -51,7 +51,7 @@ def __init__(self):
row = Gtk.ListBoxRow()
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
row.add(hbox)
label = Gtk.Label("Date Format", xalign=0)
label = Gtk.Label(label="Date Format", xalign=0)
combo = Gtk.ComboBoxText()
combo.insert(0, "0", "24-hour")
combo.insert(1, "1", "AM/PM")
Expand Down
6 changes: 3 additions & 3 deletions examples/layout_stack_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def __init__(self):
stack = Gtk.Stack()
stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
stack.set_transition_duration(1000)
checkbutton = Gtk.CheckButton("Click me!")

checkbutton = Gtk.CheckButton(label="Click me!")
stack.add_titled(checkbutton, "check", "Check Button")

label = Gtk.Label()
label.set_markup("<big>A fancy label</big>")
stack.add_titled(label, "label", "A label")
Expand Down
2 changes: 1 addition & 1 deletion examples/layout_table_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TableWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Table Example")

table = Gtk.Table(3, 3, True)
table = Gtk.Table.new(3, 3, True)
self.add(table)

button1 = Gtk.Button(label="Button 1")
Expand Down
2 changes: 1 addition & 1 deletion examples/linkbutton_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def __init__(self):
Gtk.Window.__init__(self, title="LinkButton Demo")
self.set_border_width(10)

button = Gtk.LinkButton("http://www.gtk.org", "Visit GTK+ Homepage")
button = Gtk.LinkButton(uri="http://www.gtk.org", label="Visit GTK+ Homepage")
self.add(button)

win = LinkButtonWindow()
Expand Down
Loading

0 comments on commit dba418b

Please sign in to comment.