本文整理汇总了Python中quodlibet.qltk.entry.UndoEntry.set_activates_default方法的典型用法代码示例。如果您正苦于以下问题:Python UndoEntry.set_activates_default方法的具体用法?Python UndoEntry.set_activates_default怎么用?Python UndoEntry.set_activates_default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类quodlibet.qltk.entry.UndoEntry
的用法示例。
在下文中一共展示了UndoEntry.set_activates_default方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GetStringDialog
# 需要导入模块: from quodlibet.qltk.entry import UndoEntry [as 别名]
# 或者: from quodlibet.qltk.entry.UndoEntry import set_activates_default [as 别名]
class GetStringDialog(Dialog):
"""Simple dialog to return a string from the user"""
def __init__(self, parent, title, text,
button_label=_("_OK"), button_icon=Icons.DOCUMENT_OPEN,
tooltip=None):
super(GetStringDialog, self).__init__(
title=title, transient_for=parent, use_header_bar=True)
self.set_border_width(6)
self.set_resizable(True)
self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
self.add_icon_button(button_label, button_icon, Gtk.ResponseType.OK)
self.vbox.set_spacing(6)
self.set_default_response(Gtk.ResponseType.OK)
box = Gtk.VBox(spacing=6)
lab = Gtk.Label(label=text)
box.set_border_width(6)
lab.set_line_wrap(True)
lab.set_justify(Gtk.Justification.CENTER)
box.pack_start(lab, True, True, 0)
self._val = UndoEntry()
if tooltip:
self._val.set_tooltip_text(tooltip)
self._val.set_max_width_chars(50)
box.pack_start(self._val, True, True, 0)
self.vbox.pack_start(box, True, True, 0)
self.get_child().show_all()
def _verify_clipboard(self, text):
"""Return an altered text or None if the content was invalid."""
return
def run(self, text="", clipboard=False, test=False):
"""Shows the dialog and returns the entered value.
If clipboard is set, the initial value will be pulled from the
clipboard and can be verified/altered by _verify_clipboard. In case the
verification fails text will be used as fallback"""
self.show()
if clipboard:
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
clip = clipboard.wait_for_text()
if clip is not None:
clip = self._verify_clipboard(clip)
if clip is not None:
text = clip
self._val.set_text(text)
self._val.set_activates_default(True)
self._val.grab_focus()
resp = Gtk.ResponseType.OK
if not test:
resp = super(GetStringDialog, self).run()
if resp == Gtk.ResponseType.OK:
value = self._val.get_text()
else:
value = None
self.destroy()
return value
示例2: GetStringDialog
# 需要导入模块: from quodlibet.qltk.entry import UndoEntry [as 别名]
# 或者: from quodlibet.qltk.entry.UndoEntry import set_activates_default [as 别名]
class GetStringDialog(gtk.Dialog):
def __init__(
self, parent, title, text, options=[], okbutton=gtk.STOCK_OPEN):
super(GetStringDialog, self).__init__(title, parent)
self.set_border_width(6)
self.set_has_separator(False)
self.set_resizable(False)
self.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
okbutton, gtk.RESPONSE_OK)
self.vbox.set_spacing(6)
self.set_default_response(gtk.RESPONSE_OK)
box = gtk.VBox(spacing=6)
lab = gtk.Label(text)
box.set_border_width(6)
lab.set_line_wrap(True)
lab.set_justify(gtk.JUSTIFY_CENTER)
box.pack_start(lab)
if options:
self._entry = gtk.combo_box_entry_new_text()
for o in options: self._entry.append_text(o)
self._val = self._entry.child
box.pack_start(self._entry)
else:
self._val = UndoEntry()
box.pack_start(self._val)
self.vbox.pack_start(box)
self.child.show_all()
def _verify_clipboard(self, text):
"""Return an altered text or None if the content was invalid."""
return
def run(self, text="", clipboard=False, test=False):
"""Shows the dialog and returns the entered value.
If clipboard is set, the initial value will be pulled from the
clipboard and can be verified/altered by _verify_clipboard. In case the
verification fails text will be used as fallback"""
self.show()
if clipboard:
clipboard = gtk.clipboard_get()
clip = clipboard.wait_for_text()
if clip is not None:
clip = self._verify_clipboard(clip)
if clip is not None:
text = clip
self._val.set_text(text)
self._val.set_activates_default(True)
self._val.grab_focus()
resp = gtk.RESPONSE_OK
if not test:
resp = super(GetStringDialog, self).run()
if resp == gtk.RESPONSE_OK:
value = self._val.get_text()
else: value = None
self.destroy()
return value