def run(self): from PyQt4 import uic _translate_re = re.compile( r'QtGui\.QApplication.translate\(.*?, (.*?), None, ' r'QtGui\.QApplication\.UnicodeUTF8\)') for uifile in glob.glob("ui/*.ui"): pyfile = "ui_%s.py" % os.path.splitext(os.path.basename(uifile))[0] pyfile = os.path.join("picard", "ui", pyfile) if newer(uifile, pyfile): log.info("compiling %s -> %s", uifile, pyfile) tmp = StringIO() uic.compileUi(uifile, tmp) source = _translate_re.sub(r'_(\1)', tmp.getvalue()) f = open(pyfile, "w") f.write(source) f.close() qrcfile = os.path.join("resources", "picard.qrc") pyfile = os.path.join("picard", "resources.py") build_resources = False if newer("resources/picard.qrc", pyfile): build_resources = True for datafile in glob.glob("resources/images/*.*"): if newer(datafile, pyfile): build_resources = True break if build_resources: log.info("compiling %s -> %s", qrcfile, pyfile) os.system("pyrcc4 %s -o %s" % (qrcfile, pyfile))
def _generate(self): """ Generate the Python code. """ needs_close = False if sys.hexversion >= 0x03000000: if self._opts.output == '-': from io import TextIOWrapper pyfile = TextIOWrapper(sys.stdout.buffer, encoding='utf8') else: pyfile = open(self._opts.output, 'wt', encoding='utf8') needs_close = True else: if self._opts.output == '-': pyfile = sys.stdout else: pyfile = open(self._opts.output, 'wt') needs_close = True compileUi(self._ui_file, pyfile, self._opts.execute, self._opts.indent, self._opts.pyqt3_wrapper, self._opts.from_imports, self._opts.resource_suffix) if needs_close: pyfile.close()
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 PyQt4 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, e: print "Error importing %s" % py_ui_file print e.message
def ui_file_python_convert(file_name): try: with open(file_name, 'r') as qtUi: with open(file_name.replace('.ui', '.py'), 'w') as pythonUI: uic.compileUi(qtUi, pythonUI, execute=False) except Exception as e: print(str(e))
def build_forms(srcdir, info=None): import re, cStringIO from PyQt4.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 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: info('\tCompiling form', form) buf = cStringIO.StringIO() compileUi(form, buf) dat = buf.getvalue() dat = dat.replace('__appname__', 'calibre') dat = dat.replace('import images_rc', '') dat = dat.replace('from library import', 'from calibre.gui2.library import') dat = dat.replace('from widgets import', 'from calibre.gui2.widgets import') dat = dat.replace('from convert.xpath_wizard import', 'from calibre.gui2.convert.xpath_wizard import') dat = re.compile(r'QtGui.QApplication.translate\(.+?,\s+"(.+?)(?<!\\)",.+?\)', re.DOTALL).sub(r'_("\1")', dat) dat = dat.replace('_("MMM yyyy")', '"MMM yyyy"') dat = pat.sub(sub, dat) dat = dat.replace('from QtWebKit.QWebView import QWebView', 'from PyQt4 import QtWebKit\nfrom PyQt4.QtWebKit import QWebView') open(compiled_form, 'wb').write(dat)
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 run(self): import os import glob from PyQt4.uic import compileUi for infile in glob.glob(os.path.join('glue', 'qt', 'ui', '*.ui')): print("Compiling " + infile) directory, filename = os.path.split(infile) outfile = os.path.join(directory, filename.replace('.ui', '.py')) compileUi(infile, open(outfile, 'wb')) import sys import subprocess print("Compiling glue/qt/glue.qrc") if sys.version_info[0] == 2: option = '-py2' else: option = '-py3' try: subprocess.call([self.pyrcc4, option, 'glue/qt/glue.qrc', '-o', 'glue/qt/glue_qt_resources.py']) except OSError: print("pyrcc4 command failed - make sure that pyrcc4 " "is in your $PATH, or specify a custom command with " "--pyrcc4=command")
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 PyQt4 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, e: print "Error importing %s" % py_ui_file print e.message
def run(self): from PyQt4.uic import compileUi for infile in glob(os.path.join('glue', 'qt', 'ui', '*.ui')): print("Compiling " + infile) directory, filename = os.path.split(infile) outfile = os.path.join(directory, filename.replace('.ui', '.py')) with open(outfile, 'wb') as out: compileUi(infile, out) import subprocess from shutil import copyfile print("Compiling glue/qt/glue.qrc") if sys.version_info[0] == 2: option = '-py2' else: option = '-py3' try: subprocess.call([self.pyrcc4, option, 'glue/qt/glue.qrc', '-o', 'glue/qt/glue_qt_resources.py']) except OSError: print("pyrcc4 command failed - make sure that pyrcc4 " "is in your $PATH, or specify a custom command with " "--pyrcc4=command") #XXX Hack: pyuic seems to expect glue/qt/ui/glue_rc.py when #loading icons. Copy it there copyfile('glue/qt/glue_qt_resources.py', 'glue/qt/ui/glue_rc.py')
def process_ui_files(): ui_files = ['gui.ui'] for f in ui_files: out_filename = (os.path.join(generated_ui_output, os.path.splitext(os.path.basename(f))[0].replace(' ', '')+'.py')) out_file = open(out_filename, 'w') uic.compileUi(f, out_file) out_file.close()
def compile_ui(): ui_file = file(UIFILE_PATH) py_file = file(PYFILE_PATH, "w") uic.compileUi(ui_file, py_file) ui_file.close() py_file.close() print("finished compiling")
def updateUi(qt): # input file root name to be updated mwui = qt+".ui" mwpy = qt+".py" if fileModTime(mwpy) < fileModTime(mwui): file = open(mwpy, "w") compileUi(mwui, file, execute=True) file.close()
def build_forms(srcdir, info=None): import re, cStringIO from PyQt4.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 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: info('\tCompiling form', form) buf = cStringIO.StringIO() compileUi(form, buf) dat = buf.getvalue() dat = dat.replace('__appname__', 'calibre') dat = dat.replace('import images_rc', '') dat = dat.replace('from library import', 'from calibre.gui2.library import') dat = dat.replace('from widgets import', 'from calibre.gui2.widgets import') dat = dat.replace('from convert.xpath_wizard import', 'from calibre.gui2.convert.xpath_wizard import') dat = re.sub(r'^ {4}def _translate\(context, text, disambig\):\s+return.*$', ' pass', dat, flags=re.M) dat = re.compile(r'(?:QtGui.QApplication.translate|(?<!def )_translate)\(.+?,\s+"(.+?)(?<!\\)",.+?\)', re.DOTALL).sub(r'_("\1")', dat) dat = dat.replace('_("MMM yyyy")', '"MMM yyyy"') dat = pat.sub(sub, dat) dat = dat.replace('from QtWebKit.QWebView import QWebView', 'from PyQt4 import QtWebKit\nfrom PyQt4.QtWebKit import QWebView') open(compiled_form, 'wb').write(dat)
def updateUi(qt): # input file root name to be updated mwui = qt + ".ui" mwpy = qt + ".py" if fileModTime(mwpy) < fileModTime(mwui): file = open(mwpy, "w") compileUi(mwui, file, execute=True) file.close()
def main(): print("*** Compiling UI files ***") inPath = os.path.join(".") outPath = os.path.join(inPath, "ui.py") print("Input folder: {0}".format(inPath)) print("Output file: {0}".format(outPath)) if os.path.exists(outPath): print("Making backup copy: {0}.backup".format(outPath)) gui = open(outPath, 'r') backup = open(outPath + '.backup', 'w') for line in gui.readlines(): backup.write(line) gui.close() backup.close() outFile = open(outPath, "w") for f in os.listdir(inPath): if f.endswith(".ui"): print("Compiling file {0}".format(f)) uiFile = open(os.path.join(inPath, f), 'r') compileUi(uiFile, outFile) uiFile.close() outFile.close()
def compile_ui(ui_dir, ui_file): # 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 = 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, 'rt', encoding = 'utf-8') py_file = open(py_path, 'wt', encoding = 'utf-8') try: compileUi(ui_file, py_file, **compileUi_args) finally: ui_file.close() py_file.close()
def run(self): from PyQt4 import uic _translate_re = ( re.compile( r'QtGui\.QApplication.translate\(.*?, (.*?), None, ' r'QtGui\.QApplication\.UnicodeUTF8\)'), re.compile( r'\b_translate\(.*?, (.*?), None\)') ) for uifile in glob.glob("ui/*.ui"): pyfile = "ui_%s.py" % os.path.splitext(os.path.basename(uifile))[0] pyfile = os.path.join("picard", "ui", pyfile) if newer(uifile, pyfile): log.info("compiling %s -> %s", uifile, pyfile) tmp = StringIO() uic.compileUi(uifile, tmp) source = tmp.getvalue() for r in list(_translate_re): source = r.sub(r'_(\1)', source) f = open(pyfile, "w") f.write(source) f.close() from resources import compile, makeqrc makeqrc.main() compile.main()
def build_forms(srcdir, info=None, summary=False): import re, cStringIO from PyQt4.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 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 = re.sub(r'^ {4}def _translate\(context, text, disambig\):\s+return.*$', ' pass', dat, flags=re.M) dat = re.compile(r'(?:QtGui.QApplication.translate|(?<!def )_translate)\(.+?,\s+"(.+?)(?<!\\)",.+?\)', re.DOTALL).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 = dat.replace('from QtWebKit.QWebView import QWebView', 'from PyQt4 import QtWebKit\nfrom PyQt4.QtWebKit import QWebView') open(compiled_form, 'wb').write(dat) num += 1 if num: info('Compiled %d forms' % num)
def compile_ui(self, ui_file): from PyQt4 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, pyqt3_wrapper=True, from_imports=True) fp.close()
def compile(): from PyQt4 import uic for i in glob.glob("*.ui"): base = i.replace('.ui', '') print "Compiling %s"%base fout = open(base+".py", "w") uic.compileUi(base+".ui", fout) fout.close()
def ui(): for uifile in glob("{{cookiecutter.package_name}}/ui/*.ui"): pyfile = os.path.splitext(uifile)[0] + ".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 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 ui(): for uifile in glob("mendeleyreopen/ui/*.ui"): pyfile = os.path.splitext(uifile)[0] + ".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(): from PyQt4 import uic for i in glob.glob("*.ui"): base = i.replace('.ui', '') print "Compiling %s" % base fout = open(base + ".py", "w") uic.compileUi(base + ".ui", fout) fout.close()
def __init__(self): # Recompile ui with open("LightFieldVisualizer.ui") as ui_file: with open("LightFieldVisualizer_ui.py", "w") as py_ui_file: uic.compileUi(ui_file, py_ui_file) self.app = QtGui.QApplication([]) self.main_window = MainApp() self.main_window.show()
def compile_ui(): uifiles = glob.glob(UI_FILES) if len(uifiles) == 0: print 'none!' return with open('Generated/generatedGUI.py', 'w+b') as pyfile: for uifile in uifiles: uic.compileUi(uifile, pyfile) pyfile.close()
def do_uic(options, force=False): from PyQt4.uic import compileUi for uifile in glob.glob('mozregui/ui/*.ui'): pyfile = os.path.splitext(uifile)[0] + '.py' if force or not os.path.isfile(pyfile) or \ (os.path.getmtime(uifile) > os.path.getmtime(pyfile)): print "uic'ing %s -> %s" % (uifile, pyfile) with open(pyfile, 'w') as f: compileUi(uifile, f, False, 4, False)
def compile_uis_from_dir(ui_dir, out_dir, should_force=False): try: #mkdir -p $ui_dir if not os.access(out_dir, os.F_OK): os.mkdir(out_dir) #touch $FORM_DIR/__init__.py touch_file(out_dir + '/__init__.py') #processing ui files = glob.glob(os.path.join(ui_dir, '*.ui')) for ui_file_path in files: ui_fname = ui_file_path.split(os.path.sep)[-1] ui_stats = os.stat(ui_file_path) ui_last_mod_time = time.localtime(ui_stats[8]) fname_no_ext = ''.join(ui_fname.split('.')[:-1]) out_file_path = os.path.join(out_dir, fname_no_ext + '.py') out_file_exists = os.path.exists(out_file_path) if os.path.exists(out_file_path): out_stats = os.stat(out_file_path) out_last_mod_time = time.localtime(out_stats[8]) if should_force or (not out_file_exists) or (ui_last_mod_time > out_last_mod_time): print('Building {0}'.format(out_file_path)) out_file = open(out_file_path, 'w') compileUi(ui_file_path, out_file, from_imports="ufo") out_file.close() #processing qrc files = glob.glob(ui_dir + '/*.qrc') for ui_file_path in files: ui_fname = ui_file_path.split(os.path.sep)[-1] ui_stats = os.stat(ui_file_path) ui_last_mod_time = time.localtime(ui_stats[8]) fname_no_ext = ''.join(ui_fname.split('.')[:-1]) out_file_path = out_dir + '/' + fname_no_ext + '_rc.py' #execute pyrcc4 -o resources_rc.py resources.qrc command = "pyrcc4 -py3 -o {0} {1}".format(out_file_path, ui_file_path) print(command) os.system(command) if len(files) > 0: print('All ({0}) ui files compiled'.format(len(files))) else: print('No ui files in located at {0}'.format(ui_dir)) except OSError as err: print(err)
def compile_ui(self, ui_file, py_file): # Search for pyuic4 in python bin dir, then in the $Path. try: from PyQt4 import uic fp = open(py_file, 'w') uic.compileUi(ui_file, fp) fp.close() except Exception, e: print 'Unable to compile user interface', e return
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 _generate(self): """ Generate the Python code. """ if self._opts.output == "-": pyfile = sys.stdout else: pyfile = open(self._opts.output, 'wt') compileUi(self._ui_file, pyfile, self._opts.execute, self._opts.indent, self._opts.pyqt3_wrapper)
def compile_uis_from_dir(ui_dir, out_dir, should_force=False): try: #mkdir -p $ui_dir if not os.access(out_dir, os.F_OK): os.mkdir(out_dir) #touch $FORM_DIR/__init__.py touch_file(out_dir+'/__init__.py') #processing ui files = glob.glob(os.path.join(ui_dir, '*.ui')) for ui_file_path in files: ui_fname = ui_file_path.split(os.path.sep)[-1] ui_stats = os.stat(ui_file_path) ui_last_mod_time = time.localtime(ui_stats[8]) fname_no_ext = ''.join(ui_fname.split('.')[:-1]) out_file_path = os.path.join(out_dir, fname_no_ext + '.py') out_file_exists = os.path.exists(out_file_path) if os.path.exists(out_file_path): out_stats = os.stat(out_file_path) out_last_mod_time = time.localtime(out_stats[8]) if should_force or (not out_file_exists) or (ui_last_mod_time > out_last_mod_time): print('Building {0}'.format(out_file_path)) out_file = open(out_file_path, 'w') compileUi(ui_file_path, out_file, from_imports="ufo") out_file.close() #processing qrc files = glob.glob(ui_dir+'/*.qrc') for ui_file_path in files: ui_fname = ui_file_path.split(os.path.sep)[-1] ui_stats = os.stat(ui_file_path) ui_last_mod_time = time.localtime(ui_stats[8]) fname_no_ext = ''.join(ui_fname.split('.')[:-1]) out_file_path = out_dir+'/'+fname_no_ext+'_rc.py' #execute pyrcc4 -o resources_rc.py resources.qrc command = "pyrcc4 -py3 -o {0} {1}".format(out_file_path, ui_file_path) print(command) os.system(command) if len(files) > 0: print('All ({0}) ui files compiled'.format(len(files))) else: print('No ui files in located at {0}'.format(ui_dir)) except OSError as err: print(err)
def _ui2py(self, ui_file, py_file): try: from PyQt4 import uic fp = open(py_file, 'w') uic.compileUi(ui_file, fp) fp.close() except Exception as e: self.warn('Unable to compile user interface %s: %s' % (py_file, e)) if not os.path.exists(py_file) or not open(py_file).read(): raise SystemExit(1) return
def use_ui_layout(): DIR = os.path.dirname(os.path.abspath(__file__)) print DIR ui_file = DIR + '/layout.ui' py_file = DIR + '/layout.py' with open(py_file, 'w') as open_file: uic.compileUi(ui_file, open_file) import_name = os.path.splitext(os.path.basename(py_file))[0] print "import name", import_name globals()[import_name] = imp.load_source(import_name, py_file)
def compile_ui_file(uipath): if not uipath.endswith('.ui'): raise Exception, 'Invalid UI file %s.' % uipath with open(''.join((uipath[:-2], 'py')), 'w') as pyfile: # *.ui --> *.py with open(uipath, 'r') as uifile: try: compileUi(uifile, pyfile) except: raise Exception, 'Could not compile UI file %s.' % uipath
def build_item(item, verbose=True): """Build the ui file at the path in "item" to python file in the same directory. The output file name is specified by the get_output_file_name function""" dirname = os.path.dirname(item) basename = os.path.basename(item) output_file_name = get_output_file_name(basename) output_file_path = os.path.join(dirname, output_file_name) with open(output_file_path, 'w') as f_out: uic.compileUi(item, f_out) if verbose: print("{0} ==> {1}".format(item, output_file_path))
def _generate(self): """ Generate the Python code. """ if self._opts.output == "-": pyfile = sys.stdout elif sys.hexversion >= 0x03000000: pyfile = open(self._opts.output, 'wt', encoding='utf8') else: pyfile = open(self._opts.output, 'wt') compileUi(self._ui_file, pyfile, self._opts.execute, self._opts.indent, self._opts.pyqt3_wrapper, self._opts.from_imports)
def main(): print 'Finding forms and resources to compile...' mydir = os.path.join(os.getcwd(), 'forms/') for file in os.listdir(mydir): nameExt = os.path.splitext(file) # Use pyuic4 to compile the said file, that is if the corresponding .py file hasn't been created or # is older than the .ui file if nameExt[1] == '.ui': lastTime = os.path.getmtime(os.path.join(mydir, file)) # Check to see if corresponding py file exists pyExportName = nameExt[0] + '_ui.py' if os.path.exists(os.path.join(mydir, pyExportName)): lastTime2 = os.path.getmtime(os.path.join(mydir, pyExportName)) if lastTime2 < lastTime: print 'Compiling', file pyfile = open(os.path.join(mydir, pyExportName), 'w') uic.compileUi(os.path.join(mydir, file), pyfile) else: print 'Compiling', file pyfile = open(os.path.join(mydir, pyExportName), 'w') uic.compileUi(os.path.join(mydir, file), pyfile) # Do the same routine here for the resource files. if nameExt[1] == '.qrc': lastTime = os.path.getmtime(os.path.join(mydir, file)) # Check to see if corresponding py file exists pyExportName = nameExt[0] + '_rc.py' if os.path.exists(os.path.join(mydir, pyExportName)): lastTime2 = os.path.getmtime(os.path.join(mydir, pyExportName)) if lastTime2 < lastTime: print 'Compiling resource', file data = check_output(['pyrcc4', os.path.join(mydir, file)]) pyfile = open(os.path.join(mydir, pyExportName), 'wb') pyfile.write(data) pyfile.close() else: print 'Compiling resource', file data = check_output(['pyrcc4', os.path.join(mydir, file)]) pyfile = open(os.path.join(mydir, pyExportName), 'wb') pyfile.write(data) pyfile.close() print 'Done!'
def run(self): from PyQt4 import uic for uifile in glob.glob("tombqt/*.ui"): pyfile = "ui_%s.py" % os.path.splitext(os.path.basename(uifile))[0] pyfile = os.path.join('tombqt', pyfile) if newer(uifile, pyfile): log.info("compiling %s -> %s", uifile, pyfile) tmp = StringIO() uic.compileUi(uifile, tmp) source = tmp.getvalue() f = open(pyfile, "w") f.write(source) f.close()
def compile_ui(ui_file, py_dir=None): if py_dir is None: py_dir = '' py_file = join(py_dir, splitext(split(ui_file)[-1])[0] + ".py") try: from PyQt4 import uic fp = open(py_file, 'w') uic.compileUi(ui_file, fp) fp.close() print "compiled", ui_file, "into", py_file except Exception, e: print 'Unable to compile user interface', e return
def _compileForms(): from PyQt4.uic import compileUi forms = _findForms() for form in forms: formName = os.path.split(form)[1] compiledFormName = "{0}_ui.py".format(os.path.splitext(formName)[0]) pathToCompiledForm = os.path.join(_FORMS_DIR, compiledFormName) if not os.path.exists(pathToCompiledForm) or os.stat(form).st_mtime > os.stat(pathToCompiledForm).st_mtime: with open(pathToCompiledForm, "w", encoding="utf-8") as file: compileUi(form, file, from_imports=True)
def compileUi(cls, uifile, pyfile, **kwargs): """ Call uic compile Args: uifile: input ui file pyfile: path of file object for the compiled file **kwargs: uic.compile parameters Returns: None """ uic.compileUi(uifile, pyfile, **kwargs)
def main(): for file in os.listdir(os.path.dirname(__file__)): filename = os.path.dirname(__file__) + '/' + file prefix = os.path.dirname(__file__) + '/uic_generated/' if fnmatch.fnmatch(filename, '*.ui'): print file uic.compileUi(file, open(prefix + file[:-2] + 'py', "w"), execute=True) if fnmatch.fnmatch(filename, '*.qrc'): print file subprocess.call( ["pyrcc4", filename, "-o", prefix + file[:-4] + '_rc.py'])
def rebuild_lgt_pyui_file(filename): uifile_patch = LGT_PATCH + LGT_UI_PATCH + filename pyfile_patch = LGT_PATCH + LGT_UI_PATCH + filename.split(".")[0] + ".py" uifile_time = os.path.getmtime(uifile_patch) pyfile_time = os.path.getmtime(pyfile_patch) if pyfile_time < uifile_time: uifile = open(uifile_patch, "r") pyfile = open(pyfile_patch, "w") uic.compileUi(uifile, pyfile) print "RECOMPILE: " + LGT_PATCH + LGT_UI_PATCH + filename uifile.close() pyfile.close() else: print "ACTUAL: " + LGT_PATCH + LGT_UI_PATCH + filename
def _compileForms(): from PyQt4.uic import compileUi forms = _findForms() for form in forms: formName = os.path.split(form)[1] compiledFormName = "{0}_ui.py".format(os.path.splitext(formName)[0]) pathToCompiledForm = os.path.join(_FORMS_DIR, compiledFormName) if not os.path.exists(pathToCompiledForm) or os.stat( form).st_mtime > os.stat(pathToCompiledForm).st_mtime: with open(pathToCompiledForm, "w", encoding="utf-8") as file: compileUi(form, file, from_imports=True)
def __init__(self): QtGui.QMainWindow.__init__(self) uic.loadUi('../ui/mainwindow.ui', self) with open("comple.py", "w") as pyfile: uic.compileUi('../ui/mainwindow.ui', pyfile) self.move(10, 10) self.init_component() self.init_defaultUI() self.init_cnavas() self.init_connect() self.init_data_path()
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 = (u"\n\n# Automatically generated - don't edit.\n" u"# 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()