def build_widget(self): vb = Gtk.VBox() l = Gtk.Label(label=self.label) vb.pack_start(l, False, True, 0) hb = Gtk.HBox() eb = Gtk.EventBox() ar = Gtk.Arrow(Gtk.ArrowType.LEFT, Gtk.ShadowType.IN) ar.set_tooltip_text( _("Click to see more frames or scroll with the mouse wheel")) eb.connect('button-press-event', lambda b, e: self.update_offset(-1)) eb.add(ar) hb.pack_start(eb, False, True, 0) r = None for i in range(self.count): r = TimestampRepresentation(0, None, self.controller, width=self.frame_width, visible_label=True, precision=0) r.add_class("frameselector_frame") r.add_class("frameselector_frame_%s" % self.border_mode) self.frames.append(r) r.connect("clicked", self.select_time) def enter_bookmark(widget, event): widget.add_class('frameselector_selected') return False def leave_bookmark(widget, event): widget.remove_class('frameselector_selected') return False r.connect('enter-notify-event', enter_bookmark) r.connect('leave-notify-event', leave_bookmark) hb.pack_start(r, False, True, 0) hb.connect("draw", self.check_size) eb = Gtk.EventBox() ar = Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.IN) ar.set_tooltip_text( _("Click to see more frames or scroll with the mouse wheel")) eb.connect('button-press-event', lambda b, e: self.update_offset(+1)) eb.add(ar) hb.pack_start(eb, False, True, 0) vb.add(hb) vb.set_events(Gdk.EventMask.SCROLL_MASK | Gdk.EventMask.KEY_PRESS_MASK) vb.connect('scroll-event', self.handle_scroll_event) vb.connect('key-press-event', self.handle_key_press) self.update_timestamp(self.timestamp) return vb
def __init__(self): Gtk.Window.__init__(self, title="HeaderBar Demo") self.set_border_width(10) self.set_default_size(400, 200) hb = Gtk.HeaderBar() hb.set_show_close_button(True) hb.props.title = "HeaderBar example" self.set_titlebar(hb) button = Gtk.Button() icon = Gio.ThemedIcon(name="mail-send-receive-symbolic") 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)) box.add(button) button = Gtk.Button() button.add(Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE)) box.add(button) hb.pack_start(box) self.add(Gtk.TextView())
def __init__(self): Gtk.Window.__init__(self, title="Header Bar") self.set_border_width(10) self.set_default_size(1000, 600) header_bar = Gtk.HeaderBar() header_bar.set_show_close_button(True) header_bar.props.title = "HEADER BAR" self.set_titlebar(header_bar) # Olusturulan kutu da baglanmis ogeler kutu = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) Gtk.StyleContext.add_class(kutu.get_style_context(), "linked") # Sol ok isareti sol_ok = Gtk.Button() sol_ok.add(Gtk.Arrow(Gtk.ArrowType.LEFT, Gtk.ShadowType.NONE)) kutu.add(sol_ok) # Sag ok isareti sag_ok = Gtk.Button() sag_ok.add(Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE)) kutu.add(sag_ok) header_bar.pack_start(kutu) self.add(Gtk.TextView())
def build_bars(self): self.__header = Titlebar(title="Tarpon", show_close_button=True) if hasattr(Gtk.HeaderBar, 'set_decoration_layout'): self.__header.set_decoration_layout(":close") self.__back = Gtk.Button() self.__back.add(Gtk.Arrow(Gtk.ArrowType.LEFT, Gtk.ShadowType.NONE)) self.__forward = Gtk.Button() self.__forward.add(Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE)) self.__new_tab = toolbar_button("tab-new-symbolic", Gtk.Button) self.__search = toolbar_button("edit-find-symbolic", Gtk.ToggleButton) self.__menu = toolbar_button("open-menu-symbolic", Gtk.MenuButton) builder = Gtk.Builder() builder.add_from_file(views(self.__application.pkgdatadir, "menu.ui")) if hasattr(Gtk, 'Popover'): popover = Gtk.Popover.new_from_model(self.__menu, builder.get_object("menu")) self.__menu.set_popover(popover) else: print("Gtk.Popover not supported. Using menu model.") self.__menu.set_menu_model(builder.get_object("menu")) # Add buttons to header # TODO: Add buttons to a toolbar instead of Titlebar if using Unity. # Unity attaches the menu to the top of the screen, so Gtk.HeaderBar # looks out of place and a button for opening the menu is unnecessary. self.__header.add_buttons_to_left((self.__back, self.__forward), linked=True, spacing=0) self.__header.add_buttons_to_right((self.__new_tab, self.__menu))
def do_activate(self): self.hb = Gtk.HeaderBar() self.hb.props.show_close_button = True self.hb.set_title("Liferea") # Left side buttons 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.set_action_name("app.prev-read-item") button.set_tooltip_text(_("Previous Item")) box.add(button) button = Gtk.Button() button.add(Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE)) button.set_action_name("app.next-read-item") button.set_tooltip_text(_("Next Item")) box.add(button) button = Gtk.Button() icon = Gio.ThemedIcon(name="edit-redo-symbolic") image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON) button.add(image) button.set_action_name("app.next-unread-item") button.set_tooltip_text(_("_Next Unread Item").replace("_", "")) box.add(button) button = Gtk.Button() icon = Gio.ThemedIcon(name="emblem-ok-symbolic") image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON) button.add(image) button.set_action_name("app.mark-selected-feed-as-read") button.set_tooltip_text(_("_Mark Items Read").replace("_", "")) box.add(button) self.hb.pack_start(box) # Right side buttons button = Gtk.MenuButton() icon = Gio.ThemedIcon(name="open-menu-symbolic") image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON) builder = self.shell.get_property("builder") button.set_menu_model(builder.get_object("menubar")) button.add(image) self.hb.pack_end(button) button = Gtk.Button() icon = Gio.ThemedIcon(name="edit-find-symbolic") image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON) button.add(image) button.set_action_name("app.search-feeds") button.set_tooltip_text(_("Search All Feeds...")) self.hb.pack_end(button) self.shell.lookup("mainwindow").set_titlebar(self.hb) self.shell.lookup("mainwindow").set_show_menubar(False) self.shell.lookup("maintoolbar").set_visible(False) self.hb.show_all()
def __init__(self): Gtk.Window.__init__(self, title = "Window Title") self.set_border_width(10) self.set_default_size(500, 400) header_bar = Gtk.HeaderBar() header_bar.set_show_close_button(True) header_bar.props.title = "Header Bar title" self.set_titlebar(header_bar) # Icons - Audio button on the right audio_button = Gtk.Button() cd_icon = Gio.ThemedIcon(name="gnome-dev-cdrom-audio") image = Gtk.Image.new_from_gicon(cd_icon, Gtk.IconSize.BUTTON) audio_button.add(image) header_bar.pack_end(audio_button) # Create box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) Gtk.StyleContext.add_class(box.get_style_context(), "linked") # Left arrow left_arrow = Gtk.Button() left_arrow.add(Gtk.Arrow(Gtk.ArrowType.LEFT, Gtk.ShadowType.NONE)) box.add(left_arrow) # Right arrow right_arrow = Gtk.Button() right_arrow.add(Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE)) box.add(right_arrow) header_bar.pack_start(box) self.add(Gtk.TextView())
def __init__(this): Gtk.Window.__init__(this) this.set_border_width(10) this.set_default_size(500, 300) hb = Gtk.HeaderBar() hb.set_title("HeaderBar Example") hb.set_show_close_button(True) this.set_titlebar(hb) button = Gtk.Button() icon = Gio.ThemedIcon(name="mail-send-receive-symbolic") # image is scaled to the size of the Button image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON) button.add(image) # Mark the way an image is applied to the button hb.pack_end(button) box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) # adds the linked style to the current style Gtk.StyleContext.add_class(box.get_style_context(), "linked") button = Gtk.Button() button.add(Gtk.Arrow(Gtk.ArrowType.LEFT, Gtk.ShadowType.NONE)) box.add(button) button = Gtk.Button() button.add(Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE)) box.add(button) hb.pack_start(box) # we need not put this on a layout because this is the only widget of our window this.add(Gtk.TextView())
def __init__(self): super().__init__(title=TITLE) self.props.border_width = 10 self.set_default_size(800, 600) header_bar = Gtk.HeaderBar() header_bar.props.show_close_button = True header_bar.props.title = TITLE self.set_titlebar(header_bar) add_btn = Gtk.Button() add_icon = Gio.ThemedIcon(name='list-add-symbolic') add_btn.add(Gtk.Image.new_from_gicon(add_icon, Gtk.IconSize.BUTTON)) add_btn.connect('clicked', self.on_add_clicked) header_bar.pack_end(add_btn) nav_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) Gtk.StyleContext.add_class(nav_box.get_style_context(), 'linked') header_bar.pack_start(nav_box) left_btn = Gtk.Button() left_btn.add(Gtk.Arrow(Gtk.ArrowType.LEFT)) left_btn.connect('clicked', self.on_left_clicked) nav_box.add(left_btn) right_btn = Gtk.Button() right_btn.add(Gtk.Arrow(Gtk.ArrowType.RIGHT)) right_btn.connect('clicked', self.on_right_clicked) nav_box.add(right_btn) fancy_lbl = Gtk.Label('hai') self.add(fancy_lbl)
def __init__(self): self.window = Gtk.Window() self.window.set_icon_from_file(get_resource_path("icon.png")) self.window.set_size_request(1000, 600) self.window.set_default_size(800, 600) self.s = Gtk.ScrolledWindow() self.context = WebKit2.WebContext.get_default() sm = self.context.get_security_manager() self.cookies = self.context.get_cookie_manager() self.manager = WebKit2.UserContentManager() self.view = WebKit2.WebView.new_with_user_content_manager(self.manager) self.settings = self.view.get_settings() cookies_path = '/tmp/cookies.txt' storage = WebKit2.CookiePersistentStorage.TEXT policy = WebKit2.CookieAcceptPolicy.ALWAYS self.cookies.set_accept_policy(policy) self.cookies.set_persistent_storage(cookies_path, storage) self.view.load_uri("https://music.yandex.ru/") self.s.add(self.view) self.hb = Gtk.HeaderBar() self.hb.set_show_close_button(True) self.window.set_titlebar(self.hb) button = Gtk.Button() icon = Gio.ThemedIcon(name="mail-send-receive-symbolic") image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON) button.add(image) button.connect("clicked", self.on_refresh) self.hb.pack_end(button) box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) Gtk.StyleContext.add_class(box.get_style_context(), "linked") button1 = Gtk.Button() button1.add(Gtk.Arrow(Gtk.ArrowType.LEFT, Gtk.ShadowType.NONE)) button1.connect("clicked", self.on_back) box.add(button1) self.button_play = Gtk.Button.new_with_label("Play/Pause") self.button_play.connect("clicked", self.on_play) box.add(self.button_play) button2 = Gtk.Button() button2.add(Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE)) button2.connect("clicked", self.on_next) box.add(button2) self.hb.pack_start(box) self.window.add(self.s) self.window.show_all() self.window.connect('destroy', self.destroy)
def on_button_clicked(self, widget): numpage = self.notebook.get_n_pages() + 1 #label = Gtk.Label(label='label{}'.format(numpage)) #creating new tab label = Gtk.Label('new tab{}'.format(numpage)) tab = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2) #web view main_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2) view_box = Gtk.Box() self.webview = WebKit2.WebView() self.webview.show() view_box.pack_start(self.webview, True, True, 0) #url bar address_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=2) self.backward_button = Gtk.Button() self.backward_button.add( Gtk.Arrow(Gtk.ArrowType.LEFT, Gtk.ShadowType.NONE)) self.backward_button.connect("clicked", lambda x: self.webview.go_back()) self.forward_button = Gtk.Button() self.forward_button.add( Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE)) self.forward_button.connect("clicked", lambda x: self.webview.go_forward()) self.go_button = Gtk.Button(label="Go") self.go_button.connect("clicked", self._load_url) self.url_bar = Gtk.Entry() self.url_bar.set_text("Enter URL") self.url_bar.connect("activate", self._load_url) self.close_button = Gtk.Button(label="close tab") self.close_button.connect("clicked", self._close_tab) address_box.add(self.backward_button) address_box.add(self.forward_button) address_box.add(self.go_button) address_box.pack_start(self.url_bar, True, True, 0) address_box.add(self.close_button) #adding boxes main_box.add(address_box) main_box.pack_start(view_box, True, True, 0) tab.pack_start(main_box, True, True, 0) self.notebook.append_page(tab, label) print(self.notebook.get_n_pages()) self.notebook.show_all()
def __init__(self, text, menu): GObject.GObject.__init__(self) self.menu = menu hbox1 = Gtk.HBox() hbox2 = Gtk.HBox() icon = Gtk.Image() icon.set_from_file(datafile_path('bokken-small.svg')) hbox1.pack_start(icon, True, True, 3) label = Gtk.Label() label.set_markup("<b>" + text + "</b>") hbox1.pack_start(label, True, True, 3) arrow = Gtk.Arrow(Gtk.ArrowType.DOWN, Gtk.ShadowType.IN) hbox1.pack_start(arrow, False, False, 3) hbox2.pack_start(hbox1, True, True, 0) # MEOW Text settings #attrs = Pango.AttrList() #attrs.change(Pango.AttrWeight(Pango.Weight.SEMIBOLD, 0, -1)) #label.set_attributes(attrs) self.add(hbox2) self.set_relief(Gtk.ReliefStyle.NORMAL) self.set_can_focus(True) self.set_can_default(False) self.connect("toggled", self.on_toggled) for sig in "selection-done", "deactivate", "cancel": menu.connect(sig, self.on_menu_dismiss)
def __resetSortArrow(self): """Re-create the arrow widget used to display the current. This method""" self.sortEventBox.remove(self.sortArrow) self.sortArrow = Gtk.Arrow(Gtk.ArrowType.DOWN, Gtk.ShadowType.NONE) self.sortArrow.show() self.sortEventBox.add(self.sortArrow)
def __init__(self, name): GObject.GObject.__init__(self) self.set_name(name) self.set_relief(Gtk.ReliefStyle.NONE) self.label = label = Gtk.Label() label.set_alignment(0, 0.5) self.hbox = hbox = Gtk.HBox() self.image = Gtk.Image() hbox.pack_start(self.image, False, False, 0) hbox.pack_start(label, True, True, 0) arrow = Gtk.Arrow(Gtk.ArrowType.DOWN, Gtk.ShadowType.OUT) hbox.pack_start(arrow, False, False, 0) self.add(hbox) self.show_all() self.connect("button_press_event", self.button_press) self.connect("key_press_event", self.key_press) self.connect("scroll_event", self.scroll_event) self.menu = menu = Gtk.Menu() menu.connect("deactivate", self.deactivate) menu.attach_to_widget(self, None) self.markup = "", "" self._active = -1 self._items = []
def __init__(self, default_label): super().__init__() self.default_label = default_label self.box = Gtk.Box(orientation=Orientation.HORIZONTAL) self.label = Gtk.Label(label=default_label) down_arrow = Gtk.Arrow(Gtk.ArrowType.DOWN) down_arrow.set_valign(Gtk.Align.BASELINE) self.box.pack_start(self.label, False, False, 0) self.box.pack_start(down_arrow, False, False, 8) self.add(self.box) self.box.set_can_focus(False) self.box.set_focus_on_click(False) self.bulbs_popover = Gtk.Popover() self.bulbs_popover_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=8) self.bulbs_popover.add(self.bulbs_popover_box) self.bulbs_popover.set_position(Gtk.PositionType.BOTTOM) self.set_use_popover(True) self.set_popover(self.bulbs_popover) self.set_sensitive(False) self.show_all()
def __init__(self, today): gtk.ToggleButton.__init__(self) self._ui = load_ui_file("date_range.ui") self.popup = self.get_widget("range_popup") self.today = today hbox = gtk.HBox() hbox.set_spacing(3) self.label = gtk.Label() hbox.add(self.label) hbox.add(gtk.Arrow(gtk.ArrowType.DOWN, gtk.ShadowType.ETCHED_IN)) self.add(hbox) self.start_date, self.end_date = None, None self.current_range = None self.popup.connect("focus-out-event", self.on_focus_out) self.connect("toggled", self.on_toggle) self._ui.connect_signals(self) self.connect("destroy", self.on_destroy) self._hiding = False
def _init_header(self, side_vbox): """Initialize the side pane button header.""" header_hbox = gaupol.util.new_hbox(spacing=12) header_hbox.set_border_width(1) self._toggle_button.set_relief(Gtk.ReliefStyle.NONE) self._toggle_button.set_focus_on_click(False) toggle_button_hbox = gaupol.util.new_hbox(spacing=6) gaupol.util.pack_start_expand(toggle_button_hbox, self._label) arrow = Gtk.Arrow(arrow_type=Gtk.ArrowType.DOWN, shadow_type=Gtk.ShadowType.NONE) gaupol.util.pack_start_expand(toggle_button_hbox, arrow) self._toggle_button.add(toggle_button_hbox) callback = self._on_header_toggle_button_button_press_event self._toggle_button.connect("button-press-event", callback) callback = self._on_header_toggle_button_key_press_event self._toggle_button.connect("key-press-event", callback) gaupol.util.pack_start(header_hbox, self._toggle_button) gaupol.util.pack_start_expand(header_hbox, Gtk.Label()) close_button = Gtk.Button() image = gaupol.util.get_icon_image("window-close-symbolic", "window-close", Gtk.IconSize.MENU) close_button.add(image) close_button.set_relief(Gtk.ReliefStyle.NONE) close_button.set_focus_on_click(False) callback = self._on_header_close_button_clicked close_button.connect("clicked", callback) gaupol.util.pack_start(header_hbox, close_button) gaupol.util.pack_start(side_vbox, header_hbox)
def __init__(self, button, default_label=""): self.button = button self.default_label = default_label self.label = None self._menu = None self._icon = None children = self.button.get_children() if len(children) == 1 and type(children[0]) == Gtk.HBox: children = children[0].get_children() for child in children: if type(child) == Gtk.Label: self.label = child break else: for child in list(button.get_children()): button.remove(child) hbox = Gtk.HBox() self.label = Gtk.Label() arrow = Gtk.Arrow(arrow_type=Gtk.ArrowType.DOWN, shadow_type=Gtk.ShadowType.IN) hbox.set_spacing(2) hbox.pack_start(self.label, True, True, 0) hbox.pack_end(arrow, False, False, 0) button.add(hbox) if not self.label: raise ValueError("%s is not a ChooserButton" % button.get_name()) self.connect("clicked", self._show_menu) self.reset()
def _add_back_button(self): self.back_button = Gtk.Button() self.back_button.add(Gtk.Arrow(Gtk.ArrowType.LEFT, Gtk.ShadowType.NONE)) self.back_button.connect("clicked", self.on_back_button_clicked) self.hb.pack_start(self.back_button) self.back_button.props.visible = False
def __init__(self): Gtk.Window.__init__( self, title="HeaderBar Demo" ) #Initialize window as though not using a HeaderBar self.set_border_width(10) self.set_default_size(400, 200) wrapperbar.make_wrapper(self) #Run once to initialize the wrapper contents = Gtk.Grid() #Grid instance for window content contents.attach(self.in_content_bar, 0, 0, 1, 1) #Packing the in_content_bar GtkBox. #This GtkBox was created by wrapperbar.make_wrapper() and is empty when HeaderBar is in use. #When the HeaderBar is disabled, the contents of said HeaderBar is placed in this GtkBox. #For best results ensure that this GtkBox is displayed, is the highest widget in the window, and spans the entire window width. #All other window contents can be added to the Grid, even in another Container entry_box = Gtk.TextView() #Such As this TextView entry_box.set_vexpand(True) contents.attach(entry_box, 0, 1, 1, 1) self.add(contents) #Shows window content Grid #Construction of buttons in HeaderBar #This section was changed very minimally from original. These changes are to use wrapperbar pack calls button = Gtk.Button() button.connect("clicked", self.toggle_headerbar) icon = Gio.ThemedIcon(name="mail-send-receive-symbolic") image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON) button.add(image) wrapperbar.pack_end( self, button) #wrapperbar pack call in place of HeaderBar pack call 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)) box.add(button) button = Gtk.Button() button.add(Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE)) box.add(button) wrapperbar.pack_start( self, box) #wrapperbar pack call in place of HeaderBar pack call
def create_body(self): # create box for text window main_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5) self.add(main_box) # add poem title label = Gtk.Label(self.poem) label.set_markup("<span size=\"x-large\">" + self.poem + "</span>") main_box.pack_start(label, False, False, 0) # add navigation buttons to the box navigation_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) Gtk.StyleContext.add_class(navigation_box.get_style_context(), "linked") button = Gtk.Button() button.add(Gtk.Arrow(Gtk.ArrowType.LEFT, Gtk.ShadowType.NONE)) button.set_size_request(30, 30) button.set_tooltip_text("Previous Canto") button.connect("clicked", self.on_nav_clicked, -1) navigation_box.pack_start(button, True, True, 0) button = Gtk.Button() button.add(Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE)) button.set_size_request(30, 30) button.set_tooltip_text("Next Canto") button.connect("clicked", self.on_nav_clicked, 1) navigation_box.pack_start(button, True, True, 0) main_box.pack_start(navigation_box, False, False, 0) # read the text files self.cantos = {} for chapter in self.chapters: logging.debug("Adding content for chapter \"%s\"", chapter) chapter_file = self.root[chapter] # open the text file containing the chapter content = read_file( os.path.join("poems", self.folder, chapter_file)) # divide the chapter in cantos using canto_name as separator self.cantos[chapter] = [ self.separator + c for c in content.split(self.separator)[1:] ] textbuffer = self.textviews[chapter][0].get_buffer() textbuffer.set_text(self.cantos[chapter][0]) self.apply_tags(textbuffer) # add stack (see create_header) to the container main_box.pack_start(self.stack, True, True, 30)
def __init__(self, dbstate, uistate, pageview, configfile, defaults): Gtk.Notebook.__init__(self) self.dbstate = dbstate self.uistate = uistate self.pageview = pageview self.configfile = os.path.join(VERSION_DIR, "%s.ini" % configfile) self.defaults = defaults self.detached_gramplets = [] self.empty = False self.close_buttons = [] self.set_group_name("grampletbar") self.set_show_border(False) self.set_scrollable(True) book_button = Gtk.Button() # Arrow is too small unless in a box box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) arrow = Gtk.Arrow(arrow_type=Gtk.ArrowType.DOWN, shadow_type=Gtk.ShadowType.NONE) arrow.show() box.add(arrow) box.show() book_button.add(box) book_button.set_relief(Gtk.ReliefStyle.NONE) book_button.connect('clicked', self.__button_clicked) book_button.set_property("tooltip-text", _("Gramplet Bar Menu")) book_button.show() self.set_action_widget(book_button, Gtk.PackType.END) self.connect('page-added', self.__page_added) self.connect('page-removed', self.__page_removed) self.connect('create-window', self.__create_window) config_settings, opts_list = self.__load(defaults) opts_list.sort(key=lambda opt: opt["page"]) for opts in opts_list: if opts["name"] in AVAILABLE_GRAMPLETS(): all_opts = get_gramplet_opts(opts["name"], opts) gramplet = make_requested_gramplet(TabGramplet, self, all_opts, self.dbstate, self.uistate) if gramplet: self.__add_tab(gramplet) if len(opts_list) == 0: self.empty = True self.__create_empty_tab() if config_settings[0]: self.show() self.set_current_page(config_settings[1]) uistate.connect('grampletbar-close-changed', self.cb_close_changed) # Connect after gramplets added to prevent making them active self.connect('switch-page', self.__switch_page)
def __init__(self, run_callback): self.cells = [] self.cellcount = 0 self.run_callback = run_callback Gtk.Window.__init__(self, title="Giac GTK") self.set_border_width(10) self.set_default_size(400, 200) hb = Gtk.HeaderBar() hb.set_show_close_button(True) hb.set_decoration_layout("menu:minimize,close") hb.props.title = "Giac GTK" self.set_titlebar(hb) button = Gtk.Button() icon = Gio.ThemedIcon(name="document-new-symbolic") image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON) button.add(image) button.connect("clicked", self.add_cell) 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.DOWN, Gtk.ShadowType.NONE)) box.add(button) button = Gtk.Button() button.add(Gtk.Arrow(Gtk.ArrowType.UP, Gtk.ShadowType.NONE)) box.add(button) hb.pack_start(box) img = Gtk.Image.new_from_file('/tmp/latex-test/main.svg') self.body = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.add(self.body) self.add_cell() state = self.get_state() self.fgColor = self.get_style_context().get_color(state)
def make_tool_button_widget(label): """Make a GtkToolButton label-widget suggestive of a menu dropdown""" arrow = Gtk.Arrow(Gtk.ArrowType.DOWN, Gtk.ShadowType.NONE) label = Gtk.Label(label=label) hbox = Gtk.HBox(spacing=3) hbox.pack_end(arrow, True, True, 0) hbox.pack_end(label, True, True, 0) hbox.show_all() return hbox
def __make_category(self, grid, use_text, cat_num, cat_name, cat_icon): """ Create a row in the sidebar for a category. """ # create the button button = Gtk.ToggleButton() button.set_relief(Gtk.ReliefStyle.NONE) button.set_alignment(0, 0.5) self.buttons.append(button) # create the drop-down button to display views if len(self.views[cat_num]) > 1: dropdown = Gtk.Button() dropdown.set_relief(Gtk.ReliefStyle.NONE) dropdown.set_alignment(0.5, 0.5) arrow = Gtk.Arrow(arrow_type=Gtk.ArrowType.DOWN, shadow_type=Gtk.ShadowType.NONE) dropdown.add(arrow) dropdown.connect('clicked', self.__view_clicked, cat_num) dropdown.set_tooltip_text(_('Click to select a view')) grid.attach(dropdown, 1, cat_num, 1, 1) # add the tooltip button.set_tooltip_text(cat_name) # connect the signal, along with the cat_num as user data handler_id = button.connect('clicked', self.__category_clicked, cat_num) self.button_handlers.append(handler_id) button.show() # add the image. If we are using text, use the BUTTON (larger) size. # otherwise, use the smaller size hbox = Gtk.Box() hbox.show() image = Gtk.Image() if use_text: image.set_from_stock(cat_icon, Gtk.IconSize.BUTTON) else: image.set_from_stock(cat_icon, Gtk.IconSize.DND) image.show() hbox.pack_start(image, False, False, 0) hbox.set_spacing(4) # add text if requested if use_text: label = Gtk.Label(label=cat_name) label.show() hbox.pack_start(label, False, True, 0) button.add(hbox) # Enable view switching during DnD button.drag_dest_set(0, [], 0) button.connect('drag_motion', self.cb_switch_page_on_dnd, cat_num) grid.attach(button, 0, cat_num, 1, 1)
def _create_menu_button(self): self.menu_box = Gtk.VBox() self.menu_button = Gtk.ToggleButton() self.menu_button.set_relief(Gtk.ReliefStyle.NONE) self.menu_button.set_can_focus(False) self.menu_button.add(Gtk.Arrow(Gtk.ArrowType.DOWN, Gtk.ShadowType.NONE)) self.menu_button.connect("released", self.show_popupmenu) self.menu_button.set_size_request(-1, self.ICON_HEIGHT)
def _add_arrow_buttons(self): self.arrow_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) Gtk.StyleContext.add_class(self.arrow_box.get_style_context(), "linked") self.back_button = Gtk.Button() self.back_button.add(Gtk.Arrow(Gtk.ArrowType.LEFT, Gtk.ShadowType.NONE)) self.arrow_box.add(self.back_button) self.back_button.connect("clicked", self.on_back_button_clicked) self.forward_button = Gtk.Button() self.forward_button.add( Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE)) self.arrow_box.add(self.forward_button) self.forward_button.connect("clicked", self.on_forward_button_clicked) self.hb.pack_start(self.arrow_box)
def __init__(self): Gtk.Window.__init__(self, title="Exemplo Gtk.Flowbox") self.set_default_size(600, 450) self.set_border_width(5) cabeceira = Gtk.HeaderBar(title="Exemplo FlowBox") cabeceira.set_subtitle("Exemplo de headerBar") cabeceira.props.show_close_button = True btnBoton = Gtk.Button() icono = Gio.ThemedIcon(name="mail-send-receive-symbolic") imaxe = Gtk.Image.new_from_gicon(icono, Gtk.IconSize.BUTTON) btnBoton.add(imaxe) cabeceira.pack_end(btnBoton) caixa = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) Gtk.StyleContext.add_class(caixa.get_style_context(), "linked") btnFrechaI = Gtk.Button() btnFrechaI.add(Gtk.Arrow(Gtk.ArrowType.LEFT, Gtk.ShadowType.NONE)) caixa.add(btnFrechaI) btnFrechaD = Gtk.Button() btnFrechaD.add(Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE)) caixa.add(btnFrechaD) cabeceira.pack_start(caixa) #Configuración do FlowBox flowBox = Gtk.FlowBox() #Los align indican como se ajusta el contenido del flowbox si sobra espacio #START se pega arriba(valign) o izqueirda(halign), END abajo/derecha, CENTER medio, FILL intenta llenar tudo el espacio flowBox.set_valign(Gtk.Align.CENTER) flowBox.set_halign(Gtk.Align.FILL) flowBox.set_max_children_per_line(30) flowBox.set_selection_mode(Gtk.SelectionMode.NONE) self.crea_flowbox(flowBox) scroll = Gtk.ScrolledWindow() #Valores de set_policy(valor horizontal,valor vertical) scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) #metemos el flowbox al scrollbar scroll.add(flowBox) #y el scroll bar a la window self.add(scroll) self.set_titlebar(cabeceira) self.connect("delete-event", Gtk.main_quit) self.show_all()
def __init__(self): Gtk.Window.__init__(self, title="Hello World") self.grid = Gtk.Grid() self.add(self.grid) self.box = Gtk.Box(spacing=2) self.box.set_border_width(2)## set border width, not the container width self.button1 = Gtk.Button(label="Hello") self.button1.connect("clicked", self.on_button1_clicked) self.box.pack_start(self.button1, True, True, 0) self.button2 = Gtk.Button(label="Goodbye") self.button2.connect("clicked", self.on_button2_clicked) self.box.pack_start(self.button2, True, True, 0) self.grid.add(self.box) # self.upButton = Gtk.Button(label="up") # self.upButton.connect("clicked", self.on_upButton_clicked) # self.grid.attach(self.upButton, 1, 0, 1, 1)## object, col, row, width, height # # self.downButton = Gtk.Button(label="down") # self.downButton.connect("clicked", self.on_downButton_clicked) # self.grid.attach(self.downButton, 1, 1, 1, 1)## object, col, row, width, height box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) box.set_border_width(2)## set border width, not the container width Gtk.StyleContext.add_class(box.get_style_context(), "linked") button = Gtk.Button() button.add(Gtk.Arrow(Gtk.ArrowType.UP, Gtk.ShadowType.NONE)) button.connect("clicked", self.on_upButton_clicked) box.add(button) button = Gtk.Button() button.add(Gtk.Arrow(Gtk.ArrowType.DOWN, Gtk.ShadowType.NONE)) button.connect("clicked", self.on_downButton_clicked) box.add(button) self.grid.add(box) self.set_decorated(False)
def __init__(self, calendar): Gtk.Window.__init__(self) self.connect('destroy', self.on_destroy) self.calendar = calendar self.connect('key-press-event', self.on_key_press) self.set_size_request(1000, 100) self.set_default_size(600, 250) self.cal = calendar.Calendar(6) self.date = date.today() self.header = Gtk.HeaderBar() self.header.set_show_close_button(False) bbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) back = Gtk.Button() back.add(Gtk.Arrow(Gtk.ArrowType.LEFT, Gtk.ShadowType.NONE)) back.connect('clicked', self.prev_month) bbox.add(back) fbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) forward = Gtk.Button() forward.add(Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE)) forward.connect('clicked', self.next_month) fbox.add(forward) self.header.pack_start(bbox) self.header.pack_end(fbox) self.set_titlebar(self.header) self.grid = Gtk.Grid() self.grid.set_row_homogeneous(True) self.grid.set_column_homogeneous(True) self.add(self.grid) self.refresh() self.draw_month()
def __init__(self, viewmanager): self.viewmanager = viewmanager self.pages = [] self.active_cat = None self.active_view = None self.ui_category = {} self.view_toggle_actions = {} self.cat_view_group = None self.merge_ids = [] self.top = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) frame = Gtk.Frame() hbox = Gtk.Box() hbox.show() frame.add(hbox) frame.show() self.select_button = Gtk.ToggleButton() self.select_button.set_relief(Gtk.ReliefStyle.NONE) select_hbox = Gtk.Box() self.title_label = Gtk.Label(label='') arrow = Gtk.Arrow(arrow_type=Gtk.ArrowType.DOWN, shadow_type=Gtk.ShadowType.NONE) select_hbox.pack_start(self.title_label, False, True, 0) select_hbox.pack_end(arrow, False, True, 0) self.select_button.add(select_hbox) self.select_button.connect('button_press_event', self.__menu_button_pressed) #close_button = Gtk.Button() #img = Gtk.Image.new_from_icon_name('window-close', Gtk.IconSize.MENU) #close_button.set_image(img) #close_button.set_relief(Gtk.ReliefStyle.NONE) #close_button.connect('clicked', self.cb_close_clicked) hbox.pack_start(self.select_button, False, True, 0) #hbox.pack_end(close_button, False, True, 0) self.top.pack_end(frame, False, True, 0) self.menu = Gtk.Menu() self.menu.show() self.menu.connect('deactivate', cb_menu_deactivate, self.select_button) self.notebook = Gtk.Notebook() self.notebook.show() self.notebook.set_show_tabs(False) self.notebook.set_show_border(False) self.notebook.connect('switch_page', self.cb_switch_page) self.top.show() self.top.pack_start(self.notebook, True, True, 0)