Esempio n. 1
0
	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()
Esempio n. 2
0
    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()
Esempio n. 3
0
 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
Esempio n. 4
0
	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
Esempio n. 5
0
 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
Esempio n. 6
0
 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)
Esempio n. 7
0
	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)
Esempio n. 8
0
	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)
Esempio n. 9
0
    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)
Esempio n. 10
0
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
Esempio n. 11
0
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
Esempio n. 12
0
	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
Esempio n. 13
0
 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
Esempio n. 14
0
	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
Esempio n. 15
0
 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
Esempio n. 16
0
	def load_menu_list(self):
		paths = [ get_default_menus_path(), get_menus_path() ]
		self.load_user_data(paths, "*.menu", self.on_menus_loaded)
Esempio n. 17
0
            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())
Esempio n. 18
0
 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)
Esempio n. 19
0
	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)
Esempio n. 20
0
 def load_menu_list(self):
     paths = [get_default_menus_path(), get_menus_path()]
     self._load_user_data(paths, "*.menu", self.on_menus_loaded)