我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用gi.repository.Gtk.STOCK_CLOSE。
def __init__(self, filename=None): self.m_instance_number = EditorDialogBase.instance_counter EditorDialogBase.instance_counter += 1 self.m_filename = filename self.m_savetime = time.time() self.connect('delete_event', self.on_delete_event) self.g_ui_manager = Gtk.UIManager() accelgroup = self.g_ui_manager.get_accel_group() self.add_accel_group(accelgroup) self.g_actiongroup = Gtk.ActionGroup('') self.g_actiongroup.add_actions([ ('Close', Gtk.STOCK_CLOSE, None, None, None, self.close_window), ('Save', Gtk.STOCK_SAVE, None, None, None, self.on_save), ('SaveAs', Gtk.STOCK_SAVE_AS, None, None, None, self.on_save_as), ('New', Gtk.STOCK_NEW, None, None, None, self.new_file), ('Open', Gtk.STOCK_OPEN, None, None, None, self.on_open), ('Help', Gtk.STOCK_HELP, None, None, None, self.on_show_help), ])
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 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 build_error_dialog(self, message_label, on_signal=None, callback=None): """ Create a :class:`Gtk.MessageDialog` to notifiy user that an error occurred. :param message_label: text displayed to user as :class`str` :param on_signal: Gtk signal as :class:`str` :param callback: callback to connect to ``signal`` """ error_dialog = Gtk.MessageDialog( message_type=Gtk.MessageType.ERROR, message_format=message_label) error_dialog.set_icon_from_file(self.images.logo_favicon_path) error_dialog.set_title("Error") error_dialog.add_button(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE) error_dialog.set_modal(True) if on_signal and callback: error_dialog.connect(on_signal, callback) else: error_dialog.connect("response", self.default_error_callback) error_dialog.run()
def do_activate(self): if not self.window: self.window = self.builder.get_object("main_window") self.window.set_application(self) self.window.present() #The preferences dialog self.preferences_dialog = Gtk.Dialog(self.window, self.window, True, ) self.preferences_dialog.add_buttons(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE, Gtk.STOCK_APPLY, Gtk.ResponseType.APPLY) self.preferences_dialog.set_title("Preferences") box = self.preferences_dialog.get_content_area() box.add(self.settings_box)
def __init__(self): Gtk.Dialog.__init__(self, buttons=(Gtk.STOCK_CLOSE, Gtk.ResponseType.ACCEPT)) view = SearchView(_('Search for exercises. Each exercise you click will be added to the section of the front page.'), fields=['link-with-filename-tooltip', 'module']) view.on_link_clicked = self.on_link_clicked self.vbox.pack_start(view, True, True, 0) self.show_all()
def popup_stack(self, widget): dialog = Gtk.Dialog('The stack', self, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, (Gtk.STOCK_CLOSE,Gtk.ResponseType.CLOSE)) ui.gtk3.common.set_bokken_icon(dialog) stack_img = Gtk.Image() stack_img.set_from_file(datafile_path('stack.png')) dialog.vbox.pack_start(self.create_h1_label("The stack"), False, False, 2) dialog.vbox.pack_start(stack_img, True, True, 2) dialog.show_all() dialog.run() dialog.destroy()
def popup_registers(self, widget): dialog = Gtk.Dialog('16-bit and 8-bit registers', self, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, (Gtk.STOCK_CLOSE,Gtk.ResponseType.CLOSE)) ui.gtk3.common.set_bokken_icon(dialog) reg_img = Gtk.Image() reg_img.set_from_file(datafile_path('registers.png')) reg_label = Gtk.Label("The four primary general purpose registers (EAX, EBX, ECX and EDX)\nhave 16 and 8 bit overlapping aliases.") reg_label.set_alignment(0.1, 0.1) reg_label.set_padding (0, 3) dialog.vbox.pack_start(reg_label, False, False, 2) dialog.vbox.pack_start(reg_img, True, True, 2) dialog.show_all() dialog.run() dialog.destroy()
def __init__(self, parent=None, title='', description='', long_description=''): Gtk.Window.__init__(self, title=title) self.set_parent(parent) self.set_transient_for(parent) self.set_destroy_with_parent(False) self.set_default_size(600, 500) self.vbox = Gtk.VBox(spacing=0) self.add(self.vbox) self.text_buffer = Gtk.TextBuffer() self.text_buffer.insert_at_cursor(description) self.text_buffer.insert_at_cursor( '\n\n' + '############################################################' + '\n') self.text_buffer.insert_at_cursor( 'Complete file implementing the input method follows here:\n') self.text_buffer.insert_at_cursor( '############################################################' + '\n') self.text_buffer.insert_at_cursor(long_description) self.text_view = Gtk.TextView() self.text_view.set_buffer(self.text_buffer) self.text_view.set_editable(False) self.text_view.set_cursor_visible(False) self.text_view.set_justification(Gtk.Justification.LEFT) self.text_view.set_wrap_mode(Gtk.WrapMode.WORD) self.scrolledwindow = Gtk.ScrolledWindow() self.scrolledwindow.set_hexpand(True) self.scrolledwindow.set_vexpand(True) self.scrolledwindow.add(self.text_view) self.vbox.pack_start(self.scrolledwindow, True, True, 0) self.close_button = Gtk.Button(stock=Gtk.STOCK_CLOSE) self.close_button.connect("clicked", self.on_close_button_clicked) self.hbox = Gtk.HBox(spacing=0) self.hbox.pack_end(self.close_button, False, False, 0) self.vbox.pack_start(self.hbox, False, False, 5)
def __init__(self, title, pixbuf, parent=None): Gtk.Dialog.__init__(self) # find parent window for the dialog if not parent: parent = self.get_parent() while parent: parent = parent.get_parent() # screenshot img = Gtk.Image.new_from_pixbuf(pixbuf) # scolled window for screenshot scroll = Gtk.ScrolledWindow() scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) scroll.add_with_viewport(img) content_area = self.get_content_area() content_area.pack_start(scroll, True, True, 0) # dialog self.set_title(title) self.set_transient_for(parent) self.set_destroy_with_parent(True) self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT) self.add_button(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE) self.set_default_size(SimpleShowImageDialog.DEFAULT_WIDTH, SimpleShowImageDialog.DEFAULT_HEIGHT)
def create_goglib_tab_empty(self): self.unauthorized_grid = Gtk.Grid( name = 'goglib_tab', halign = Gtk.Align.CENTER, valign = Gtk.Align.CENTER, row_spacing = 10, column_spacing = 10, margin_top = 10, margin_bottom = 10, margin_left = 10, margin_right = 10, ) self.unauthorized_message = Gtk.Label( label = _("You are not authorized on GOG.COM and can't download games."), wrap = True, ) self.unauthorized_grid.attach(self.unauthorized_message, 0, 0, 1, 1) if os.path.exists(os.getenv('HOME') + '/.games_nebula/config/games_list'): self.button_start_offline = Gtk.Button( label = _("Start in offline mode"), halign = Gtk.Align.CENTER ) self.button_start_offline.connect('clicked', self.goglib_start_offline_mode) self.unauthorized_grid.attach(self.button_start_offline, 0, 1, 1, 1) self.unauthorized_tab_box = Gtk.Box( spacing = 10, ) self.unauthorized_tab_label = Gtk.Label( label = _("GOG LIBRARY") ) self.unauthorized_tab_close_button = Gtk.Button( name = "Downloads", image = Gtk.Image(stock=Gtk.STOCK_CLOSE), relief = Gtk.ReliefStyle.NONE, focus_on_click = False, ) self.unauthorized_tab_close_button.connect('clicked', self.close_tab, self.unauthorized_grid) self.unauthorized_tab_box.pack_start(self.unauthorized_tab_label, True, True, 0) self.unauthorized_tab_box.pack_start(self.unauthorized_tab_close_button, True, True, 0) self.unauthorized_tab_box.show_all() self.notebook.append_page(self.unauthorized_grid, self.unauthorized_tab_box) self.notebook.set_tab_reorderable(self.unauthorized_grid, True) self.notebook.set_tab_detachable(self.unauthorized_grid, True)
def create_gogcom_tab(self): gi.require_version('WebKit2', '4.0') from gi.repository import WebKit2 from gi.repository import Soup import webbrowser self.webkit = WebKit2 self.soup = Soup self.webbrowser = webbrowser self.setup_cookies() self.webpage = self.webkit.WebView() self.webpage.load_uri('https://www.gog.com') self.gogcom_tab_scrolled_window = Gtk.ScrolledWindow( name = 'gogcom_tab' ) self.gogcom_tab_scrolled_window.add(self.webpage) self.check_gogcom_tab() self.gogcom_tab_box = Gtk.Box( orientation = Gtk.Orientation.HORIZONTAL, spacing = 10 ) self.gogcom_tab_label = Gtk.Label( label = _("GOG.COM") ) self.gogcom_tab_close_button = Gtk.Button( image = Gtk.Image(stock=Gtk.STOCK_CLOSE), relief = Gtk.ReliefStyle.NONE, focus_on_click = False, ) self.gogcom_tab_close_button.connect('clicked', self.close_tab, self.gogcom_tab_scrolled_window) self.gogcom_tab_box.pack_start(self.gogcom_tab_label, True, True, 0) self.gogcom_tab_box.pack_start(self.gogcom_tab_close_button, False, False, 0) self.gogcom_tab_box.show_all() self.notebook.append_page(self.gogcom_tab_scrolled_window, self.gogcom_tab_box) self.notebook.set_tab_reorderable(self.gogcom_tab_scrolled_window, True) self.notebook.set_tab_detachable(self.gogcom_tab_scrolled_window, True)
def create_queue_tab(self): self.queue_tab_scrolled_window = Gtk.ScrolledWindow( name = 'queue_tab' ) self.queue_tab_box = Gtk.Box( spacing = 20, margin_top = 20, margin_bottom = 20, margin_left = 20, margin_right = 20, orientation = Gtk.Orientation.VERTICAL ) self.queue_tab = Gtk.Box( orientation = Gtk.Orientation.HORIZONTAL, spacing = 10 ) self.queue_tab_label = Gtk.Label( label = _("QUEUE") ) self.queue_tab_close_button = Gtk.Button( name = "Downloads", image = Gtk.Image(stock=Gtk.STOCK_CLOSE), relief = Gtk.ReliefStyle.NONE, focus_on_click = False, ) self.queue_tab_close_button.connect('clicked', self.close_tab, self.queue_tab_scrolled_window) self.queue_tab.pack_start(self.queue_tab_label, True, True, 0) self.queue_tab.pack_start(self.queue_tab_close_button, False, False, 0) self.queue_tab.show_all() self.queue_tab_scrolled_window.add(self.queue_tab_box) if self.queue_tab_at_start: self.notebook.append_page(self.queue_tab_scrolled_window, self.queue_tab) self.notebook.set_tab_reorderable(self.queue_tab_scrolled_window, True) self.notebook.set_tab_detachable(self.queue_tab_scrolled_window, True)
def __init__(self): Gtk.Dialog.__init__(self, _("GNU Solfege Preferences"), solfege.win, 0, (Gtk.STOCK_HELP, Gtk.ResponseType.HELP, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)) cfg.ConfigUtils.__init__(self, 'configwindow') self.connect('response', self.apply_and_close) # We do this so that the window is only hidden when the # user click on the close button provided by the window manager. self.connect('delete-event', self.on_destroy)#lambda w, e: True) hbox = Gtk.HBox() hbox.set_spacing(gu.hig.SPACE_LARGE) hbox.set_border_width(gu.hig.SPACE_SMALL) self.vbox.pack_start(hbox, True, True, 0) frame = Gtk.Frame() self.g_pages = Gtk.TreeStore(str) self.g_pview = Gtk.TreeView(self.g_pages) self.g_pview.set_headers_visible(False) hbox.pack_start(frame, False, False, 0) frame.add(self.g_pview) self.g_page_box = Gtk.HBox() hbox.pack_start(self.g_page_box, True, True, 0) self.m_page_mapping = {} def cursor_changed(treeview): path, col = treeview.get_cursor() if not path: return path = tuple(path) for key, page in self.m_page_mapping.items(): if key == path: page.show() else: page.hide() self.m_page_mapping[path].show_all() tvcol = Gtk.TreeViewColumn("Col 0") self.g_pview.append_column(tvcol) cell = Gtk.CellRendererText() tvcol.pack_start(cell, True) tvcol.add_attribute(cell, 'text', 0) hbox.show_all() self.create_midi_config() self.create_user_config() self.create_external_programs_config() self.create_gui_config() self.create_practise_config() self.create_sound_config() self.create_statistics_config() self.g_pview.connect('cursor-changed', cursor_changed)
def __init__(self, icon_window, app, path): file_path, file_name = os.path.split(path) # modify file_name if path is '/' if not file_name: file_name = '/' super().__init__(file_name + _(' Properties'), app.window, Gtk.DialogFlags.MODAL, (Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)) self.set_border_width(15) box = self.get_content_area() grid = Gtk.Grid() grid.props.row_spacing = 8 if Config.GTK_GE_312: grid.props.margin_start = 15 else: grid.props.margin_left = 15 grid.props.column_spacing = 15 box.pack_start(grid, True, True, 10) name_label = LeftLabel(_('Name:')) grid.attach(name_label, 0, 0, 1, 1) name_label2 = SelectableLeftLabel(file_name) grid.attach(name_label2, 1, 0, 1, 1) location_label = LeftLabel(_('Location:')) grid.attach(location_label, 0, 1, 1, 1) location_label2 = SelectableLeftLabel(file_path) grid.attach(location_label2, 1, 1, 1, 1) file_count = 0 folder_count = 0 for row in icon_window.liststore: if row[ISDIR_COL]: folder_count = folder_count + 1 else: file_count = file_count + 1 contents = _('{0} folders, {1} files').format(folder_count, file_count) content_label = LeftLabel(_('Contents:')) grid.attach(content_label, 0, 2, 1, 1) content_label2 = SelectableLeftLabel(contents) grid.attach(content_label2, 1, 2, 1, 1) box.show_all()
def _build_search(self, widget): '''Builds the search bar.''' self.srchtab = Gtk.HBox() # close button close = Gtk.Image() close.set_from_stock(Gtk.STOCK_CLOSE, Gtk.IconSize.MENU) eventbox = Gtk.EventBox() eventbox.add(close) eventbox.connect("button-release-event", self._close) self.srchtab.pack_start(eventbox, False, False, 3) # label label = Gtk.Label(label="Find:") self.srchtab.pack_start(label, False, False, 3) # entry self.search_entry = Gtk.Entry() self.search_entry.set_tooltip_text("Type here the phrase you want to find") self.search_entry.connect("activate", self._find, "next") self.search_entry.connect("changed", self._find_cb, "find") self.srchtab.pack_start(self.search_entry, False, False, 3) # find next button if self.small: but_text = '' else: but_text = 'Next' butn = SemiStockButton(but_text, Gtk.STOCK_GO_DOWN) butn.set_relief(Gtk.ReliefStyle.NONE) butn.connect("clicked", self._find, "next") butn.set_tooltip_text("Find the next ocurrence of the phrase") self.srchtab.pack_start(butn, False, False, 3) # find previous button if self.small: but_text = '' else: but_text = ('Previous') butp = SemiStockButton(but_text, Gtk.STOCK_GO_UP) butp.set_relief(Gtk.ReliefStyle.NONE) butp.connect("clicked", self._find, "previous") butp.set_tooltip_text("Find the previous ocurrence of the phrase") self.srchtab.pack_start(butp, False, False, 3) # make last two buttons equally width # MEOW wn,hn = butn.get_preferred_size() wp,hp = butp.get_preferred_size() newwidth = max(wn.width, wp.width) butn.set_size_request(newwidth, hn.height) butp.set_size_request(newwidth, hp.height) # Match case CheckButton butCase = Gtk.CheckButton(('Match case')) butCase.set_active(self._matchCaseValue) butCase.connect("clicked", self._matchCase) # FIXME # current version of Gtk.TextIter doesn't support SEARCH_CASE_INSENSITIVE #butCase.show() #self.srchtab.pack_start(butCase, expand=False, fill=False, padding=3) self.pack_start(self.srchtab, False, False, 0) # Results self._resultsLabel = Gtk.Label(label="") self.srchtab.pack_start(self._resultsLabel, False, False, 3) self.searching = False