Example fixes

- replaced Gtk.HBox/Gtk.VBox by GtkBox as seen in [1] and [2]
GtkHbox and GtkVBox are deprecated
- use delete-event instead of destroy event in GtkWindow
- replaced icon_size for pixel_size where used
it's also deprecated as seen in commit [3]
- use sugar_theme in all examples; set it manually not by just
importing common module
- fixed GtkBox.pack_start arguments
- flake/pep8 fixes

[1] https://developer.gnome.org/gtk3/stable/GtkHBox.html
[2] https://developer.gnome.org/gtk3/stable/GtkVBox.html
[3] 5802d67ee1
This commit is contained in:
Ignacio Rodríguez 2017-01-11 14:23:08 -03:00
parent f4fc8c0d1f
commit b6d449681d
27 changed files with 140 additions and 128 deletions

View File

@ -1,10 +1,7 @@
from gi.repository import Gtk
from sugar3.graphics.alert import TimeoutAlert
def _destroy_cb(widget, data=None):
Gtk.main_quit()
from common import set_theme
set_theme()
def __start_response_cb(widget, data=None):
@ -12,9 +9,9 @@ def __start_response_cb(widget, data=None):
w = Gtk.Window()
w.connect("destroy", _destroy_cb)
w.connect("delete-event", Gtk.main_quit)
box = Gtk.VBox()
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
w.add(box)
alert = TimeoutAlert(9)

View File

@ -4,8 +4,12 @@ from sugar3.graphics import animator
from sugar3.graphics.icon import Icon
from sugar3.graphics import style
from common import set_theme
set_theme()
class _Animation(animator.Animation):
def __init__(self, icon, start_size, end_size):
animator.Animation.__init__(self, 0.0, 1.0)
@ -22,14 +26,10 @@ def __animation_completed_cb(anim):
print 'Animation completed'
def _destroy_cb(widget, data=None):
Gtk.main_quit()
w = Gtk.Window()
w.connect("destroy", _destroy_cb)
w.connect('delete-event', Gtk.main_quit)
box = Gtk.VBox()
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
w.add(box)
anim = animator.Animator(5)

View File

@ -6,57 +6,57 @@ import common
test = common.Test()
test.show()
vbox = Gtk.VBox()
test.pack_start(vbox, True, True, 0)
vbox.show()
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
test.pack_start(box, True, True, 0)
box.show()
# test Gtk.SpinButton:
adj = Gtk.Adjustment(0, 0, 10, 1, 32, 0)
spin = Gtk.SpinButton()
spin.set_adjustment(adj)
vbox.pack_start(spin, False, False, 1)
box.pack_start(spin, False, False, 1)
spin.show()
# test Gtk.RadioButton:
radio_1 = Gtk.RadioButton.new_with_label_from_widget(None, 'Radio 1')
vbox.pack_start(radio_1, False, False, 1)
box.pack_start(radio_1, False, False, 1)
radio_1.show()
radio_2 = Gtk.RadioButton.new_with_label_from_widget(radio_1, 'Radio 2')
vbox.pack_start(radio_2, False, False, 1)
box.pack_start(radio_2, False, False, 1)
radio_2.show()
radio_3 = Gtk.RadioButton.new_with_label_from_widget(radio_1, 'Radio 3')
vbox.pack_start(radio_3, False, False, 1)
box.pack_start(radio_3, False, False, 1)
radio_3.show()
# test Gtk.CheckButton:
check_1 = Gtk.CheckButton('Check 1')
vbox.pack_start(check_1, False, False, 1)
box.pack_start(check_1, False, False, 1)
check_1.show()
check_2 = Gtk.CheckButton('Check 2')
vbox.pack_start(check_2, False, False, 1)
box.pack_start(check_2, False, False, 1)
check_2.show()
# test Gtk.Button:
button = Gtk.Button('Button')
vbox.pack_start(button, False, False, 1)
box.pack_start(button, False, False, 1)
button.show()
# test Gtk.Button insensitive:
insensitive_button = Gtk.Button('Insensitive Button')
vbox.pack_start(insensitive_button, False, False, 1)
box.pack_start(insensitive_button, False, False, 1)
insensitive_button.props.sensitive = False
insensitive_button.show()
# test Gtk.ToggleButton:
toggle_button = Gtk.ToggleButton('ToggleButton')
vbox.pack_start(toggle_button, False, False, 1)
box.pack_start(toggle_button, False, False, 1)
toggle_button.show()

View File

@ -10,21 +10,23 @@ import common
test = common.Test()
test.show()
vbox = Gtk.VBox()
test.pack_start(vbox, True, True, 0)
vbox.show()
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
test.pack_start(box, True, True, 0)
box.show()
toolbar_box = ToolbarBox()
vbox.pack_start(toolbar_box, False, False, 0)
box.pack_start(toolbar_box, False, False, 0)
toolbar_box.show()
separator = Gtk.SeparatorToolItem()
toolbar_box.toolbar.insert(separator, -1)
separator.show()
def color_changed_cb(button, pspec):
print button.get_color()
color_button = ColorToolButton()
color_button.connect("notify::color", color_changed_cb)
toolbar_box.toolbar.insert(color_button, -1)

View File

@ -1,6 +1,8 @@
from gi.repository import Gtk
from sugar3.graphics.combobox import ComboBox
from common import set_theme
set_theme()
def __combo_changed_cb(combo):
@ -8,7 +10,7 @@ def __combo_changed_cb(combo):
w = Gtk.Window()
w.connect("destroy", Gtk.main_quit)
w.connect("delete-event", Gtk.main_quit)
combo = ComboBox()
combo.append_item(True, 'one')

View File

@ -33,15 +33,16 @@ def set_theme():
settings.set_property('gtk-icon-theme-name', 'sugar')
class Test(Gtk.Box):
def __init__(self):
GObject.GObject.__init__(self, orientation=Gtk.Orientation.VERTICAL)
set_theme()
class Test(Gtk.VBox):
def __init__(self):
GObject.GObject.__init__(self)
class TestPalette(Test):
def __init__(self):
Test.__init__(self)
@ -51,7 +52,7 @@ class TestPalette(Test):
toolbar.insert(self._invoker, -1)
self._invoker.show()
self.pack_start(toolbar, False)
self.pack_start(toolbar, False, False, 0)
toolbar.show()
def set_palette(self, palette):
@ -59,9 +60,10 @@ class TestPalette(Test):
class TestRunner(object):
def run(self, test):
window = Gtk.Window()
window.connect('destroy', lambda w: Gtk.main_quit())
window.connect('delete-event', Gtk.main_quit)
window.add(test)
test.show()

View File

@ -8,6 +8,7 @@ We can do the cleanup in the python destructor method instead.
class MyCellRenderer(Gtk.CellRenderer):
def __init__(self):
Gtk.CellRenderer.__init__(self)

View File

@ -1,26 +1,25 @@
#!/usr/bin/python
from gi.repository import Gtk
import common
test = common.Test()
test.show()
class MyBox(Gtk.VBox):
class MyBox(Gtk.Box):
def __init__(self):
Gtk.VBox.__init__(self)
Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
self.scrolled = Gtk.ScrolledWindow()
self.scrolled.set_policy(Gtk.PolicyType.AUTOMATIC,
scrolled = Gtk.ScrolledWindow()
scrolled.set_policy(Gtk.PolicyType.AUTOMATIC,
Gtk.PolicyType.AUTOMATIC)
self.store = Gtk.ListStore(str, str)
store = Gtk.ListStore(str, str)
for i in range(5):
self.store.append([str(i), 'Item %s' % i])
store.append([str(i), 'Item %s' % i])
self.treeview = Gtk.TreeView(self.store)
treeview = Gtk.TreeView(store)
renderer_no_sens = Gtk.CellRendererText()
# set 'sensitive' property
renderer_no_sens.set_property('sensitive', False)
@ -29,21 +28,21 @@ class MyBox(Gtk.VBox):
column = Gtk.TreeViewColumn('\'sensitive\' False',
renderer_no_sens, text=0)
self.treeview.append_column(column)
treeview.append_column(column)
column = Gtk.TreeViewColumn('\'sensitive\' True',
renderer, text=1)
self.treeview.append_column(column)
treeview.append_column(column)
self.scrolled.add(self.treeview)
self.add(self.scrolled)
scrolled.add(treeview)
self.pack_start(scrolled, True, True, 0)
self.show_all()
vbox = MyBox()
test.pack_start(vbox, True, True, 0)
vbox.show()
box = MyBox()
test.pack_start(box, True, True, 0)
box.show()
if __name__ == '__main__':
common.main(test)

View File

@ -12,15 +12,15 @@ import common
test = common.Test()
test.show()
vbox = Gtk.VBox()
test.pack_start(vbox, True, True, 0)
vbox.show()
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
test.pack_start(box, True, True, 0)
box.show()
# An XO Icon, normal size, setting the color via the XoColor object
icon = Icon(icon_name='computer-xo',
pixel_size=style.STANDARD_ICON_SIZE,
xo_color=XoColor('#00BEFF,#FF7800'))
vbox.pack_start(icon, False, False, 0)
box.pack_start(icon, False, False, 0)
icon.show()
# You can mix constructor keyword argument and setting
@ -34,7 +34,7 @@ icon.props.fill_color = 'rgb(230, 0, 10)'
icon.props.stroke_color = '#78E600'
# Unlike normal icons, EventIcons support palettes:
icon.props.palette = Palette('Hello World')
vbox.pack_start(icon, False, False, 0)
box.pack_start(icon, False, False, 0)
icon.show()

View File

@ -23,6 +23,7 @@ from gi.repository import Gtk
from sugar3.graphics.icon import Icon
from sugar3.graphics.xocolor import XoColor
from sugar3.graphics import style
import common
@ -55,7 +56,7 @@ def _button_activated_cb(button):
for d in data:
icon = Icon(icon_name=d[0],
icon_size=Gtk.IconSize.LARGE_TOOLBAR,
pixel_size=style.STANDARD_ICON_SIZE,
xo_color=XoColor(d[1]))
test.pack_start(icon, True, True, 0)
icon.show()

View File

@ -1,10 +1,8 @@
from gi.repository import Gtk
from sugar3.graphics import iconentry
def _destroy_cb(widget, data=None):
Gtk.main_quit()
from common import set_theme
set_theme()
def __go_next_cb(entry, icon_pos, data=None):
@ -16,9 +14,9 @@ def __entry_activate_cb(widget, data=None):
w = Gtk.Window()
w.connect("destroy", _destroy_cb)
w.connect("delete-event", Gtk.main_quit)
box = Gtk.VBox()
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
w.add(box)
entry = iconentry.IconEntry()

View File

@ -23,44 +23,45 @@ from gi.repository import Gtk
from sugar3.graphics.icon import Icon
from sugar3.graphics.xocolor import XoColor
from sugar3.graphics import style
import common
test = common.Test()
hbox = Gtk.HBox()
test.pack_start(hbox, True, True, 0)
sensitive_box = Gtk.VBox()
insensitive_box = Gtk.VBox()
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
test.pack_start(box, True, True, 0)
sensitive_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
insensitive_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
hbox.pack_start(sensitive_box, True, True, 0)
hbox.pack_start(insensitive_box, True, True, 0)
hbox.show_all()
box.pack_start(sensitive_box, True, True, 0)
box.pack_start(insensitive_box, True, True, 0)
box.show_all()
def create_icon_widgets(box, sensitive=True):
icon = Icon(icon_name='go-previous')
icon.props.icon_size = Gtk.IconSize.LARGE_TOOLBAR
icon.props.pixel_size = style.STANDARD_ICON_SIZE
box.pack_start(icon, True, True, 0)
icon.set_sensitive(sensitive)
icon.show()
icon = Icon(icon_name='computer-xo',
icon_size=Gtk.IconSize.LARGE_TOOLBAR,
pixel_size=style.STANDARD_ICON_SIZE,
xo_color=XoColor())
box.pack_start(icon, True, True, 0)
icon.set_sensitive(sensitive)
icon.show()
icon = Icon(icon_name='battery-000',
icon_size=Gtk.IconSize.LARGE_TOOLBAR,
pixel_size=style.STANDARD_ICON_SIZE,
badge_name='emblem-busy')
box.pack_start(icon, True, True, 0)
icon.set_sensitive(sensitive)
icon.show()
icon = Icon(icon_name='gtk-new',
icon_size=Gtk.IconSize.LARGE_TOOLBAR,
pixel_size=style.STANDARD_ICON_SIZE,
badge_name='gtk-cancel')
box.pack_start(icon, True, True, 0)
icon.set_sensitive(sensitive)

View File

@ -1,16 +1,14 @@
from gi.repository import Gtk
from sugar3.graphics.notebook import Notebook
def _destroy_cb(widget, data=None):
Gtk.main_quit()
from common import set_theme
set_theme()
w = Gtk.Window()
w.connect("destroy", _destroy_cb)
w.connect("delete-event", Gtk.main_quit)
box = Gtk.VBox()
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
w.add(box)
nb = Notebook(can_close_tabs=True)

View File

@ -6,7 +6,7 @@ import common
test = common.Test()
test.show()
box = Gtk.HBox()
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
test.pack_start(box, True, False, 10)
box.show()

View File

@ -10,11 +10,11 @@ import common
test = common.Test()
vbox = Gtk.VBox()
test.pack_start(vbox, True, True, 0)
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
test.pack_start(box, True, True, 0)
toolbar_box = ToolbarBox()
vbox.pack_start(toolbar_box, False, False, 0)
box.pack_start(toolbar_box, False, False, 0)
separator = Gtk.SeparatorToolItem()
toolbar_box.toolbar.insert(separator, -1)

View File

@ -3,14 +3,17 @@ from gi.repository import Gtk
from sugar3.graphics.radiopalette import RadioPalette, RadioMenuButton, \
RadioToolsButton
from sugar3.graphics.radiotoolbutton import RadioToolButton
from common import set_theme
set_theme()
window = Gtk.Window()
box = Gtk.VBox()
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
window.add(box)
toolbar = Gtk.Toolbar()
box.pack_start(toolbar, False)
box.pack_start(toolbar, False, False, 0)
text_view = Gtk.TextView()
box.pack_start(text_view, True, True, 0)
@ -70,5 +73,6 @@ palette.append(button, 'menu.document-send')
button = RadioToolsButton(palette=palette)
toolbar.insert(button, -1)
window.connect('delete-event', Gtk.main_quit)
window.show_all()
Gtk.main()

View File

@ -1,15 +1,17 @@
from gi.repository import Gtk
from sugar3.graphics.radiotoolbutton import RadioToolButton
from sugar3.graphics.radiopalette import RadioPalette, RadioMenuButton
from sugar3.graphics.xocolor import XoColor
from common import set_theme
set_theme()
window = Gtk.Window()
window.show()
window.connect("destroy", Gtk.main_quit)
window.connect("delete-event", Gtk.main_quit)
box = Gtk.HBox()
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
window.add(box)
box.show()

View File

@ -7,7 +7,7 @@ import common
test = common.Test()
test.show()
box = Gtk.HBox()
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
test.pack_start(box, True, True, 0)
box.show()
@ -18,7 +18,7 @@ box.pack_start(notebook, True, True, 0)
notebook.show()
for i in range(3):
hbox = Gtk.HBox()
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
notebook.append_page(hbox, Gtk.Label('Page %d' % (i + 1)))
hbox.show()
@ -38,7 +38,7 @@ notebook.set_action_widget(button, Gtk.PackType.END)
button.show()
for i in range(3):
hbox = Gtk.HBox()
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
notebook.append_page(hbox, Gtk.Label('Page %d' % (i + 1)))
hbox.show()

View File

@ -25,6 +25,7 @@ from gi.repository import Gtk
from sugar3.graphics.palette import Palette
from sugar3.graphics.icon import Icon
from sugar3.graphics import style
import common
@ -33,23 +34,23 @@ test = common.TestPalette()
palette = Palette('Test radio and toggle')
test.set_palette(palette)
box = Gtk.HBox()
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
toggle = Gtk.ToggleButton()
icon = Icon(icon_name='go-previous', icon_size=Gtk.IconSize.LARGE_TOOLBAR)
icon = Icon(icon_name='go-previous', pixel_size=style.STANDARD_ICON_SIZE)
toggle.set_image(icon)
box.pack_start(toggle, False)
box.pack_start(toggle, False, False, 0)
toggle.show()
radio = Gtk.RadioButton()
icon = Icon(icon_name='go-next', icon_size=Gtk.IconSize.LARGE_TOOLBAR)
icon = Icon(icon_name='go-next', pixel_size=style.STANDARD_ICON_SIZE)
radio.set_image(icon)
radio.set_mode(False)
box.pack_start(radio, False)
box.pack_start(radio, False, False, 0)
radio.show()
palette.set_content(box)

View File

@ -28,7 +28,7 @@ import common
test = common.Test()
toolbar = Gtk.Toolbar()
test.pack_start(toolbar, False)
test.pack_start(toolbar, False, False, 0)
toolbar.show()
button = ToolButton('go-previous')

View File

@ -9,12 +9,12 @@ import common
test = common.Test()
test.show()
vbox = Gtk.VBox()
test.pack_start(vbox, True, True, 0)
vbox.show()
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
test.pack_start(box, True, True, 0)
box.show()
toolbar_box = ToolbarBox()
vbox.pack_start(toolbar_box, False, False, 0)
box.pack_start(toolbar_box, False, False, 0)
toolbar_box.show()
favorite_button = ToggleToolButton('emblem-favorite')

View File

@ -2,14 +2,17 @@ from gi.repository import Gtk
from sugar3.graphics.toolbutton import ToolButton
from sugar3.graphics.toolbarbox import ToolbarBox, ToolbarButton
from common import set_theme
set_theme()
window = Gtk.Window()
box = Gtk.VBox()
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
window.add(box)
toolbar = ToolbarBox()
box.pack_start(toolbar, False)
box.pack_start(toolbar, False, False, 0)
tollbarbutton_1 = ToolbarButton(
page=Gtk.Button('sub-widget #1'),
@ -48,5 +51,6 @@ tollbarbutton_4 = ToolbarButton(
icon_name='document-save')
toolbar.toolbar.insert(tollbarbutton_4, -1)
window.connect('delete-event', Gtk.main_quit)
window.show_all()
Gtk.main()

View File

@ -28,12 +28,12 @@ import common
test = common.Test()
vbox = Gtk.VBox()
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
theme_icons = Gtk.IconTheme.get_default().list_icons()
toolbar = Gtk.Toolbar()
vbox.pack_start(toolbar, False)
box.pack_start(toolbar, False, False, 0)
toolbar.show()
for i in range(0, 5):
@ -43,11 +43,11 @@ for i in range(0, 5):
button.show()
content = Gtk.Label()
vbox.pack_start(content, True, True, 0)
box.pack_start(content, True, True, 0)
content.show()
tray = HTray()
vbox.pack_start(tray, False)
box.pack_start(tray, False, False, 0)
tray.show()
for i in range(0, 30):
@ -56,8 +56,8 @@ for i in range(0, 30):
tray.add_item(button)
button.show()
test.pack_start(vbox, True, True, 0)
vbox.show()
test.pack_start(box, True, True, 0)
box.show()
test.show()

View File

@ -8,11 +8,11 @@ import common
test = common.Test()
vbox = Gtk.VBox()
test.pack_start(vbox, True, True, 0)
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
test.pack_start(box, True, True, 0)
toolbar_box = ToolbarBox()
vbox.pack_start(toolbar_box, False, False, 0)
box.pack_start(toolbar_box, False, False, 0)
separator = Gtk.SeparatorToolItem()
toolbar_box.toolbar.insert(separator, -1)

View File

@ -11,12 +11,12 @@ import common
test = common.Test()
test.show()
vbox = Gtk.VBox()
test.pack_start(vbox, True, True, 0)
vbox.show()
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
test.pack_start(box, True, True, 0)
box.show()
toolbar_box = ToolbarBox()
vbox.pack_start(toolbar_box, False, False, 0)
box.pack_start(toolbar_box, False, False, 0)
toolbar_box.show()
radial_button = RadioToolButton(icon_name='view-radial')

View File

@ -28,7 +28,7 @@ import common
test = common.Test()
vbox = Gtk.VBox()
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
tray = HTray()
vbox.pack_start(tray, False, False, 0)
@ -50,7 +50,7 @@ for i in range(0, 10):
tray.add_item(icon)
icon.show()
hbox = Gtk.HBox()
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
tray = VTray()
hbox.pack_start(tray, False, False, 0)