def compile_ui(ui_dir, ui_file): """ Local function to compile a single .ui file. @param ui_dir directory containing the .ui file (string) @param ui_file file name of the .ui file (string) """ # Ignore if it doesn't seem to be a .ui file. if ui_file.endswith('.ui'): py_dir = ui_dir py_file = ui_file[:-3] + '.py' # Allow the caller to change the name of the .py file or # generate it in a different directory. if map is not None: py_dir, py_file = list(map(py_dir, py_file)) # Make sure the destination directory exists. try: os.makedirs(py_dir) except: pass ui_path = os.path.join(ui_dir, ui_file) py_path = os.path.join(py_dir, py_file) ui_file = open(ui_path, 'r') py_file = open(py_path, 'w') try: compileUi(ui_file, py_file, **compileUi_args) finally: ui_file.close() py_file.close()
def build(): # copy all the python files into the build directory for path in find_files(PYTHON_SRC_PATH, "*.py"): build_file_path = os.path.join(BUILD_DIR, os.path.relpath(path, PYTHON_SRC_PATH)) os.makedirs(os.path.dirname(build_file_path), exist_ok=True) shutil.copy(path, build_file_path) # compile the resource files for path in find_files(RESOURCE_SRC_PATH, "*.qrc"): file_name = os.path.splitext(os.path.basename(path))[0] built_file_path = os.path.join(BUILD_DIR, "{}_rc.py".format(file_name)) if os.system("pyrcc5 {} -o {}".format(path, built_file_path)) != 0: print("Failed to compile resource: {}".format(path)) sys.exit(1) # compile the UI files for path in find_files(UI_SRC_PATH, "*.ui"): built_file_path = os.path.join(BUILD_DIR, "{}_ui.py".format(os.path.splitext(os.path.basename(path))[0])) with open(built_file_path, 'w') as py_file: uic.compileUi(path, py_file) # generate _version.py with open(os.path.join(BUILD_DIR, "_version.py"), "w") as f: f.write("VERSION={}\n".format(APP_VERSION)) if args.git_commit: commit = args.git_commit else: import subprocess commit = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode("ascii").strip() f.write("COMMIT=\"{}\"\n".format(commit))
def compile_ui(dir_ui: Path, dir_module: Path): for uifn in dir_ui.glob('*.ui'): pyfn = (dir_module / ('ui_' + uifn.stem)).with_suffix('.py') logger.info('Creating ui_*.py file: %s from %s', pyfn, uifn) with pyfn.open('wt', encoding='utf-8') as pyfile, \ uifn.open('rt', encoding='utf-8') as uifile: compileUi(uifile, pyfile, from_imports=True)
def compile_ui(uifile, pyfile): if newer(uifile, pyfile): print("compiling %s -> %s" % (uifile, pyfile)) with open(pyfile, "w") as out: uic.compileUi(uifile, out) else: print("skipping %s -> %s: up to date" % (uifile, pyfile))
def compile_ui(self, ui_file): from PyQt5 import uic py_file = os.path.splitext(ui_file)[0] + "_ui.py" if not distutils.dep_util.newer(ui_file, py_file): return with open(py_file, "w") as a_file: uic.compileUi(ui_file, a_file, from_imports=True)
def build_forms(srcdir, info=None, summary=False): import re, cStringIO from PyQt5.uic import compileUi forms = find_forms(srcdir) if info is None: from calibre import prints info = prints 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) transpat = re.compile(r'_translate\s*\(.+?,\s+"(.+?)(?<!\\)"\)', re.DOTALL) for form in forms: compiled_form = form_to_compiled_form(form) if not os.path.exists(compiled_form) or os.stat(form).st_mtime > os.stat(compiled_form).st_mtime: if not summary: info('\tCompiling form', form) buf = cStringIO.StringIO() compileUi(form, buf) dat = buf.getvalue() dat = dat.replace('import images_rc', '') dat = transdef_pat.sub('', dat) 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) open(compiled_form, 'wb').write(dat) num += 1 if num: info('Compiled %d forms' % num)
def compile_and_import_ui_files(): """ Automatically compiles all .ui files found in the same directory as the application py file. They will have the same name as the .ui files just with a .py extension. Needs to be defined in the same file as function loading the gui as it modifies the globals to be able to automatically import the created py-ui files. Its just very convenient. """ directory = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) for filename in iglob(os.path.join(directory, "*.ui")): ui_file = filename py_ui_file = os.path.splitext(ui_file)[0] + os.path.extsep + "py" if not os.path.exists(py_ui_file) or (os.path.getmtime(ui_file) >= os.path.getmtime(py_ui_file)): from PyQt5 import uic print("Compiling ui file: %s" % ui_file) with open(py_ui_file, "w") as open_file: uic.compileUi(ui_file, open_file) # Import the (compiled) file. try: import_name = os.path.splitext(os.path.basename(py_ui_file))[0] globals()[import_name] = imp.load_source(import_name, py_ui_file) except ImportError as e: print("Error importing %s" % py_ui_file) print(e.message)
def compile_ui(ui_file, py_file): if use_pyqt5: from PyQt5 import uic else: from PyQt4 import uic with open(py_file, 'w') as fp: uic.compileUi(ui_file, fp)
def compile_ui(self, ui_file): from PyQt5 import uic py_file = os.path.splitext(ui_file)[0] + "_ui.py" if not newer(ui_file, py_file): return fp = open(py_file, "w") uic.compileUi(ui_file, fp, from_imports=True) fp.close()
def ui(): for uifile in glob("*.ui"): pyfile = os.path.join('nbmanager', 'ui_' + uifile[:-3] + ".py") #if outdated(pyfile, uifile): print(uifile) pyfile = open(pyfile, "wt", encoding="utf-8") uifile = open(uifile, "rt", encoding="utf-8") compileUi(uifile, pyfile, from_imports=True)
def compile_ui(self, ui_file): from PyQt5 import uic py_file = os.path.splitext(ui_file)[0] + "_ui.py" if not newer(ui_file, py_file): return fp = open(py_file, "w") uic.compileUi(ui_file, fp, from_imports = True) fp.close()
def make_ui(self, ui): from PyQt5 import uic py = splitext(ui)[0] + '_ui.py' if not newer(ui, py): return with open(py, 'w') as file: uic.compileUi(ui, file, from_imports=True)
def ui_to_py(): from PyQt5 import uic uiname = "C:/Users/Kelebek/Desktop/DHT22/Arduino_anapen.ui" pyname = "C:/Users/Kelebek/Desktop/DHT22/Arduino_anapen.py" with open(pyname, 'w', encoding="utf-8") as fout: uic.compileUi(uiname, fout)
def compile(self): print("start compile") for item in self.__dataInfo: try: with open(item[1], "w") as f: uic.compileUi(item[0], f, True) print(item, "compile success") except Exception as reason: print(item, "compile failed : %s" % str(reason)) print("end compile")
def compileUIFiles(uiDir): for name in os.listdir(uiDir): uiFilePath = os.path.join(uiDir, name) if os.path.isfile(uiFilePath): if name.endswith(".ui"): uiResultPath = ('ui_' + name[:-3] + ".py").lower() with open(os.path.join(uiDir, uiResultPath), "w") as f: compileUi(uiFilePath, f)
def run(self): from PyQt5 import uic print("Building Gui") building_path = os.path.dirname(os.path.realpath(__file__)) with open(os.path.join(building_path, "hsw", "ui", "ui_packages.py"), "w") as ui_writer: uic.compileUi(uifile=os.path.join(building_path, "ui", "ui_packages.ui"), pyfile=ui_writer) build_py.run(self)
def convert(uifile, outputfile=None): if outputfile is None: uifilename = uifile[0:len(uifile) - 3] outputfile = uifilename + '_ui.py' print('Converting ' + uifile + '\t->\t' + outputfile) fp = open(outputfile, 'w') uic.compileUi(uifile, fp) fp.close() print('Saved as ' + outputfile)
def compileUi(path): ''' Compile a .ui file made by QtDesigner to a .py file. Paramters: path: str the path to the .ui file Returns: str the path to the created .py file ''' def checkLines(target, lines): for index, line in enumerate(lines): if target in line: return index other, ext = os.path.splitext(path) if not ext == '.ui': raise Exception('Input file must be a file with the extension .ui') else: with open(path, 'r') as i: o_path = other + '_ui.py' with open(o_path, 'w') as o: uic.compileUi(i, o) print('{:*^50}'.format('compiled')) print('Source: {0}'.format(path)) print('Output: {0}'.format(o_path)) pro_path = other + '.py' if os.path.isfile(pro_path): pass else: #create a template file temp_path = kuchinawa.Template.__file__ with open(temp_path, 'r') as temp: lines = temp.readlines() index = checkLines('class Sample(Main):', lines) directory, module = os.path.split(other) module_name = module + '_ui' import_str = 'import ' + module_name + '\n\n' lines.insert(index, import_str) index = checkLines('super().__init__()', lines) super_str = lines[index] indent = super_str.split('super()')[0] instantiate_str = indent + 'self.ui=' + module_name + '.Ui_Form()\n' set_str = indent + 'self.setUI(self.ui)\n' lines.insert(index + 1, instantiate_str) lines.insert(index + 2, set_str) with open(pro_path, 'w') as program: program.writelines(lines) print('{:*^50}'.format('generated a template file')) print('Template: {0}'.format(pro_path))
def pyuic(c): # pylint: disable=unused-argument """ Run UI compiler Compiles *.ui files found in :py:data:UI_DIR into .py files in :py:data:COMPILED_DIR """ from PyQt5.uic import compileUi for path in UI_DIR.glob('*.ui'): target_path: Path = COMPILED_DIR / path.with_suffix('.py').name print(f'Compiling {path.name} to {target_path}') compileUi(str(path), target_path.open('w'), import_from='edp.gui.compiled', from_imports=True, resource_suffix='')
def compile_ui(self, src, dst): """ Compile UI file `src` into the python file `dst`. This is similar to what the pyuic script is doing but with some predefined values. """ import PyQt5.uic as uic out = open(dst, 'w', encoding='utf-8') # see the docstring of PyQt5.uic.compileUi for more! uic.compileUi(src, out, execute=False, indent=4) out.close()
def compile_ui(uifile, pyfile): log.info("compiling %s -> %s", uifile, pyfile) tmp = StringIO() uic.compileUi(uifile, tmp) source = tmp.getvalue() rc = re.compile(r'\n\n#.*?(?=\n\n)', re.MULTILINE|re.DOTALL) comment = ("\n\n# Automatically generated - don't edit.\n" "# Use `python setup.py %s` to update it." % _get_option_name(self)) for r in list(_translate_re): source = r.sub(r'_(\1)', source) source = rc.sub(comment, source) f = open(pyfile, "w") f.write(source) f.close()
def setup_ui_from_design(w, ui_path, debug=False): # Change working directory, because uic supports relative path only and # resource files are not handled correctly without doing it. head, file_name = os.path.split(ui_path) if head: old_path = os.getcwd() os.chdir(head) # Load and set up UI. w.ui = uic.loadUiType(file_name)[0]() w.ui.setupUi(w) # NOTE Here, resources are loaded. if debug: uic.compileUi(file_name, sys.stdout) # Print UI code. # Change working directory back. if head: os.chdir(old_path)
def compile_ui(self): 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 # >>> Entry point self._log_location() compiled_forms = {} self._find_forms() # Cribbed from gui2.__init__:build_forms() for form in self.forms: with open(form) as form_file: soup = BeautifulStoneSoup(form_file.read()) property = soup.find('property', attrs={'name': 'windowTitle'}) string = property.find('string') window_title = string.renderContents() compiled_form = self._form_to_compiled_form(form) if (not os.path.exists(compiled_form) or os.stat(form).st_mtime > os.stat(compiled_form).st_mtime): if not os.path.exists(compiled_form): self._log(' compiling %s' % form) else: self._log(' recompiling %s' % form) os.remove(compiled_form) buf = cStringIO.StringIO() compileUi(form, buf) dat = buf.getvalue() dat = dat.replace('__appname__', 'calibre') dat = dat.replace('import images_rc', '') dat = re.compile(r'(?:QtGui.QApplication.translate|(?<!def )_translate)\(.+?,\s+"(.+?)(?<!\\)",.+?\)').sub(r'_("\1")', dat) dat = dat.replace('_("MMM yyyy")', '"MMM yyyy"') dat = pat.sub(sub, dat) with open(compiled_form, 'wb') as cf: cf.write(dat) compiled_forms[window_title] = compiled_form.rpartition(os.sep)[2].partition('.')[0] return compiled_forms
def build_forms(srcdir, info=None, summary=False): import re from io import StringIO from PyQt5.uic import compileUi 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) transpat = re.compile(r'_translate\s*\(.+?,\s+"(.+?)(?<!\\)"\)', re.DOTALL) # Ensure that people running from source have all their forms rebuilt for # the qt5 migration #force_compile = check_for_migration and not gprefs.get('migrated_forms_to_qt5', False) forms = find_forms(srcdir) for form in forms: compiled_form = form_to_compiled_form(form) if not os.path.exists(compiled_form) or os.path.getmtime(form) > os.path.getmtime(compiled_form): if not summary: print('\tCompiling form', form) buf = StringIO() compileUi(form, buf) dat = buf.getvalue() dat = dat.replace('import pics_rc', '') dat = transdef_pat.sub('', dat) dat = transpat.sub(r'_("\1")', dat) dat = dat.replace('_("MMM yyyy")', '"MMM yyyy"') dat = dat.replace('_("d MMM yyyy")', '"d MMM yyyy"') dat = dat.replace('"pics/', '":/pics/') dat = dat.replace('"./pics/', '":/pics/') dat = dat.replace('"../pics/', '":/pics/') open(compiled_form, 'w').write(dat) num += 1 if num: print('Compiled %d forms' % num)
def compile_ui(self, ui_fname): name = os.path.basename(ui_fname) outname = "Ui_%s.py" % name.rstrip(".ui") pyfile = os.path.join(self.DEST_FOLDER, outname) info("compiling %s" % ui_fname) f = open(pyfile, "w") uic.compileUi(ui_fname, f, execute=True) f.close() f = open(pyfile, "r") data = f.read() f.close() newdata = data for removal in self.REMOVALS: newdata = newdata.replace(removal, "") newdata = re.sub(r'_translate\((".*?"), (".*?")\)', self.gettext_wrap, newdata, 0, re.DOTALL) for orig, new in self.REPLACEMENTS: newdata = newdata.replace(orig, new) newdata = version_fixes(newdata) if newdata != data: f = open(pyfile, "w") f.write(newdata) f.close() else: info("om_pyuic made no changes to the standard uic output!") return pyfile
def compile_ui(): compileUi(open("UI_Files/about.ui"), open("Compiled_UI/about.py",'w')) compileUi(open("UI_Files/main_window.ui"), open("Compiled_UI/MainWindow.py", 'w'))
from PyQt5.uic import compileUi with open('untitled.ui', encoding='utf-8')as f: with open('qtui.py', 'w', encoding='utf-8') as ff: compileUi(f, ff)
from time import perf_counter as timer from io import StringIO testui = "C:/Python33/Lib/site-packages/PyQt5/myprojects/ui/testui.ui" out = StringIO() from PyQt5 import uic with open(testui, 'r') as f: uic.compileUi(f, out) print(out.getvalue())
import warnings import datetime as dt import numpy as np import pymba from scipy import misc, optimize from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog from PyQt5.QtGui import QImage, QPixmap # mainwindowui.py has to be generated from mainwindow.ui with pyuic5 QTCREATORUIFILE = 'mainwindow.ui' PYQT5UIFILE = 'mainwindowui.py' if os.stat(QTCREATORUIFILE).st_mtime > os.stat(PYQT5UIFILE).st_mtime: from PyQt5 import uic with open(QTCREATORUIFILE, 'r') as uifile, open(PYQT5UIFILE, 'w') as pyfile: uic.compileUi(uifile, pyfile) print("Updated the {} file.".format(PYQT5UIFILE)) from mainwindowui import Ui_MainWindow PARSER = argparse.ArgumentParser( \ description='Acquire a series of frames from an Allied Vision GigE camera.') PARSER.add_argument('--nframes', '-n', metavar='num', type=int, nargs=1, default=[100], help='number of frames to collect (>=1)') PARSER.add_argument('--dt', '-t', metavar='time', type=float, nargs=1, default=[1.0], help='time period between frames, ' 'in case of exponential periods it\'s the first period') PARSER.add_argument('--exptmax', '-e', metavar='time', type=float, nargs=1, help='if set, will use exponentially increasing periods between shots, ' 'dt_0 = dt (argument), dt_{n+1} = \\tau dt_n, where \\tau > 1, ' 'up to total time exptmax since the first shot') PARSER.add_argument('--output', '-o', metavar='path', type=str, nargs=1,
def __init__(self, parent, dbspec, ids, db): import re, cStringIO from calibre import prints as info from PyQt5.uic import compileUi ResizableDialog.__init__(self, parent) self.dbspec, self.ids = dbspec, ids # Display the number of books we've been passed self.count.setText(unicode(self.count.text()).format(len(ids))) # Display the last-used title self.title.setText(dynamic.get("catalog_last_used_title", _("My Books"))) self.fmts, self.widgets = [], [] for plugin in catalog_plugins(): if plugin.name in config["disabled_plugins"]: continue name = plugin.name.lower().replace(" ", "_") if getattr(plugin, "plugin_path", None) is None: try: catalog_widget = importlib.import_module("calibre.gui2.catalog." + name) pw = catalog_widget.PluginWidget() pw.initialize(name, db) pw.ICON = I("forward.png") self.widgets.append(pw) [self.fmts.append([file_type.upper(), pw.sync_enabled, pw]) for file_type in plugin.file_types] except ImportError: info("ImportError initializing %s" % name) continue else: # Load dynamic tab form = os.path.join(plugin.resources_path, "%s.ui" % name) klass = os.path.join(plugin.resources_path, "%s.py" % name) compiled_form = os.path.join(plugin.resources_path, "%s_ui.py" % name) if os.path.exists(form) and os.path.exists(klass): # info("Adding widget for user-installed Catalog plugin %s" % plugin.name) # Compile the .ui form provided in plugin.zip if not os.path.exists(compiled_form): # info('\tCompiling form', form) buf = cStringIO.StringIO() compileUi(form, buf) dat = buf.getvalue() dat = re.compile(r'QtGui.QApplication.translate\(.+?,\s+"(.+?)(?<!\\)",.+?\)', re.DOTALL).sub( r'_("\1")', dat ) open(compiled_form, "wb").write(dat) # Import the dynamic PluginWidget() from .py file provided in plugin.zip try: sys.path.insert(0, plugin.resources_path) catalog_widget = importlib.import_module(name) pw = catalog_widget.PluginWidget() pw.initialize(name) pw.ICON = I("forward.png") self.widgets.append(pw) [self.fmts.append([file_type.upper(), pw.sync_enabled, pw]) for file_type in plugin.file_types] except ImportError: info("ImportError with %s" % name) continue finally: sys.path.remove(plugin.resources_path) else: info("No dynamic tab resources found for %s" % name) self.widgets = sorted(self.widgets, cmp=lambda x, y: cmp(x.TITLE, y.TITLE)) # Generate a sorted list of installed catalog formats/sync_enabled pairs fmts = sorted([x[0] for x in self.fmts]) self.sync_enabled_formats = [] for fmt in self.fmts: if fmt[1]: self.sync_enabled_formats.append(fmt[0]) # Callbacks when format, title changes self.format.currentIndexChanged.connect(self.format_changed) self.format.currentIndexChanged.connect(self.settings_changed) self.title.editingFinished.connect(self.settings_changed) # Add the installed catalog format list to the format QComboBox self.format.blockSignals(True) self.format.addItems(fmts) pref = dynamic.get("catalog_preferred_format", "CSV") idx = self.format.findText(pref) if idx > -1: self.format.setCurrentIndex(idx) self.format.blockSignals(False) if self.sync.isEnabled(): self.sync.setChecked(dynamic.get("catalog_sync_to_device", True)) self.format.currentIndexChanged.connect(self.show_plugin_tab) self.buttonBox.button(self.buttonBox.Apply).clicked.connect(self.apply) self.buttonBox.button(self.buttonBox.Help).clicked.connect(self.help) self.show_plugin_tab(None) geom = dynamic.get("catalog_window_geom", None) if geom is not None: self.restoreGeometry(bytes(geom))
import os.path from PyQt5 import QtCore, QtGui, QtWidgets, uic # compile ui file if necessary if os.path.getmtime("mainwindow.py") < os.path.getmtime("mainwindow.ui"): with open("mainwindow.py", "w") as file: print("compiling ui") uic.compileUi("mainwindow.ui", file)
# -*- coding: utf-8 -*- from os.path import join, dirname from PyQt5 import uic PATH = dirname(__file__) with open(join(PATH, 'uiMainWindow.py'), 'w', encoding='utf-8') as f: uic.compileUi(join(PATH, 'mainWindow.ui'), f) with open(join(PATH, 'uiWidgetJobfile.py'), 'w', encoding='utf-8') as f: uic.compileUi(join(PATH, 'widgetJobfile.ui'), f) with open(join(PATH, 'uiDialogNewjobOnstart.py'), 'w', encoding='utf-8') as f: uic.compileUi(join(PATH, 'dialogNewjobOnstart.ui'), f) with open(join(PATH, 'uiDialogNewjobOntime.py'), 'w', encoding='utf-8') as f: uic.compileUi(join(PATH, 'dialogNewjobOntime.ui'), f) with open(join(PATH, 'uiDialogNewjobPertime.py'), 'w', encoding='utf-8') as f: uic.compileUi(join(PATH, 'dialogNewjobPertime.ui'), f) with open(join(PATH, 'uiDialogNewjobCron.py'), 'w', encoding='utf-8') as f: uic.compileUi(join(PATH, 'dialogNewjobCron.ui'), f) with open(join(PATH, 'uiDialogLog.py'), 'w', encoding='utf-8') as f: uic.compileUi(join(PATH, 'dialogLog.ui'), f)
from PyQt5.uic import compileUi __author__ = 'Iurii Sergiichuk <*****@*****.**>' with open("main.ui", 'r') as ui: with open("gui.py", 'w') as gui: compileUi(ui, gui)
def __init__(self, parent, dbspec, ids, db): import re, io from calibre import prints as info from PyQt5.uic import compileUi QDialog.__init__(self, parent) self.setupUi(self) self.dbspec, self.ids = dbspec, ids # Display the number of books we've been passed self.count.setText(unicode_type(self.count.text()).format(len(ids))) # Display the last-used title self.title.setText(dynamic.get('catalog_last_used_title', _('My books'))) self.fmts, self.widgets = [], [] for plugin in catalog_plugins(): if plugin.name in config['disabled_plugins']: continue name = plugin.name.lower().replace(' ', '_') if getattr(plugin, 'plugin_path', None) is None: try: catalog_widget = importlib.import_module('calibre.gui2.catalog.'+name) pw = catalog_widget.PluginWidget() pw.parent_ref = weakref.ref(self) pw.initialize(name, db) pw.ICON = I('forward.png') self.widgets.append(pw) [self.fmts.append([file_type.upper(), pw.sync_enabled,pw]) for file_type in plugin.file_types] except ImportError: info("ImportError initializing %s" % name) continue else: # Load dynamic tab form = os.path.join(plugin.resources_path,'%s.ui' % name) klass = os.path.join(plugin.resources_path,'%s.py' % name) compiled_form = os.path.join(plugin.resources_path,'%s_ui.py' % name) if os.path.exists(form) and os.path.exists(klass): # info("Adding widget for user-installed Catalog plugin %s" % plugin.name) # Compile the .ui form provided in plugin.zip if not os.path.exists(compiled_form): # info('\tCompiling form', form) buf = io.BytesIO() compileUi(form, buf) dat = buf.getvalue() dat = re.compile(r'QtGui.QApplication.translate\(.+?,\s+"(.+?)(?<!\\)",.+?\)', re.DOTALL).sub(r'_("\1")', dat) open(compiled_form, 'wb').write(dat) # Import the dynamic PluginWidget() from .py file provided in plugin.zip try: sys.path.insert(0, plugin.resources_path) catalog_widget = importlib.import_module(name) pw = catalog_widget.PluginWidget() pw.initialize(name) pw.ICON = I('forward.png') self.widgets.append(pw) [self.fmts.append([file_type.upper(), pw.sync_enabled,pw]) for file_type in plugin.file_types] except ImportError: info("ImportError with %s" % name) continue finally: sys.path.remove(plugin.resources_path) else: info("No dynamic tab resources found for %s" % name) self.widgets = sorted(self.widgets, key=lambda x: x.TITLE) # Generate a sorted list of installed catalog formats/sync_enabled pairs fmts = sorted([x[0] for x in self.fmts]) self.sync_enabled_formats = [] for fmt in self.fmts: if fmt[1]: self.sync_enabled_formats.append(fmt[0]) # Callbacks when format, title changes self.format.currentIndexChanged.connect(self.format_changed) self.format.currentIndexChanged.connect(self.settings_changed) self.title.editingFinished.connect(self.settings_changed) # Add the installed catalog format list to the format QComboBox self.format.blockSignals(True) self.format.addItems(fmts) pref = dynamic.get('catalog_preferred_format', 'CSV') idx = self.format.findText(pref) if idx > -1: self.format.setCurrentIndex(idx) self.format.blockSignals(False) if self.sync.isEnabled(): self.sync.setChecked(dynamic.get('catalog_sync_to_device', True)) self.add_to_library.setChecked(dynamic.get('catalog_add_to_library', True)) self.format.currentIndexChanged.connect(self.show_plugin_tab) self.buttonBox.button(self.buttonBox.Apply).clicked.connect(self.apply) self.buttonBox.button(self.buttonBox.Help).clicked.connect(self.help) self.show_plugin_tab(None) geom = dynamic.get('catalog_window_geom', None) if geom is not None: self.restoreGeometry(bytes(geom)) else: self.resize(self.sizeHint()) d = QCoreApplication.instance().desktop() g = d.availableGeometry(d.screenNumber(self)) self.setMaximumWidth(g.width() - 50) self.setMaximumHeight(g.height() - 50)
import subprocess from PyQt5.uic import compileUi ui_files = ['mainwindow', 'clipboard_template'] for file in ui_files: with open(file + '.py', 'w') as f: compileUi(file + '.ui', f) try: version = subprocess.check_output(['git', 'describe', '--tags', '--long', '--always']).decode() except: version = 'v?.?-??-??????' with open('version.txt', 'w') as f: f.write(version)