Python gi.repository.Gtk.ComboBoxText() Examples

The following are 14 code examples of gi.repository.Gtk.ComboBoxText(). 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: rightcombo.py    From bokken with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, tviews, uicore):
        super(RightCombo,self).__init__(1, 7, False)

        self.tviews = tviews
        self.uicore = uicore

        # Theme Label
        self.theme_label = Gtk.Label(label='Color theme:')
        self.attach(self.theme_label, 0, 1, 0, 1)

        # Theme ComboBox
        self.theme_combo = Gtk.ComboBoxText()
        options = ['Classic', 'Cobalt', 'kate', 'Oblivion', 'Tango']
        for option in options:
            self.theme_combo.append_text(option)
        # Set first by default
        self.theme_combo.set_active(0)

        self.theme_combo.connect("changed", self.theme_combo_change)
        self.attach(self.theme_combo, 1, 2, 0, 1) 
Example #2
Source File: __init__.py    From zim-desktop-wiki with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, parent):
		Dialog.__init__(self, parent, _("Enable Version Control?")) # T: Question dialog
		self.add_text(
			_("Version control is currently not enabled for this notebook.\n"
			  "Do you want to enable it?") # T: Detailed question
		)

		self.combobox = Gtk.ComboBoxText()
		for option in (VCS.BZR, VCS.GIT, VCS.HG, VCS.FOSSIL):
			if VCS.check_dependencies(option):
				self.combobox.append_text(option)
		self.combobox.set_active(0)

		hbox = Gtk.Box(spacing=5)
		hbox.add(Gtk.Label(_('Backend') + ':'))
		hbox.add(self.combobox)
			# T: option to chose versioncontrol backend
		hbox.set_halign(Gtk.Align.CENTER)
		self.vbox.pack_start(hbox, False, False, 0)
		hbox.show_all() 
Example #3
Source File: plugins.py    From king-phisher with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_widget(self, _, value):
		widget = Gtk.ComboBoxText()
		widget.set_hexpand(True)
		for choice in self.choices:
			widget.append_text(choice)
		self.set_widget_value(widget, value)
		return widget 
Example #4
Source File: DenominoViso.py    From addons-source with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, option, dbstate, uistate, track, override=False):
        Gtk.HBox.__init__(self)
        self.__option = option
        value_str = self.__option.get_value()
        (incl, attr, attr_value) = value_str.split(', ',2)
        incl = int(incl.replace('L', ''))
        self.cbe_w = Gtk.ComboBoxText.new_with_entry()
        image_attributes = dbstate.db.get_media_attribute_types()
        image_attributes.insert(0,' ')
        for attrib in image_attributes:
            self.cbe_w.append_text(attrib)
        try:
            idx = image_attributes.index(attr)
            self.cbe_w.set_active(idx)
        except ValueError:
            pass
        self.cbe_w.connect('changed',self.__value_changed)
        self.l1_w = Gtk.Label(label=_("equal to"))
        self.e_w = Gtk.Entry()
        self.e_w.set_text(attr_value)
        self.e_w.connect('changed',self.__value_changed)
        self.l2_w = Gtk.Label(label=_("should be"))
        self.cb2_w = Gtk.ComboBoxText()
        self.cb2_w.append_text('Included')
        self.cb2_w.append_text('Excluded')
        self.cb2_w.set_active(incl)
        self.cb2_w.connect('changed',self.__value_changed)
        self.pack_start(self.cbe_w, False, True, 0)
        self.pack_start(self.l1_w, False, True, 5)
        self.pack_start(self.e_w, False, True, 0)
        self.pack_start(self.l2_w, False, True, 5)
        self.pack_start(self.cb2_w, False, True, 0) 
Example #5
Source File: FCNoteBook.py    From FlatCAM with MIT License 5 votes vote down vote up
def __init__(self):
        Gtk.Notebook.__init__(self, vexpand=True, vexpand_set=True, valign=1, expand=True)

        ###############
        ### Project ###
        ###############
        self.project_contents = Gtk.VBox(vexpand=True, valign=0, vexpand_set=True, expand=True)
        sw1 = Gtk.ScrolledWindow(vexpand=True, valign=0, vexpand_set=True, expand=True)
        sw1.add_with_viewport(self.project_contents)
        self.project_page_num = self.append_page(sw1, Gtk.Label("Project"))

        ################
        ### Selected ###
        ################
        self.selected_contents = Gtk.VBox()
        sw2 = Gtk.ScrolledWindow()
        sw2.add_with_viewport(self.selected_contents)
        self.selected_page_num = self.append_page(sw2, Gtk.Label("Selected"))

        ###############
        ### Options ###
        ###############
        self.options_contents_super = Gtk.VBox()
        sw3 = Gtk.ScrolledWindow()
        sw3.add_with_viewport(self.options_contents_super)
        self.options_page_num = self.append_page(sw3, Gtk.Label("Options"))

        hb = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        ico = Gtk.Image.new_from_file("share/gear32.png")
        hb.pack_start(ico, expand=False, fill=False, padding=0)
        self.combo_options = Gtk.ComboBoxText()
        hb.pack_start(self.combo_options, expand=True, fill=True, padding=0)
        self.options_contents_super.pack_start(hb, expand=False, fill=False, padding=0)
        self.options_contents = Gtk.VBox()
        self.options_contents_super.pack_start(self.options_contents, expand=False, fill=False, padding=0)

        ############
        ### Tool ###
        ############
        self.tool_contents = Gtk.VBox()
        self.tool_page_num = self.append_page(self.tool_contents, Gtk.Label("Tool")) 
Example #6
Source File: FlatCAMApp.py    From FlatCAM with MIT License 5 votes vote down vote up
def populate_objects_combo(self, combo):
        """
        Populates a Gtk.Comboboxtext with the list of the object in the project.

        :param combo: Name or instance of the comboboxtext.
        :type combo: str or Gtk.ComboBoxText
        :return: None
        """
        App.log.debug("Populating combo!")
        if type(combo) == str:
            combo = self.builder.get_object(combo)

        combo.remove_all()
        for name in self.collection.get_names():
            combo.append_text(name) 
Example #7
Source File: FlatCAMApp.py    From FlatCAM with MIT License 5 votes vote down vote up
def on_toggle_pointbox(self, widget):
        """
        Callback for radio selection change between point and box in the
        Double-sided PCB tool. Updates the UI accordingly.

        :param widget: Ignored.
        :return: None
        """

        # Where the entry or combo go
        box = self.builder.get_object("box_pointbox")

        # Clear contents
        children = box.get_children()
        for child in children:
            box.remove(child)

        choice = self.get_radio_value({"rb_mirror_point": "point",
                                       "rb_mirror_box": "box"})

        if choice == "point":
            self.point_entry = Gtk.Entry()
            self.builder.get_object("box_pointbox").pack_start(self.point_entry,
                                                               False, False, 1)
            self.point_entry.show()
        else:
            self.box_combo = Gtk.ComboBoxText()
            self.builder.get_object("box_pointbox").pack_start(self.box_combo,
                                                               False, False, 1)
            self.populate_objects_combo(self.box_combo)
            self.box_combo.show() 
Example #8
Source File: custom.py    From Dindo-Bot with MIT License 5 votes vote down vote up
def __init__(self, data_list=[], sort=False):
		Gtk.ComboBoxText.__init__(self)
		# set max chars width
		for renderer in self.get_cells():
			renderer.props.max_width_chars = 10
			renderer.props.ellipsize = Pango.EllipsizeMode.END
		# append data
		self.append_list(data_list, sort) 
Example #9
Source File: preferences_dialog.py    From ebook-viewer with GNU General Public License v3.0 5 votes vote down vote up
def __populate_preferences(self):
        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        hbox_theme = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
        themes = ["Day (light)", "Night (dark)"]
        self.themes_combo = Gtk.ComboBoxText()
        self.themes_combo.set_entry_text_column(0)
        self.themes_combo.connect("changed", self.__on_themes_combo_changed)
        for theme in themes:
            self.themes_combo.append_text(theme)
        if self.window.config_provider.config["Application"]["stylesheet"] == "Day":
            self.themes_combo.set_active(0)
        else:
            self.themes_combo.set_active(1)
        hbox_theme.pack_end(self.themes_combo, False, True, 0)
        theme_label = Gtk.Label(_("Application theme") ,xalign=0)
        hbox_theme.pack_start(theme_label, False, True, 0)
        vbox.pack_start(hbox_theme, False, True, 0)
        try:
            vbox.set_margin_start(20)
            vbox.set_margin_end(20)
        except AttributeError:
            print("Gtk-WARNING **: GTK+ ver. below 3.12 will cause application interface to misbehave")
            vbox.set_margin_left(20)
            vbox.set_margin_right(20)
        vbox.set_margin_top(20)
        self.add(vbox) 
Example #10
Source File: utilities.py    From drawing with GNU General Public License v3.0 5 votes vote down vote up
def _ask_overwrite_alpha(window, can_save_as):
	"""Warn the user about the replacement of the alpha channel for JPG or BMP
	files, but it will quickly annoy users to see a dialog so it's an option."""
	dialog = DrMessageDialog(window)
	cancel_id = dialog.set_action(_("Cancel"), None, False)
	if can_save_as:
		save_as_id = dialog.set_action(_("Save as…"), None, False)
	replace_id = dialog.set_action(_("Replace"), None, True)

	dialog.add_string(_("This file format doesn't support transparent colors."))
	if can_save_as:
		dialog.add_string(_("You can save the image as a PNG file, or " \
		                                          "replace transparency with:"))
	else:
		dialog.add_string(_("Replace transparency with:"))

	alpha_combobox = Gtk.ComboBoxText(halign=Gtk.Align.CENTER)
	alpha_combobox.append('white', _("White"))
	alpha_combobox.append('black', _("Black"))
	alpha_combobox.append('checkboard', _("Checkboard"))
	alpha_combobox.append('nothing', _("Nothing"))
	alpha_combobox.set_active_id('white') # If we run the dialog, it means the
	# active preference is 'ask', so there is no way we can set the default
	# value to something pertinent.
	dialog.add_widget(alpha_combobox)

	result = dialog.run()
	repl = alpha_combobox.get_active_id()
	dialog.destroy()
	if result != replace_id:
		raise Exception(result)
	return repl

################################################################################ 
Example #11
Source File: settsmanager.py    From AutomaThemely with GNU General Public License v3.0 5 votes vote down vote up
def get_object_data(obj, *args):
    if isinstance(obj, Gtk.ComboBoxText):
        return obj.get_active_id() if obj.get_active_id() != 'none' else ''
    elif isinstance(obj, Gtk.Switch):
        return obj.get_active()
    elif isinstance(obj, Gtk.SpinButton):
        return obj.get_value_as_int()
    elif isinstance(obj, Gtk.Entry):
        text = obj.get_text()
        if obj.get_name() == 'float_only' and isfloat(text):
            return float(text)
        else:
            return text 
Example #12
Source File: settsmanager.py    From AutomaThemely with GNU General Public License v3.0 5 votes vote down vote up
def scan_comboboxtext_descendants(obj, match):
    try:
        children = obj.get_children()
    except AttributeError:
        return
    else:
        if children:
            comboboxtexts = []
            for child in children:
                scan = scan_comboboxtext_descendants(child, match)
                if scan:
                    comboboxtexts.extend(scan)
            return comboboxtexts
        elif isinstance(obj, Gtk.ComboBoxText) and match in Gtk.Buildable.get_name(obj):
            return [obj] 
Example #13
Source File: sourceview.py    From zim-desktop-wiki with GNU General Public License v2.0 4 votes vote down vote up
def _init_view(self):
		self.buffer.object_attrib.connect('changed', self.on_attrib_changed)

		self.view = GtkSource.View()
		self.view.set_buffer(self.buffer)
		self.view.modify_font(Pango.FontDescription('monospace'))
		self.view.set_auto_indent(True)
		self.view.set_smart_home_end(True)
		self.view.set_highlight_current_line(True)
		self.view.set_right_margin_position(80)
		self.view.set_show_right_margin(True)
		self.view.set_tab_width(4)
		self.view.set_show_line_numbers(self.buffer.object_attrib['linenumbers'])
		self.view.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)

		self.WRAP_MODE = {
			WRAP_NONE: Gtk.WrapMode.NONE,
			WRAP_WORD_CHAR: Gtk.WrapMode.WORD_CHAR,
			WRAP_CHAR: Gtk.WrapMode.CHAR,
			WRAP_WORD: Gtk.WrapMode.WORD,
		}

		# simple toolbar
		#~ bar = Gtk.HBox() # FIXME: use Gtk.Toolbar stuff
		#~ lang_selector = Gtk.ComboBoxText()
		#~ lang_selector.append_text('(None)')
		#~ for l in lang_names: lang_selector.append_text(l)
		#~ try:
			#~ lang_selector.set_active(lang_ids.index(self._attrib['lang'])+1)
			#~ self.set_language(self._attrib['lang'] or None, False)
		#~ except (ValueError, KeyError):
			#~ lang_selector.set_active(0)
			#~ self.set_language(None, False)
		#~ lang_selector.connect('changed', self.on_lang_changed)
		#~ bar.pack_start(lang_selector, False, False)

		#~ line_numbers = Gtk.ToggleButton('Line numbers')
		#~ try:
			#~ line_numbers.set_active(self._attrib['linenumbers']=='true')
			#~ self.show_line_numbers(self._attrib['linenumbers'], False)
		#~ except (ValueError, KeyError):
			#~ line_numbers.set_active(True)
			#~ self.show_line_numbers(True, False)
		#~ line_numbers.connect('toggled', self.on_line_numbers_toggled)
		#~ bar.pack_start(line_numbers, False, False)
		#~ self.add_header(bar)

		# TODO: other toolbar options
		# TODO: autohide toolbar if textbuffer is not active

		win = ScrolledWindow(self.view, Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER, Gtk.ShadowType.NONE)
		self.add(win)

		self.view.connect('populate-popup', self.on_populate_popup) 
Example #14
Source File: settsmanager.py    From AutomaThemely with GNU General Public License v3.0 4 votes vote down vote up
def populate_themes_cboxt(self, cboxt):
        # If ComboBoxText has an active id it has already been populated
        if cboxt.get_active_id():
            return

        cboxt_id = Gtk.Buildable.get_name(cboxt)
        cboxt_path = split_id_delimiter(cboxt_id)[0]
        cboxt_attr = cboxt.get_name()

        val = read_dict(self.us_se, cboxt_path.split('.'))
        themes = []

        if cboxt_id.startswith('*themes'):
            theme_type = cboxt_attr.split('-')[2]

            if not self.system_themes or theme_type not in self.system_themes:
                tmp = cboxt.get_children()
                cboxt.set_sensitive(False)
                return
            else:
                themes = self.system_themes[theme_type]

        elif cboxt_id.startswith('*extras'):
            cboxt_split = cboxt_attr.split('-')
            theme_type = cboxt_split[1]
            extra_type = cboxt_split[2]

            if theme_type not in self.extras[extra_type]:
                cboxt.set_sensitive(False)
            else:
                themes = self.extras[extra_type][theme_type]

        for theme in themes:
            t_id = theme[0]
            if len(theme) > 1:
                t_name = theme[1]
            else:
                t_name = t_id[0].upper() + t_id[1:]
            cboxt.append(t_id, t_name)

        active_id = try_or_default_type(val, str)
        if active_id:
            cboxt.set_active_id(active_id)
        else:
            # So it doesn't continue populating repeated options on non-set CBoxTs
            cboxt.set_active_id('none')

    #       HANDLERS
    # noinspection PyAttributeOutsideInit