예제 #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
 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
예제 #3
0
파일: MainWindow.py 프로젝트: saisai/mozo
    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 (matemenu.TYPE_ENTRY, matemenu.TYPE_DIRECTORY):
            return

        if item.get_type() == matemenu.TYPE_ENTRY:
            file_path = os.path.join(util.getUserItemPath(), item.get_desktop_file_id())
            file_type = "Item"
        elif item.get_type() == matemenu.TYPE_DIRECTORY:
            if item.get_desktop_file_path() == None:
                file_path = util.getUniqueFileId("mozo-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(["mate-desktop-item-edit", file_path], env=os.environ)
            gobject.timeout_add(100, self.waitForEditProcess, process, file_path)
예제 #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('mozo-made', '.desktop'))
     process = subprocess.Popen(['mate-desktop-item-edit', file_path], env=os.environ)
     GLib.timeout_add(100, self.waitForNewItemProcess, process, parent.get_menu_id(), file_path)
예제 #5
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_path = os.path.join(util.getUserDirectoryPath(), util.getUniqueFileId('mozo-made', '.directory'))
		process = subprocess.Popen(['mate-desktop-item-edit', file_path], env=os.environ)
		gobject.timeout_add(100, self.waitForNewMenuProcess, process, parent.menu_id, file_path)
예제 #6
0
파일: MainWindow.py 프로젝트: saisai/mozo
 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("mozo-made", ".desktop"))
     process = subprocess.Popen(["mate-desktop-item-edit", file_path], env=os.environ)
     gobject.timeout_add(100, self.waitForNewItemProcess, process, parent.menu_id, file_path)
 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
예제 #8
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
예제 #9
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()

        with open(os.path.join(util.getUserItemPath(), file_id), 'w') as f:
            f.write(contents)
        return file_id
예제 #10
0
파일: MenuEditor.py 프로젝트: tamplan/mozo
    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 = keyfile.to_data()[0]

        with open(os.path.join(util.getUserItemPath(), file_id), 'w') as f:
            f.write(contents)
        return file_id
예제 #11
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 (matemenu.TYPE_ENTRY,
                                   matemenu.TYPE_DIRECTORY):
            return

        if item.get_type() == matemenu.TYPE_ENTRY:
            file_path = os.path.join(util.getUserItemPath(),
                                     item.get_desktop_file_id())
            file_type = 'Item'
        elif item.get_type() == matemenu.TYPE_DIRECTORY:
            if item.get_desktop_file_path() == None:
                file_path = util.getUniqueFileId('mozo-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(['mate-desktop-item-edit', file_path],
                                       env=os.environ)
            gobject.timeout_add(100, self.waitForEditProcess, process,
                                file_path)
예제 #12
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()

        with open(os.path.join(util.getUserDirectoryPath(), file_id), 'w') as f:
            f.write(contents)
        return file_id
예제 #13
0
파일: MenuEditor.py 프로젝트: tamplan/mozo
    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 = keyfile.to_data()[0]

        with open(os.path.join(util.getUserDirectoryPath(), file_id), 'w') as f:
            f.write(contents)
        return file_id
예제 #14
0
파일: MenuEditor.py 프로젝트: tamplan/mozo
    def copyItem(self, item, new_parent, before=None, after=None):
        dom = self.__getMenu(new_parent).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))

        file_id = util.getUniqueFileId(os.path.basename(file_path).split(".desktop", 1)[0], ".desktop")
        out_path = os.path.join(util.getUserItemPath(), file_id)

        contents = keyfile.to_data()[0]

        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.__addUndo([self.__getMenu(new_parent), ('Item', file_id)])
        self.save()
        return file_id
 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
예제 #16
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 = GLib.KeyFile()
		keyfile.load_from_file(file_path, util.KEY_FILE_FLAGS)

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

		file_id = util.getUniqueFileId(item.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.__addUndo([self.__getMenu(new_parent), ('Item', file_id)])
		self.save()
		return file_id
예제 #17
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