controlpanel.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:Packages 作者: Keypirinha 项目源码 文件源码
def _list_item_info(self, clsid, reg_clsid):
        def _getregstr(hkey, sub_path, value_name):
            try:
                if sub_path is not None:
                    hkey_sub = winreg.OpenKey(hkey, sub_path)
                else:
                    hkey_sub = hkey
                (val, typ) = winreg.QueryValueEx(hkey_sub, value_name)
                if sub_path is not None:
                    winreg.CloseKey(hkey_sub)
                if isinstance(val, str) and len(val) > 0:
                    return val
            except OSError:
                pass
            return None

        cpitem = {
            'clsid': clsid,
            'canonical_name': _getregstr(reg_clsid, None, "System.ApplicationName"),
            'open_command': _getregstr(reg_clsid, "Shell\\Open\\Command", None),
            'label': None,
            'short_desc': None,
            'icon_location': _getregstr(reg_clsid, "DefaultIcon", None),
            'icon_handle': None}

        # skip item if it doesn't have a canonical name or a command to execute
        if not cpitem['canonical_name'] and not cpitem['open_command']:
            return None

        # label
        location = _getregstr(reg_clsid, None, "LocalizedString")
        if location is not None:
            cpitem['label'] = kpu.shell_string_resource(location)
        if cpitem['label'] is None:
            cpitem['label'] = _getregstr(reg_clsid, None, None)

        # skip item if it doesn't have a label
        if not cpitem['label']:
            return None

        # short_desc
        location = _getregstr(reg_clsid, None, "InfoTip")
        if location is not None:
            cpitem['short_desc'] = kpu.shell_string_resource(location)
        if cpitem['short_desc'] is None:
            cpitem['short_desc'] = ""

        # icon
        if cpitem['icon_location'] is not None:
            if cpitem['icon_location'][0] != '@':
                cpitem['icon_location'] = '@' + cpitem['icon_location']
            cpitem['icon_handle'] = self.load_icon(cpitem['icon_location'])

        return cpitem
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号