本文整理汇总了Python中gi.repository.Gtk.ComboBox方法的典型用法代码示例。如果您正苦于以下问题:Python Gtk.ComboBox方法的具体用法?Python Gtk.ComboBox怎么用?Python Gtk.ComboBox使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.Gtk
的用法示例。
在下文中一共展示了Gtk.ComboBox方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gtk_combobox_set_entry_completion
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ComboBox [as 别名]
def gtk_combobox_set_entry_completion(combobox):
"""
Add completion for a :py:class:`Gtk.ComboBox` widget which contains an
entry. They combobox's ``entry-text-column`` property it used to determine
which column in its model contains the strings to suggest for completion.
.. versionadded:: 1.14.0
:param combobox: The combobox to add completion for.
:type: :py:class:`Gtk.ComboBox`
"""
utilities.assert_arg_type(combobox, Gtk.ComboBox)
completion = Gtk.EntryCompletion()
completion.set_model(combobox.get_model())
completion.set_text_column(combobox.get_entry_text_column())
entry = combobox.get_child()
entry.set_completion(completion)
示例2: display_value
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ComboBox [as 别名]
def display_value(self, key, w):
"""
Sets value on UI element for single key. May be overridden
by subclass to handle special values.
"""
if isinstance(w, Gtk.SpinButton):
w.get_adjustment().set_value(ints(self.get_value(strip_v(key))))
elif isinstance(w, Gtk.Entry):
w.set_text(unicode(self.get_value(strip_v(key))))
elif isinstance(w, Gtk.ComboBox):
val = self.get_value(strip_v(key))
m = w.get_model()
for i in xrange(0, len(m)):
if str(val) == str(m[i][0]).strip():
w.set_active(i)
break
else:
w.set_active(0)
elif isinstance(w, Gtk.CheckButton):
w.set_active(self.get_value(strip_v(key)))
else:
log.warning("display_value: %s class cannot handle widget %s, key %s", self.__class__.__name__, w, key)
if not w is None: w.set_sensitive(False)
示例3: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ComboBox [as 别名]
def __init__(self, data_list=[], model=None, text_key=None, value_key=None, sort_key=None):
Gtk.ComboBox.__init__(self)
# set max chars width
renderer_text = Gtk.CellRendererText()
renderer_text.props.max_width_chars = 10
renderer_text.props.ellipsize = Pango.EllipsizeMode.END
# append data
if model is None:
self.model = Gtk.ListStore(str, str)
else:
self.model = model
self.append_list(data_list, text_key, value_key, sort_key)
self.set_model(self.model)
self.pack_start(renderer_text, True)
self.add_attribute(renderer_text, 'text', 0)
# save data list values (for further use)
self.values = [ item[value_key] for item in data_list ]
示例4: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ComboBox [as 别名]
def __init__(self, section, option, items=[], default_item=None):
Gtk.ComboBox.__init__(self)
self.section = section
self.option = option
self.items = items
self.default_item = default_item
self.model = Gtk.ListStore(str)
self.set_model(self.model)
for item in self.items:
self.model.append([item])
renderer_text = Gtk.CellRendererText()
self.pack_start(renderer_text, True)
self.add_attribute(renderer_text, "text", 0)
self.item = prefs.get(self.section, self.option, self.default_item, str)
self.set_selected(self.item)
self.connect("changed", self.on_selection_changed)
示例5: colorscheme_box_change
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ComboBox [as 别名]
def colorscheme_box_change(self, widget):
x = self.colorscheme.get_active()
# set the ComboBox in color_grid
self.cpage.set_edit_combo(x)
示例6: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ComboBox [as 别名]
def __init__(self):
GObject.GObject.__init__(self)
Gtk.ActionBar.__init__(self)
self.set_border_width(12)
self._save_btn = Gtk.Button()
self._output_format = Gtk.ComboBox()
self._setup_widgets()
示例7: get_save_dialog
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ComboBox [as 别名]
def get_save_dialog(export=False):
savedialog = Gtk.FileChooserDialog(
"", mainwindow(), Gtk.FileChooserAction.SAVE,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE,
Gtk.ResponseType.ACCEPT))
savedialog.set_current_folder(os.path.expanduser("~"))
# Add widgets to the savedialog
savecombo = Gtk.ComboBox()
savecombo.set_name("savecombo")
crt = Gtk.CellRendererText()
savecombo.pack_start(crt, True)
savecombo.add_attribute(crt, 'text', 0)
crt = Gtk.CellRendererText()
savecombo.pack_start(crt, False)
savecombo.add_attribute(crt, 'text', 1)
if export:
savecombo.set_model(exportformats)
else:
savecombo.set_model(saveformats)
savecombo.set_active(1) # pgn
savedialog.set_extra_widget(savecombo)
return savedialog, savecombo
示例8: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ComboBox [as 别名]
def __init__(self):
GObject.GObject.__init__(self)
self.widgets = widgets = tasker_widgets
tasker = widgets["newGameTasker"]
tasker.unparent()
self.add(tasker)
startButton = self.widgets["startButton"]
startButton.set_name("startButton")
combo = Gtk.ComboBox()
uistuff.createCombo(combo, [
(get_pixbuf("glade/white.png"), _("White")),
(get_pixbuf("glade/black.png"), _("Black")),
(get_pixbuf("glade/random.png"), _("Random"))])
widgets["colorDock"].add(combo)
if combo.get_active() < 0:
combo.set_active(0)
widgets['yourColorLabel'].set_mnemonic_widget(combo)
# We need to wait until after engines have been discovered, to init the
# playerCombos. We use connect_after to make sure, that newGameDialog
# has also had time to init the constants we share with them.
self.playerCombo = Gtk.ComboBox()
widgets["opponentDock"].add(self.playerCombo)
discoverer.connect_after("all_engines_discovered",
self.__initPlayerCombo, widgets)
widgets['opponentLabel'].set_mnemonic_widget(self.playerCombo)
def on_skill_changed(scale):
# Just to make sphinx happy...
try:
pix = newGameDialog.skillToIconLarge[int(scale.get_value())]
widgets["skillImage"].set_from_pixbuf(pix)
except TypeError:
pass
widgets["skillSlider"].connect("value-changed", on_skill_changed)
on_skill_changed(widgets["skillSlider"])
widgets["startButton"].connect("clicked", self.startClicked)
self.widgets["opendialog1"].connect("clicked", self.openDialogClicked)
示例9: ui_value_changed
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ComboBox [as 别名]
def ui_value_changed(self, w, *a):
"""
Handler for widget that controls state of other widgets
"""
key = self.get_widget_id(w)
if not self._loading:
if key in self.SETTING_NEEDS_RESTART:
self[self.RESTART_NEEDED_WIDGET].set_visible(True)
if key != None:
if isinstance(w, Gtk.CheckButton):
self.set_value(strip_v(key), w.get_active())
self.update_special_widgets()
if isinstance(w, Gtk.ComboBox):
self.set_value(strip_v(key), str(w.get_model()[w.get_active()][0]).strip())
self.update_special_widgets()
示例10: store_value
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ComboBox [as 别名]
def store_value(self, key, w):
"""
Loads single value from UI element to self.values dict. May be
overriden by subclass to handle special values.
"""
if isinstance(w, Gtk.SpinButton):
self.set_value(strip_v(key), int(w.get_adjustment().get_value()))
elif isinstance(w, Gtk.Entry):
self.set_value(strip_v(key), w.get_text().decode("utf-8"))
elif isinstance(w, Gtk.CheckButton):
self.set_value(strip_v(key), w.get_active())
elif isinstance(w, Gtk.ComboBox):
self.set_value(strip_v(key), str(w.get_model()[w.get_active()][0]).strip())
# else nothing, unknown widget class cannot be read
示例11: gtk_combobox_set_active_text
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ComboBox [as 别名]
def gtk_combobox_set_active_text(combobox, text):
'''Opposite of C{Gtk.ComboBox.get_active_text()}. Sets the
active item based on a string. Will match this string against the
list of options and select the correct index.
@raises ValueError: when the string is not found in the list.
'''
model = combobox.get_model()
for i, value in enumerate(model):
if value[0] == text:
return combobox.set_active(i)
else:
raise ValueError(text)
示例12: _focus_next
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ComboBox [as 别名]
def _focus_next(self, widget, activatable=False):
# If 'activatable' is True we only focus widgets that have
# an 'activated' signal (mainly just TextEntries). This is used
# to fine tune the last-activated signal
if widget is None:
i = 0
else:
for k, v in list(self.widgets.items()):
if v == widget:
i = self._widgets.index(k) + 1
break
else:
raise ValueError
for k in self._widgets[i:]:
widget = self.widgets[k]
if widget.get_property('sensitive') \
and widget.get_property('visible') \
and not (
activatable
and not isinstance(widget, (Gtk.Entry, Gtk.ComboBox))
):
widget.grab_focus()
return True
else:
return False
#}
#{ Dict access methods
示例13: __getitem__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ComboBox [as 别名]
def __getitem__(self, key):
if not key in self._keys:
raise KeyError(key)
elif key in self.widgets:
widget = self.widgets[key]
if isinstance(widget, LinkEntry):
return widget.get_text() # Could be either page or file
elif isinstance(widget, (PageEntry, NamespaceEntry)):
return widget.get_path()
elif isinstance(widget, FSPathEntry):
return widget.get_path()
elif isinstance(widget, InputEntry):
return widget.get_text()
elif isinstance(widget, Gtk.CheckButton):
return widget.get_active()
elif isinstance(widget, Gtk.ComboBox):
if hasattr(widget, 'zim_key_mapping'):
label = widget.get_active_text()
return widget.zim_key_mapping.get(label) or label
else:
return widget.get_active_text()
elif isinstance(widget, Gtk.SpinButton):
return int(widget.get_value())
elif isinstance(widget, Gtk.ColorButton):
return widget.get_rgba().to_string()
else:
raise TypeError(widget.__class__.name)
else:
# Group of RadioButtons
for name, widget in self._get_radiogroup(key):
if widget.get_active():
x, name = name.rsplit(':', 1)
# using rsplit to assure another ':' in the
# group name is harmless
return name
示例14: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ComboBox [as 别名]
def __init__ (self,
title = 'Save file',
parent = None,
action = Gtk.FileChooserAction.SAVE,
buttons = (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_SAVE, Gtk.ResponseType.OK),
path = None,
filetypes = [],
default_filetype = None
):
super (FileChooserDialog, self).__init__ (title, parent, action,
buttons)
self.set_default_response (Gtk.ResponseType.OK)
if not path: path = os.getcwd() + os.sep
# create an extra widget to list supported image formats
self.set_current_folder (path)
self.set_current_name ('image.' + default_filetype)
hbox = Gtk.Box(spacing=10)
hbox.pack_start(Gtk.Label(label="File Format:"), False, False, 0)
liststore = Gtk.ListStore(GObject.TYPE_STRING)
cbox = Gtk.ComboBox() #liststore)
cbox.set_model(liststore)
cell = Gtk.CellRendererText()
cbox.pack_start(cell, True)
cbox.add_attribute(cell, 'text', 0)
hbox.pack_start(cbox, False, False, 0)
self.filetypes = filetypes
self.sorted_filetypes = filetypes.items()
self.sorted_filetypes.sort()
default = 0
for i, (ext, name) in enumerate(self.sorted_filetypes):
liststore.append(["%s (*.%s)" % (name, ext)])
if ext == default_filetype:
default = i
cbox.set_active(default)
self.ext = default_filetype
def cb_cbox_changed (cbox, data=None):
"""File extension changed"""
head, filename = os.path.split(self.get_filename())
root, ext = os.path.splitext(filename)
ext = ext[1:]
new_ext = self.sorted_filetypes[cbox.get_active()][0]
self.ext = new_ext
if ext in self.filetypes:
filename = root + '.' + new_ext
elif ext == '':
filename = filename.rstrip('.') + '.' + new_ext
self.set_current_name (filename)
cbox.connect ("changed", cb_cbox_changed)
hbox.show_all()
self.set_extra_widget(hbox)
示例15: __init__
# 需要导入模块: from gi.repository import Gtk [as 别名]
# 或者: from gi.repository.Gtk import ComboBox [as 别名]
def __init__(self,
title = 'Save file',
parent = None,
action = Gtk.FileChooserAction.SAVE,
buttons = (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_SAVE, Gtk.ResponseType.OK),
path = None,
filetypes = [],
default_filetype = None
):
super().__init__(title, parent, action, buttons)
self.set_default_response(Gtk.ResponseType.OK)
self.set_do_overwrite_confirmation(True)
if not path:
path = os.getcwd()
# create an extra widget to list supported image formats
self.set_current_folder(path)
self.set_current_name('image.' + default_filetype)
hbox = Gtk.Box(spacing=10)
hbox.pack_start(Gtk.Label(label="File Format:"), False, False, 0)
liststore = Gtk.ListStore(GObject.TYPE_STRING)
cbox = Gtk.ComboBox()
cbox.set_model(liststore)
cell = Gtk.CellRendererText()
cbox.pack_start(cell, True)
cbox.add_attribute(cell, 'text', 0)
hbox.pack_start(cbox, False, False, 0)
self.filetypes = filetypes
sorted_filetypes = sorted(filetypes.items())
default = 0
for i, (ext, name) in enumerate(sorted_filetypes):
liststore.append(["%s (*.%s)" % (name, ext)])
if ext == default_filetype:
default = i
cbox.set_active(default)
self.ext = default_filetype
def cb_cbox_changed(cbox, data=None):
"""File extension changed"""
head, filename = os.path.split(self.get_filename())
root, ext = os.path.splitext(filename)
ext = ext[1:]
new_ext = sorted_filetypes[cbox.get_active()][0]
self.ext = new_ext
if ext in self.filetypes:
filename = root + '.' + new_ext
elif ext == '':
filename = filename.rstrip('.') + '.' + new_ext
self.set_current_name(filename)
cbox.connect("changed", cb_cbox_changed)
hbox.show_all()
self.set_extra_widget(hbox)