コード例 #1
0
ファイル: snapfly_core.py プロジェクト: Futurile/snapfly
def parse_desktop_dir(term_cmd=None, hideList=None):
    menu_items = {}
    settings = config.ConfigController()
    logINFO('scan dir and parse .desktop file ..')
    blacklist = None
    desktop_dir = []
    blacklist_path = os.path.join(CONFIG_PATH, 'blacklist')
    if os.path.exists(blacklist_path):
        if os.path.isfile(blacklist_path):
            f = open(blacklist_path, "r")
            blacklist = filter(None, map(lambda l: l.strip().rstrip(), f.readlines()))
        elif os.path.isdir(blacklist_path):
            blacklist = filter(lambda l: l.endswith('.desktop'), os.listdir(blacklist_path))
    else:
        blacklist = []

    for dir_item in settings.getValue("desktop_dirs"):
        if os.path.exists(dir_item):
            desktop_dir.append(dir_item)

    for dir_item in desktop_dir:
        listdir = filter(lambda i: i.endswith('.desktop') and i not in blacklist, os.listdir(dir_item))
        logINFO ( listdir )
        for info in filter(None, map(lambda i: info_desktop(dir_item + i, hideList, term_cmd), listdir)):
            menu_items.setdefault(info[3], []).append(info)

    return menu_items
コード例 #2
0
ファイル: snapfly_core.py プロジェクト: Futurile/snapfly
def hex2rgb(color_hex):
    ## convert Hex color to RGB
    hexcolor = color_hex.strip()[1:]
    if len(hexcolor) != 6:
        logINFO('Invalid hex color, use #RRGGBB format.')
        return 0.0, 0.0, 0.0
    hexcolor = int(hexcolor, 16)
    r, g, b = hexcolor >> 16, (hexcolor >> 8) & 255, hexcolor & 255
    return r / 255., g / 255., b / 255. # max is 0xff, trust me
コード例 #3
0
ファイル: snapfly_core.py プロジェクト: Futurile/snapfly
 def __init__ (self, callback_action, move_on_scroll_action,
               terminal=None, hideList=None, showFavorites='false'):
     logINFO('MakeMenu ..')
     self.callback_action = callback_action
     self.move_on_scroll_action = move_on_scroll_action
     self.terminal = terminal
     self.hideList = hideList
     self.cat_visible = True
     self.showFavorites = showFavorites == 'true'
コード例 #4
0
ファイル: gui.py プロジェクト: Futurile/snapfly
 def pixbuf_from_file(self,filename, width=None, height=None):
     pixbuf = None
     if filename is not None or filename == '':
         if os.path.isfile(filename):
             try:
                 if not width and not height:
                     pixbuf = gdk.pixbuf_new_from_file(filename)
                 else:
                     width, height = int(width), int(height)
                     pixbuf = gdk.pixbuf_new_from_file_at_size(filename, width, height)
             except:
                 logINFO("is an image ? => %s" % filename)
                 pixbuf = None
         else:
             logINFO("is a image ? => %s" % filename)
     return pixbuf
コード例 #5
0
ファイル: config.py プロジェクト: Futurile/snapfly
 def __init__(self):
     if PATH_search('x-terminal-emulator'):
         terminal = 'x-terminal-emulator'
     else:
         terminal = 'xterm'
     self.default = {'terminal': terminal,
                     'systray': 'true',
                     'rounded': '4',
                     'menu_width': '430',
                     'bg_color': '#DCDCDC',
                     'border_color': '#4D4D4D',
                     'hide_list': 'None',
                     'category_click': 'true',
                     'favorites': 'false',
                     'desktop_dirs': ["/usr/share/applications/",
                                     "%s/.local/share/applications/"
                                     % os.getenv('HOME'),
                                     "/usr/local/share/applications/",
                                     "/usr/share/applications/kde4/",
                                     "/usr/local/share/applications/kde4/"
                                     ]
                     }
     config = {}
     try:
         f = open(CONFIG_FILE, 'r')
         logINFO("Found user config.")
         for line in f:
             if line == '\n' or line.startswith('#'):
                 continue
             else:
                 line = line.strip('\n ').split('=')
                 if line[0] == "desktop_dirs":
                     config["desktop_dirs"] = filter( None, 
                                   map ( lambda ln: expanduser( expandvars ( ln.lstrip().rstrip() ) ),
                                        line[1].split(",") ) 
                                  )
                 else:
                     config[line[0]] = line[1]
         f.close()
     except IOError,e:
         printERROR(u"I/O error: %s" % repr(e))
コード例 #6
0
ファイル: snapfly_core.py プロジェクト: Futurile/snapfly
def parse_user_menu(config):
    logINFO('Parse user menu ..')
    cfg_file = USERMENU
    cat_index = None
    if os.access(cfg_file, os.F_OK | os.R_OK):
        logINFO('Found user menu ..')
        f = open(cfg_file, 'r')
        for line in f:
            try:
                if line == '\n' or line.startswith('#'):
                    continue
                elif line.startswith('@'):
                    if line.count("##") > 0:
                        cat = line[1:].strip('\n ').split("##")
                        config[cat[0]] = []
                        cat_icon[cat[0]] = expanduser( expandvars ( cat[1] ) )
                        cat_index = cat[0]
                    else:
                        printERROR(u"# Error reading line: %s, not enough parameters"
                              u" (must be at least 2)" % line)
                else:
                    if line.count("##") > 2:
                        if cat_index is not None:
                            #Parameters:#[0]CMD#[1]Icon#[2]Name#[3]--/--#[4]Desc
                            cmd_line = line.strip('\n\t ').split('##') 
                            cmd_line[0] = expanduser( expandvars ( cmd_line[0] ) )
                            cmd_line[1] = expanduser( expandvars ( cmd_line[1] ) )
                            cmd_line.insert(3, "")
                            cmd_line[0] = parse_cmd(cmd_line[0], "", cmd_line[1], cmd_line[2])
                            config[cat_index].append(cmd_line)
                        else:
                            printERROR( u"# Error reading line: %s, not enough parameters"
                                  u" (must be at least 3)" % line)
                    else:
                        printERROR( u"# Error reading line: %s, not enough parameters"
                              u" (must be at least 3)" % line)
            except:
                logINFO("# Error in user config menu at line: %s" % line)
                logTRACEBACK()
        f.close()
    return config
コード例 #7
0
ファイル: snapfly_core.py プロジェクト: Futurile/snapfly
def info_desktop(filename, hideList, term_cmd=None):
    cmd = icon = name = comment = generic_name = None
    comment_locales, name_locales, generic_name_locales = {}, {}, {}
    category = 'Other'
    terminal = False
    #has_desktop_entry: если уже была секция с описанием .desktop файла - то дальше парсить .desktop файл нету
    #смысла. Если её еще не было - парсим дальше.
    has_desktop_entry = False
    try:
        cfile = open(filename, "r")
        for line in cfile:
            if line.startswith("[Desktop Entry]"):
                has_desktop_entry = True
            if "[Property::" in line:
                if has_desktop_entry:
                    break
            if line.startswith("[") and not line.startswith("[Desktop Entry]"):
                if has_desktop_entry:
                    break
            if '=' in line:
                key, value = line.strip().split('=', 1)
                if key == 'Type' and value != 'Application':
                    icon, category = None, None
                    break
                elif key == 'NoDisplay' and value == 'true':
                    icon, category = None, None
                    break
                elif key == 'OnlyShowIn':
                    showinlist = line.split(';')
                    hideList = set(hideList)
                    if not [item for item in showinlist if item not in hideList]:
                        # Original behaivour was strange; if we forbid GNOME
                        # and app is for GNOME and XFCE, we used to ban it.
                        # Todo: add support for NotShowIn.
                        icon, category = None, None
                        break
                elif key == 'Terminal' and value == 'true':
                    terminal = True
                elif key.startswith('Name'):
                    name_locales[key] = value
                elif key.startswith('Comment'):
                    comment_locales[key] = value
                elif key.startswith('GenericName'):
                    generic_name_locales[key] = value
                elif key == 'Icon' and value:
                    icon = value
                    if not icon[0] == '/':
                        icon = icon.split('.', 1)[0]
                if key == 'Exec':
                    cmd = value
                elif key == 'TryExec':
                    tryexec = config.PATH_search(value)
                    if tryexec is None:
                        icon, category = None, None
                        continue
                if key == 'Categories':
                    tab = value.split(';')

                    for cat in tab:
                        found = False
                        for c_name in cat_name:
                            if cat in cat_name[c_name]:
                                category = c_name
                                found = True
                                break
                        if found:
                            break

        name = get_i18n_name(name_locales)
        comment = get_i18n_comment(comment_locales)
        generic_name = get_i18n_generic_name(generic_name_locales)

        if cmd is not None:
            cmd = parse_cmd(cmd, filename, icon, name)

            # if command is 'console only', launch it with terminal ..
            if terminal:
                cmd = [term_cmd if term_cmd else 'xterm', '-e'] + cmd

        cfile.close()

        if comment is None:
            comment = generic_name
        
        if not category:
            category = 'Other'

        if category:
            logINFO("%s: %s->%s" % ( os.path.basename(filename), category, name ))
            return cmd, icon, name, category, comment

    except:
        logINFO(u"# Error : parsing %s" % filename)
        logTRACEBACK()
    return None
コード例 #8
0
ファイル: launcher.py プロジェクト: Futurile/snapfly
def launch_command(cmd):
    try:
        p = Popen(cmd, stdout = devnull, stderr = devnull )
        q.put(p)
    except OSError, e:
        logINFO("unable to execute a command: %s : %s" % (repr(cmd), repr(e) ))