def __init__(self, text_label=None, icon_name=None, text_maxlen=style.MENU_WIDTH_CHARS, xo_color=None, file_name=None): GObject.GObject.__init__(self) self._accelerator = None label = Gtk.AccelLabel(label=text_label) label.set_alignment(0.0, 0.5) label.set_accel_widget(self) if text_maxlen > 0: label.set_ellipsize(style.ELLIPSIZE_MODE_DEFAULT) label.set_max_width_chars(text_maxlen) self.add(label) label.show() if icon_name is not None: icon = Icon(icon_name=icon_name, pixel_size=style.SMALL_ICON_SIZE) if xo_color is not None: icon.props.xo_color = xo_color self.set_image(icon) icon.show() elif file_name is not None: icon = Icon(file=file_name, pixel_size=style.SMALL_ICON_SIZE) if xo_color is not None: icon.props.xo_color = xo_color self.set_image(icon) icon.show() self.connect('can-activate-accel', self.__can_activate_accel_cb) self.connect('hierarchy-changed', self.__hierarchy_changed_cb)
def __init__(self, text_label=None, icon_name=None, text_maxlen=60, xo_color=None, file_name=None): GObject.GObject.__init__(self) self._accelerator = None label = Gtk.AccelLabel(label=text_label) label.set_alignment(0.0, 0.5) label.set_accel_widget(self) if text_maxlen > 0: label.set_ellipsize(Pango.EllipsizeMode.MIDDLE) label.set_max_width_chars(text_maxlen) self.add(label) label.show() if icon_name is not None: icon = Icon(icon_name=icon_name, icon_size=Gtk.IconSize.SMALL_TOOLBAR) if xo_color is not None: icon.props.xo_color = xo_color self.set_image(icon) icon.show() elif file_name is not None: icon = Icon(file=file_name, icon_size=Gtk.IconSize.SMALL_TOOLBAR) if xo_color is not None: icon.props.xo_color = xo_color self.set_image(icon) icon.show() self.connect('can-activate-accel', self.__can_activate_accel_cb) self.connect('hierarchy-changed', self.__hierarchy_changed_cb)
def __init__(self, text_label=None, icon_name=None, text_maxlen=60, xo_color=None, file_name=None, image=None): super(MenuItem, self).__init__() self._accelerator = None self.props.submenu = None label = Gtk.AccelLabel(text_label) label.set_alignment(0.0, 0.5) label.set_accel_widget(self) if text_maxlen > 0: label.set_ellipsize(Pango.EllipsizeMode.MIDDLE) label.set_max_width_chars(text_maxlen) self.add(label) label.show() if image is not None: self.set_image(image) image.show() elif icon_name is not None: icon = Icon(icon_name=icon_name, icon_size=Gtk.IconSize.SMALL_TOOLBAR) if xo_color is not None: icon.props.xo_color = xo_color self.set_image(icon) icon.show() elif file_name is not None: icon = Icon(file=file_name, icon_size=Gtk.IconSize.SMALL_TOOLBAR) if xo_color is not None: icon.props.xo_color = xo_color self.set_image(icon) icon.show()
def __init__(self, code_window, ir_window, solution_view): Gtk.HBox.__init__(self) self.code_window = code_window self.ir_window = ir_window self.solution_view = solution_view self.command_label = Gtk.Label() self.run_button = Gtk.Button() self.run_label = Gtk.AccelLabel("Run") self.run_label.set_accel_widget(Gtk.Label("F8")) self.run_label.set_accel(Gdk.KEY_A, Gdk.ModifierType.CONTROL_MASK) self.run_button.add(self.run_label) self.accel_group = Gtk.AccelGroup() window.add_accel_group(self.accel_group) self.run_button.add_accelerator("activate", self.accel_group, Gdk.KEY_A, Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.MASK) self.command_label.set_halign(Gtk.Align.START) self.command_label.set_valign(Gtk.Align.START) self.pack_start(self.command_label, True, True, 0) self.pack_start(self.run_button, False, False, 0) self.run_button.connect("clicked", self.on_click_run)
def __init__(self, label, stock=None): """An menu item with an (option) icon. you can use this in three different ways: ContextMenuItem('foo') ContextMenuItem('foo', Gtk.STOCK_PASTE) ContextMenuItem(Gtk.STOCK_PASTE) The first will display an label 'foo'. The second will display the same label with the paste icon, and the last will display the paste icon with the default paste label """ Gtk.ImageMenuItem.__init__(self) if not stock: stock = label info = Gtk.stock_lookup(label) if info: try: label = info.label # For PyGTk except AttributeError: label = info[1] lbl = Gtk.AccelLabel(label=label) lbl.set_alignment(0, 0.5) lbl.set_use_underline(True) lbl.set_use_markup(True) self.add(lbl) image = Gtk.Image() image.set_from_stock(stock, Gtk.IconSize.MENU) self.set_image(image)
def __init__(self): Gtk.Window.__init__(self) self.set_title("AccelLabel") self.set_default_size(200, -1) self.connect("destroy", Gtk.main_quit) grid = Gtk.Grid() self.add(grid) accelgroup = Gtk.AccelGroup() self.add_accel_group(accelgroup) accellabel = Gtk.AccelLabel("Button accelerator:") accellabel.set_hexpand(True) grid.attach(accellabel, 0, 0, 2, 1) button = Gtk.Button("Save") button.add_accelerator("clicked", accelgroup, Gdk.keyval_from_name("s"), Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE) button.connect("clicked", self.on_button_clicked) accellabel.set_accel_widget(button) grid.attach(button, 0, 1, 2, 1)
def get_menu_item(self, label, icon, key): item = Gtk.MenuItem() pack = Gtk.HBox() img = Gtk.Image() label = Gtk.AccelLabel(label) label.set_accel(key, Gdk.ModifierType.CONTROL_MASK) img.set_from_stock(icon, 1) pack.pack_start(img, False, False, 0) pack.pack_start(label, True, True, 0) item.add(pack) return item
def _build_menu_item(self, name, menu, image=None, on_signal="activate", callback=None, accelerator_key=None): """ """ menu_item = Gtk.MenuItem() if image: hbox = Gtk.Box(Gtk.Orientation.HORIZONTAL) try: icon = Gtk.Image.new_from_icon_name(image, 1) except TypeError: # ``image`` is a Gtk.Image already loaded. icon = image label = Gtk.Label(name) utils.pack_widgets(hbox, icon, label) menu_item.add(hbox) else: menu_item.set_label(name) if callback: menu_item.connect(on_signal, callback) if accelerator_key: key, modifier = Gtk.accelerator_parse(accelerator_key) menu_item.add_accelerator("activate", self.accel_group, key, modifier, Gtk.AccelFlags.VISIBLE) accel_label = Gtk.AccelLabel() accel_label.set_accel_widget(menu_item) hbox.pack_end(accel_label, True, True, 0) menu.append(menu_item) return menu_item
def __init__(self, label=None, accel_path=None, text_maxlen=style.MENU_WIDTH_CHARS, **kwargs): # DEPRECATED: label is passed with the primary-text property, # accel_path is set via the invoker property self._primary_text = None self._secondary_text = None self._icon = None self._icon_visible = True self._palette_state = self.PRIMARY self._primary_event_box = Gtk.EventBox() self._primary_event_box.show() self._primary_box = Gtk.HBox() self._primary_event_box.add(self._primary_box) self._primary_box.show() self._icon_box = Gtk.HBox() self._icon_box.set_size_request(style.GRID_CELL_SIZE, -1) self._primary_box.pack_start(self._icon_box, False, True, 0) labels_box = Gtk.VBox() self._label_alignment = Gtk.Alignment(xalign=0, yalign=0.5, xscale=1, yscale=0.33) self._label_alignment.set_padding( style.DEFAULT_SPACING, style.DEFAULT_SPACING, style.DEFAULT_SPACING, style.DEFAULT_SPACING) self._label_alignment.add(labels_box) self._label_alignment.show() self._primary_box.pack_start(self._label_alignment, True, True, 0) labels_box.show() self._label = Gtk.AccelLabel(label='') self._label.set_alignment(0, 0.5) if text_maxlen > 0: self._label.set_max_width_chars(text_maxlen) self._label.set_ellipsize(Pango.EllipsizeMode.MIDDLE) labels_box.pack_start(self._label, True, True, 0) self._primary_event_box.connect('button-release-event', self.__button_release_event_cb) self._primary_event_box.set_events(Gdk.EventMask.BUTTON_RELEASE_MASK) self._secondary_label = Gtk.Label() self._secondary_label.set_alignment(0, 0.5) labels_box.pack_start(self._secondary_label, True, True, 0) self._secondary_box = Gtk.VBox() self._separator = Gtk.HSeparator() self._secondary_box.pack_start(self._separator, True, True, 0) self._secondary_anim = animator.Animator(2.0, 10) self._secondary_anim.add(_SecondaryAnimation(self)) # we init after initializing all of our containers PaletteWindow.__init__(self, **kwargs) self._full_request = [0, 0] self._content = None # we set these for backward compatibility if label is not None: self.props.primary_text = label self._add_content() self.action_bar = PaletteActionBar() self._secondary_box.pack_start(self.action_bar, True, True, 0) self.action_bar.show() self.connect('notify::invoker', self.__notify_invoker_cb) self.connect('popdown', self.__popdown_cb) # Default to a normal window palette self._content_widget = None self.set_content(None)
def __init__(self, text_label=None, icon_name=None, text_maxlen=60, xo_color=None, file_name=None, accelerator=None): """ text_label -- str a text to display in the menu. icon_name -- str the name of a sugar icon to be displayed. Takse precedence over file_name. text_maxlen -- int the desired maximum width of the label, in characters. By default is 60. xo_color -- sugar.graphics.XoColor the color to be applied to the icon. file_name -- str the path to a svg file used as icon. accelerator -- str a text used to display the keyboard shortcut associated to the menu. """ Gtk.EventBox.__init__(self) self.set_above_child(True) self.icon = None self._hbox = Gtk.HBox() vbox = Gtk.VBox() self.add(vbox) vbox.show() hbox = Gtk.HBox() vbox.pack_start(hbox, True, True, style.DEFAULT_PADDING) hbox.show() hbox.pack_start(self._hbox, True, True, style.DEFAULT_PADDING) if icon_name is not None: self.icon = Icon(icon_name=icon_name, pixel_size=style.SMALL_ICON_SIZE) if xo_color is not None: self.icon.props.xo_color = xo_color self._hbox.pack_start(self.icon, expand=False, fill=False, padding=style.DEFAULT_PADDING) elif file_name is not None: self.icon = Icon(file=file_name, pixel_size=style.SMALL_ICON_SIZE) if xo_color is not None: self.icon.props.xo_color = xo_color self._hbox.pack_start(self.icon, expand=False, fill=False, padding=style.DEFAULT_PADDING) align = Gtk.Alignment(xalign=0.0, yalign=0.5, xscale=0.0, yscale=0.0) self.label = Gtk.Label(text_label) if text_maxlen > 0: self.label.set_max_width_chars(text_maxlen) self.label.set_ellipsize(style.ELLIPSIZE_MODE_DEFAULT) align.add(self.label) self._hbox.pack_start(align, expand=True, fill=True, padding=style.DEFAULT_PADDING) self._accelerator_label = Gtk.AccelLabel('') if accelerator is not None: self._accelerator_label.set_text(accelerator) self._hbox.pack_start(self._accelerator_label, expand=False, fill=False, padding=style.DEFAULT_PADDING) self.id_bt_release_cb = self.connect('button-release-event', self.__button_release_cb) self.id_enter_notify_cb = self.connect('enter-notify-event', self.__enter_notify_cb) self.id_leave_notify_cb = self.connect('leave-notify-event', self.__leave_notify_cb) self.show_all()
def __init__(self, text_label=None, icon_name=None, text_maxlen=60, xo_color=None, file_name=None, accelerator=None): Gtk.EventBox.__init__(self) self.set_above_child(True) self.icon = None self._hbox = Gtk.HBox() vbox = Gtk.VBox() self.add(vbox) vbox.show() hbox = Gtk.HBox() vbox.pack_start(hbox, True, True, style.DEFAULT_PADDING) hbox.show() hbox.pack_start(self._hbox, True, True, style.DEFAULT_PADDING) if icon_name is not None: self.icon = Icon(icon_name=icon_name, pixel_size=style.SMALL_ICON_SIZE) if xo_color is not None: self.icon.props.xo_color = xo_color self._hbox.pack_start(self.icon, expand=False, fill=False, padding=style.DEFAULT_PADDING) elif file_name is not None: self.icon = Icon(file=file_name, pixel_size=style.SMALL_ICON_SIZE) if xo_color is not None: self.icon.props.xo_color = xo_color self._hbox.pack_start(self.icon, expand=False, fill=False, padding=style.DEFAULT_PADDING) align = Gtk.Alignment(xalign=0.0, yalign=0.5, xscale=0.0, yscale=0.0) self.label = Gtk.Label(text_label) if text_maxlen > 0: self.label.set_max_width_chars(text_maxlen) self.label.set_ellipsize(style.ELLIPSIZE_MODE_DEFAULT) align.add(self.label) self._hbox.pack_start(align, expand=True, fill=True, padding=style.DEFAULT_PADDING) self._accelerator_label = Gtk.AccelLabel('') if accelerator is not None: self._accelerator_label.set_text(accelerator) self._hbox.pack_start(self._accelerator_label, expand=False, fill=False, padding=style.DEFAULT_PADDING) self.id_bt_release_cb = self.connect('button-release-event', self.__button_release_cb) self.id_enter_notify_cb = self.connect('enter-notify-event', self.__enter_notify_cb) self.id_leave_notify_cb = self.connect('leave-notify-event', self.__leave_notify_cb) self.show_all()
from gi.repository import Gtk, Gdk def button_clicked(widget): print("Save button clicked") window = Gtk.Window() window.set_default_size(200, -1) window.connect("destroy", lambda q: Gtk.main_quit()) grid = Gtk.Grid() window.add(grid) accelgroup = Gtk.AccelGroup() window.add_accel_group(accelgroup) accellabel = Gtk.AccelLabel("Button accelerator:") accellabel.set_hexpand(True) grid.attach(accellabel, 0, 0, 2, 1) button = Gtk.Button("Save") button.add_accelerator("clicked", accelgroup, Gdk.keyval_from_name("s"), Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE) button.connect("clicked", button_clicked) accellabel.set_accel_widget(button) grid.attach(button, 0, 1, 2, 1) window.show_all() Gtk.main()