Python gi.repository.Gtk.STOCK_CLEAR Examples

The following are 5 code examples of gi.repository.Gtk.STOCK_CLEAR(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gi.repository.Gtk , or try the search function .
Example #1
Source File: widgets.py    From zim-desktop-wiki with GNU General Public License v2.0 6 votes vote down vote up
def set_icon_to_clear(self):
		'''Adds a "clear" icon in the entry widget

		This method calls L{set_icon()} with the right defaults for
		a stock "Clear" icon. In addition it makes the icon insensitive
		when there is no text in the entry. Clicking the icon will
		clear the entry.

		@returns: C{True} if successfull, C{False} if not supported
		by Gtk version
		'''
		self.set_icon(Gtk.STOCK_CLEAR, self.clear, _('Clear'))
			# T: tooltip for the inline icon to clear a text entry widget

		def check_icon_sensitive(self):
			text = self.get_text()
			self.set_property('secondary-icon-sensitive', bool(text))

		check_icon_sensitive(self)
		self.connect('changed', check_icon_sensitive)

		return True 
Example #2
Source File: ImportGramplet.py    From addons-source with GNU General Public License v2.0 5 votes vote down vote up
def init(self):
        """
        Constructs the GUI, consisting of a text area, and
        an Import and Clear buttons.
        """
        from gi.repository import Gtk
        # GUI setup:
        self.set_tooltip(_("Enter text to import and then click\n"
                           "the Import button at bottom"))
        # create
        self.import_text = Gtk.TextView()
        self.import_text.set_wrap_mode(Gtk.WrapMode.NONE)
        self.import_text.set_editable(True)
        import_button = Gtk.Button()
        clear_button = Gtk.Button()
        # layout
        scrolled_window = Gtk.ScrolledWindow()
        scrolled_window.add(self.import_text)
        buttonbox = Gtk.HButtonBox()
        buttonbox.set_layout(Gtk.ButtonBoxStyle.SPREAD)
        buttonbox.pack_start(clear_button, False, False, 0)
        buttonbox.pack_start(import_button, False, False, 0)
        vbox = Gtk.VBox()
        vbox.pack_start(scrolled_window, True, True, 0)
        vbox.pack_start(buttonbox, False, False, 0)
        scrolled_window = self.gui.get_container_widget()
        for widget in scrolled_window.get_children():
            widget.destroy()
        scrolled_window.add_with_viewport(vbox)
        scrolled_window.get_children()[0].set_shadow_type(Gtk.ShadowType.NONE)
        # bindings
        actiongroup = Gtk.ActionGroup('GrampletImportActions')
        actiongroup.add_actions([
            ('import', None, _("_Import"), '<Alt>i', None, self.run),
            ('clear', Gtk.STOCK_CLEAR, None, None, None, self.clear)])
        import_button.set_related_action(actiongroup.get_action('import'))
        clear_button.set_related_action(actiongroup.get_action('clear'))
        # show
        vbox.show_all() 
Example #3
Source File: console_textview.py    From bokken with GNU General Public License v2.0 5 votes vote down vote up
def _populate_menu(self, textview, menu):
        opc = Gtk.ImageMenuItem((Gtk.STOCK_CLEAR))
        opc.get_children()[0].set_label('Clear text')
        menu.prepend(Gtk.SeparatorMenuItem())
        menu.prepend(opc)
        opc.connect("activate", self._clear, iter)
        menu.show_all() 
Example #4
Source File: search.py    From rednotebook with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, combo_box, main_window):
        CustomComboBoxEntry.__init__(self, combo_box)

        self.main_window = main_window
        self.journal = main_window.journal

        self.entry.set_icon_from_stock(1, Gtk.STOCK_CLEAR)
        self.entry.connect("icon-press", lambda *args: self.set_active_text(""))

        self.entry.connect("changed", self.on_entry_changed)
        self.entry.connect("activate", self.on_entry_activated) 
Example #5
Source File: annotationPanel.py    From pychess with GNU General Public License v3.0 4 votes vote down vote up
def menu_edit_comment(self, widget=None, board=None, index=0):
        """
        The method will create/update or delete a comment.
        The popup window will receive an additional button if there is an existing comment.
        """
        creation = True
        if not board.children:
            board.children.append("")
        elif not isinstance(board.children[index], str):
            board.children.insert(index, "")
        else:
            creation = False

        buttons_list = () if creation else (Gtk.STOCK_CLEAR, Gtk.ResponseType.REJECT)
        buttons_list = buttons_list + (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                       Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)

        dialog = Gtk.Dialog(_("Add comment") if creation else _("Edit comment"),
                            mainwindow(),
                            Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
                            buttons_list)

        textedit = Gtk.TextView()
        textedit.set_editable(True)
        textedit.set_cursor_visible(True)
        textedit.set_wrap_mode(Gtk.WrapMode.WORD)
        textedit.set_accepts_tab(False)

        textbuffer = textedit.get_buffer()
        textbuffer.set_text(board.children[index])

        sw = Gtk.ScrolledWindow()
        sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        sw.add(textedit)

        dialog.get_content_area().pack_start(sw, True, True, 0)
        dialog.resize(300, 200)
        dialog.show_all()

        response = dialog.run()
        dialog.destroy()
        if response == Gtk.ResponseType.DELETE_EVENT:  # Escape key implies Cancel
            response = Gtk.ResponseType.CANCEL

        (iter_first, iter_last) = textbuffer.get_bounds()
        comment = '' if response == Gtk.ResponseType.REJECT else textbuffer.get_text(iter_first, iter_last, False)
        if response != Gtk.ResponseType.CANCEL and board.children[index] != comment:
            if len(comment) == 0:
                del board.children[index]
            else:
                board.children[index] = comment
            self.gamemodel.needsSave = True
            self.update()