def __get_playlist_name(name="Quod Libet playlist"): dialog = GetStringDialog(None, _("Export playlist to Squeezebox"), _("Playlist name (will overwrite existing)"), button_label=_("_Save"), button_icon=Icons.DOCUMENT_SAVE) name = dialog.run(text=name) return name
def __add(self, *args): dialog = GetStringDialog(self, _("Enter new value"), "", button_label=_("_Add"), button_icon=Icons.LIST_ADD) new = dialog.run() if new: self.model.append(row=[new])
def __get_playlist_name(name="Quod Libet playlist"): dialog = GetStringDialog(None, _("Export playlist to Squeezebox"), _("Playlist name (will overwrite existing)"), okbutton=Gtk.STOCK_SAVE) name = dialog.run(text=name) return name
def __add(self, *args): tooltip = _('Tag expression e.g. people:real or ~album~year.') dialog = GetStringDialog(self, _("Enter new tag"), "", button_icon=None, tooltip=tooltip) new = dialog.run() if new: self.model.append(row=[new])
def __add(self, *args): dialog = GetStringDialog(self, _("Enter new value"), "", okbutton=Gtk.STOCK_ADD) new = dialog.run() if new: self.model.append(row=[new])
def plugin_songs(self, songs): value = -1 while not 0 <= value <= 1: input_string = GetStringDialog( self.plugin_window, self.PLUGIN_NAME, _("Please give your desired rating on a scale " "from 0.0 to 1.0"), _("_Apply"), Icons.NONE ).run() if input_string is None: return try: value = float(input_string) except ValueError: continue count = len(songs) if (count > 1 and config.getboolean("browsers", "rating_confirm_multiple")): confirm_dialog = ConfirmRateMultipleDialog( self.plugin_window, _("Change _Rating"), count, value) if confirm_dialog.run() != Gtk.ResponseType.YES: return for song in songs: song["~#rating"] = value
def __mkdir(self, button): model, paths = self.get_selection().get_selected_rows() if len(paths) != 1: return path = paths[0] directory = model[path][0] dir_ = GetStringDialog(None, _("New Folder"), _("Enter a name for the new folder:")).run() if not dir_: return dir_ = glib2fsn(dir_) fullpath = os.path.realpath(os.path.join(directory, dir_)) try: os.makedirs(fullpath) except EnvironmentError as err: error = "<b>%s</b>: %s" % (err.filename, err.strerror) qltk.ErrorMessage(None, _("Unable to create folder"), error).run() return self.emit('test-expand-row', model.get_iter(path), path) self.expand_row(path, False)
def run(self, songs): """ Runs this command on `songs`, splitting into multiple calls if necessary """ args = [] if self.parameter: value = GetStringDialog(None, _("Input value"), _("Value for %s?") % self.parameter).run() self.command = self.command.format(**{self.parameter: value}) print_d("Actual command=%s" % self.command) for song in songs: arg = str(self.__pat.format(song)) if not arg: print_w("Couldn't build shell command using \"%s\"." "Check your pattern?" % self.pattern) break if not self.unique: args.append(arg) elif arg not in args: args.append(arg) max = int((self.max_args or 10000)) com_words = self.command.split(" ") while args: print_d( "Running %s with %d substituted arg(s) (of %d%s total)..." % (self.command, min(max, len(args)), len(args), " unique" if self.unique else "")) util.spawn(com_words + args[:max]) args = args[max:]
class TGetStringDialog(TestCase): def setUp(self): self.gsd1 = GetStringDialog(None, "title", "enter a string") self.gsd2 = _ClipboadTestClass(None, "title", "enter a string") def test_getstring(self): ret = self.gsd1.run(text="foobar", test=True) self.failUnlessEqual(ret, "foobar") def test_clipboard(self): clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) clipboard.set_text("42", -1) ret = self.gsd2.run(text="24", clipboard=True, test=True) self.failUnlessEqual(ret, "42") def tearDown(self): self.gsd1.destroy() self.gsd2.destroy()
class TGetStringDialog(TestCase): def setUp(self): self.gsd1 = GetStringDialog(None, "title", "enter a string") self.gsd2 = _ClipboadTestClass(None, "title", "enter a string", options=["1", "2"]) def test_getstring(self): ret = self.gsd1.run(text="foobar", test=True) self.failUnlessEqual(ret, "foobar") def test_clipboard(self): clipboard = gtk.clipboard_get() clipboard.set_text("42", -1) ret = self.gsd2.run(text="24", clipboard=True, test=True) self.failUnlessEqual(ret, "42") def tearDown(self): self.gsd1.destroy() self.gsd2.destroy()
def __mkdir(self, button): model, rows = self.get_selection().get_selected_rows() if len(rows) != 1: return row = rows[0] directory = model[row][0] dir = GetStringDialog( None, _("New Folder"), _("Enter a name for the new folder:")).run() if dir: dir = util.fsnative(dir.decode('utf-8')) fullpath = os.path.realpath(os.path.join(directory, dir)) try: os.makedirs(fullpath) except EnvironmentError, err: error = "<b>%s</b>: %s" % (err.filename, err.strerror) qltk.ErrorMessage( None, _("Unable to create folder"), error).run() else: self.emit('test-expand-row', model.get_iter(row), row) self.expand_row(row, False)
class TGetStringDialog(TestCase): def setUp(self): parent = Gtk.Window() self.gsd1 = GetStringDialog(parent, "title", "enter a string") self.gsd2 = _ClipboadTestClass(parent, "title", "enter a string") def test_getstring(self): ret = self.gsd1.run(text="foobar", test=True) self.failUnlessEqual(ret, "foobar") def test_clipboard(self): clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) clipboard.set_text("42", -1) ret = self.gsd2.run(text="24", clipboard=True, test=True) self.failUnlessEqual(ret, "42") clipboard.clear() def tearDown(self): self.gsd1.destroy() self.gsd2.destroy()
def __mkdir(self, button): model, paths = self.get_selection().get_selected_rows() if len(paths) != 1: return path = paths[0] directory = model[path][0] dir_ = GetStringDialog(None, _("New Folder"), _("Enter a name for the new folder:")).run() if not dir_: return dir_ = util.fsnative(dir_.decode('utf-8')) fullpath = os.path.realpath(os.path.join(directory, dir_)) try: os.makedirs(fullpath) except EnvironmentError, err: error = "<b>%s</b>: %s" % (err.filename, err.strerror) qltk.ErrorMessage(None, _("Unable to create folder"), error).run() return
class TGetStringDialog(TestCase): def setUp(self): parent = Gtk.Window() self.gsd1 = GetStringDialog(parent, "title", "enter a string") self.gsd2 = _ClipboadTestClass(parent, "title", "enter a string") def test_getstring(self): ret = self.gsd1.run(text="foobar", test=True) self.failUnlessEqual(ret, "foobar") def test_tooltip(self): foo = GetStringDialog(Gtk.Window(), "title", "", tooltip="foo bar") self.failUnlessEqual(foo._val.get_tooltip_text(), "foo bar") def test_clipboard(self): clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) clipboard.set_text("42", -1) ret = self.gsd2.run(text="24", clipboard=True, test=True) self.failUnlessEqual(ret, "42") clipboard.clear() def tearDown(self): self.gsd1.destroy() self.gsd2.destroy()
def run(self, songs, playlist_name=None): """ Runs this command on `songs`, splitting into multiple calls if necessary. `playlist_name` if populated contains the Playlist's name. """ args = [] template_vars = {} if self.parameter: value = GetStringDialog(None, _("Input value"), _("Value for %s?") % self.parameter).run() template_vars[self.parameter] = value if playlist_name: print_d("Playlist command for %s" % playlist_name) template_vars["PLAYLIST"] = playlist_name actual_command = self.command.format(**template_vars) print_d("Actual command=%s" % actual_command) for i, song in enumerate(songs): wrapped = SongWrapper(song) if playlist_name: wrapped["~playlistname"] = playlist_name wrapped["~playlistindex"] = str(i + 1) wrapped["~#playlistindex"] = i + 1 arg = str(self.__pat.format(wrapped)) if not arg: print_w("Couldn't build shell command using \"%s\"." "Check your pattern?" % self.pattern) break if not self.unique: args.append(arg) elif arg not in args: args.append(arg) max = int((self.max_args or 10000)) com_words = actual_command.split(" ") if self.reverse: args.reverse() while args: print_d( "Running %s with %d substituted arg(s) (of %d%s total)..." % (actual_command, min(max, len(args)), len(args), " unique" if self.unique else "")) util.spawn(com_words + args[:max]) args = args[max:]
def open_location(self, action): name = GetStringDialog(self, _("Add a Location"), _("Enter the location of an audio file:"), okbutton=Gtk.STOCK_ADD).run() if name: if not util.uri_is_valid(name): ErrorMessage( self, _("Unable to add location"), _("<b>%s</b> is not a valid location.") % ( util.escape(name))).run() elif not app.player.can_play_uri(name): ErrorMessage( self, _("Unable to add location"), _("<b>%s</b> uses an unsupported protocol.") % ( util.escape(name))).run() else: if name not in self.__library: self.__library.add([RemoteFile(name)])
def open_location(self, action): name = GetStringDialog(self, _("Add a Location"), _("Enter the location of an audio file:"), button_label=_("_Add"), button_icon=Icons.LIST_ADD).run() if name: if not uri_is_valid(name): ErrorMessage( self, _("Unable to add location"), _("%s is not a valid location.") % ( util.bold(util.escape(name)))).run() elif not app.player.can_play_uri(name): ErrorMessage( self, _("Unable to add location"), _("%s uses an unsupported protocol.") % ( util.bold(util.escape(name)))).run() else: if name not in self.__library: self.__library.add([RemoteFile(name)])
def setUp(self): parent = Gtk.Window() self.gsd1 = GetStringDialog(parent, "title", "enter a string") self.gsd2 = _ClipboadTestClass(parent, "title", "enter a string")
def test_tooltip(self): foo = GetStringDialog(Gtk.Window(), "title", "", tooltip="foo bar") self.failUnlessEqual(foo._val.get_tooltip_text(), "foo bar")
def setUp(self): self.gsd1 = GetStringDialog(None, "title", "enter a string") self.gsd2 = _ClipboadTestClass(None, "title", "enter a string", options=["1", "2"])
def setUp(self): self.gsd1 = GetStringDialog(None, "title", "enter a string") self.gsd2 = _ClipboadTestClass(None, "title", "enter a string")