Index: contrib/prefstore.py ================================================================== --- contrib/prefstore.py +++ contrib/prefstore.py @@ -1,10 +1,10 @@ # encoding: UTF-8 # api: streamtuner2 # title: Config save/import/reset # description: Allows to store, reimport or delete all preferences -# version: 0.1 +# version: 0.2 # type: feature # category: config # priority: optional # # Adds a context menu "Staton > Extensions > Config ...", which allows @@ -12,11 +12,11 @@ from config import * from channels import * import ahttp -from uikit import uikit +from uikit import uikit, gtk import action import re import json @@ -35,11 +35,11 @@ uikit.add_menu([parent.extensions], "Config restore", self.restore) uikit.add_menu([parent.extensions], "Config delete", self.reset) # Save conf. def save(self, *w): - fn = uikit.save_file(title="Export streamtuner2 config",fn="streatuner2-config.json", formats=[("*.json", "*.json")]) + fn = uikit.save_file(title="Export streamtuner2 config", fn="streatuner2-config.json", formats=[("*.json", "*.json")]) if not fn: return data = vars(conf) del data["args"] with open(fn, "w") as f: @@ -46,11 +46,11 @@ f.write(json.dumps(data, indent=4, sort_keys=True)) self.parent.status("Settings saved to " + fn) # Save conf. def restore(self, *w): - fn = uikit.save_file(title="Import streamtuner2 config",fn="streatuner2-config.json", formats=[("*.json", "*.json")]) + fn = uikit.save_file(title="Import streamtuner2 config", fn="streatuner2-config.json", formats=[("*.json", "*.json")], action=gtk.FILE_CHOOSER_ACTION_OPEN, action_btn=gtk.STOCK_OPEN) if not fn: return with open(fn, "r") as f: conf.update(json.load(f)) conf.save() Index: uikit.py ================================================================== --- uikit.py +++ uikit.py @@ -363,23 +363,24 @@ #-- Save-As dialog # + save_formats = [("*.pls", "*.pls"), ("*.xspf", "*.xpsf"), ("*.m3u", "*.m3u"), ("*.jspf", "*.jspf"), ("*.asx", "*.asx"), ("*.json", "*.json"), ("*.smil", "*.smil"), ("*.desktop", "*.desktop"), ("*","*")] @staticmethod - def save_file(title="Save As", parent=None, fn="", formats=[("*.pls", "*.pls"), ("*.xspf", "*.xpsf"), ("*.m3u", "*.m3u"), ("*.jspf", "*.jspf"), ("*.asx", "*.asx"), ("*.json", "*.json"), ("*.smil", "*.smil"), ("*.desktop", "*.desktop"), ("*","*")]): + def save_file(title="Save As", parent=None, fn="", formats=None, action=gtk.FILE_CHOOSER_ACTION_SAVE, action_btn=gtk.STOCK_SAVE): # With overwrite confirmation - c = gtk.FileChooserDialog(title, parent, action=gtk.FILE_CHOOSER_ACTION_SAVE, - buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK)) + buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, action_btn, gtk.RESPONSE_OK) + c = gtk.FileChooserDialog(title, parent, action=action, buttons=buttons) c.set_do_overwrite_confirmation(True) # Params if fn: c.set_current_name(fn) fn = "" - for fname,ftype in formats: + for fname,ftype in (formats or self.save_formats): f = gtk.FileFilter() f.set_name(fname) f.add_pattern(ftype) c.add_filter(f) # Yes, that's how to retrieve signals for changed filter selections