def main(argv=None): if argv is None: argv = sys.argv app = QApplication(argv) engine = QScriptEngine() if HAS_DEBUGGER: debugger = QScriptEngineDebugger() debugger.attachTo(engine) debugWindow = debugger.standardWindow() debugWindow.resize(1024, 640) scriptFileName = './calculator.js' scriptFile = QFile(scriptFileName) scriptFile.open(QIODevice.ReadOnly) engine.evaluate(unicode(scriptFile.readAll()), scriptFileName) scriptFile.close() loader = QUiLoader() ui = loader.load(':/calculator.ui') ctor = engine.evaluate('Calculator') scriptUi = engine.newQObject(ui, QScriptEngine.ScriptOwnership) calc = ctor.construct([scriptUi]) if HAS_DEBUGGER: display = ui.findChild(QLineEdit, 'display') display.connect(display, SIGNAL('returnPressed()'), debugWindow, SLOT('show()')) ui.show() return app.exec_()
def readRcTextFile(path): """Read whole text file from qt resources system.""" assert path.startswith(':/') f = QFile(path) if not f.open(QFile.ReadOnly | QFile.Text): raise FileNotFoundError('failed to read rc text %s' % path) text = str(f.readAll()) f.close() return text
def main(): pid_file = 'av-control.pid' fp = open(pid_file, 'w') try: fcntl.lockf(fp, fcntl.LOCK_EX | fcntl.LOCK_NB) except IOError: # another instance is running print "av-control is already running." sys.exit(1) logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', level=logging.INFO) app = QApplication(sys.argv) parser = argparse.ArgumentParser() parser.add_argument("-f", "--fullscreen", help="Run in fullscreen mode and hide the mouse cursor", action="store_true") parser.add_argument("-c", help="Specify the controller ID to connect to", metavar="CONTROLLERID", default="") args = parser.parse_args() try: ssf = QFile(":/stylesheet") ssf.open(QFile.ReadOnly) styleSheet = str(ssf.readAll()) app.setStyleSheet(styleSheet) except IOError: # never mind logging.warn("Cannot find stylesheet, using default system styles.") try: controller = Controller.fromPyro(args.c) myapp = MainWindow(controller) client = AvControlClient(myapp) client.setDaemon(True) client.start() client.started.wait() atexit.register(lambda: controller.unregisterClient(client.uri)) controller.registerClient(client.uri) if args.fullscreen: QApplication.setOverrideCursor(Qt.BlankCursor) myapp.showFullScreen() else: myapp.show() sys.exit(app.exec_()) except VersionMismatchError as e: Dialogs.errorBox(str(e))
def testImage(self): #Test loading of sample.png resource f = open(adjust_filename('sample.png', __file__), "rb") orig = f.read() f.close() f = QFile(':/sample.png') f.open(QIODevice.ReadOnly) copy = f.readAll() f.close() self.assertEqual(len(orig), len(copy)) self.assertEqual(orig, copy)
def testPhrase(self): #Test loading of quote.txt resource f = open(adjust_filename('quoteEnUS.txt', __file__), "r") orig = f.read() f.close() f = QFile(':/quote.txt') f.open(QIODevice.ReadOnly) #|QIODevice.Text) print("Error:", f.errorString()) copy = f.readAll() f.close() self.assertEqual(orig, copy)
def parse_asn1(*files, **options): ''' Call the ASN.1 parser on a number of files, and return the module containing the AST This function uses QProcess to launch the ASN.1 compiler because the subprocess module from Python has issues on the Windows platform ''' ast_version = options.get('ast_version', ASN1.UniqueEnumeratedNames) rename_policy = options.get('rename_policy', ASN1.NoRename) flags = options.get('flags', [ASN1.AstOnly]) pprint = options.get('pretty_print', False) assert isinstance(ast_version, ASN1) assert isinstance(rename_policy, ASN1) assert isinstance(flags, list) path_to_asn1scc = spawn.find_executable('asn1.exe') if not path_to_asn1scc: raise TypeError('ASN.1 Compiler not found in path') if os.name == 'posix': path_to_mono = spawn.find_executable('mono') if not path_to_mono: raise TypeErorr('"mono" not found in path. Please install it.') binary = path_to_mono arg0 = path_to_asn1scc else: binary = path_to_asn1scc arg0 = '' asn1scc_root = os.path.abspath(os.path.dirname(path_to_asn1scc)) # Create a temporary directory to store dataview.py and import it tempdir = tempfile.mkdtemp() sys.path.append(tempdir) if os.name == 'nt': # On windows, remove the drive letter, workaround to ASN1SCC bug tempdir = tempdir[2:] asn1scc_root = asn1scc_root[2:] filename = str(uuid.uuid4()).replace('-', '_') filepath = tempdir + os.sep + filename + '.py' stg = asn1scc_root + os.sep + 'python.stg' if pprint: # Generate an html file with pretty-printed ASN.1 types stg_qrc = QFile(':misc/pretty_print_asn1.stg') stg_qrc.open(1) content = stg_qrc.readAll() stgfile = tempdir + os.sep + 'pretty_print_asn1.stg' with open(stgfile, 'w') as tmpfile: tmpfile.write(content.data()) out_html = tempdir + os.sep + 'dataview.html' html = ['-customIcdUper', stgfile + '::' + out_html] else: html = [] args = [ arg0, '-customStgAstVerion', str(ast_version.value), '-customStg', stg + '::' + filepath, '-renamePolicy', str(rename_policy.value) ] + html + list(*files) asn1scc = QProcess() LOG.debug(os.getcwd()) LOG.debug(binary + ' ' + ' '.join(args)) asn1scc.start(binary, args) _ = waitfor_qprocess(asn1scc, "ASN.1 Compiler") if filename in AST.viewkeys(): # Re-import module if it was already loaded ast = AST[filename] reload(ast) else: ast = importlib.import_module(filename) AST[filename] = ast if pprint: # add the path to the optionally-gernated pretty-printed HTML file ast.html = out_html return ast
def loadStyleSheet(sheetName): file = QFile(sheetName) file.open(QFile.ReadOnly) styleSheet = file.readAll() return str(styleSheet)
def parse_asn1(*files, **options): ''' Call the ASN.1 parser on a number of files, and return the module containing the AST This function uses QProcess to launch the ASN.1 compiler because the subprocess module from Python has issues on the Windows platform ''' # use basic caching to avoid re-parsing when loading the model project_cache = os.getenv ("PROJECT_CACHE") if project_cache is not None and not os.path.isdir(project_cache): raise TypeError ( "The configured cache folder \"" + project_cache + "\" is not there!\n") # make sure the same files are not parsed more than once if not modified filehash = hashlib.md5() file_list = sorted(list(*files)) try: for each in file_list: filehash.update(open(each).read()) # also hash the file path: it is used in the AST, so it is # not enough to hash the content of the ASN.1 files, as two sets # of input files may have the same hash filehash.update(each) except IOError as err: raise TypeError (str(err)) new_hash = filehash.hexdigest() # names of the files that will be generated by asn1scc and then parsed out_py_name = new_hash + ".py" out_html_name = new_hash + ".html" if new_hash in AST.viewkeys(): return AST[new_hash] elif project_cache is not None: outdir = project_cache elif project_cache is None: outdir = tempfile.mkdtemp() # to allow the import sys.path.append(outdir) ast_version = options.get('ast_version', ASN1.UniqueEnumeratedNames) rename_policy = options.get('rename_policy', ASN1.NoRename) flags = options.get('flags', [ASN1.AstOnly]) pprint = options.get('pretty_print', False) assert isinstance(ast_version, ASN1) assert isinstance(rename_policy, ASN1) assert isinstance(flags, list) path_to_asn1scc = spawn.find_executable('asn1.exe') if not path_to_asn1scc: raise TypeError('ASN.1 Compiler not found in path') if os.name == 'posix': path_to_mono = spawn.find_executable('mono') if not path_to_mono: raise TypeError('"mono" not found in path. Please install it.') binary = path_to_mono arg0 = path_to_asn1scc else: binary = path_to_asn1scc arg0 = '' asn1scc_root = os.path.abspath(os.path.dirname(path_to_asn1scc)) if os.name == 'nt': # On windows, remove the drive letter, workaround to ASN1SCC bug outdir = outdir[2:] asn1scc_root = asn1scc_root[2:] # The two possible files that can be generated with complete path: py_filepath = outdir + os.sep + out_py_name html_filepath = outdir + os.sep + out_html_name # call the ASN.1 compiler only if there is no existing cached file if project_cache is None or not os.path.exists(py_filepath): stg = asn1scc_root + os.sep + 'python.stg' if pprint: # Generate an html file with pretty-printed ASN.1 types stg_qrc = QFile(':misc/pretty_print_asn1.stg') stg_qrc.open(1) content = stg_qrc.readAll() stgfile = outdir + os.sep + 'pretty_print_asn1.stg' with open(stgfile, 'w') as tmpfile: tmpfile.write(content.data()) html = ['-customIcdUper', stgfile + '::' + html_filepath] else: html = [] args = [arg0, '-customStgAstVersion', str(ast_version.value), '-customStg', stg + '::' + py_filepath, '-renamePolicy', str(rename_policy.value)] + html + file_list asn1scc = QProcess() LOG.debug(os.getcwd()) LOG.debug(binary + ' ' + ' '.join(args)) asn1scc.start(binary, args) _ = waitfor_qprocess(asn1scc, "ASN.1 Compiler") ast = importlib.import_module(new_hash) AST[new_hash] = ast if pprint: # add the path to the optionally-generated pretty-printed HTML file ast.html = html_filepath return ast
def main(): pid_file = 'av-control.pid' fp = open(pid_file, 'w') try: fcntl.lockf(fp, fcntl.LOCK_EX | fcntl.LOCK_NB) except IOError: # another instance is running print "av-control is already running." sys.exit(1) logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', level=logging.INFO) app = QApplication(sys.argv) parser = argparse.ArgumentParser() parser.add_argument("-f", "--fullscreen", help="Run in fullscreen mode and hide the mouse cursor", action="store_true") parser.add_argument("-c", help="Specify the controller ID to connect to", metavar="CONTROLLERID", default="") parser.add_argument("-j", "--joystick", help="Path to joystick device to use for camera control") args = parser.parse_args() try: ssf = QFile(":/stylesheet") ssf.open(QFile.ReadOnly) styleSheet = str(ssf.readAll()) app.setStyleSheet(styleSheet) except IOError: # never mind logging.warn("Cannot find stylesheet, using default system styles.") try: controller = Controller.fromPyro(args.c) js = None joystickDevice = args.joystick print args try: if args.joystick: if os.path.exists(joystickDevice): logging.info("Configuring joystick {}".format(joystickDevice)) js = Joystick(joystickDevice) js.start() else: logging.error("Specified joystick device {} does not exist!".format(joystickDevice)) except IOError: logging.exception("Unable to configure joystick") pass jsa = SensitivityPrefsCameraJoystickAdapter(js) jsa.start() myapp = MainWindow(controller, jsa) client = AvControlClient(myapp) client.setDaemon(True) client.start() client.started.wait() atexit.register(lambda: controller.unregisterClient(client.uri)) controller.registerClient(client.uri) if args.fullscreen: QApplication.setOverrideCursor(Qt.BlankCursor) myapp.showFullScreen() else: myapp.show() sys.exit(app.exec_()) except VersionMismatchError as e: Dialogs.errorBox(str(e))
def main(): pid_file = 'av-control.pid' fp = open(pid_file, 'w') try: fcntl.lockf(fp, fcntl.LOCK_EX | fcntl.LOCK_NB) except IOError: # another instance is running print "av-control is already running." sys.exit(1) logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', level=logging.INFO) app = QApplication(sys.argv) parser = argparse.ArgumentParser() parser.add_argument( "-f", "--fullscreen", help="Run in fullscreen mode and hide the mouse cursor", action="store_true") parser.add_argument("-c", help="Specify the controller ID to connect to", metavar="CONTROLLERID", default="") parser.add_argument( "-j", "--joystick", help="Path to joystick device to use for camera control") args = parser.parse_args() try: ssf = QFile(":/stylesheet") ssf.open(QFile.ReadOnly) styleSheet = str(ssf.readAll()) app.setStyleSheet(styleSheet) except IOError: # never mind logging.warn("Cannot find stylesheet, using default system styles.") try: controller = Controller.fromPyro(args.c) js = None joystickDevice = args.joystick print args try: if args.joystick: if os.path.exists(joystickDevice): logging.info( "Configuring joystick {}".format(joystickDevice)) js = Joystick(joystickDevice) js.start() else: logging.error( "Specified joystick device {} does not exist!".format( joystickDevice)) except IOError: logging.exception("Unable to configure joystick") pass jsa = SensitivityPrefsCameraJoystickAdapter(js) jsa.start() myapp = MainWindow(controller, jsa) client = AvControlClient(myapp) client.setDaemon(True) client.start() client.started.wait() atexit.register(lambda: controller.unregisterClient(client.uri)) controller.registerClient(client.uri) if args.fullscreen: QApplication.setOverrideCursor(Qt.BlankCursor) myapp.showFullScreen() else: myapp.show() sys.exit(app.exec_()) except VersionMismatchError as e: Dialogs.errorBox(str(e))
# DatabaseManager.db = DatabaseManager.DatabaseManager(host="localhost", # databaseName="salaryManagement_test_1", # username="******", # password="******") DatabaseManager.db = DatabaseManager.DatabaseManager(host="sql12.freemysqlhosting.net", username="******", password="******", databaseName="sql12269310") w = MainWindow() styleSheetFile = QFile("styleSheet/lightStyleSheet.css") styleSheetFile.open(QIODevice.ReadOnly) w.setStyleSheet(str(styleSheetFile.readAll())) w.show() splash.finish(w) except mysql.connector.Error as e: splash.close() ShowMysqlError(e) sys.exit() # except Exception as e: # splash.close() # msg = QMessageBox(QMessageBox.Critical, "Error", "Unexpected error occured!\n" + str(e)) # msg.exec_() # sys.exit()