def __init__(self, filename=None, completion=None, accel_group=None, timeout=DEFAULT_TIMEOUT, validator=Query.validator, star=None): super(SearchBarBox, self).__init__(spacing=6) if filename is None: filename = os.path.join(quodlibet.get_user_dir(), "lists", "queries") combo = ComboBoxEntrySave(filename, count=8, validator=validator, title=_("Saved Searches"), edit_title=_(u"Edit saved searches…")) self.__deferred_changed = DeferredSignal(self.__filter_changed, timeout=timeout, owner=self) self.__combo = combo entry = combo.get_child() self.__entry = entry if completion: entry.set_completion(completion) self._star = star self._query = None self.__sig = combo.connect('text-changed', self.__text_changed) entry.connect('clear', self.__filter_changed) entry.connect('backspace', self.__text_changed) entry.connect('populate-popup', self.__menu) entry.connect('activate', self.__filter_changed) entry.connect('activate', self.__save_search) entry.connect('focus-out-event', self.__save_search) entry.connect('key-press-event', self.__key_pressed) entry.set_placeholder_text(_("Search")) entry.set_tooltip_text( _("Search your library, " "using free text or QL queries")) combo.enable_clear_button() self.pack_start(combo, True, True, 0) if accel_group: key, mod = Gtk.accelerator_parse("<Primary>L") accel_group.connect(key, mod, 0, lambda *x: entry.mnemonic_activate(True)) for child in self.get_children(): child.show_all()
def __init__(self, filename=None, button=True, completion=None, accel_group=None): super(SearchBarBox, self).__init__(spacing=6) if filename is None: filename = os.path.join(const.USERDIR, "lists", "queries") combo = ComboBoxEntrySave(filename, count=8, validator=Query.is_valid_color, title=_("Saved Searches"), edit_title=_("Edit saved searches...")) combo.enable_clear_button() self.__refill_id = None self.__combo = combo entry = combo.child self.__entry = entry if completion: entry.set_completion(completion) self.connect('destroy', lambda w: w.__remove_timeout()) self.__sig = combo.connect('changed', self.__text_changed) entry.connect('clear', self.__filter_changed) entry.connect('backspace', self.__text_changed) entry.connect('populate-popup', self.__menu) entry.connect('activate', self.__filter_changed) entry.connect('activate', self.__save_search) entry.connect('focus-out-event', self.__save_search) label = gtk.Label(_("_Search:")) label.set_use_underline(True) label.connect('mnemonic-activate', self.__mnemonic_activate) label.set_mnemonic_widget(entry) self.pack_start(label, expand=False) self.pack_start(combo) # search button if button: search = Button(_("Search"), gtk.STOCK_FIND, size=gtk.ICON_SIZE_MENU) search.connect('clicked', self.__filter_changed) search.set_tooltip_text(_("Search your library")) self.pack_start(search, expand=False) if accel_group: key, mod = gtk.accelerator_parse("<ctrl>L") accel_group.connect_group(key, mod, 0, lambda *x: label.mnemonic_activate(True)) self.show_all()
def __init__(self, filename=None, completion=None, accel_group=None, timeout=DEFAULT_TIMEOUT, validator=Query.validator, star=None): super(SearchBarBox, self).__init__(spacing=6) if filename is None: filename = os.path.join( quodlibet.get_user_dir(), "lists", "queries") combo = ComboBoxEntrySave(filename, count=8, validator=validator, title=_("Saved Searches"), edit_title=_(u"Edit saved searches…")) self.__deferred_changed = DeferredSignal( self.__filter_changed, timeout=timeout, owner=self) self.__combo = combo entry = combo.get_child() self.__entry = entry if completion: entry.set_completion(completion) self._star = star self._query = None self.__sig = combo.connect('text-changed', self.__text_changed) entry.connect('clear', self.__filter_changed) entry.connect('backspace', self.__text_changed) entry.connect('populate-popup', self.__menu) entry.connect('activate', self.__filter_changed) entry.connect('activate', self.__save_search) entry.connect('focus-out-event', self.__save_search) entry.connect('key-press-event', self.__key_pressed) entry.set_placeholder_text(_("Search")) entry.set_tooltip_text(_("Search your library, " "using free text or QL queries")) combo.enable_clear_button() self.pack_start(combo, True, True, 0) if accel_group: key, mod = Gtk.accelerator_parse("<Primary>L") accel_group.connect(key, mod, 0, lambda *x: entry.mnemonic_activate(True)) for child in self.get_children(): child.show_all()
def __init__(self, filename=None, completion=None, accel_group=None): super(SearchBarBox, self).__init__(spacing=6) if filename is None: filename = os.path.join(const.USERDIR, "lists", "queries") combo = ComboBoxEntrySave(filename, count=8, validator=Query.is_valid_color, title=_("Saved Searches"), edit_title=_("Edit saved searches...")) self.__refill_id = None self.__combo = combo entry = combo.get_child() self.__entry = entry if completion: entry.set_completion(completion) self.connect('destroy', lambda w: w.__remove_timeout()) self.__sig = combo.connect('text-changed', self.__text_changed) entry.connect('clear', self.__filter_changed) entry.connect('backspace', self.__text_changed) entry.connect('populate-popup', self.__menu) entry.connect('activate', self.__filter_changed) entry.connect('activate', self.__save_search) entry.connect('focus-out-event', self.__save_search) entry.set_placeholder_text(_("Search")) entry.set_tooltip_text( _("Search your library, " "using free text or QL queries")) combo.enable_clear_button() self.pack_start(combo, True, True, 0) if accel_group: key, mod = Gtk.accelerator_parse("<ctrl>L") accel_group.connect(key, mod, 0, lambda *x: entry.mnemonic_activate(True)) for child in self.get_children(): child.show_all()
class TComboBoxEntrySave(TestCase): memory = "pattern 1\npattern 2\n" saved = "pattern text\npattern name\n" def setUp(self): quodlibet.config.init() h, self.fname = mkstemp() os.close(h) with open(self.fname, "w") as f: f.write(self.memory) with open(self.fname + ".saved", "w") as f: f.write(self.saved) self.cbes = ComboBoxEntrySave(self.fname, count=2) self.cbes2 = ComboBoxEntrySave(self.fname, count=2) def test_equivalence(self): model1 = self.cbes.get_model() model2 = self.cbes2.get_model() self.failUnlessEqual(model1, model2) rows1 = list(model1) rows2 = list(model2) for row1, row2 in zip(rows1, rows2): self.failUnlessEqual(row1[0], row2[0]) self.failUnlessEqual(row1[1], row2[1]) self.failUnlessEqual(row1[2], row2[2]) def test_text_changed_signal(self): called = [0] def cb(*args): called[0] += 1 def get_count(): c = called[0] called[0] = 0 return c self.cbes.connect("text-changed", cb) entry = self.cbes.get_child() entry.set_text("foo") self.failUnlessEqual(get_count(), 1) self.cbes.prepend_text("bar") # in case the model got changed but the entry is still the same # the text-changed signal should not be triggered self.failUnlessEqual(entry.get_text(), "foo") self.failUnlessEqual(get_count(), 0) def test_shared_model(self): self.cbes.prepend_text("a test") self.test_equivalence() def test_initial_size(self): # 1 saved, Edit, separator, 2 remembered self.failUnlessEqual(5, len(self.cbes.get_model())) def test_prepend_text(self): self.cbes.prepend_text("pattern 3") self.memory = "pattern 3\npattern 1\n" self.test_save() def test_save(self): self.cbes.write() self.failUnlessEqual(self.memory, open(self.fname).read()) self.failUnlessEqual(self.saved, open(self.fname + ".saved").read()) def test_set_text_then_prepend(self): self.cbes.get_child().set_text("foobar") self.cbes.prepend_text("foobar") self.memory = "foobar\npattern 1\n" self.test_save() def tearDown(self): self.cbes.destroy() self.cbes2.destroy() os.unlink(self.fname) os.unlink(self.fname + ".saved") quodlibet.config.quit()
class TComboBoxEntrySave(TestCase): memory = "pattern 1\npattern 2\n" saved = "pattern text\npattern name\n" def setUp(self): quodlibet.config.init() h, self.fname = mkstemp() os.close(h) f = file(self.fname, "w") f.write(self.memory) f.close() f = file(self.fname + ".saved", "w") f.write(self.saved) f.close() self.cbes = ComboBoxEntrySave(self.fname, count=2) self.cbes2 = ComboBoxEntrySave(self.fname, count=2) def test_equivalence(self): model1 = self.cbes.get_model() model2 = self.cbes2.get_model() self.failUnlessEqual(model1, model2) rows1 = list(model1) rows2 = list(model2) for row1, row2 in zip(rows1, rows2): self.failUnlessEqual(row1[0], row2[0]) self.failUnlessEqual(row1[1], row2[1]) self.failUnlessEqual(row1[2], row2[2]) def test_text_changed_signal(self): called = [0] def cb(*args): called[0] += 1 def get_count(): c = called[0] called[0] = 0 return c self.cbes.connect("text-changed", cb) entry = self.cbes.get_child() entry.set_text("foo") self.failUnlessEqual(get_count(), 1) self.cbes.prepend_text("bar") # in case the model got changed but the entry is still the same # the text-changed signal should not be triggered self.failUnlessEqual(entry.get_text(), "foo") self.failUnlessEqual(get_count(), 0) def test_shared_model(self): self.cbes.prepend_text("a test") self.test_equivalence() def test_initial_size(self): # 1 saved, Edit, separator, 2 remembered self.failUnlessEqual(5, len(self.cbes.get_model())) def test_prepend_text(self): self.cbes.prepend_text("pattern 3") self.memory = "pattern 3\npattern 1\n" self.test_save() def test_save(self): self.cbes.write() self.failUnlessEqual(self.memory, file(self.fname).read()) self.failUnlessEqual(self.saved, file(self.fname + ".saved").read()) def test_set_text_then_prepend(self): self.cbes.get_child().set_text("foobar") self.cbes.prepend_text("foobar") self.memory = "foobar\npattern 1\n" self.test_save() def tearDown(self): self.cbes.destroy() self.cbes2.destroy() os.unlink(self.fname) os.unlink(self.fname + ".saved") quodlibet.config.quit()