def __init__(self, addons_manager):
StatusBar.__init__(self, addons_manager.view)
self.addons_manager = addons_manager
self.cache = self.addons_manager.view.cache
self.applying = False
# TRANSLATORS: Free here means Gratis
self.label_price = Gtk.Label(_("Free"))
self.hbox.pack_start(self.label_price, False, False, 0)
self.hbuttonbox = Gtk.HButtonBox()
self.hbuttonbox.set_layout(Gtk.ButtonBoxStyle.END)
self.button_apply = Gtk.Button(_("Apply Changes"))
self.button_apply.connect("clicked", self._on_button_apply_clicked)
self.button_cancel = Gtk.Button(_("Cancel"))
self.button_cancel.connect("clicked", self.addons_manager.restore)
self.hbox.pack_end(self.button_apply, False, False, 0)
self.hbox.pack_end(self.button_cancel, False, False, 0)
#self.hbox.pack_start(self.hbuttonbox, False, False, 0)
python类Button()的实例源码
def get_test_buttons_window():
win = Gtk.Window()
win.set_size_request(200, 200)
vb = Gtk.VBox(spacing=12)
win.add(vb)
link = Link("<small>test link</small>", uri="www.google.co.nz")
vb.pack_start(link, False, False, 0)
button = Gtk.Button()
button.set_label("channels")
channels_button = ChannelSelector(button)
channels_button.parent_style_type = Gtk.Window
channels_button.set_build_func(_build_channels_list)
hb = Gtk.HBox()
hb.pack_start(button, False, False, 0)
hb.pack_start(channels_button, False, False, 0)
vb.pack_start(hb, False, False, 0)
win.show_all()
win.connect("destroy", Gtk.main_quit)
return win
def __init__(self):
super(VideoPlayerGtk3, self).__init__()
self.uri = ""
# gtk ui
self.movie_window = Gtk.DrawingArea()
self.pack_start(self.movie_window, True, True, 0)
self.button = Gtk.Button(_("Play"))
self.pack_start(self.button, False, True, 0)
self.button.connect("clicked", self.on_play_clicked)
# player
self.player = Gst.ElementFactory.make("playbin2", "player")
# bus stuff
bus = self.player.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()
bus.connect("message", self.on_message)
# FIXME: no sync messages currently so no playing in the widget :/
# the former appears to be not working anymore with GIR, the
# later is not exported (introspectable=0 in the GIR)
bus.connect("sync-message", self.on_sync_message)
#bus.set_sync_handler(self.on_sync_message)
def add_button(self, id, label, result, *result_args):
"""Adds a button and shows the bar.
Keyword arguments:
id -- A unique identifier for the button
label -- A string for the button label
result -- A function to be called on button click
result_args -- Any arguments for the result function
"""
overwrite = self.get_button(id)
if overwrite:
self._btns.remove(overwrite)
btn = Gtk.Button(label)
btn.connect("clicked", self._callback(result, result_args))
btn.id = id
btn.show()
self._btns.pack_start(btn, False, True, 0)
if not self._visible:
# always animate with buttons
self._show(animate=True)
def __init__(self, id_, url, cancellable, gallery):
Gtk.Button.__init__(self)
self.id_ = id_
def download_complete_cb(loader, path):
width, height = ThumbnailGallery.THUMBNAIL_SIZE_CONTRAINTS
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
path,
width, height, # width, height constraints
True) # respect image proportionality
im = Gtk.Image.new_from_pixbuf(pixbuf)
self.add(im)
self.show_all()
loader = SimpleFileDownloader()
loader.connect("file-download-complete", download_complete_cb)
loader.download_file(
url, use_cache=ScreenshotGallery.USE_CACHING)
self.connect("draw", self.on_draw)
def __init__(self, addons_manager):
StatusBar.__init__(self, addons_manager.view)
self.addons_manager = addons_manager
self.cache = self.addons_manager.view.cache
self.applying = False
# TRANSLATORS: Free here means Gratis
self.label_price = Gtk.Label(_("Free"))
self.hbox.pack_start(self.label_price, False, False, 0)
self.hbuttonbox = Gtk.HButtonBox()
self.hbuttonbox.set_layout(Gtk.ButtonBoxStyle.END)
self.button_apply = Gtk.Button(_("Apply Changes"))
self.button_apply.connect("clicked", self._on_button_apply_clicked)
self.button_cancel = Gtk.Button(_("Cancel"))
self.button_cancel.connect("clicked", self.addons_manager.restore)
self.hbox.pack_end(self.button_apply, False, False, 0)
self.hbox.pack_end(self.button_cancel, False, False, 0)
#self.hbox.pack_start(self.hbuttonbox, False, False, 0)
def get_test_buttons_window():
win = Gtk.Window()
win.set_size_request(200, 200)
vb = Gtk.VBox(spacing=12)
win.add(vb)
link = Link("<small>test link</small>", uri="www.google.co.nz")
vb.pack_start(link, False, False, 0)
button = Gtk.Button()
button.set_label("channels")
channels_button = ChannelSelector(button)
channels_button.parent_style_type = Gtk.Window
channels_button.set_build_func(_build_channels_list)
hb = Gtk.HBox()
hb.pack_start(button, False, False, 0)
hb.pack_start(channels_button, False, False, 0)
vb.pack_start(hb, False, False, 0)
win.show_all()
win.connect("destroy", Gtk.main_quit)
return win
def __init__(self):
super(VideoPlayerGtk3, self).__init__()
self.uri = ""
# gtk ui
self.movie_window = Gtk.DrawingArea()
self.pack_start(self.movie_window, True, True, 0)
self.button = Gtk.Button(_("Play"))
self.pack_start(self.button, False, True, 0)
self.button.connect("clicked", self.on_play_clicked)
# player
self.player = Gst.ElementFactory.make("playbin2", "player")
# bus stuff
bus = self.player.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()
bus.connect("message", self.on_message)
# FIXME: no sync messages currently so no playing in the widget :/
# the former appears to be not working anymore with GIR, the
# later is not exported (introspectable=0 in the GIR)
bus.connect("sync-message", self.on_sync_message)
#bus.set_sync_handler(self.on_sync_message)
def add_button(self, id, label, result, *result_args):
"""Adds a button and shows the bar.
Keyword arguments:
id -- A unique identifier for the button
label -- A string for the button label
result -- A function to be called on button click
result_args -- Any arguments for the result function
"""
overwrite = self.get_button(id)
if overwrite:
self._btns.remove(overwrite)
btn = Gtk.Button(label)
btn.connect("clicked", self._callback(result, result_args))
btn.id = id
btn.show()
self._btns.pack_start(btn, False, True, 0)
if not self._visible:
# always animate with buttons
self._show(animate=True)
def __init__(self, id_, url, cancellable, gallery):
Gtk.Button.__init__(self)
self.id_ = id_
def download_complete_cb(loader, path):
width, height = ThumbnailGallery.THUMBNAIL_SIZE_CONTRAINTS
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
path,
width, height, # width, height constraints
True) # respect image proportionality
im = Gtk.Image.new_from_pixbuf(pixbuf)
self.add(im)
self.show_all()
loader = SimpleFileDownloader()
loader.connect("file-download-complete", download_complete_cb)
loader.download_file(
url, use_cache=ScreenshotGallery.USE_CACHING)
self.connect("draw", self.on_draw)
def __init__(self, desc):
super(KeybindingWidget, self).__init__()
self.desc = desc
self.label = Gtk.Label(label=desc)
if self.desc != "":
self.pack_start(self.label, False, False, 0)
self.button = Gtk.Button()
self.button.set_tooltip_text(_("Click to set a new accelerator key for opening and closing the menu. ") +
_("Press Escape or click again to cancel the operation. ") +
_("Press Backspace to clear the existing keybinding."))
self.button.connect("clicked", self.clicked)
self.button.set_size_request(200, -1)
self.pack_start(self.button, False, False, 4)
self.show_all()
self.event_id = None
self.teaching = False
def build_contents(self):
""" Build the main UI display regions """
self.stack = Gtk.Stack()
self.box.pack_start(self.stack, True, True, 0)
button = Gtk.Button("Install")
lab_disclaimer = Gtk.Label(
"This is a third party package and is not officially supported"
" by Solus")
img_warn = Gtk.Image.new_from_icon_name(
"dialog-warning-symbolic", Gtk.IconSize.BUTTON)
self.abar.pack_start(img_warn)
self.abar.pack_start(lab_disclaimer)
self.abar.pack_end(button)
button.get_style_context().add_class("destructive-action")
# Details
dumb = Gtk.Label("Details ...")
self._fix_label(dumb)
dumb.set_property("margin", 12)
self.stack.add_titled(dumb, "desc", "Details")
# Files
dumb = Gtk.Label("Files ...")
self._fix_label(dumb)
dumb.set_property("margin", 12)
self.stack.add_titled(dumb, "files", "Files")
def generate_header_bar(self):
"""
Generate the header bar box
"""
self.hb.props.title = _("Add a new account")
left_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
right_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
cancel_button = Gtk.Button.new_with_label(_("Cancel"))
cancel_button.connect("clicked", self.close_window)
cancel_button.get_style_context().add_class("destructive-action")
left_box.add(cancel_button)
self.apply_button = Gtk.Button.new_with_label(_("Add"))
self.apply_button.get_style_context().add_class("suggested-action")
self.apply_button.connect("clicked", self.add_account)
self.apply_button.set_sensitive(False)
qr_button = Gtk.Button()
qr_icon = Gio.ThemedIcon(name="qrscanner-symbolic")
qr_image = Gtk.Image.new_from_gicon(qr_icon, Gtk.IconSize.BUTTON)
qr_button.set_tooltip_text(_("Scan a QR code"))
qr_button.set_image(qr_image)
qr_button.connect("clicked", self.on_qr_scan)
right_box.add(qr_button)
right_box.add(self.apply_button)
self.hb.pack_start(left_box)
self.hb.pack_end(right_box)
self.set_titlebar(self.hb)
def build_button(label, icon_name=None, icon_widget=None, use_stock=False):
""" Builds button situable for action area """
b = Gtk.Button.new_from_stock(label) if use_stock \
else Gtk.Button.new_with_label(label)
b.set_use_underline(True)
if not icon_name is None:
icon_widget = Gtk.Image()
icon_widget.set_from_icon_name(icon_name, Gtk.IconSize.BUTTON)
if not icon_widget is None:
b.set_image(icon_widget)
b.set_always_show_image(True)
return b
def __init__(self):
Gtk.Dialog.__init__(self, 'File Downloader',None,Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
self.set_size_request(400, 100)
self.set_title('? ubi site file downloader')
self.connect('destroy', self.close_application)
#
vbox0 = Gtk.VBox(spacing = 10)
vbox0.set_border_width(5)
self.get_content_area().add(vbox0)
#
table1 = Gtk.Table(3,2,False)
vbox0.add(table1)
label10 = Gtk.Label('Extension:')
label10.set_alignment(0, 0.5)
table1.attach(label10,0,1,0,1)
#
self.entry10 = Gtk.Entry()
table1.attach(self.entry10,1,2,0,1)
#
label11 = Gtk.Label('Url:')
label11.set_alignment(0, 0.5)
table1.attach(label11,0,1,1,2)
#
self.entry11 = Gtk.Entry()
table1.attach(self.entry11,1,2,1,2)
#
#self.button = Gtk.Button('Select folder')
#self.button.connect('clicked',self.on_button_clicked)
#table1.attach(self.button,0,2,2,3)
#
self.show_all()
def __init__(self):
Gtk.Dialog.__init__(self, 'File Downloader',None,Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT,Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))
self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
self.set_size_request(400, 100)
self.set_title('? ubi site file downloader')
self.connect('destroy', self.close_application)
#
vbox0 = Gtk.VBox(spacing = 10)
vbox0.set_border_width(5)
self.get_content_area().add(vbox0)
#
table1 = Gtk.Table(3,2,False)
vbox0.add(table1)
label10 = Gtk.Label('Extension:')
label10.set_alignment(0, 0.5)
table1.attach(label10,0,1,0,1)
#
self.entry10 = Gtk.Entry()
table1.attach(self.entry10,1,2,0,1)
#
label11 = Gtk.Label('Url:')
label11.set_alignment(0, 0.5)
table1.attach(label11,0,1,1,2)
#
self.entry11 = Gtk.Entry()
table1.attach(self.entry11,1,2,1,2)
#
#self.button = Gtk.Button('Select folder')
#self.button.connect('clicked',self.on_button_clicked)
#table1.attach(self.button,0,2,2,3)
#
self.show_all()
def __init__(self, configuration, channels):
Gtk.Frame.__init__(self)
self.configuration = configuration
self.channels = channels
vbox = Gtk.Box(self, orientation=Gtk.Orientation.VERTICAL, spacing=2)
vbox.set_homogeneous(False)
self.add(vbox)
self.label = Gtk.Label()
vbox.pack_start(self.label, False, True, 0)
if "group" in configuration:
self.label.set_text(configuration["group"])
hbox = Gtk.Box(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
hbox.set_homogeneous(False)
vbox.pack_start(hbox, False, True, 0)
self.button_settings = Gtk.Button.new()
self.button_settings.set_image(Gtk.Image.new_from_stock(Gtk.STOCK_PREFERENCES, Gtk.IconSize.BUTTON))
self.button_settings.connect("clicked", self.on_settings_clicked)
hbox.pack_start(self.button_settings, False, True, 0)
self.hbox = Gtk.Box(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
hbox.pack_start(self.hbox, True, True, 0)
if "functions" in configuration:
for func in configuration["functions"]:
button = Gtk.Button(func["label"])
button.connect("clicked", self.on_button_clicked)
button.brick_function = func
self.hbox.pack_start(button, True, True, 0)
self.sbrick = None
self.hbox.set_sensitive(False)
def __init__(self, parent):
Gtk.Dialog.__init__(self, "File Dialog", parent, 0,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
self.set_default_size(500, 550)
box = self.get_content_area()
self.verticalbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=3)
box.add(self.verticalbox)
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
from_file = Gtk.Button("From File")
from_file.connect("clicked", self.on_file)
from_clipboard = Gtk.Button("Clipboard")
from_clipboard.connect("clicked", self.on_clipboard)
hbox1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, homogeneous=True)
hbox1.pack_start(from_file, True, True, 0)
hbox1.pack_start(from_clipboard, True, True, 0)
self.verticalbox.pack_start(hbox1, False, False, 0)
# Just holding the Place for real treeview widget
self.scrollable_treelist = Gtk.Label()
self.verticalbox.pack_start(self.scrollable_treelist, True, True, 0)
self.show_all()
def createButtons(amount):
print ("[GUI] Creating " + str(amount) + " buttons")
for i in range(1, amount + 1):
#Add the buttons to the window class
setattr(win, "prediction" + str(i), Gtk.Button(label = "Prediction #" + str(i)))
#Add the buttons to the box
win.box.pack_start(getattr(win, "prediction" + str(i)), True, True, 0)
#Connect the buttons clicked event to the on_prediction_click function
getattr(win, "prediction" + str(i)).connect("clicked", on_prediction_click, i)
def __init__(self):
Gtk.Window.__init__(self, title="LexicGUITest")
self.set_keep_above(True)
self.set_decorated(False)
#Creates the top level parent box contain 2 children boxes
self.mainBox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=20)
self.add(self.mainBox)
#Creates the box for the top of the GUI
self.topBox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
self.mainBox.pack_start(self.topBox, True, True, 0)
#Create vertical box that the buttons will be placed in
self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
#Add the box to the window
#self.add(self.box)
self.mainBox.pack_start(self.box, True, True, 0)
#Add textField, and add it to the box
self.searchField = Gtk.Entry()
self.searchField.connect("key-release-event", enter_check)
self.topBox.pack_start(self.searchField, True, True, 0)
self.searchField.set_text("is")
#Add search button
self.search = Gtk.Button(label = "Search")
self.topBox.pack_start(self.search, True, True, 0)
self.search.connect("clicked", on_search_click, self.searchField.get_text())
#Add the Suggestions label
self.label = Gtk.Label(label="Suggestions:")
self.box.pack_start(self.label, True, True, 0)