def another_instance_wants_to_talk(self): s = self.local_server.nextPendingConnection() if s is None: return s.waitForReadyRead(1000) stream = QTextStream(s) stream.setCodec('UTF-8') raw = stream.readAll() try: command = json.loads(raw) except Exception as e: self.error('Invalid data from other instance: %s' % e) return finally: s.close() del s if not isinstance(command, dict): self.error('Invalid data from other instance: %r' % command) return ac = command.get('action') if ac == 'shutdown': return self.shutdown() urls = command.get('open', []) if not isinstance(urls, list): self.error('Invalid data from other instance: %r' % command) return urls = [x for x in urls if isinstance(x, str)] if urls: self.open_urls(urls, in_current_tab='dynamic', switch_to_tab=True)
def handlePreview(self): f = QFile("Qrcodes.html") f.open(QFile.ReadOnly | QFile.Text) istream = QTextStream(f) self.textfield.setHtml(istream.readAll()) f.close() dialog = QtPrintSupport.QPrintPreviewDialog() dialog.paintRequested.connect(self.textfield.print)#self.textEdit1.print)#editor.print_) dialog.exec_()
def lrelease(self, tsInputFile, qmOutputFile, stripped=True): verbose = False metTranslations = False tor = metaTranslator() f = QFile(tsInputFile) if not f.open(QtCore.QIODevice.ReadOnly): print("lrelease error: Cannot open file '%s'" % tsInputFile) return t = QTextStream(f) fullText = t.readAll() f.close() if fullText.find("<!DOCTYPE TS>") >= 0: if qmOutputFile is None: self.releaseTsFile(tsInputFile, verbose, stripped) else: self.loadTsFile(tor, tsInputFile, verbose) else: # modId = self.db_.managerModules().idModuleOfFile(tsInputFile) key = self.db_.managerModules().shaOfFile(tsInputFile) # dir = filedir("../tempdata/cache/%s/%s/file.ts/%s" % # (self._prj.conn.db_name, modId, key)) tagMap = fullText # TODO: hay que cargar todo el contenido del fichero en un diccionario for key, value in tagMap: toks = value.split(" ") for t in toks: if key == "TRANSLATIONS": metTranslations = True self.releaseTsFile(t, verbose, stripped) if not metTranslations: print( "lrelease warning: Met no 'TRANSLATIONS' entry in project file '%s'" % tsInputFile) if qmOutputFile: self.releaseMetaTranslator(tor, qmOutputFile, verbose, stripped)
# -*- coding: utf-8 -*- import sys, os if hasattr(sys, 'frozen'): os.environ['PATH'] = sys._MEIPASS + ";" + os.environ['PATH'] from PyQt5.Qt import QApplication, QFile, QTextStream from scripts.MainWindow import MainWindow from scripts import Utils if __name__ == '__main__': app = QApplication(sys.argv) mainWin = MainWindow() theme = Utils.get_local_config()['THEME'] file = QFile(theme + '.qss') file.open(QFile.ReadOnly | QFile.Text) stream = QTextStream(file) mainWin.setStyleSheet(stream.readAll()) mainWin.show() sys.exit(app.exec_())