mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Use the convenience icon load method in .ui files
This commit is contained in:
parent
0476d5bdf1
commit
1e51e4a09a
@ -30,11 +30,6 @@ def build_forms(srcdir, info=None, summary=False, check_for_migration=False):
|
||||
forms = find_forms(srcdir)
|
||||
if info is None:
|
||||
info = print
|
||||
pat = re.compile(r'''(['"]):/images/([^'"]+)\1''')
|
||||
|
||||
def sub(match):
|
||||
ans = 'I(%s%s%s)'%(match.group(1), match.group(2), match.group(1))
|
||||
return ans
|
||||
|
||||
num = 0
|
||||
transdef_pat = re.compile(r'^\s+_translate\s+=\s+QtCore.QCoreApplication.translate$', flags=re.M)
|
||||
@ -47,6 +42,13 @@ def build_forms(srcdir, info=None, summary=False, check_for_migration=False):
|
||||
from calibre.gui2 import gprefs
|
||||
force_compile |= not gprefs.get(f'migrated_forms_to_qt{qt_major}', False)
|
||||
|
||||
icon_constructor_pat = re.compile(r'\s*\S+\s+=\s+QtGui.QIcon\(\)')
|
||||
icon_pixmap_adder_pat = re.compile(r'''(\S+?)\.addPixmap\(.+?(['"]):/images/([^'"]+)\2.+''')
|
||||
|
||||
def icon_pixmap_sub(match):
|
||||
ans = match.group(1) + ' = QtGui.QIcon.ic(' + match.group(2) + match.group(3) + match.group(2) + ')'
|
||||
return ans
|
||||
|
||||
for form in forms:
|
||||
compiled_form = form_to_compiled_form(form)
|
||||
if force_compile or not os.path.exists(compiled_form) or os.stat(form).st_mtime > os.stat(compiled_form).st_mtime:
|
||||
@ -60,7 +62,8 @@ def build_forms(srcdir, info=None, summary=False, check_for_migration=False):
|
||||
dat = transpat.sub(r'_("\1")', dat)
|
||||
dat = dat.replace('_("MMM yyyy")', '"MMM yyyy"')
|
||||
dat = dat.replace('_("d MMM yyyy")', '"d MMM yyyy"')
|
||||
dat = pat.sub(sub, dat)
|
||||
dat = icon_constructor_pat.sub('', dat)
|
||||
dat = icon_pixmap_adder_pat.sub(icon_pixmap_sub, dat)
|
||||
if not isinstance(dat, bytes):
|
||||
dat = dat.encode('utf-8')
|
||||
open(compiled_form, 'wb').write(dat)
|
||||
|
Loading…
x
Reference in New Issue
Block a user