def generate_copy_name(self, name): """ Generates name for profile copy. That is 'New Profile X', where X is number that makes name unique. """ new_name = _("%s (copy)") % (name,) filename = os.path.join(get_profiles_path(), new_name + ".sccprofile") i = 2 while os.path.exists(filename): new_name = _("%s (copy %s)") % (name,) filename = os.path.join(get_profiles_path(), new_name + ".sccprofile") i += 1 return new_name
def generate_new_name(self): """ Generates name for new profile. That is 'New Profile X', where X is number that makes name unique. """ i = 1 new_name = _("New Profile %s") % (i,) filename = os.path.join(get_profiles_path(), new_name + ".sccprofile") while os.path.exists(filename): i += 1 new_name = _("New Profile %s") % (i,) filename = os.path.join(get_profiles_path(), new_name + ".sccprofile") return new_name
def on_new_clicked(self, ps, name): new_name = _("Copy of %s") % (name,) filename = os.path.join(get_profiles_path(), new_name + ".sccprofile") i = 0 while os.path.exists(filename): i += 1 new_name = _("Copy of %s (%s)") % (name, i) filename = os.path.join(get_profiles_path(), new_name + ".sccprofile") dlg = self.builder.get_object("dlgNewProfile") txNewProfile = self.builder.get_object("txNewProfile") txNewProfile.set_text(new_name) dlg.set_transient_for(self.window) dlg.show()
def cmd_list_profiles(argv0, argv): """ Lists available profiles Usage: scc list-profiles [-a] Arguments: -a Include names begining with dot """ from scc.paths import get_profiles_path, get_default_profiles_path paths = [get_default_profiles_path(), get_profiles_path()] include_hidden = "-a" in argv lst = set() for path in paths: try: for x in os.listdir(path): if x.endswith(".sccprofile"): if not include_hidden and x.startswith("."): continue lst.add(x[0:-len(".sccprofile")]) except OSError: pass for x in sorted(lst): print x return 0
def on_mnuProfileDelete_activate(self, *a): mnuPS = self.builder.get_object("mnuPS") name = mnuPS.ps.get_profile_name() is_override = profile_is_override(name) if is_override: text = _("Really revert current profile to default values?") else: text = _("Really delete current profile?") d = Gtk.MessageDialog(parent=self.window, flags = Gtk.DialogFlags.MODAL, type = Gtk.MessageType.WARNING, buttons = Gtk.ButtonsType.OK_CANCEL, message_format = text, ) d.format_secondary_text(_("This action is not undoable!")) if d.run() == -5: # OK button, no idea where is this defined... fname = os.path.join(get_profiles_path(), name + ".sccprofile") try: os.unlink(fname) try: os.unlink(fname + ".mod") except: # non-existing .mod file is expected pass for ps in self.profile_switchers: ps.refresh_profile_path(name) except Exception, e: log.error("Failed to remove %s: %s", fname, e)
def cmd_list_profiles(argv0, argv): """ Lists available profiles Usage: scc list-profiles [-a] Arguments: -a Include names begining with dot """ from scc.paths import get_profiles_path, get_default_profiles_path paths = [ get_default_profiles_path(), get_profiles_path() ] include_hidden = "-a" in argv lst = set() for path in paths: try: for x in os.listdir(path): if x.endswith(".sccprofile"): if not include_hidden and x.startswith("."): continue lst.add(x[0:-len(".sccprofile")]) except OSError: pass for x in sorted(lst): print x return 0
def on_btRenameProfile_clicked(self, *a): dlg = self.builder.get_object("dlgRenameProfile") txRename = self.builder.get_object("txRename") old_name = dlg._name new_name = txRename.get_text() old_fname = os.path.join(get_profiles_path(), old_name + ".sccprofile") new_fname = os.path.join(get_profiles_path(), new_name + ".sccprofile") try: os.rename(old_fname, new_fname) for n in (old_fname, new_fname): try: os.unlink(n + ".mod") except: # non-existing .mod file is expected pass except Exception, e: log.error("Failed to rename %s: %s", old_fname, e)
def _save_osk_profile(self, profile): """ Saves on-screen keyboard profile and calls daemon.reconfigure() Used by methods that are changing it. """ profile.save(os.path.join(get_profiles_path(), OSDKeyboard.OSK_PROF_NAME + ".sccprofile")) self.app.dm.reconfigure()
def _save_osk_profile(self, profile): """ Saves on-screen keyboard profile and calls daemon.reconfigure() Used by methods that are changing it. """ profile.save(os.path.join(get_profiles_path(), OSDKeyboard.OSK_PROF_NAME + ".sccprofile")) self.app.dm.reconfigure()
def save_profile(self, *a): """ Saves osk profile from 'profile' object into 'giofile'. Calls on_profile_saved when done """ self.current.save(os.path.join(get_profiles_path(), OSDKeyboard.OSK_PROF_NAME + ".sccprofile")) # OSK reloads profile when daemon reports configuration change self.app.dm.reconfigure()
def save_profile(self, *a): """ Saves osk profile from 'profile' object into 'giofile'. Calls on_profile_saved when done """ self.current.save(os.path.join(get_profiles_path(), OSDKeyboard.OSK_PROF_NAME + ".sccprofile")) # OSK reloads profile when daemon reports configuration change self.app.dm.reconfigure()
def __init__(self): profiles_path = get_profiles_path() if not os.path.exists(profiles_path): log.info("Creting profile directory '%s'" % (profiles_path, )) os.makedirs(profiles_path) menus_path = get_menus_path() if not os.path.exists(menus_path): log.info("Creting menu directory '%s'" % (menus_path, )) os.makedirs(menus_path)
def __init__(self): profiles_path = get_profiles_path() if not os.path.exists(profiles_path): log.info("Creting profile directory '%s'" % (profiles_path,)) os.makedirs(profiles_path) menus_path = get_menus_path() if not os.path.exists(menus_path): log.info("Creting menu directory '%s'" % (menus_path,)) os.makedirs(menus_path)
def profile_is_override(name): """ Returns True if named profile exists both in user config directory and default_profiles directory. """ filename = "%s.sccprofile" % (name, ) if os.path.exists(os.path.join(get_profiles_path(), filename)): if os.path.exists(os.path.join(get_default_profiles_path(), filename)): return True return False
def profile_is_override(name): """ Returns True if named profile exists both in user config directory and default_profiles directory. """ filename = "%s.sccprofile" % (name,) if os.path.exists(os.path.join(get_profiles_path(), filename)): if os.path.exists(os.path.join(get_default_profiles_path(), filename)): return True return False
def generate(self, menuhandler): # TODO: Cannot load directory content asynchronously here and I'm # TODO: not happy about it rv, all_profiles = [], {} for d in (get_default_profiles_path(), get_profiles_path()): for x in os.listdir(d): if x.endswith(".sccprofile") and not x.startswith("."): all_profiles[x] = os.path.join(d, x) for p in sorted(all_profiles, key=lambda s: s.lower()): menuitem = MenuItem("generated", p[0:-11]) # strips ".sccprofile" menuitem.filename = all_profiles[p] menuitem.callback = self.callback rv.append(menuitem) return rv
def generate(self, menuhandler): # TODO: Cannot load directory content asynchronously here and I'm # TODO: not happy about it rv, all_profiles = [], {} for d in (get_default_profiles_path(), get_profiles_path()): for x in os.listdir(d): if x.endswith(".sccprofile") and not x.startswith("."): all_profiles[x] = os.path.join(d, x) for p in sorted(all_profiles, key=lambda s: s.lower()): menuitem = MenuItem("generated", p[0:-11]) # strips ".sccprofile" menuitem.filename = all_profiles[p] menuitem.callback = self.callback rv.append(menuitem) return rv
def find_profile(name): """ Returns filename for specified profile name. This is done by searching for name + '.sccprofile' in ~/.config/scc/profiles first and in /usr/share/scc/default_profiles if file is not found in first location. Returns None if profile cannot be found. """ filename = "%s.sccprofile" % (name,) for p in (get_profiles_path(), get_default_profiles_path()): path = os.path.join(p, filename) if os.path.exists(path): return path return None
def find_profile(name): """ Returns filename for specified profile name. This is done by searching for name + '.sccprofile' in ~/.config/scc/profiles first and in /usr/share/scc/default_profiles if file is not found in first location. Returns None if profile cannot be found. """ filename = "%s.sccprofile" % (name, ) for p in (get_profiles_path(), get_default_profiles_path()): path = os.path.join(p, filename) if os.path.exists(path): return path return None
def on_btNewProfile_clicked(self, *a): """ Called when new profile name is set and OK is clicked """ txNewProfile = self.builder.get_object("txNewProfile") dlg = self.builder.get_object("dlgNewProfile") cb = self.builder.get_object("cbProfile") name = txNewProfile.get_text() filename = txNewProfile.get_text() + ".sccprofile" path = os.path.join(get_profiles_path(), filename) self.current_file = Gio.File.new_for_path(path) self.recursing = True model = cb.get_model() model.insert(0, ( name, self.current_file, None )) cb.set_active(0) self.recursing = False self.save_profile(self.current_file, self.current) dlg.hide()
def load_profile_list(self): """ Loads lists of profiles. Uses GLib to do it on background. """ # First list is for default profiles, 2nd for user profiles # Number is increased when list is loaded until it reaches 2 data = [ None, None ] paths = [ get_default_profiles_path(), get_profiles_path() ] for i in (0, 1): f = Gio.File.new_for_path(paths[i]) f.enumerate_children_async( "*.sccprofile", Gio.FileQueryInfoFlags.NONE, 1, None, self._on_profile_list_loaded, data, i )
def _save_profile_local(self, giofile, profile): filename = os.path.split(giofile.get_path())[-1] localpath = os.path.join(get_profiles_path(), filename) giofile = Gio.File.new_for_path(localpath) self.save_profile(giofile, profile)
def load_profile_list(self, category=None): paths = [get_default_profiles_path(), get_profiles_path()] self.load_user_data(paths, "*.sccprofile", category, self.on_profiles_loaded)
def _save_profile_local(self, giofile, profile): filename = os.path.split(giofile.get_path())[-1] localpath = os.path.join(get_profiles_path(), filename) giofile = Gio.File.new_for_path(localpath) self.save_profile(giofile, profile)
def load_profile_list(self, category=None): paths = [ get_default_profiles_path(), get_profiles_path() ] self.load_user_data(paths, "*.sccprofile", category, self.on_profiles_loaded)
def new_profile(self, profile, name): filename = os.path.join(get_profiles_path(), name + ".sccprofile") self.current_file = Gio.File.new_for_path(filename) self.save_profile(self.current_file, profile)
def new_profile(self, profile, name): filename = os.path.join(get_profiles_path(), name + ".sccprofile") self.current_file = Gio.File.new_for_path(filename) self.save_profile(self.current_file, profile)
def load_profile_list(self): paths = [get_default_profiles_path(), get_profiles_path()] self._load_user_data(paths, "*.sccprofile", self.on_profiles_loaded)