def copy_selected(self, label=None): """Copy the selected versions and items to the clipboard""" d = {} items = self.tree.selectedItems() if not items: QMessageBox.warning(self, "No packages selected!", "Please select packages in the tree!") return for item in items: d[item.text(0)] = item.text(1) if label is None: label = QApplication.clipboard() label.setText("\n".join( '%s: %s' % t for t in d.items())) self.info_label.setText('Packages copied to clipboard.') self.timer.start(3000)
def reload_autosaved(self): """Reload the autosaved straditizer and close the old one""" from straditize.straditizer import Straditizer if not self.autosaved: return answer = QMessageBox.question( self, 'Reload autosave', 'Shall I reload the last autosaved stage? This will close the ' 'current figures.') if answer == QMessageBox.Yes: self.close_straditizer() stradi = Straditizer.from_dataset(self.autosaved.pop(0)) self.menu_actions.finish_loading(stradi)
def about(self): """About the tool""" versions = { key: d['version'] for key, d in psyplot.get_versions(False).items() } versions.update(psyplot_gui.get_versions()['requirements']) versions.update(psyplot._get_versions()['requirements']) versions['github'] = 'https://github.com/psyplot/psyplot' versions['author'] = psyplot.__author__ QMessageBox.about( self, "About psyplot", u"""<b>psyplot: Interactive data visualization with python</b> <br>Copyright © 2017- Philipp Sommer <br>Licensed under the terms of the GNU General Public License v2 (GPLv2) <p>Created by %(author)s</p> <p>Most of the icons come from the <a href="https://www.iconfinder.com/"> iconfinder</a>.</p> <p>For bug reports and feature requests, please go to our <a href="%(github)s">Github website</a> or contact the author via mail.</p> <p>This package uses (besides others) the following packages:<br> <ul> <li>psyplot %(psyplot)s</li> <li>Python %(python)s </li> <li>numpy %(numpy)s</li> <li>xarray %(xarray)s</li> <li>pandas %(pandas)s</li> <li>psyplot_gui %(psyplot_gui)s</li> <li>Qt %(qt)s</li> <li>PyQt %(pyqt)s</li> <li>qtconsole %(qtconsole)s</li> </ul></p> <p>For a full list of requirements see the <em>dependencies</em> in the <em>Help</em> menu.</p> <p>This software is provided "as is", without warranty or support of any kind.</p>""" % versions)
def about(self): """About the tool""" versions = { key: d['version'] for key, d in psyplot.get_versions(False).items() } versions.update(psyplot_gui.get_versions()['requirements']) versions.update(psyplot._get_versions()['requirements']) versions['github'] = 'https://github.com/Chilipp/psyplot' versions['author'] = psyplot.__author__ QMessageBox.about( self, "About psyplot", u"""<b>psyplot: Interactive data visualization with python</b> <br>Copyright © 2017- Philipp Sommer <br>Licensed under the terms of the GNU General Public License v2 (GPLv2) <p>Created by %(author)s</p> <p>Most of the icons come from the <a href="https://www.iconfinder.com/"> iconfinder</a>.</p> <p>For bug reports and feature requests, please go to our <a href="%(github)s">Github website</a> or contact the author via mail.</p> <p>This package uses (besides others) the following packages:<br> <ul> <li>psyplot %(psyplot)s</li> <li>Python %(python)s </li> <li>numpy %(numpy)s</li> <li>xarray %(xarray)s</li> <li>pandas %(pandas)s</li> <li>psyplot_gui %(psyplot_gui)s</li> <li>Qt %(qt)s</li> <li>PyQt %(pyqt)s</li> <li>qtconsole %(qtconsole)s</li> </ul></p> <p>For a full list of requirements see the <em>dependencies</em> in the <em>Help</em> menu.</p> <p>This software is provided "as is", without warranty or support of any kind.</p>""" % versions)
def rotate_image(self): """Rotate the image based on the specified :attr:`angle`""" angle = self.angle if angle is None: return sw = self.straditizer_widgets answer = QMessageBox.Yes if sw.always_yes else QMessageBox.question( self, 'Restart project?', 'This will close the straditizer and create new figures. ' 'Are you sure, you want to continue?') if answer == QMessageBox.Yes: image = self.straditizer.image.rotate(angle, expand=True) attrs = self.straditizer.attrs self.straditizer_widgets.close_straditizer() self.straditizer_widgets.menu_actions.open_straditizer( image, attrs=attrs) self._rotating = self._ha = self._va = False
def rescale(self, ask=None): """Rescale and start a new straditizer Parameters ---------- ask: bool Whether to ask with a QMessageBox. If None, it defaults to the :attr:`straditize.widgets.StraditizerWidgers.always_yes`""" if ask is None: ask = not self.straditizer_widgets.always_yes answer = QMessageBox.Yes if not ask else QMessageBox.question( self, 'Restart project?', 'This will close the straditizer and create new figures. ' 'Are you sure, you want to continue?') if answer == QMessageBox.Yes: image = self.resize_stradi_image(self.slider.val) attrs = self.straditizer.attrs self.straditizer_widgets.close_straditizer() self.straditizer_widgets.menu_actions.open_straditizer( image, attrs=attrs)
def open_straditizer(self, fname=None, *args, **kwargs): """Open a straditizer from an image or project file Parameters ---------- fname: :class:`str`, :class:`PIL.Image.Image` or ``None`` The path to the file to import. If None, a QFileDialog is opened and the user is asked for a file name. The action then depends on the ending of ``fname``: ``'.nc'`` or ``'.nc4'`` we expect a netCDF file and open it with :func:`xarray.open_dataset` and load the straditizer with the :meth:`straditize.straditizer.Straditizer.from_dataset` constructor ``'.pkl'`` We expect a pickle file and load the straditizer with :func:`pickle.load` any other ending We expect an image file and use the :func:`PIL.Image.open` function At the end, the loading is finished with the :meth:`finish_loading` method""" from straditize.straditizer import Straditizer if fname is None or (not isinstance(fname, six.string_types) and np.ndim(fname) < 2): fname = QFileDialog.getOpenFileName( self.straditizer_widgets, 'Straditizer project', self._dirname_to_use or self._start_directory, 'Projects and images ' '(*.nc *.nc4 *.pkl *.jpeg *.jpg *.pdf *.png *.raw *.rgba *.tif' ' *.tiff);;' 'NetCDF files (*.nc *.nc4);;' 'Pickle files (*.pkl);;' 'All images ' '(*.jpeg *.jpg *.pdf *.png *.raw *.rgba *.tif *.tiff);;' 'Joint Photographic Experts Group (*.jpeg *.jpg);;' 'Portable Document Format (*.pdf);;' 'Portable Network Graphics (*.png);;' 'Raw RGBA bitmap (*.raw *.rbga);;' 'Tagged Image File Format(*.tif *.tiff);;' 'All files (*)') if with_qt5: # the filter is passed as well fname = fname[0] if not np.ndim(fname) and not fname: return elif np.ndim(fname) >= 2: stradi = Straditizer(fname, *args, **kwargs) elif fname.endswith('.nc') or fname.endswith('.nc4'): import xarray as xr ds = xr.open_dataset(fname) stradi = Straditizer.from_dataset(ds.load(), *args, **kwargs) stradi.set_attr('project_file', fname) ds.close() stradi.set_attr('loaded', str(dt.datetime.now())) elif fname.endswith('.pkl'): stradi = Straditizer.load(fname, *args, **kwargs) stradi.set_attr('project_file', fname) stradi.set_attr('loaded', str(dt.datetime.now())) else: from PIL import Image with Image.open(fname) as _image: image = Image.fromarray(np.array(_image.convert('RGBA')), 'RGBA') w, h = image.size im_size = w * h if im_size > 20e6: recom_frac = 17403188.0 / im_size answer = ( QMessageBox.Yes if self.straditizer_widgets.always_yes else QMessageBox.question( self.straditizer_widgets, "Large straditizer image", "This is a rather large image with %1.0f pixels. " "Shall I reduce it to %1.0f%% of it's size for a " "better interactive experience?<br>" "If not, you can rescale it via<br><br>" "Transform source image → Rescale image" % (im_size, 100. * recom_frac))) if answer == QMessageBox.Yes: image = image.resize((int(round(w * recom_frac)), int(round(h * recom_frac)))) stradi = Straditizer(image, *args, **kwargs) stradi.set_attr('image_file', fname) self.finish_loading(stradi) self._dirname_to_use = None