Ejemplo n.º 1
0
	def __writeItem(self, item=None, icon=None, name=None, comment=None, command=None, use_term=None, no_display=None, startup_notify=None, hidden=None):
		if item:
			file_path = item.get_desktop_file_path()
			file_id = item.get_desktop_file_id()
			keyfile = util.DesktopParser(file_path)
		elif item == None and name == None:
			raise Exception('New menu items need a name')
		else:
			file_id = util.getUniqueFileId(name, '.desktop')
			keyfile = util.DesktopParser()
		if icon:
			keyfile.set('Icon', icon)
			keyfile.set('Icon', icon, self.locale)
		if name:
			keyfile.set('Name', name)
			keyfile.set('Name', name, self.locale)
		if comment:
			keyfile.set('Comment', comment)
			keyfile.set('Comment', comment, self.locale)
		if command:
			keyfile.set('Exec', command)
		if use_term != None:
			keyfile.set('Terminal', use_term)
		if no_display != None:
			keyfile.set('NoDisplay', no_display)
		if startup_notify != None:
			keyfile.set('StartupNotify', startup_notify)
		if hidden != None:
			keyfile.set('Hidden', hidden)
		out_path = os.path.join(util.getUserItemPath(), file_id)
		keyfile.write(open(out_path, 'w'))
		return file_id
Ejemplo n.º 2
0
	def __writeItem(self, item=None, icon=None, name=None, comment=None, command=None, use_term=None, no_display=None, startup_notify=None, hidden=None):
		if item:
			file_path = item.get_desktop_file_path()
			file_id = item.get_desktop_file_id()
			keyfile = util.DesktopParser(file_path)
		elif item == None and name == None:
			raise Exception('New menu items need a name')
		else:
			file_id = util.getUniqueFileId(name, '.desktop')
			keyfile = util.DesktopParser()
		if icon:
			keyfile.set('Icon', icon)
			keyfile.set('Icon', icon, self.locale)
		if name:
			keyfile.set('Name', name)
			keyfile.set('Name', name, self.locale)
		if comment:
			keyfile.set('Comment', comment)
			keyfile.set('Comment', comment, self.locale)
		if command:
			keyfile.set('Exec', command)
		if use_term != None:
			keyfile.set('Terminal', use_term)
		if no_display != None:
			keyfile.set('NoDisplay', no_display)
		if startup_notify != None:
			keyfile.set('StartupNotify', startup_notify)
		if hidden != None:
			keyfile.set('Hidden', hidden)
		out_path = os.path.join(util.getUserItemPath(), file_id)
		keyfile.write(open(out_path, 'w'))
		return file_id
Ejemplo n.º 3
0
	def on_edit_properties_activate(self, menu):
		item_tree = self.tree.get_object('item_tree')
		items, iter = item_tree.get_selection().get_selected()
		if not iter:
			return
		item = items[iter][3]
		if item.get_type() not in (gmenu.TYPE_ENTRY, gmenu.TYPE_DIRECTORY):
			return

		if item.get_type() == gmenu.TYPE_ENTRY:
			file_path = os.path.join(util.getUserItemPath(), item.get_desktop_file_id())
			file_type = 'Item'
		elif item.get_type() == gmenu.TYPE_DIRECTORY:
			if item.get_desktop_file_path() == None:
				file_path = util.getUniqueFileId('alacarte-made', '.directory')
				parser = util.DesktopParser(file_path, 'Directory')
				parser.set('Name', item.get_name())
				parser.set('Comment', item.get_comment())
				parser.set('Icon', item.get_icon())
				parser.write(open(file_path))
			else:
				file_path = os.path.join(util.getUserDirectoryPath(), os.path.split(item.get_desktop_file_path())[1])
			file_type = 'Menu'

		if not os.path.isfile(file_path):
			data = open(item.get_desktop_file_path()).read()
			open(file_path, 'w').write(data)
			self.editor._MenuEditor__addUndo([(file_type, os.path.split(file_path)[1]),])
		else:
			self.editor._MenuEditor__addUndo([item,])
		if file_path not in self.edit_pool:
			self.edit_pool.append(file_path)
			process = subprocess.Popen(['gnome-desktop-item-edit', file_path], env=os.environ)
			gobject.timeout_add(100, self.waitForEditProcess, process, file_path)
Ejemplo n.º 4
0
 def on_new_item_button_clicked(self, button):
     menu_tree = self.tree.get_object('menu_tree')
     menus, iter = menu_tree.get_selection().get_selected()
     if not iter:
         parent = menus[(0,)][2]
         menu_tree.expand_to_path((0,))
         menu_tree.get_selection().select_path((0,))
     else:
         parent = menus[iter][2]
     file_path = os.path.join(util.getUserItemPath(), util.getUniqueFileId('alacarte-made', '.desktop'))
     process = subprocess.Popen(['gnome-desktop-item-edit', file_path], env=os.environ)
     GObject.timeout_add(100, self.waitForNewItemProcess, process, parent.get_menu_id(), file_path)
Ejemplo n.º 5
0
    def on_new_item_button_clicked(self, button):
        menu_tree = self.tree.get_object('menu_tree')
        menus, iter = menu_tree.get_selection().get_selected()
        if not iter:
            parent = menus[(0,)][2]
            menu_tree.expand_to_path((0,))
            menu_tree.get_selection().select_path((0,))
        else:
            parent = menus[iter][2]
        file_path = os.path.join(util.getUserItemPath(), util.getUniqueFileId('alacarte-made', '.desktop'))

        editor = LauncherEditor(self.main_window, file_path)
        editor.run()
Ejemplo n.º 6
0
	def copyItem(self, item, new_parent, before=None, after=None):
		dom = self.__getMenu(new_parent).dom
		file_path = item.get_desktop_file_path()
		keyfile = util.DesktopParser(file_path)
		#erase Categories in new file
		keyfile.set('Categories', ('',))
		keyfile.set('Hidden', False)
		file_id = util.getUniqueFileId(item.get_name(), '.desktop')
		out_path = os.path.join(util.getUserItemPath(), file_id)
		keyfile.write(open(out_path, 'w'))
		self.__addItem(new_parent, file_id, dom)
		self.__positionItem(new_parent, ('Item', file_id), before, after)
		self.__addUndo([self.__getMenu(new_parent), ('Item', file_id)])
		self.save()
		return file_id
Ejemplo n.º 7
0
	def copyItem(self, item, new_parent, before=None, after=None):
		dom = self.__getMenu(new_parent).dom
		file_path = item.get_desktop_file_path()
		keyfile = util.DesktopParser(file_path)
		#erase Categories in new file
		keyfile.set('Categories', ('',))
		keyfile.set('Hidden', False)
		file_id = util.getUniqueFileId(item.get_name(), '.desktop')
		out_path = os.path.join(util.getUserItemPath(), file_id)
		keyfile.write(open(out_path, 'w'))
		self.__addItem(new_parent, file_id, dom)
		self.__positionItem(new_parent, ('Item', file_id), before, after)
		self.__addUndo([self.__getMenu(new_parent), ('Item', file_id)])
		self.save()
		return file_id
Ejemplo n.º 8
0
 def on_new_item_button_clicked(self, button):
     menu_tree = self.tree.get_object('menu_tree')
     menus, iter = menu_tree.get_selection().get_selected()
     if not iter:
         parent = menus[(0, )][2]
         menu_tree.expand_to_path((0, ))
         menu_tree.get_selection().select_path((0, ))
     else:
         parent = menus[iter][2]
     file_path = os.path.join(
         util.getUserItemPath(),
         util.getUniqueFileId('alacarte-made', '.desktop'))
     process = subprocess.Popen(['gnome-desktop-item-edit', file_path],
                                env=os.environ)
     GObject.timeout_add(100, self.waitForNewItemProcess, process,
                         parent.get_menu_id(), file_path)
Ejemplo n.º 9
0
    def on_new_item_button_clicked(self, button):
        menu_tree = self.tree.get_object("menu_tree")
        menus, iter = menu_tree.get_selection().get_selected()
        if not iter:
            parent = menus[(0,)][2]
            menu_tree.expand_to_path((0,))
            menu_tree.get_selection().select_path((0,))
        else:
            parent = menus[iter][2]
        file_name = util.getUniqueFileId("alacarte-made", ".desktop")
        file_path = os.path.join(util.getUserItemPath(), file_name)

        editor = LauncherEditor(self.main_window, file_path)
        editor.file_name = file_name
        editor.parent = parent.get_menu_id()
        editor.connect("response", self.on_item_created)
        editor.run()
Ejemplo n.º 10
0
    def on_new_menu_button_clicked(self, button):
        menu_tree = self.tree.get_object('menu_tree')
        menus, iter = menu_tree.get_selection().get_selected()
        if not iter:
            parent = menus[(0,)][2]
            menu_tree.expand_to_path((0,))
            menu_tree.get_selection().select_path((0,))
        else:
            parent = menus[iter][2]
        file_name = util.getUniqueFileId('alacarte-made', '.directory')
        file_path = os.path.join(util.getUserDirectoryPath(), file_name)

        editor = DirectoryEditor(self.main_window, file_path)
        editor.file_name = file_name;
        editor.parent = parent.get_menu_id()
        editor.connect('response', self.on_directory_created)
        editor.run()
Ejemplo n.º 11
0
    def on_new_item_button_clicked(self, button):
        menu_tree = self.tree.get_object('menu_tree')
        menus, iter = menu_tree.get_selection().get_selected()
        if not iter:
            parent = menus[(0, )][2]
            menu_tree.expand_to_path((0, ))
            menu_tree.get_selection().select_path((0, ))
        else:
            parent = menus[iter][2]
        file_name = util.getUniqueFileId('alacarte-made', '.desktop')
        file_path = os.path.join(util.getUserItemPath(), file_name)

        editor = LauncherEditor(self.main_window, file_path)
        editor.file_name = file_name
        editor.parent = parent.get_menu_id()
        editor.connect('response', self.on_item_created)
        editor.run()
Ejemplo n.º 12
0
    def writeItem(self, item, **kwargs):
        if item is not None:
            file_path = item.get_desktop_file_path()
        else:
            file_path = None

        keyfile = self.makeKeyFile(file_path, kwargs)

        if item is not None:
            file_id = item.get_desktop_file_id()
        else:
            file_id = util.getUniqueFileId(keyfile.get_string(GLib.KEY_FILE_DESKTOP_GROUP, 'Name'), '.desktop')

        contents, length = keyfile.to_data()
        f = open(os.path.join(util.getUserItemPath(), file_id), 'w')
        f.write(contents)
        f.close()
        return file_id
Ejemplo n.º 13
0
    def on_edit_properties_activate(self, menu):
        item_tree = self.tree.get_object('item_tree')
        items, iter = item_tree.get_selection().get_selected()
        if not iter:
            return
        item = items[iter][3]
        if item.get_type() not in (gmenu.TYPE_ENTRY, gmenu.TYPE_DIRECTORY):
            return

        if item.get_type() == gmenu.TYPE_ENTRY:
            file_path = os.path.join(util.getUserItemPath(),
                                     item.get_desktop_file_id())
            file_type = 'Item'
        elif item.get_type() == gmenu.TYPE_DIRECTORY:
            if item.get_desktop_file_path() == None:
                file_path = util.getUniqueFileId('alacarte-made', '.directory')
                parser = util.DesktopParser(file_path, 'Directory')
                parser.set('Name', item.get_name())
                parser.set('Comment', item.get_comment())
                parser.set('Icon', item.get_icon())
                parser.write(open(file_path))
            else:
                file_path = os.path.join(
                    util.getUserDirectoryPath(),
                    os.path.split(item.get_desktop_file_path())[1])
            file_type = 'Menu'

        if not os.path.isfile(file_path):
            data = open(item.get_desktop_file_path()).read()
            open(file_path, 'w').write(data)
            self.editor._MenuEditor__addUndo([
                (file_type, os.path.split(file_path)[1]),
            ])
        else:
            self.editor._MenuEditor__addUndo([
                item,
            ])
        if file_path not in self.edit_pool:
            self.edit_pool.append(file_path)
            process = subprocess.Popen(['gnome-desktop-item-edit', file_path],
                                       env=os.environ)
            gobject.timeout_add(100, self.waitForEditProcess, process,
                                file_path)
Ejemplo n.º 14
0
    def writeItem(self, item, **kwargs):
        if item is not None:
            file_path = item.get_desktop_file_path()
        else:
            file_path = None

        keyfile = self.makeKeyFile(file_path, kwargs)

        if item is not None:
            file_id = item.get_desktop_file_id()
        else:
            file_id = util.getUniqueFileId(
                keyfile.get_string(GLib.KEY_FILE_DESKTOP_GROUP, 'Name'),
                '.desktop')

        contents, length = keyfile.to_data()
        f = open(os.path.join(util.getUserItemPath(), file_id), 'w')
        f.write(contents)
        f.close()
        return file_id
Ejemplo n.º 15
0
    def writeMenu(self, menu, **kwargs):
        if menu is not None:
            file_id = os.path.split(menu.get_desktop_file_path())[1]
            file_path = menu.get_desktop_file_path()
            keyfile = GLib.KeyFile()
            keyfile.load_from_file(file_path, util.KEY_FILE_FLAGS)
        elif menu is None and 'Name' not in kwargs:
            raise Exception('New menus need a name')
        else:
            file_id = util.getUniqueFileId(kwargs['Name'], '.directory')
            keyfile = GLib.KeyFile()

        util.fillKeyFile(keyfile, kwargs)

        contents, length = keyfile.to_data()

        f = open(os.path.join(util.getUserDirectoryPath(), file_id), 'w')
        f.write(contents)
        f.close()
        return file_id
Ejemplo n.º 16
0
    def writeMenu(self, menu, **kwargs):
        if menu is not None:
            file_id = os.path.split(menu.get_desktop_file_path())[1]
            file_path = menu.get_desktop_file_path()
            keyfile = GLib.KeyFile()
            keyfile.load_from_file(file_path, util.KEY_FILE_FLAGS)
        elif menu is None and 'Name' not in kwargs:
            raise Exception('New menus need a name')
        else:
            file_id = util.getUniqueFileId(kwargs['Name'], '.directory')
            keyfile = GLib.KeyFile()

        util.fillKeyFile(keyfile, kwargs)

        contents, length = keyfile.to_data()

        f = open(os.path.join(util.getUserDirectoryPath(), file_id), 'w')
        f.write(contents)
        f.close()
        return file_id
Ejemplo n.º 17
0
    def copyItem(self, item, new_parent, before=None, after=None):
        dom = self.dom
        file_path = item.get_desktop_file_path()
        keyfile = GLib.KeyFile()
        keyfile.load_from_file(file_path, util.KEY_FILE_FLAGS)

        util.fillKeyFile(keyfile, dict(Categories=[], Hidden=False))

        app_info = item.get_app_info()
        file_id = util.getUniqueFileId(app_info.get_name().replace(os.sep, '-'), '.desktop')
        out_path = os.path.join(util.getUserItemPath(), file_id)

        contents, length = keyfile.to_data()

        with open(out_path, 'w') as f:
            f.write(contents)

        self.addItem(new_parent, file_id, dom)
        self.positionItem(new_parent, ('Item', file_id), before, after)
        self.save()
        return file_id
Ejemplo n.º 18
0
    def copyItem(self, item, new_parent, before=None, after=None):
        dom = self.dom
        file_path = item.get_desktop_file_path()
        keyfile = GLib.KeyFile()
        keyfile.load_from_file(file_path, util.KEY_FILE_FLAGS)

        util.fillKeyFile(keyfile, dict(Categories=[], Hidden=False))

        app_info = item.get_app_info()
        file_id = util.getUniqueFileId(
            app_info.get_name().replace(os.sep, '-'), '.desktop')
        out_path = os.path.join(util.getUserItemPath(), file_id)

        contents, length = keyfile.to_data()

        with open(out_path, 'w') as f:
            f.write(contents)

        self.addItem(new_parent, file_id, dom)
        self.positionItem(new_parent, ('Item', file_id), before, after)
        self.save()
        return file_id
Ejemplo n.º 19
0
	def __writeMenu(self, menu=None, icon=None, name=None, comment=None, no_display=None):
		if menu:
			file_id = os.path.split(menu.get_desktop_file_path())[1]
			file_path = menu.get_desktop_file_path()
			keyfile = util.DesktopParser(file_path)
		elif menu == None and name == None:
			raise Exception('New menus need a name')
		else:
			file_id = util.getUniqueFileId(name, '.directory')
			keyfile = util.DesktopParser(file_type='Directory')
		if icon:
			keyfile.set('Icon', icon)
		if name:
			keyfile.set('Name', name)
			keyfile.set('Name', name, self.locale)
		if comment:
			keyfile.set('Comment', comment)
			keyfile.set('Comment', comment, self.locale)
		if no_display != None:
			keyfile.set('NoDisplay', no_display)
		out_path = os.path.join(util.getUserDirectoryPath(), file_id)
		keyfile.write(open(out_path, 'w'))
		return file_id
Ejemplo n.º 20
0
	def __writeMenu(self, menu=None, icon=None, name=None, comment=None, no_display=None):
		if menu:
			file_id = os.path.split(menu.get_desktop_file_path())[1]
			file_path = menu.get_desktop_file_path()
			keyfile = util.DesktopParser(file_path)
		elif menu == None and name == None:
			raise Exception('New menus need a name')
		else:
			file_id = util.getUniqueFileId(name, '.directory')
			keyfile = util.DesktopParser(file_type='Directory')
		if icon:
			keyfile.set('Icon', icon)
		if name:
			keyfile.set('Name', name)
			keyfile.set('Name', name, self.locale)
		if comment:
			keyfile.set('Comment', comment)
			keyfile.set('Comment', comment, self.locale)
		if no_display != None:
			keyfile.set('NoDisplay', no_display)
		out_path = os.path.join(util.getUserDirectoryPath(), file_id)
		keyfile.write(open(out_path, 'w'))
		return file_id