def viewInBrowser(self): dstPath = os.path.join(TemporaryDir.path(), Settings()['template'] + '.htm') report = Report(self.model(), Settings()['template'], dstPath, self) indexes = self.selectedRows() fileName = report.generate(indexes) if fileName: executor = QDesktopServices() executor.openUrl(QtCore.QUrl.fromLocalFile(fileName))
def _saveTmpImage(self): tmpDir = QDir(TemporaryDir.path()) file = QTemporaryFile(tmpDir.absoluteFilePath("img_XXXXXX.jpg")) file.setAutoRemove(False) file.open() fileName = QFileInfo(file).absoluteFilePath() self.image.save(fileName) return fileName
def mouseDoubleClickEvent(self, e): tmpDir = QDir(TemporaryDir.path()) file = QTemporaryFile(tmpDir.absoluteFilePath("img_XXXXXX.jpg")) file.setAutoRemove(False) file.open() fileName = QFileInfo(file).absoluteFilePath() self.image.save(fileName) executor = QDesktopServices() executor.openUrl(QUrl.fromLocalFile(fileName))
def mouseDoubleClickEvent(self, e): fileName = self._photo.fileName() if not fileName: tmpDir = QtCore.QDir(TemporaryDir.path()) file = QtCore.QTemporaryFile(tmpDir.absoluteFilePath("img_XXXXXX.jpg")) file.setAutoRemove(False) file.open() fileName = QtCore.QFileInfo(file).absoluteFilePath() self.image.save(fileName) executor = QtGui.QDesktopServices() executor.openUrl(QtCore.QUrl.fromLocalFile(fileName))
def viewInBrowser(self, indexes=None): if not indexes: indexes = self.selectedRows() records = [] for index in indexes: records.append(self.model().record(index.row())) dstPath = os.path.join(TemporaryDir.path(), Settings()['template'] + '.htm') report = Report(self.model(), Settings()['template'], dstPath) fileName = report.generate(records) if fileName: executor = QDesktopServices() executor.openUrl(QtCore.QUrl.fromLocalFile(fileName))
def viewInBrowser(self, template=None): if not template: template = Settings()['template'] template_name = os.path.basename(template) dstPath = os.path.join(TemporaryDir.path(), template_name + '.htm') report = Report(self.model(), template, dstPath, self) indexes = self.selectedRows() if indexes: fileName = report.generate(indexes) if fileName: executor = QDesktopServices() executor.openUrl(QtCore.QUrl.fromLocalFile(fileName)) else: QMessageBox.information( self, self.tr("Report preview"), self.tr("Nothing selected.\nSelect required coins by clicking " "with Ctrl or Shift, or Ctrl+A for select all coins."))
def _templateChanged(self, index): template_name = self.templateSelector.currentText() dstPath = os.path.join(TemporaryDir.path(), template_name + '.htm') report = Report.Report(self.model, template_name, dstPath) self.fileName = report.generate(self.records, True) if not self.fileName: return file = QtCore.QFile(self.fileName) file.open(QtCore.QIODevice.ReadOnly) out = QtCore.QTextStream(file) out.setCodec(QtCore.QTextCodec.codecForName('utf-8')) html = out.readAll() basePath = QtCore.QFileInfo(self.fileName).absolutePath() baseUrl = QtCore.QUrl.fromLocalFile(basePath + '/') self.webView.setHtml(html, baseUrl)
def _templateChanged(self, index): template_name = self.templateSelector.currentText() dstPath = os.path.join(TemporaryDir.path(), template_name + '.htm') report = Report.Report(self.model, template_name, dstPath, self.parent()) self.fileName = report.generate(self.indexes, True) if not self.fileName: return if importedQtWebKit: self.webView.load(QtCore.QUrl.fromLocalFile(self.fileName)) else: file = open(self.fileName, 'r', encoding='utf-8') html = file.read() basePath = QtCore.QFileInfo(self.fileName).absolutePath() baseUrl = QtCore.QUrl.fromLocalFile(basePath + '/') self.webView.setBaseUrl(baseUrl) self.webView.setHtml(html) self._loadFinished(True)
def _templateChanged(self, index): template_name = self.templateSelector.currentText() template = self.templateSelector.currentData() dstPath = os.path.join(TemporaryDir.path(), template_name + '.htm') report = Report.Report(self.model, template, dstPath, self.parent()) self.fileName = report.generate(self.indexes, True) if not self.fileName: return if importedQtWebKit: self.webView.load(QtCore.QUrl.fromLocalFile(self.fileName)) else: file = open(self.fileName, 'r', encoding='utf-8') html = file.read() basePath = QtCore.QFileInfo(self.fileName).absolutePath() baseUrl = QtCore.QUrl.fromLocalFile(basePath + '/') self.webView.setBaseUrl(baseUrl) self.webView.setHtml(html) self._loadFinished(True)
def main(): try: locale.setlocale(locale.LC_ALL, '') except: # Work around system locale not specified (under Linux or Mac OS) pass app = QApplication(sys.argv) QCoreApplication.setOrganizationName(version.Company) QCoreApplication.setApplicationName(version.AppName) if OpenNumismat.PORTABLE: QCoreApplication.setOrganizationName('.') QSettings.setDefaultFormat(QSettings.IniFormat) QSettings.setPath(QSettings.IniFormat, QSettings.UserScope, OpenNumismat.PRJ_PATH) settings = Settings() if settings['error']: sys.excepthook = exceptHook if not os.path.exists(settings['reference']): # Create default dirs and files if not exists try: ref_path = os.path.dirname(settings['reference']) dst_ref = os.path.join(ref_path, 'reference.ref') if not os.path.exists(dst_ref): os.makedirs(ref_path, exist_ok=True) src_ref = os.path.join(OpenNumismat.PRJ_PATH, 'db', 'reference_%s.ref' % settings['locale']) if not os.path.exists(src_ref): src_ref = os.path.join(OpenNumismat.PRJ_PATH, 'db', 'reference_en.ref') shutil.copy(src_ref, dst_ref) dst_demo_db = os.path.join(OpenNumismat.HOME_PATH, 'demo.db') if not os.path.exists(dst_demo_db): os.makedirs(OpenNumismat.HOME_PATH, exist_ok=True) src_demo_db = os.path.join(OpenNumismat.PRJ_PATH, 'db', 'demo_%s.db' % settings['locale']) if not os.path.exists(src_demo_db): src_demo_db = os.path.join(OpenNumismat.PRJ_PATH, 'db', 'demo_en.ref') shutil.copy(src_demo_db, dst_demo_db) templates_path = os.path.join(OpenNumismat.HOME_PATH, 'templates') os.makedirs(templates_path, exist_ok=True) except: pass TemporaryDir.init(version.AppName) lang = settings['locale'] translator = QTranslator() translator.load('translations/lang_' + lang, OpenNumismat.PRJ_PATH) app.installTranslator(translator) translatorQt = QTranslator() translatorQt.load('translations/qtbase_' + lang, OpenNumismat.PRJ_PATH) app.installTranslator(translatorQt) if not settings['verify_ssl']: ssl._create_default_https_context = ssl._create_unverified_context mainWindow = MainWindow() mainWindow.show() mainWindow.raise_() # this will raise the window on Mac OS X status = app.exec_() # Clear temporary files TemporaryDir.remove() sys.exit(status)
def main(): try: locale.setlocale(locale.LC_ALL, '') except: # Work around system locale not specified (under Linux or Mac OS) pass app = QApplication(sys.argv) QCoreApplication.setOrganizationName(version.Company) QCoreApplication.setApplicationName(version.AppName) settings = Settings() if settings['error']: sys.excepthook = exceptHook if not os.path.exists(settings['reference']): # Create default dirs and files if not exists try: ref_path = os.path.dirname(settings['reference']) dst_ref = os.path.join(ref_path, 'reference.ref') if not os.path.exists(dst_ref): os.makedirs(ref_path, exist_ok=True) src_ref = os.path.join(OpenNumismat.PRJ_PATH, 'db', 'reference_%s.ref' % settings['locale']) if not os.path.exists(src_ref): src_ref = os.path.join(OpenNumismat.PRJ_PATH, 'db', 'reference_en.ref') shutil.copy(src_ref, dst_ref) dst_demo_db = os.path.join(OpenNumismat.HOME_PATH, 'demo.db') if not os.path.exists(dst_demo_db): os.makedirs(OpenNumismat.HOME_PATH, exist_ok=True) src_demo_db = os.path.join(OpenNumismat.PRJ_PATH, 'db', 'demo_%s.db' % settings['locale']) if not os.path.exists(src_demo_db): src_demo_db = os.path.join(OpenNumismat.PRJ_PATH, 'db', 'demo_en.ref') shutil.copy(src_demo_db, dst_demo_db) templates_path = os.path.join(OpenNumismat.HOME_PATH, 'templates') os.makedirs(templates_path, exist_ok=True) except: pass TemporaryDir.init(version.AppName) lang = settings['locale'] translator = QTranslator() translator.load('lang_' + lang, OpenNumismat.PRJ_PATH) app.installTranslator(translator) translatorQt = QTranslator() translatorQt.load('qtbase_' + lang, OpenNumismat.PRJ_PATH) app.installTranslator(translatorQt) if not settings['verify_ssl']: ssl._create_default_https_context = ssl._create_unverified_context mainWindow = MainWindow() mainWindow.show() mainWindow.raise_() # this will raise the window on Mac OS X status = app.exec_() # Clear temporary files TemporaryDir.remove() sys.exit(status)