mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Open With: Fix error when scanning for default programs on windows for some file types
This commit is contained in:
parent
d6aee3987a
commit
977d76db87
@ -73,13 +73,23 @@ if iswindows:
|
|||||||
return sort_key(entry.get('name') or '')
|
return sort_key(entry.get('name') or '')
|
||||||
|
|
||||||
def finalize_entry(entry):
|
def finalize_entry(entry):
|
||||||
data = load_icon_resource(entry.pop('icon_resource', None), as_data=True)
|
try:
|
||||||
|
data = load_icon_resource(entry.pop('icon_resource', None), as_data=True)
|
||||||
|
except Exception:
|
||||||
|
data = None
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
if data:
|
if data:
|
||||||
entry['icon_data'] = data
|
entry['icon_data'] = data
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
def entry_to_item(entry, parent):
|
def entry_to_item(entry, parent):
|
||||||
icon = load_icon_resource(entry.get('icon_resource'))
|
try:
|
||||||
|
icon = load_icon_resource(entry.get('icon_resource'))
|
||||||
|
except Exception:
|
||||||
|
icon = None
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
if not icon:
|
if not icon:
|
||||||
icon = entry_to_icon_text(entry)[0]
|
icon = entry_to_icon_text(entry)[0]
|
||||||
ans = QListWidgetItem(QIcon(icon), entry.get('name') or _('Unknown'), parent)
|
ans = QListWidgetItem(QIcon(icon), entry.get('name') or _('Unknown'), parent)
|
||||||
|
@ -11,9 +11,12 @@ from collections import namedtuple
|
|||||||
from future_builtins import map
|
from future_builtins import map
|
||||||
|
|
||||||
from PyQt5.Qt import QtWin, Qt, QIcon, QByteArray, QBuffer, QPixmap
|
from PyQt5.Qt import QtWin, Qt, QIcon, QByteArray, QBuffer, QPixmap
|
||||||
import win32con, win32api, win32gui
|
import win32con, win32api, win32gui, pywintypes, winerror
|
||||||
|
|
||||||
|
from calibre import prints
|
||||||
from calibre.gui2 import must_use_qt
|
from calibre.gui2 import must_use_qt
|
||||||
|
from calibre.utils.winreg.default_programs import split_commandline
|
||||||
|
|
||||||
ICON_SIZE = 64
|
ICON_SIZE = 64
|
||||||
|
|
||||||
def hicon_to_pixmap(hicon):
|
def hicon_to_pixmap(hicon):
|
||||||
@ -33,7 +36,13 @@ def copy_to_size(pixmap, size=ICON_SIZE):
|
|||||||
|
|
||||||
def simple_load_icon(module, index, as_data=False, size=ICON_SIZE):
|
def simple_load_icon(module, index, as_data=False, size=ICON_SIZE):
|
||||||
' Use the win32 API ExtractIcon to load the icon. This restricts icon size to 32x32, but has less chance of failing '
|
' Use the win32 API ExtractIcon to load the icon. This restricts icon size to 32x32, but has less chance of failing '
|
||||||
large_icons, small_icons = win32gui.ExtractIconEx(module, index, 10)
|
try:
|
||||||
|
large_icons, small_icons = win32gui.ExtractIconEx(module, index, 10)
|
||||||
|
except pywintypes.error as err:
|
||||||
|
if err.winerror != winerror.ERROR_FILE_NOT_FOUND:
|
||||||
|
raise
|
||||||
|
prints('File %r does not exist, cannot load icon' % module)
|
||||||
|
return
|
||||||
icons = large_icons + small_icons
|
icons = large_icons + small_icons
|
||||||
try:
|
try:
|
||||||
if icons:
|
if icons:
|
||||||
@ -104,6 +113,8 @@ def load_icon_resource(icon_resource, as_data=False, size=ICON_SIZE):
|
|||||||
return
|
return
|
||||||
module, index = parts
|
module, index = parts
|
||||||
index = int(index)
|
index = int(index)
|
||||||
|
if module.startswith('"') and module.endswith('"'):
|
||||||
|
module = split_commandline(module)[0]
|
||||||
try:
|
try:
|
||||||
return load_icon(module, index, as_data=as_data, size=size)
|
return load_icon(module, index, as_data=as_data, size=size)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user