def save_image_as(self): img = self.get_selection().toImage() if img.isNull(): QMessageBox.critical(self, self.tr('Error'), self.tr('No image was selected!')) return self.hide() formats = { self.tr('Portable Network Graphics (*.png)'): 'png', self.tr('Joint Photographic Experts Group (*.jpg *.jpeg)'): 'jpg', self.tr('Graphics Interchange Format (*.gif)'): 'gif', self.tr('Bitmap (*.bmp)'): 'bmp', self.tr('All Images (*.png *.jpg *.gif *.bmp)'): 'all' } file_format = None destination = QFileDialog.getSaveFileName(self, 'Save image', '', ';;'.join(formats.keys())) if isinstance(destination, tuple): destination, file_format = destination file_format = formats[file_format] if file_format == 'all': file_format = None if not file_format: file_format = destination.rsplit('.', 1)[-1] if destination: if file_format not in formats.values(): file_format = 'png' if not destination.endswith('.' + file_format): destination += '.' + file_format img.save(destination, file_format, 0 if file_format == 'png' else 90) self.reject()
def show_report(self): """ Raise the report window. """ self.create_report_html() from orangewidget.report.owreport import HAVE_REPORT report = self._get_designated_report_view() if not HAVE_REPORT and not report.have_report_warning_shown: QMessageBox.critical( None, "Missing Component", "Orange can not display reports, because your installation " "contains neither WebEngine nor WebKit.\n\n" "If you installed Orange with conda or pip, try using another " "PyQt distribution. " "If you installed Orange with a standard installer, please " "report this bug." ) report.have_report_warning_shown = True # Should really have a signal `report_ready` or similar to decouple # the implementations. report.make_report(self) report.show() report.raise_()
def copy_to_clipboard(self): img = self.get_selection() if img.isNull(): QMessageBox.critical(self, self.tr('Error'), self.tr('No image was selected!')) return QApplication.clipboard().setPixmap(img) self.reject()
def share_clipboard(self): mime = QApplication.clipboard().mimeData() try: wnd = ShareDialog(self, mime=mime) except ValueError as e: QMessageBox.critical(self, self.tr('Error'), str(e)) return else: wnd.show() wnd.exec_()
def save_project(self, project_path=None): try: if project_path is None: project_path = QFileDialog.getExistingDirectory(self, "Select the project directory") if project_path is not None and str(project_path)!='': project_path = str(project_path) self.save({}, project_path) except Exception as e: QMessageBox.critical(self, "Error", str(e))
def save_project(self, project_path=None): try: if project_path is None: project_path = QFileDialog.getExistingDirectory( self, "Select the project directory") if project_path is not None and str(project_path) != '': project_path = str(project_path) self.save({}, project_path) except Exception as e: QMessageBox.critical(self, "Error", str(e))
def save_project(self, project_path=None): try: if project_path is None: dialog = QFileDialog() dialog.setLabelText(QFileDialog.Accept, 'Save') project_path = dialog.getExistingDirectory( self, caption="Select the project directory to save") if project_path is not None and str(project_path) != '': project_path = str(project_path) self.save({}, project_path) except Exception as e: traceback.print_exc() QMessageBox.critical(self, "Error", str(e))
def load(self): fname, _ = QFileDialog.getOpenFileName( self, "File name", self._start_dir(), "Variable definitions (*.colors)") if not fname: return try: with open(fname) as f: js = json.load(f) #: dict self._parse_var_defs(js) except IOError: QMessageBox.critical(self, "File error", "File cannot be opened.") return except (json.JSONDecodeError, InvalidFileFormat): QMessageBox.critical(self, "File error", "Invalid file format.") return
def register_hotkeys(self): if self._hotkey is not None: self.rebuild_menu() self._hotkey.unregister(winid=self.winId()) hotkey_bindings = { settings['hotkey/clipboard']: (self.share_clipboard, self._action_clip), settings['hotkey/screenshot']: (self.capture_screen, self._action_screen) } for hotkey, (callback, action) in hotkey_bindings.items(): if hotkey: if self._hotkey.register(hotkey, callback, self.winId()): sequence = QKeySequence(hotkey) if hotkey else QKeySequence() action.setShortcut(sequence) else: QMessageBox.critical(self, 'Error', 'Could not bind {} hotkey!\n' 'Key combination {} is probably already in use.' .format(const.APP_NAME, hotkey)) else: qDebug('Hotkeys are not supported on this platform')
def save_plot(data, file_formats, filename=""): _LAST_DIR_KEY = "directories/last_graph_directory" _LAST_FILTER_KEY = "directories/last_graph_filter" settings = QSettings() start_dir = settings.value(_LAST_DIR_KEY, filename) if not start_dir or \ (not os.path.exists(start_dir) and not os.path.exists(os.path.split(start_dir)[0])): start_dir = os.path.expanduser("~") last_filter = settings.value(_LAST_FILTER_KEY, "") filename, writer, filter = \ filedialogs.get_file_name(start_dir, last_filter, file_formats) if not filename: return try: writer.write(filename, data) except Exception as e: QMessageBox.critical( None, "Error", 'Error occurred while saving file "{}": {}'.format(filename, e)) else: settings.setValue(_LAST_DIR_KEY, os.path.split(filename)[0]) settings.setValue(_LAST_FILTER_KEY, filter)
def load(self, data, project_path=None): try: self._project.load(data, project_path) except Exception as e: QMessageBox.critical(self, "Error", str(e))
def load(self, data, project_path=None): try: self._project.load(data, project_path) except FileNotFoundError as e: QMessageBox.critical(self, "Error", str(e))