我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用gi.repository.Gtk.Button()。
def generate_widget(self, item): if isinstance(item, Separator): # Ignored here return None elif item.id is None: # Dummies are ignored as well return None else: icon_file, has_colors = find_icon(item.icon, False) if icon_file: # Gridmenu hides label when icon is displayed widget = Gtk.Button() widget.set_relief(Gtk.ReliefStyle.NONE) widget.set_name("osd-menu-item-big-icon") if isinstance(item, Submenu): item.callback = self.show_submenu icon = MenuIcon(icon_file, has_colors) widget.add(icon) return widget else: return Menu.generate_widget(self, item)
def setup_widgets(self): Editor.setup_widgets(self) cbButtonChooser = self.builder.get_object("cbButtonChooser") cbButtonChooser.set_row_separator_func( lambda model, iter : model.get_value(iter, 0) is None ) b = lambda a : self.builder.get_object(a) self.action_widgets = ( # Order goes: Grid, 1st Action Button, Clear Button # 1st group, 'pressed' ( b('grActions'), b('btDefault'), b('btClearDefault') ), # 2nd group, 'hold' ( b('grHold'), b('btHold'), b('btClearHold') ), # 2nd group, 'double-click' ( b('grDoubleClick'), b('btDoubleClick'), b('btClearDoubleClick') ), ) headerbar(self.builder.get_object("header"))
def do_settings(self): dialog = FunctionConfigureDialog(self.get_toplevel(), self.configuration, self.channels) response = dialog.run() if response == Gtk.ResponseType.OK: ch = self.hbox.get_children() for c in ch: self.hbox.remove(c) c.destroy() for func in self.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.label.set_text(self.configuration["group"]) self.show_all() dialog.destroy() return True else: dialog.destroy() return False
def on_prop_button_clicked(self, button): if self.m_t.q_status != self.QSTATUS_NEW: return g = self.m_t.guess_property(button.m_property_name, button.m_property_value) if g: self.g_flashbar.flash(_("Correct")) for btn in self.g_atable.get_children(): if not isinstance(btn, Gtk.Button): continue if btn.m_property_name == button.m_property_name \ and btn.m_property_value == button.m_property_value: btn.get_children()[0].set_name("BoldText") break if g == self.m_t.ALL_CORRECT: self.all_guessed_correct() else: self.g_flashbar.flash(_("Wrong"))
def on_start_practise(self): super(Gui, self).on_start_practise() self.g_music_displayer.clear() [btn.destroy() for btn in self.g_number_box.get_children()] for n in self.m_t.m_P.header.interval_number: xgettext_ignore = _i b = Gtk.Button(xgettext_ignore("interval|%s" % mpd.interval.number_name(n))) b.m_interval_number = n b.connect('clicked', self.on_interval_number_clicked, n) self.g_number_box.pack_start(b, True, True, 0) b.show() [btn.destroy() for btn in self.g_quality_box.get_children()] for n in self.m_t.m_P.header.interval_quality: b = Gtk.Button(mpd.Interval.nn_to_translated_quality(n)) b.m_interval_quality = n b.connect('clicked', self.on_interval_quality_clicked, n) self.g_quality_box.pack_start(b, True, True, 0) b.show() self.g_flashbar.require_size([ _("Correct, but you have already solved this question"), _("Wrong, but you have already solved this question"), ]) self.g_flashbar.delayed_flash(self.short_delay, _("Click 'New' to begin."))
def on_notebutton_clicked(self, btn, n, user_notename): newb = Gtk.Button(user_notename) newb.show() btn.destroy() self.m_answer.append(n) self.g_answer.pack_end(newb, False, False, 0) if not self.g_source.get_children(): # no children mean that the user has finished answering if self.m_t.guess_voicing(self.m_answer): self.g_flashbar.flash(_("Correct")) self.show_music() self.std_buttons_answer_correct() self.g_redo.set_sensitive(False) else: self.g_flashbar.flash(_("Wrong")) self.std_buttons_answer_wrong() self.g_redo.grab_focus() else: self.g_source.get_children()[0].grab_focus()
def show_music(self): self.clear_stacking_frame() md = mpd.MusicDisplayer() self.g_source.pack_start(md, True, True, 0) md.show() md.display(r"\staff{ \clef %s < %s >}" % ( mpd.select_clef(self.m_t.m_P.get_music_as_notename_string('music')), self.m_t.m_P.get_music_as_notename_string('music')), 20) # display the notenames on the buttons with octave info v = self.m_t.m_P.get_music_as_notename_list('music') v.sort(mpd.compare_notenames) for n in v: b = Gtk.Button(mpd.MusicalPitch.new_from_notename(n).get_user_octave_notename()) b.get_children()[0].set_use_markup(1) b.show() self.g_answer.pack_end(b, False, False, 0)
def __init__(self, statistics, heading): Gtk.ScrolledWindow.__init__(self) self.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.vbox = Gtk.VBox(False, 0) self.vbox.set_spacing(gu.PAD) self.vbox.set_border_width(gu.PAD) self.add_with_viewport(self.vbox) hbox = Gtk.HBox(False, 0) hbox.set_spacing(gu.hig.SPACE_SMALL) im = Gtk.Image.new_from_file("graphics/applications-system.svg") self.g_settings_button = b = Gtk.Button() b.connect('clicked', self.on_delete_statistics) b.add(im) hbox.pack_start(b, False, False, 0) self.g_heading = Gtk.Label(label=heading) self.g_heading.set_alignment(0.0, 0.5) self.g_heading.set_name("StatisticsH1") hbox.pack_start(self.g_heading, False, False, 0) self.vbox.pack_start(hbox, False, False, 0) self.m_statistics = statistics self.g_tables = Gtk.VBox(False, 0) self.g_tables.show() self.vbox.pack_start(self.g_tables, True, True, 0) self.show_all()
def create_statistics_config(self): it, page_vbox = self.new_page_box(None, _("Statistics")) box, category_vbox = gu.hig_category_vbox(_("Statistics from 3.15 and older")) page_vbox.pack_start(box, False, False, 0) self.g_old_stat_info = Gtk.Label() self.g_old_stat_info.set_line_wrap(True) self.g_old_stat_info.set_alignment(0.0, 0.5) category_vbox.pack_start(self.g_old_stat_info, False, False, 0) ### self.g_delete_old_statistics = Gtk.Button(stock=Gtk.STOCK_DELETE) self.g_delete_old_statistics.connect('clicked', self.delete_obsolete_statistics) category_vbox.pack_start(self.g_delete_old_statistics, False, False, 0) box, category_vbox = gu.hig_category_vbox(_("Statistics")) page_vbox.pack_start(box, False, False, 0) self.g_stat_info = Gtk.Label() self.g_stat_info.set_line_wrap(True) self.g_stat_info.set_alignment(0.0, 0.5) category_vbox.pack_start(self.g_stat_info, False, False, 0) b = Gtk.Button(stock=Gtk.STOCK_DELETE) b.connect('clicked', self.delete_statistics) category_vbox.pack_start(b, False, False, 0) self.update_statistics_info() self.update_old_statistics_info()
def add(self, question, callback): """add a button and set up callback function. there should not be created more than one button with the same (c locale) name. return the button created. """ if 'newline' in question and question.newline: self.newline() b = Gtk.Button() if question.name.cval in self.m_button_dict: print >> sys.stderr, "Warning: The lessonfile contain several questions with the same name:", question.name.cval print >> sys.stderr, " This is a bug in the lesson file." self.m_button_dict[question.name.cval] = b self.m_name_list.append(question.name.cval) b.m_cname = question.name.cval b.set_sensitive(question.active) b.add(lessonfilegui.new_labelobject(question.name)) b.show_all() self.attach(b, self.m_x, self.m_x+1, self.m_y, self.m_y+1) b.connect('clicked', callback) b.connect('button_release_event', callback) self.conditional_newline() return b
def __init__(self, parent): Gtk.Window.__init__(self) self.set_title(_("GNU Solfege lesson file editor") ) self.set_default_size(400, 400) self.g_parent = parent self.vbox = Gtk.VBox() self.vbox.set_spacing(8) self.add(self.vbox) self.connect('delete_event', self.delete_cb) self.g_htmlwidget = htmlwidget.HtmlWidget(None, None) self.vbox.pack_start(self.g_htmlwidget, True, True, 0) self.vbox.pack_start(Gtk.HSeparator(), False) bbox = Gtk.HButtonBox() bbox.set_border_width(8) self.vbox.pack_start(bbox, False) b = Gtk.Button(stock=Gtk.STOCK_CLOSE) b.connect('clicked', self.close_cb) bbox.pack_start(b, True, True, 0) self.show_all() self.set_focus(b)
def __init__(self, exname, name, sizegroup): Gtk.VBox.__init__(self) cfg.ConfigUtils.__dict__['__init__'](self, exname) self.m_name = name hbox = gu.bHBox(self) hbox.set_spacing(gu.PAD_SMALL) self.g_button = Gtk.Button( soundcard.instrument_names[self.get_int(self.m_name)]) self.g_button.connect('clicked', self.on_btnclick) hbox.pack_start(self.g_button, True, True, 0) g = Gtk.VolumeButton() g.props.value = self.get_int('%s_volume' % name) / MAX_VOLUME def ff(volumebutton, value): self.set_int('%s_volume' % name, int(value * MAX_VOLUME)) g.connect('value-changed', ff) hbox.pack_start(g, False, False, 0) self.g_menu = MidiInstrumentMenu(self.on_instrument_selected) self.m_instrument = self.get_int('preferred_instrument') hbox = Gtk.HBox() hbox.set_spacing(6) self.pack_start(hbox, True, True, 0)
def __init__(self, default_value): Gtk.Box.__init__(self) self.m_value = mpd.notename_to_int(default_value) self.g_entry = Gtk.Entry() self.g_entry.set_editable(False) self.g_entry.set_text(mpd.int_to_user_octave_notename(self.m_value)) self.pack_start(self.g_entry, False, False, 0) # up eb1 = Gtk.Button() eb1.add(Gtk.Arrow(Gtk.ArrowType.UP, Gtk.ShadowType.OUT)) eb1.connect('button-press-event', self.on_up_press) eb1.connect('button-release-event', self.on_up_release) self.pack_start(eb1, True, True, 0) # down eb2 = Gtk.Button() eb2.add(Gtk.Arrow(Gtk.ArrowType.DOWN, Gtk.ShadowType.IN)) eb2.connect('button-press-event', self.on_down_press) eb2.connect('button-release-event', self.on_down_release) self.pack_start(eb2, True, True, 0) self.m_timeout = None
def append_button(self, abspath, name): button = Gtk.Button() button.abspath = abspath button.set_tooltip_text(name) if abspath == '/': home_img = Gtk.Image.new_from_icon_name('user-home-symbolic', Gtk.IconSize.SMALL_TOOLBAR) button.set_image(home_img) else: button.set_label(gutil.ellipse_text(name)) if not Config.GTK_GE_312: button.set_size_request(32, -1) self.path_box.pack_start(button, False, False, 0) button.connect('clicked', self.on_button_clicked)
def color_swatch_new(self, str_color): color = Gdk.color_parse(str_color) rgba = Gdk.RGBA.from_color(color) button = Gtk.Button() area = Gtk.DrawingArea() area.set_size_request(24, 24) area.override_background_color(0, rgba) button.add(area) return button # --------------------------------- # create_flowbox # ---------------------------------
def color_swatch_new(self, str_color): color = Gdk.color_parse(str_color) rgba = Gdk.RGBA.from_color(color) button = Gtk.Button() area = Gtk.DrawingArea() area.set_size_request(24, 24) area.override_background_color(0, rgba) button.add(area) return button # print("Pedro deconnected") # --------------------------------- # color_widget # ---------------------------------
def create_tab(self, title, tab_child, icon=''): tab_box = Gtk.HBox(False, 3) close_button = Gtk.Button() image = Gtk.Image() image.set_from_stock(Gtk.STOCK_CLOSE, Gtk.IconSize.MENU) label = Gtk.Label(label=title) if icon: i = Gtk.Image() i.set_from_stock(eval('Gtk.STOCK_' + icon), Gtk.IconSize.MENU) tab_box.pack_start(i, False, False, 0) close_button.connect("clicked", self.close_tab, tab_child) close_button.set_image(image) close_button.set_relief(Gtk.ReliefStyle.NONE) tab_box.pack_start(label, True, True, 0) tab_box.pack_end(close_button, False, False, 0) tab_box.show_all() if title in ['Loading dasm...', 'Code', 'Callgraph', 'Flowgraph', 'Interactive', 'Strings', "Sections", 'Hexdump', 'Bindiff', 'File info']: close_button.hide() return tab_box
def __init__(self, part: Dict[str, Any], core: ApartCore, main_view: 'MainView'): Gtk.Box.__init__(self) self.part = part self.core = core self.main_view = main_view self.add(key_and_val('Name', self.name())) self.add(key_and_val('Type', self.part.get('fstype', 'unknown'))) self.add(key_and_val('Label', self.part.get('label', 'none'))) self.add(key_and_val('Size', humanize.naturalsize(self.part['size'], binary=True))) self.clone_button = Gtk.Button("Clone", halign=Gtk.Align.END) self.restore_button = Gtk.Button("Restore", halign=Gtk.Align.END) if self.is_mounted(): self.clone_button.set_sensitive(False) self.clone_button.set_tooltip_text('Partition is currently mounted') self.restore_button.set_sensitive(False) self.restore_button.set_tooltip_text('Partition is currently mounted') else: self.clone_button.connect('clicked', lambda b: self.main_view.show_new_clone()) self.restore_button.connect('clicked', lambda b: self.main_view.show_new_restore()) buttons = Gtk.Box(hexpand=True, halign=Gtk.Align.END) buttons.add(self.clone_button) buttons.add(self.restore_button) self.add(buttons) main_view.connect('notify::visible-child', self.on_main_view_change)
def on_menuitem_custom_activate(self, widget): self.custom_window = Gtk.Window() self.custom_window.set_default_size(640, 480) self.custom_window.set_position(Gtk.WindowPosition.CENTER) self.custom_window.set_title("Custom CSS") self.custom_vbox = Gtk.VBox() self.custom_scroller = Gtk.ScrolledWindow() self.custom_button = Gtk.Button("Apply") self.custom_vbox.pack_end(self.custom_button, False, False, 0) self.custom_text_view = Gtk.TextView() self.custom_text_buffer = Gtk.TextBuffer() self.custom_text_buffer.set_text(self.custom_css) self.custom_text_view.set_buffer(self.custom_text_buffer) self.custom_scroller.add(self.custom_text_view) self.custom_vbox.pack_start(self.custom_scroller, True, True, 0) self.custom_window.add(self.custom_vbox) self.custom_window.show_all() self.custom_button.connect("clicked", self.apply_custom_css, self.custom_window, self.custom_text_buffer)
def __init__(self): window = Gtk.Window(Gtk.WindowType.TOPLEVEL) window.set_title("Audio-Player") window.set_default_size(300, -1) window.connect("destroy", Gtk.main_quit, "WM destroy") vbox = Gtk.VBox() window.add(vbox) self.entry = Gtk.Entry() vbox.pack_start(self.entry, False, True, 0) self.button = Gtk.Button("Start") self.button.connect("clicked", self.start_stop) vbox.add(self.button) window.show_all() self.player = Gst.ElementFactory.make("playbin", "player") fakesink = Gst.ElementFactory.make("fakesink", "fakesink") self.player.set_property("video-sink", fakesink) bus = self.player.get_bus() bus.add_signal_watch() bus.connect("message", self.on_message)
def __init__(self,parent): Gtk.Grid.__init__(self,column_homogeneous=False, column_spacing=10,row_spacing=0) button1 = Gtk.Button("Choose File") button1.connect("clicked", self.on_file_clicked) self.add(button1) self.text_file = Gtk.Entry() self.text_file.set_hexpand(True) self.attach(self.text_file, 1, 0, 4, 1) button2 = Gtk.Button("Choose Folder") button2.connect("clicked", self.on_folder_clicked) self.attach_next_to(button2, button1, Gtk.PositionType.BOTTOM, 1, 1) self.text_folder = Gtk.Entry() self.attach(self.text_folder, 1, 1, 4, 1)
def __init__(self,MainGrid): Gtk.VBox.__init__(self) self.btn1=Gtk.Button() self.btn1.set_image(Gtk.Image.new_from_icon_name("filenew",Gtk.IconSize.DIALOG)) self.btn1.set_name("button1") self.add(self.btn1) # # self.win_width = MainGrid.window.win_width # self.win_height = MainGrid.window.win_height # wid = self.win_width * 0.1 # hei = self.win_height # print "requested width: ",wid # print "requested height: ",hei # print "-----------------------------" # self.set_size_request(wid, hei)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.headerbar.set_subtitle('Group {id}'.format(id=self.model.group_id)) delete_button = Gtk.Button(label='Delete', visible=True) delete_button.connect('clicked', self._on_delete_click) self.headerbar.pack_end(delete_button) self.lights_list = SelectableLightList( self.model.bridge.lights_by_id.values(), set(light.light_id for light in self.model.lights) ) self.content.pack_start(self.lights_list, True, True, 6) self.content.reorder_child(self.lights_list, 2)
def __init__(self, desc): super(KeybindingWidget, self).__init__() self.desc = desc self.label = Gtk.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 __init__(self): Gtk.Window.__init__(self, title = "Choose a method of Sculpture Generation") self.set_border_width(10) self.set_default_size(400, 50) #initiates Gtk box window self.box = Gtk.Box(spacing = 6) self.add(self.box) #Initializes Vector Animation Button, places in box self.VectorButton = Gtk.Button(label = "Vector Animation") self.VectorButton.connect("clicked", self.on_VectorButton_clicked) self.VectorButton.connect("clicked", Gtk.main_quit) self.box.pack_start(self.VectorButton, True, True, 0) #Initializes Perlin Noise Button, places in box self.PerlinButton = Gtk.Button(label = "Perlin Noise") self.PerlinButton.connect("clicked", self.on_PerlinButton_clicked) self.PerlinButton.connect("clicked", Gtk.main_quit) self.box.pack_start(self.PerlinButton, True, True, 0) #when VectorButton clicked, toggles to new GUI
def create_main_window(self): self.main_window = Gtk.Window( title = _("Omikron: The Nomad Soul"), type = Gtk.WindowType.TOPLEVEL, window_position = Gtk.WindowPosition.CENTER_ALWAYS, resizable = False, ) self.main_window.connect('delete-event', self.quit_app) button_patch = Gtk.Button( label = _("Old Games Widescreen Patch"), margin_top = 10, margin_bottom = 10, margin_left = 10, margin_right = 10 ) button_patch.connect('clicked', self.cb_button_patch) self.main_window.add(button_patch) self.main_window.show_all()
def __init__(self): self.main_window = Gtk.Window() self.main_window.set_border_width(5) self.main_window.connect("destroy", self._destroy) self.main_vbox = Gtk.VBox() self.select_hbox = Gtk.HBox() self.select_button = Gtk.Button("Select") self.select_button.connect("clicked", self._select_clicked) self.select_hbox.pack_start(self.select_button, False, True, 0) self.file_combo = Gtk.ComboBoxText() self.file_combo.connect("changed", self._file_combo_changed) self.select_hbox.pack_start(self.file_combo, True, True, 0) self.main_vbox.pack_start(self.select_hbox, False, True, 0) self.metadata_table = Gtk.Table(1, 1) self.metadata_table.attach( Gtk.Label("Select a file to view metadata information..."), 0, 1, 0, 1) self.main_vbox.pack_start(self.metadata_table, True, True, 0) self.main_window.add(self.main_vbox) self.main_window.show_all()
def __init__(self, files): self.files = files Gtk.Window.__init__(self, title="TMSU") self.set_size_request(200, 100) self.set_border_width(10) self.set_type_hint(Gdk.WindowTypeHint.DIALOG) vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6) self.add(vbox) prompt_text = 'Add (space-separated) tags to %d file%s' % (len(files), '' if len(files)==1 else 's') self.prompt_label = Gtk.Label(label=prompt_text) vbox.pack_start(self.prompt_label, True, True, 0) self.entry = Gtk.Entry() self.entry.connect("activate", self.on_entry_activated) vbox.pack_start(self.entry, True, True, 0) self.button = Gtk.Button(label="Add") self.button.connect("clicked", self.on_button_clicked) vbox.pack_start(self.button, True, True, 0)
def _build_confirm_changes_button(self, label=None, on_signal="clicked", callback=None): """ Build a confirmation button used in every side bar menus. This button triggers interaction with the backend in case of settings changes. Otherwise it stays insensitive. """ if not label: label = "Confirm" button = Gtk.Button(label) button.set_sensitive(False) button.set_margin_top(12) if callback: button.connect(on_signal, callback) return button
def __init__(self): self.placeholder_image = Gtk.Image.new_from_icon_name( Gtk.STOCK_NEW, Gtk.IconSize.DIALOG) self.new_feed_button = Gtk.Button("New Feed") self.new_feed_vbox = Gtk.Box(Gtk.Orientation.VERTICAL) self.new_feed_vbox.set_halign(Gtk.Align.CENTER) self.new_feed_vbox.set_valign(Gtk.Align.CENTER) _pack_widgets(self.new_feed_vbox, self.placeholder_image, self.new_feed_button) self._grid = Gtk.Grid() self._grid.set_row_homogeneous(True) self._grid.set_column_homogeneous(True) self._grid.attach(self.new_feed_vbox, 0, 0, 1, 1) self._grid.attach(Gtk.Label("FEED ELEMENT DEBUG1"), 1, 0, 1, 1) # DEBUG self._grid.attach(Gtk.Label("FEED ELEMENT DEBUG2"), 0, 1, 1, 1) # DEBUG self._grid.attach(Gtk.Label("FEED ELEMENT DEBUG3"), 1, 1, 1, 1) # DEBUG self._grid.show_all() self.container = self._grid
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, 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)