def __saveScreenshot(self): format = "png" initialPath = QDesktopServices.storageLocation( QDesktopServices.PicturesLocation) # initialPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation); if initialPath.isEmpty(): initialPath = QDir.currentPath() initialPath += "/untitled." + format fileDialog = QtGui.QFileDialog(self, u"存储为", initialPath) fileDialog.setAcceptMode(QtGui.QFileDialog.AcceptSave) fileDialog.setFileMode(QtGui.QFileDialog.AnyFile) fileDialog.setDirectory(initialPath) mimeTypes = QStringList() for bf in QImageWriter.supportedImageFormats(): mimeTypes.append(QLatin1String(bf)) # fileDialog.setMin setMimeTypeFilters(mimeTypes) # fileDialog.selectMimeTypeFilter("image/" + format); fileDialog.setDefaultSuffix(format) if fileDialog.accept(): return fileName = fileDialog.selectedFiles().first() if not self.originalPixmap.save(fileName): QtGui.QMessageBox.Warning( self, u"保存错误", u"图像无法存储到 \"%s\"." % str(QDir.toNativeSeparators(fileName)))
def dump_configinfo(self): from qgis.core import QgsApplication, QgsProviderRegistry from PyQt4.QtGui import QImageReader, QImageWriter yield QgsProviderRegistry.instance().pluginList() yield QImageReader.supportedImageFormats() yield QImageWriter.supportedImageFormats() yield QgsApplication.libraryPaths() yield "Translation file: {}".format(self.translationFile)
def __init__(self, iface, parent=None, plugin=None, pre_generate_func=None, record_process_func=None, post_generate_func=None, record_post_process_func=None): QDialog.__init__(self, parent) self.setupUi(self) self._iface = iface self.plugin = plugin self._docTemplatePath = "" self._outputFilePath = "" self.curr_profile = current_profile() self.last_data_source = None self._config_mapping = OrderedDict() self._notif_bar = NotificationBar(self.vlNotification) self._doc_generator = DocumentGenerator(self._iface, self) self._data_source = "" enable_drag_sort(self.lstDocNaming) # Configure generate button generateBtn = self.buttonBox.button(QDialogButtonBox.Ok) if not generateBtn is None: generateBtn.setText( QApplication.translate("DocumentGeneratorDialog", "Generate")) # Load supported image types supportedImageTypes = QImageWriter.supportedImageFormats() for imageType in supportedImageTypes: imageTypeStr = imageType.data() self.cboImageType.addItem(imageTypeStr) self._init_progress_dialog() # Connect signals self.btnSelectTemplate.clicked.connect(self.onSelectTemplate) self.buttonBox.accepted.connect(self.onGenerate) self.chkUseOutputFolder.stateChanged.connect( self.onToggledOutputFolder) self.rbExpImage.toggled.connect(self.onToggleExportImage) self.tabWidget.currentChanged.connect(self.on_tab_index_changed) self.chk_template_datasource.stateChanged.connect( self.on_use_template_datasource) self.btnShowOutputFolder.clicked.connect(self.onShowOutputFolder) self.pre_generate_func = pre_generate_func self.record_process_func = record_process_func self.post_generate_func = post_generate_func self.record_post_process_func = record_post_process_func
def _determine_image_formats(self): """ Determine and store all image formats we can support. """ self.formats = [str(formating, "utf-8") for formating in QImageWriter.supportedImageFormats()] # we support svg format as well self.formats.append("svg")
def _determine_image_formats(self): """ Determine and store all image formats we can support. """ self.formats = [str(formating, "utf-8") for \ formating in QImageWriter.supportedImageFormats()] # we support svg format as well self.formats.append("svg")
def _image_filters(self): #Return supported image formats for use in a QFileDialog filter formats = [] for f in QImageWriter.supportedImageFormats(): f_type = f.data() filter_format = u'{0} {1} (*.{2})'.format(f_type.upper(), self._image_tr, f_type) formats.append(filter_format) return ';;'.join(formats)
def _image_filters(self): #Return supported image formats for use in a QFileDialog filter formats = [] for f in QImageWriter.supportedImageFormats(): f_type = f.data() filter_format = u'{0} {1} (*.{2})'.format( f_type.upper(), self._image_tr, f_type ) formats.append(filter_format) return ';;'.join(formats)
def __init__(self,iface,parent=None): QDialog.__init__(self,parent) self.setupUi(self) #Class vars self._iface = iface self._docTemplatePath = "" self._outputFilePath = "" self._notifBar = NotificationBar(self.vlNotification) mapping=DeclareMapping.instance() self._dbModel=mapping.tableMapping('party') #Initialize person foreign key mapper self.personFKMapper = self.tabWidget.widget(0) self.personFKMapper.setDatabaseModel(self._dbModel) self.personFKMapper.setEntitySelector(FarmerEntitySelector) self.personFKMapper.setSupportsList(True) self.personFKMapper.setDeleteonRemove(False) ''' self.personFKMapper.addCellFormatter("GenderID",genderFormatter) self.personFKMapper.addCellFormatter("MaritalStatusID",maritalStatusFormatter) ''' self.personFKMapper.setNotificationBar(self._notifBar) self.personFKMapper.initialize() #Configure person model attribute view self.lstDocNaming.setDataModel(self._dbModel) #self.lstDocNaming.setModelDisplayMapping(tableMapping) self.lstDocNaming.load() #Configure generate button generateBtn = self.buttonBox.button(QDialogButtonBox.Ok) if generateBtn != None: generateBtn.setText(QApplication.translate("PersonDocumentGenerator","Generate")) #Load supported image types supportedImageTypes = QImageWriter.supportedImageFormats() for imageType in supportedImageTypes: imageTypeStr = imageType.data() self.cboImageType.addItem(imageTypeStr) #Connect signals self.btnSelectTemplate.clicked.connect(self.onSelectTemplate) self.buttonBox.accepted.connect(self.onGenerate) self.chkUseOutputFolder.stateChanged.connect(self.onToggledOutputFolder) self.rbExpImage.toggled.connect(self.onToggleExportImage)
def fileSaveAs(self): if self.image.isNull(): return True fname = self.filename if self.filename is not None else "." formats = (["*.{0}".format(unicode(format).lower()) for format in QImageWriter.supportedImageFormats()]) fname = unicode(QFileDialog.getSaveFileName(self, "Image Changer - Save Image", fname, "Image files ({0})".format(" ".join(formats)))) if fname: if "." not in fname: fname += ".png" self.addRecentFile(fname) self.filename = fname return self.fileSave() return False
def on_saveAsImage(self): sliceOffsetCheck = False if self._shape[1]>1: #stack z-view is stored in imageScenes[2], for no apparent reason sliceOffsetCheck = True timeOffsetCheck = self._shape[0]>1 formatList = QImageWriter.supportedImageFormats() formatList = [x for x in formatList if x in ['png', 'tif']] expdlg = ExportDialog(formatList, timeOffsetCheck, sliceOffsetCheck, None, parent=self.ilastik) expdlg.exec_() tempname = str(expdlg.path.text()) + "/" + str(expdlg.prefix.text()) filename = str(QDir.convertSeparators(tempname)) self._saveThread.start() stuff = (filename, expdlg.timeOffset, expdlg.sliceOffset, expdlg.format) self._saveThread.queue.append(stuff) self._saveThread.imagePending.set()
def _initFileOptionsWidget(self): # List all image formats supported by QImageWriter exts = [str(QString(ext)) for ext in list(QImageWriter.supportedImageFormats())] # insert them into file format combo box for ext in exts: self.fileFormatCombo.addItem(ext+' sequence') # connect handles self.fileFormatCombo.currentIndexChanged.connect(self._handleFormatChange) self.filePatternEdit.textEdited.connect(self._handlePatternChange) self.directoryEdit.textChanged.connect(self._validateFilePath) self.selectDirectoryButton.clicked.connect(self._browseForPath) # set default file format to png self.fileFormatCombo.setCurrentIndex(exts.index('png')) self._updateFilePattern() self._validateFilePath()
def on_actionSave_triggered(self): fname = self.filename if self.filename is not None else "." formats = (["*.{0}".format(unicode(format).lower()) for format in QImageWriter.supportedImageFormats()]) fname = unicode(QFileDialog.getSaveFileName(self, "Image Changer - Save Image", fname, "Image files ({0})".format(" ".join(formats)))) if fname: if "." not in fname: fname += ".png" self.filename = fname if self.image.save(self.filename, None): self.saved = True self.changeTitleOriginal() return True else: return False return False
def __init__(self,iface,parent=None): QDialog.__init__(self,parent) self.setupUi(self) #Class vars self._iface = iface self._docTemplatePath = "" self._outputFilePath = "" self._notifBar = NotificationBar(self.vlNotification) #Initialize person foreign key mapper self.personFKMapper = self.tabWidget.widget(0) self.personFKMapper.setDatabaseModel(Farmer) self.personFKMapper.setEntitySelector(FarmerEntitySelector) self.personFKMapper.setSupportsList(True) self.personFKMapper.setDeleteonRemove(False) self.personFKMapper.addCellFormatter("GenderID",genderFormatter) self.personFKMapper.addCellFormatter("MaritalStatusID",maritalStatusFormatter) self.personFKMapper.setNotificationBar(self._notifBar) self.personFKMapper.initialize() #Configure person model attribute view self.lstDocNaming.setDataModel(Farmer) self.lstDocNaming.load() #Configure generate button generateBtn = self.buttonBox.button(QDialogButtonBox.Ok) if generateBtn != None: generateBtn.setText(QApplication.translate("PersonDocumentGenerator","Generate")) #Load supported image types supportedImageTypes = QImageWriter.supportedImageFormats() for imageType in supportedImageTypes: imageTypeStr = imageType.data() self.cboImageType.addItem(imageTypeStr) #Connect signals self.btnSelectTemplate.clicked.connect(self.onSelectTemplate) self.buttonBox.accepted.connect(self.onGenerate) self.chkUseOutputFolder.stateChanged.connect(self.onToggledOutputFolder) self.rbExpImage.toggled.connect(self.onToggleExportImage)
def __init__(self, iface, parent=None, plugin=None): QDialog.__init__(self, parent) self.setupUi(self) self._iface = iface self.plugin = plugin self._docTemplatePath = "" self._outputFilePath = "" self.curr_profile = current_profile() self.last_data_source = None self._config_mapping = OrderedDict() self._notif_bar = NotificationBar(self.vlNotification) self._doc_generator = DocumentGenerator(self._iface, self) self._data_source = "" enable_drag_sort(self.lstDocNaming) #Configure generate button generateBtn = self.buttonBox.button(QDialogButtonBox.Ok) if not generateBtn is None: generateBtn.setText(QApplication.translate("DocumentGeneratorDialog", "Generate")) #Load supported image types supportedImageTypes = QImageWriter.supportedImageFormats() for imageType in supportedImageTypes: imageTypeStr = imageType.data() self.cboImageType.addItem(imageTypeStr) self._init_progress_dialog() #Connect signals self.btnSelectTemplate.clicked.connect(self.onSelectTemplate) self.buttonBox.accepted.connect(self.onGenerate) self.chkUseOutputFolder.stateChanged.connect(self.onToggledOutputFolder) self.rbExpImage.toggled.connect(self.onToggleExportImage) self.tabWidget.currentChanged.connect(self.on_tab_index_changed) self.chk_template_datasource.stateChanged.connect(self.on_use_template_datasource) self.btnShowOutputFolder.clicked.connect(self.onShowOutputFolder)
def __init__(self, data, *args): QDialog.__init__(self, *args) self._auto_update = False self._file_format = None self.thread = None self.data = data self.ui = Ui_PlottingDlg() self.ui.setupUi(self) self.options_button = self.ui.buttonBox.addButton( "Options", QDialogButtonBox.ActionRole) imgs = [ bytes(i).decode() for i in QImageWriter.supportedImageFormats() ] self.ui.fileFormat.addItems(imgs) self.img_formats = imgs self.result = None self.has_cells = False self.has_walls = False self.has_points = False self.point_coloring_method = None self.wall_coloring_method = None self.cell_coloring_method = None ellipsis_draw = EllipsisDraw(None) self.ellipsis_draw = ellipsis_draw self.preview_button = QPushButton("Preview", self) self.preview_button.setCheckable(True) self.preview_button.setEnabled(False) self.apply_button = self.ui.buttonBox.button(QDialogButtonBox.Apply) self.apply_button.setEnabled(False) self.reload_button = QPushButton("Reload classes", self) self.reload_button.setEnabled(True) self.preview = None self.ui.buttonBox.addButton(self.reload_button, QDialogButtonBox.ActionRole) self.ui.buttonBox.addButton(self.preview_button, QDialogButtonBox.ActionRole) self.preview_button.toggled[bool].connect(self.show_preview) self.reload_button.clicked.connect(self.reload_classes) self.options_button.clicked.connect(self.open_options) self.load_preferences() self.updateInterface() self.reload_classes()
def on_actionAbout_triggered(self): dlg = QMessageBox(self) dlg.setWindowTitle("About Point Tracker") dlg.setIconPixmap(self.windowIcon().pixmap(64, 64)) #dlg.setTextFormat(Qt.RichText) dlg.setText("""Point Tracker Tool version %s rev %s Developper: Pierre Barbier de Reuille <*****@*****.**> Copyright 2008 """ % (__version__, __revision__)) img_read = ", ".join(str(s) for s in QImageReader.supportedImageFormats()) img_write = ", ".join(str(s) for s in QImageWriter.supportedImageFormats()) dlg.setDetailedText("""Supported image formats: - For reading: %s - For writing: %s """ % (img_read, img_write)) dlg.exec_()
def _initFileOptionsWidget(self): # List all image formats supported by QImageWriter exts = [ str(QString(ext)) for ext in list(QImageWriter.supportedImageFormats()) ] # insert them into file format combo box for ext in exts: self.fileFormatCombo.addItem(ext + ' sequence') # connect handles self.fileFormatCombo.currentIndexChanged.connect( self._handleFormatChange) self.filePatternEdit.textEdited.connect(self._handlePatternChange) self.directoryEdit.textChanged.connect(self._validateFilePath) self.selectDirectoryButton.clicked.connect(self._browseForPath) # set default file format to png self.fileFormatCombo.setCurrentIndex(exts.index('png')) self._updateFilePattern() self._validateFilePath()
def on_actionAbout_triggered(self): dlg = QMessageBox(self) dlg.setWindowTitle("About Point Tracker") dlg.setIconPixmap(self.windowIcon().pixmap(64, 64)) #dlg.setTextFormat(Qt.RichText) dlg.setText("""Point Tracker Tool version %s rev %s Developper: Pierre Barbier de Reuille <*****@*****.**> Copyright 2008 """ % (__version__, __revision__)) img_read = ", ".join( str(s) for s in QImageReader.supportedImageFormats()) img_write = ", ".join( str(s) for s in QImageWriter.supportedImageFormats()) dlg.setDetailedText("""Supported image formats: - For reading: %s - For writing: %s """ % (img_read, img_write)) dlg.exec_()
def embed(im): """Converts a QImage or QPicture object into an ipython Image object for embedding into an ipython notebook. """ if isinstance(im, QPicture): pic = im im = QImage(im.width(), im.height(), QImage.Format_ARGB32_Premultiplied) p = QPainter() p.begin(im) p.drawPicture(0, 0, pic) p.end() w = QImageWriter() buf = QBuffer() buf.open(buf.WriteOnly) w.setFormat("png") w.setDevice(buf) w.write(im) return Image(data=str(buf.buffer()), format="png", embed=True)
def __init__(self, data, *args): QDialog.__init__(self, *args) self._auto_update = False self._file_format = None self.thread = None self.data = data self.ui = Ui_PlottingDlg() self.ui.setupUi(self) self.options_button = self.ui.buttonBox.addButton("Options", QDialogButtonBox.ActionRole) imgs = [ bytes(i).decode() for i in QImageWriter.supportedImageFormats() ] self.ui.fileFormat.addItems(imgs) self.img_formats = imgs self.result = None self.has_cells = False self.has_walls = False self.has_points = False self.point_coloring_method = None self.wall_coloring_method = None self.cell_coloring_method = None ellipsis_draw = EllipsisDraw(None) self.ellipsis_draw = ellipsis_draw self.preview_button = QPushButton("Preview", self) self.preview_button.setCheckable(True) self.preview_button.setEnabled(False) self.apply_button = self.ui.buttonBox.button(QDialogButtonBox.Apply) self.apply_button.setEnabled(False) self.reload_button = QPushButton("Reload classes", self) self.reload_button.setEnabled(True) self.preview = None self.ui.buttonBox.addButton(self.reload_button, QDialogButtonBox.ActionRole) self.ui.buttonBox.addButton(self.preview_button, QDialogButtonBox.ActionRole) self.preview_button.toggled[bool].connect(self.show_preview) self.reload_button.clicked.connect(self.reload_classes) self.options_button.clicked.connect(self.open_options) self.load_preferences() self.updateInterface() self.reload_classes()
def dump_configinfo(self): yield QgsProviderRegistry.instance().pluginList() yield QImageReader.supportedImageFormats() yield QImageWriter.supportedImageFormats() yield QgsApplication.libraryPaths() yield "Translation file: {}".format(self.translationFile)
from roam.mainwindow import MainWindow def excepthook(errorhandler, exctype, value, traceback): errorhandler(exctype, value, traceback) roam.utils.error("Uncaught exception", exc_info=(exctype, value, traceback)) start = time.time() roam.utils.info("Loading Roam") QgsApplication.setPrefixPath(prefixpath, True) QgsApplication.initQgis() roam.utils.info(QgsApplication.showSettings()) roam.utils.info(QgsProviderRegistry.instance().pluginList()) roam.utils.info(QImageReader.supportedImageFormats()) roam.utils.info(QImageWriter.supportedImageFormats()) roam.utils.info(QgsApplication.libraryPaths()) QApplication.setStyle("Plastique") QApplication.setFont(QFont('Segoe UI')) class Settings: def __init__(self, path): self.path = path self.settings = {} def load(self): settingspath = self.path with open(settingspath, 'r') as f: self.settings = yaml.load(f)