def on_mnuMenuDelete_activate(self, *a): id = self.get_selected_menu() if MenuEditor.menu_is_global(id): text = _("Really delete selected global menu?") else: text = _("Really delete selected menu?") d = Gtk.MessageDialog(parent=self.editor.window, flags = Gtk.DialogFlags.MODAL, type = Gtk.MessageType.WARNING, buttons = Gtk.ButtonsType.OK_CANCEL, message_format = text, ) if MenuEditor.menu_is_global(id): d.format_secondary_text(_("This action is not undoable!")) if d.run() == -5: # OK button, no idea where is this defined... if MenuEditor.menu_is_global(id): fname = os.path.join(get_menus_path(), id) try: os.unlink(fname) except Exception, e: log.error("Failed to remove %s: %s", fname, e) else: del self.app.current.menus[id] self.app.on_profile_modified() self.load_menu_list()
def on_mnuMenuDelete_activate(self, *a): id = self.get_selected_menu() if MenuEditor.menu_is_global(id): text = _("Really delete selected global menu?") else: text = _("Really delete selected menu?") d = Gtk.MessageDialog( parent=self.editor.window, flags=Gtk.DialogFlags.MODAL, type=Gtk.MessageType.WARNING, buttons=Gtk.ButtonsType.OK_CANCEL, message_format=text, ) if MenuEditor.menu_is_global(id): d.format_secondary_text(_("This action is not undoable!")) if d.run() == -5: # OK button, no idea where is this defined... if MenuEditor.menu_is_global(id): fname = os.path.join(get_menus_path(), id) try: os.unlink(fname) except Exception, e: log.error("Failed to remove %s: %s", fname, e) else: del self.app.current.menus[id] self.app.on_profile_modified() self.load_menu_list()
def _load_items_from_file(self, id): for p in (get_menus_path(), get_default_menus_path()): path = os.path.join(p, "%s.menu" % (id, )) if os.path.exists(path): return MenuData.from_file(path, TalkingActionParser()) # Menu file not found return None
def _load_items_from_file(self, id): for p in (get_menus_path(), get_default_menus_path()): path = os.path.join(p, "%s.menu" % (id,)) if os.path.exists(path): data = json.loads(open(path, "r").read()) return MenuData.from_json_data(data, TalkingActionParser()) # Menu file not found return None
def _load_items_from_file(self, id): for p in (get_menus_path(), get_default_menus_path()): path = os.path.join(p, "%s.menu" % (id, )) if os.path.exists(path): data = json.loads(open(path, "r").read()) return MenuData.from_json_data(data, TalkingActionParser()) # Menu file not found return None
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 _save_to_file(self, id): """ Stores menu in json file """ id = "%s.menu" % (id,) path = os.path.join(get_menus_path(), id) data = self._generate_menudata() jstr = Encoder(sort_keys=True, indent=4).encode(data) open(path, "w").write(jstr) log.debug("Wrote menu file %s", path) if self.callback: self.callback(id)
def _save_to_file(self, id): """ Stores menu in json file """ id = "%s.menu" % (id, ) path = os.path.join(get_menus_path(), id) data = self._generate_menudata() jstr = Encoder(sort_keys=True, indent=4).encode(data) open(path, "w").write(jstr) log.debug("Wrote menu file %s", path) if self.callback: self.callback(id)
def find_menu(name): """ Returns filename for specified menu name. This is done by searching for name in ~/.config/scc/menus first and in /usr/share/scc/default_menus later. Returns None if menu cannot be found. """ for p in (get_menus_path(), get_default_menus_path()): path = os.path.join(p, name) if os.path.exists(path): return path return None
def _remove_original(self): if self.original_id is None: # Created new menu pass elif self.original_type == MenuEditor.TYPE_INTERNAL: try: del self.app.current.menus[self.original_id] except: pass elif self.original_type == MenuEditor.TYPE_GLOBAL: try: path = os.path.join(get_menus_path(), "%s.menu" % (self.original_id,)) log.debug("Removing %s", path) os.unlink(path) except: pass
def _remove_original(self): if self.original_id is None: # Created new menu pass elif self.original_type == MenuEditor.TYPE_INTERNAL: try: del self.app.current.menus[self.original_id] except: pass elif self.original_type == MenuEditor.TYPE_GLOBAL: try: path = os.path.join(get_menus_path(), "%s.menu" % (self.original_id, )) log.debug("Removing %s", path) os.unlink(path) except: pass
def on_entName_changed(self, *a): id = self.builder.get_object("entName").get_text() if len(id.strip()) == 0: self._bad_id_no_id() return if "." in id or "/" in id: self._bad_id_chars() return if self.builder.get_object("rbInProfile").get_active(): # Menu stored in profile if id != self.original_id and id in self.app.current.menus: self._bad_id_duplicate() return else: # Menu stored as file if id != self.original_id: path = os.path.join(get_menus_path(), "%s.menu" % (id,)) if os.path.exists(path): self._bad_id_duplicate() return self._good_id() return
def on_entName_changed(self, *a): id = self.builder.get_object("entName").get_text() if len(id.strip()) == 0: self._bad_id_no_id() return if "." in id or "/" in id: self._bad_id_chars() return if self.builder.get_object("rbInProfile").get_active(): # Menu stored in profile if id != self.original_id and id in self.app.current.menus: self._bad_id_duplicate() return else: # Menu stored as file if id != self.original_id: path = os.path.join(get_menus_path(), "%s.menu" % (id, )) if os.path.exists(path): self._bad_id_duplicate() return self._good_id() return
def load_menu_list(self): paths = [ get_default_menus_path(), get_menus_path() ] self.load_user_data(paths, "*.menu", self.on_menus_loaded)
if isinstance(instance, MenuGenerator): items.insert(pos, Separator(instance.label)) pos += 1 items.insert(pos, instance) else: if isinstance(instance, MenuGenerator): items = [ x for x in items if not ( isinstance(x, Separator) and x.label == instance.label) ] items = [ x for x in items if instance.describe().strip(" >") != x.describe().strip(" >") ] path = os.path.join(get_menus_path(), "Default.menu") data = MenuData(*items) jstr = Encoder(sort_keys=True, indent=4).encode(data) open(path, "w").write(jstr) log.debug("Wrote menu file %s", path) def load_cbMIs(self): """ See above. This method just parses Default menu and checks boxes for present menu items. """ try: data = MenuData.from_fileobj(open(find_menu("Default.menu"), "r")) except Exception, e: # Shouldn't really happen log.error(traceback.format_exc())
def load_menu_list(self, category=None): paths = [get_default_menus_path(), get_menus_path()] self.load_user_data(paths, "*.menu", category, self.on_menus_loaded)
def load_menu_list(self, category=None): paths = [ get_default_menus_path(), get_menus_path() ] self.load_user_data(paths, "*.menu", category, self.on_menus_loaded)
def load_menu_list(self): paths = [get_default_menus_path(), get_menus_path()] self._load_user_data(paths, "*.menu", self.on_menus_loaded)