def _setupMajorObjectItemActions(self, actionsgroup=None): if actionsgroup is None: actionsgroup = QtWidgets.QActionGroup(self) # open metadata view icon = qtsupport.geticon('metadata.svg', __name__) QtWidgets.QAction( icon, self.tr('Open &Metadata View'), actionsgroup, objectName='actionOpenItemMetadataView', shortcut=self.tr('Ctrl+M'), toolTip=self.tr('Show metadata in a new window'), statusTip=self.tr('Show metadata in a new window'), triggered=self.openItemMatadataView, enabled=False) # @TODO: remove # show properties # @TODO: standard info icon from gdsview package icon = qtsupport.geticon('info.svg', 'gsdview') QtWidgets.QAction( icon, self.tr('&Show Properties'), actionsgroup, objectName='actionShowItemProperties', shortcut=self.tr('Ctrl+S'), toolTip=self.tr('Show the property dialog for the cutent item'), statusTip=self.tr('Show the property dialog for the cutent item'), triggered=self.showItemProperties) return actionsgroup
def _setupMajorObjectItemActions(self, actionsgroup=None): if actionsgroup is None: actionsgroup = QtWidgets.QActionGroup(self) # open metadata view icon = qtsupport.geticon('metadata.svg', __name__) QtWidgets.QAction(icon, self.tr('Open &Metadata View'), actionsgroup, objectName='actionOpenItemMetadataView', shortcut=self.tr('Ctrl+M'), toolTip=self.tr('Show metadata in a new window'), statusTip=self.tr('Show metadata in a new window'), triggered=self.openItemMatadataView, enabled=False) # @TODO: remove # show properties # @TODO: standard info icon from gdsview package icon = qtsupport.geticon('info.svg', 'gsdview') QtWidgets.QAction( icon, self.tr('&Show Properties'), actionsgroup, objectName='actionShowItemProperties', shortcut=self.tr('Ctrl+S'), toolTip=self.tr('Show the property dialog for the cutent item'), statusTip=self.tr('Show the property dialog for the cutent item'), triggered=self.showItemProperties) return actionsgroup
def _setupActions(self): actions = QtWidgets.QActionGroup(self) # KML export icon = qtsupport.geticon('area.svg', 'gsdview') QtWidgets.QAction( icon, self.tr('KML export'), actions, objectName='kmlExportAction', statusTip=self.tr('KML export'), triggered=self.exportKML) # Open in google earth icon = qtsupport.geticon('earth.svg', __name__) QtWidgets.QAction( icon, self.tr('Open in Google Earth'), actions, objectName='openInGoogleEarthAction', statusTip=self.tr('Open in Google Earth'), triggered=self.openInGoogleEarth) # Open in google maps icon = qtsupport.geticon('overview.svg', 'gsdview.gdalbackend') QtWidgets.QAction( icon, self.tr('Open in Google Maps'), actions, objectName='openInGoogleMapsAction', statusTip=self.tr('Open in Google Maps'), triggered=self.openInGoogleMaps) return actions
def _setupActions(self): actions = QtWidgets.QActionGroup(self) # Zoom in icon = qtsupport.geticon('zoom-in.svg', 'gsdview') QtWidgets.QAction(icon, self.tr('Zoom In'), actions, objectName='zoomOutAction', statusTip=self.tr('Zoom In'), shortcut=QtGui.QKeySequence(self.tr('Ctrl++')), enabled=False, triggered=lambda: self._zoom(+1)) # Zoom out icon = qtsupport.geticon('zoom-out.svg', 'gsdview') QtWidgets.QAction(icon, self.tr('Zoom Out'), actions, objectName='zoomOutAction', statusTip=self.tr('Zoom Out'), shortcut=QtGui.QKeySequence(self.tr('Ctrl+-')), enabled=False, triggered=lambda: self._zoom(-1)) return actions
def _setupActions(self): actions = QtWidgets.QActionGroup(self) # Zoom in icon = qtsupport.geticon('zoom-in.svg', 'gsdview') QtWidgets.QAction(icon, self.tr('Zoom In'), actions, objectName='zoomInAction', statusTip=self.tr('Zoom In'), shortcut=QtGui.QKeySequence(self.tr('Ctrl++')), triggered=self.zoomIn) # Zoom out icon = qtsupport.geticon('zoom-out.svg', 'gsdview') QtWidgets.QAction(icon, self.tr('Zoom Out'), actions, objectName='zoomOutAction', statusTip=self.tr('Zoom Out'), shortcut=QtGui.QKeySequence(self.tr('Ctrl+-')), triggered=self.zoomOut) # Zoom fit icon = qtsupport.geticon('zoom-fit.svg', 'gsdview') QtWidgets.QAction(icon, self.tr('Zoom Fit'), actions, objectName='zoomFitAction', statusTip=self.tr('Zoom to fit the window size'), triggered=self.zoomFit) # Zoom 100 icon = qtsupport.geticon('zoom-100.svg', 'gsdview') QtWidgets.QAction(icon, self.tr('Zoom 100%'), actions, objectName='zoom100Action', statusTip=self.tr('Original size'), triggered=self.zoom100) # Manual Zoom #icon = QtGui.QIcon() #qt4support.geticon('zoom-100.svg', 'gsdview') #QtWidgets.QWidgetAction( # icon, self.tr('Zoom 100%'), actions, # statusTip=self.tr('Original size'), # triggered=self.zoom100) return actions
def _setupHelpActions(self): actionsgroup = QtWidgets.QActionGroup(self) # About icon = qtsupport.geticon('about.svg', __name__) QtWidgets.QAction( icon, self.tr('&About'), actionsgroup, objectName='aboutAction', toolTip=self.tr('Show program information'), statusTip=self.tr('Show program information'), triggered=lambda: self.aboutdialog.exec_()) # AboutQt icon = QtGui.QIcon(':/qt-project.org/qmessagebox/images/qtlogo-64.png') # @COMPATIBILITY: Qt4 --> Qt5 if not icon.availableSizes(): icon = QtGui.QIcon(':/trolltech/qmessagebox/images/qtlogo-64.png') if not icon.availableSizes(): icon = QtGui.QIcon.fromTheme('qtlogo-64') QtWidgets.QAction( icon, self.tr('About &Qt'), actionsgroup, objectName='aboutQtAction', toolTip=self.tr('Show information about Qt'), statusTip=self.tr('Show information about Qt'), triggered=lambda: QtWidgets.QMessageBox.aboutQt(self)) return actionsgroup
def _setupActions(self): actions = QtWidgets.QActionGroup(self) # Zoom in icon = qtsupport.geticon('zoom-in.svg', 'gsdview') QtWidgets.QAction( icon, self.tr('Zoom In'), actions, objectName='zoomInAction', statusTip=self.tr('Zoom In'), shortcut=QtGui.QKeySequence(self.tr('Ctrl++')), triggered=self.zoomIn) # Zoom out icon = qtsupport.geticon('zoom-out.svg', 'gsdview') QtWidgets.QAction( icon, self.tr('Zoom Out'), actions, objectName='zoomOutAction', statusTip=self.tr('Zoom Out'), shortcut=QtGui.QKeySequence(self.tr('Ctrl+-')), triggered=self.zoomOut) # Zoom fit icon = qtsupport.geticon('zoom-fit.svg', 'gsdview') QtWidgets.QAction( icon, self.tr('Zoom Fit'), actions, objectName='zoomFitAction', statusTip=self.tr('Zoom to fit the window size'), triggered=self.zoomFit) # Zoom 100 icon = qtsupport.geticon('zoom-100.svg', 'gsdview') QtWidgets.QAction( icon, self.tr('Zoom 100%'), actions, objectName='zoom100Action', statusTip=self.tr('Original size'), triggered=self.zoom100) # Manual Zoom #icon = QtGui.QIcon() #qt4support.geticon('zoom-100.svg', 'gsdview') #QtWidgets.QWidgetAction( # icon, self.tr('Zoom 100%'), actions, # statusTip=self.tr('Original size'), # triggered=self.zoom100) return actions
def _setupDatasetItemActions(self, actionsgroup=None): if actionsgroup is None: actionsgroup = QtWidgets.QActionGroup(self) # open RGB # @TODO: find an icon for RGB icon = qtsupport.geticon('rasterband.svg', __name__) QtWidgets.QAction( icon, self.tr('Open as RGB'), actionsgroup, objectName='actionOpenRGBImageView', #shortcut=self.tr('Ctrl+B'), toolTip=self.tr('Display the dataset as an RGB image'), statusTip=self.tr('Open as RGB'), triggered=self.openRGBImageView) # build overviews icon = qtsupport.geticon('overview.svg', __name__) QtWidgets.QAction( icon, self.tr('&Build overviews'), actionsgroup, objectName='actionBuidOverviews', shortcut=self.tr('Ctrl+B'), toolTip=self.tr('Build overviews for all raster bands'), statusTip=self.tr('Build overviews for all raster bands'), triggered=self.buildOverviews) # @TODO: add band, add virtual band, open GCPs view # close icon = qtsupport.geticon('close.svg', 'gsdview') QtWidgets.QAction(icon, self.tr('Close'), actionsgroup, objectName='actionCloseItem', shortcut=self.tr('Ctrl+W'), toolTip=self.tr('Close the current item'), statusTip=self.tr('Close the current item'), triggered=self.closeCurrentItem) self._setupMajorObjectItemActions(actionsgroup) return actionsgroup
def _setupAction(self): icon = qtsupport.geticon('stretching.svg', __name__) action = QtWidgets.QAction( icon, self.tr('Stretch'), self, objectName='stretchAction', statusTip=self.tr('Stretch'), checkable=True, triggered=self.onButtonToggled) return action
def _setupFileActions(self): # @TODO: add a "close all" (items) action actionsgroup = QtWidgets.QActionGroup(self) # Open icon = qtsupport.geticon('open.svg', __name__) QtWidgets.QAction( icon, self.tr('&Open'), actionsgroup, objectName='openAction', shortcut=self.tr('Ctrl+O'), toolTip=self.tr('Open an existing file'), statusTip=self.tr('Open an existing file'), triggered=self.openFile) # Close icon = qtsupport.geticon('close.svg', __name__) QtWidgets.QAction( icon, self.tr('&Close'), actionsgroup, objectName='closeAction', # 'Ctrl+W' shortcu is used for closing windows #shortcut=self.tr('Ctrl+W'), toolTip=self.tr('Close the current file'), statusTip=self.tr('Close the current file'), triggered=self.closeItem) # Separator QtWidgets.QAction(actionsgroup).setSeparator(True) # objectName='separator') # Exit icon = qtsupport.geticon('quit.svg', __name__) QtWidgets.QAction( icon, self.tr('&Exit'), actionsgroup, objectName='exitAction', shortcut=self.tr('Ctrl+X'), toolTip=self.tr('Exit the program'), statusTip=self.tr('Exit the program'), triggered=self.close) return actionsgroup
def _setupDatasetItemActions(self, actionsgroup=None): if actionsgroup is None: actionsgroup = QtWidgets.QActionGroup(self) # open RGB # @TODO: find an icon for RGB icon = qtsupport.geticon('rasterband.svg', __name__) QtWidgets.QAction( icon, self.tr('Open as RGB'), actionsgroup, objectName='actionOpenRGBImageView', #shortcut=self.tr('Ctrl+B'), toolTip=self.tr('Display the dataset as an RGB image'), statusTip=self.tr('Open as RGB'), triggered=self.openRGBImageView) # build overviews icon = qtsupport.geticon('overview.svg', __name__) QtWidgets.QAction( icon, self.tr('&Build overviews'), actionsgroup, objectName='actionBuidOverviews', shortcut=self.tr('Ctrl+B'), toolTip=self.tr('Build overviews for all raster bands'), statusTip=self.tr('Build overviews for all raster bands'), triggered=self.buildOverviews) # @TODO: add band, add virtual band, open GCPs view # close icon = qtsupport.geticon('close.svg', 'gsdview') QtWidgets.QAction( icon, self.tr('Close'), actionsgroup, objectName='actionCloseItem', shortcut=self.tr('Ctrl+W'), toolTip=self.tr('Close the current item'), statusTip=self.tr('Close the current item'), triggered=self.closeCurrentItem) self._setupMajorObjectItemActions(actionsgroup) return actionsgroup
def _setupSettingsActions(self): actionsgroup = QtWidgets.QActionGroup(self) # Preferences icon = qtsupport.geticon('preferences.svg', __name__) QtWidgets.QAction( icon, self.tr('&Preferences'), actionsgroup, objectName='preferencesAction', toolTip=self.tr('Open the program preferences dialog'), statusTip=self.tr('Open the program preferences dialog'), triggered=self.showPreferencesDialog) icon = qtsupport.geticon('full-screen.svg', __name__) QtWidgets.QAction( icon, self.tr('&Full Screen'), actionsgroup, objectName='fullScreenAction', shortcut='Ctrl+Meta+F', toolTip=self.tr('Toggle full screen mode'), statusTip=self.tr('Toggle full screen mode'), triggered=self.toggleFullScreenMode) return actionsgroup
def __init__(self, parent=None, flags=QtCore.Qt.WindowFlags(0), **kwargs): super(PreferencesDialog, self).__init__(parent, flags, **kwargs) self.setupUi(self) self.setWindowIcon(qtsupport.geticon('preferences.svg', __name__)) # remove empty page page = self.stackedWidget.widget(0) self.stackedWidget.removeWidget(page) # app pages icon = qtsupport.geticon('preferences.svg', __name__) self.addPage(GeneralPreferencesPage(), icon, self.tr('General')) #~ icon = qt4support.geticon('harddisk.svg', __name__) #~ self.addPage(CachePreferencesPage(), icon, self.tr('Cache')) assert self.listWidget.count() == self.stackedWidget.count() self.listWidget.currentItemChanged.connect(self.changePage) applybutton = self.buttonBox.button(QtWidgets.QDialogButtonBox.Apply) applybutton.clicked.connect(self.apply)
def __init__(self, parent=None, flags=QtCore.Qt.WindowFlags(0), **kwargs): super().__init__(parent, flags, **kwargs) self.setupUi(self) self.setWindowIcon(qtsupport.geticon('preferences.svg', __name__)) # remove empty page page = self.stackedWidget.widget(0) self.stackedWidget.removeWidget(page) # app pages icon = qtsupport.geticon('preferences.svg', __name__) self.addPage(GeneralPreferencesPage(), icon, self.tr('General')) # icon = qtsupport.geticon('harddisk.svg', __name__) # self.addPage(CachePreferencesPage(), icon, self.tr('Cache')) assert self.listWidget.count() == self.stackedWidget.count() self.listWidget.currentItemChanged.connect(self.changePage) applybutton = self.buttonBox.button(QtWidgets.QDialogButtonBox.Apply) applybutton.clicked.connect(self.apply)
class ScrollHandMode(MouseMode): dragmode = QtWidgets.QGraphicsView.ScrollHandDrag cursor = None icon = qtsupport.geticon('hand.svg', __name__) label = 'Scroll hand' name = 'hand' def viewEventFilter(self, obj, event): if event.type() == QtCore.QEvent.Wheel: # @COMPATIBILITY: Qt4 --> Qt5 # Delta is expressed in 1/8 degree try: delta = event.angleDelta().y() / 8. # degree except AttributeError: delta = event.delta() / 8. # degree if delta == 0: event.accept() return True # Conversion from degrees to zoom factor if abs(delta) < 15: # fine resolution mouse k = 1.1 / abs(delta) else: # a factor of 1.1 every 15 degrees k = 1.1 / 15. if delta >= 0: factor = k * delta else: factor = -1 / (k * delta) obj.scale(factor, factor) event.accept() return True else: event.ignore() return False def scrollbarEventFilter(self, obj, event): # ignore wheel events if event.type() == QtCore.QEvent.Wheel: return True else: return False
def _setupActions(self): actions = QtWidgets.QActionGroup(self) # Zoom in icon = qtsupport.geticon('zoom-in.svg', 'gsdview') QtWidgets.QAction( icon, self.tr('Zoom In'), actions, objectName='zoomOutAction', statusTip=self.tr('Zoom In'), shortcut=QtGui.QKeySequence(self.tr('Ctrl++')), enabled=False, triggered=lambda: self._zoom(+1)) # Zoom out icon = qtsupport.geticon('zoom-out.svg', 'gsdview') QtWidgets.QAction( icon, self.tr('Zoom Out'), actions, objectName='zoomOutAction', statusTip=self.tr('Zoom Out'), shortcut=QtGui.QKeySequence(self.tr('Ctrl+-')), enabled=False, triggered=lambda: self._zoom(-1)) return actions
def _setupSubDatasetItemActions(self, actionsgroup=None): if actionsgroup is None: actionsgroup = QtWidgets.QActionGroup(self) # open icon = qtsupport.geticon('open.svg', __name__) QtWidgets.QAction( icon, self.tr('Open Sub Dataset'), actionsgroup, objectName='actionOpenSubDatasetItem', shortcut=self.tr('Ctrl+O'), toolTip=self.tr('Open Sub Dataset'), statusTip=self.tr('Open Sub Dataset'), triggered=self.openSubDataset) self._setupDatasetItemActions(actionsgroup) return actionsgroup
def __init__(self, contents='', mode=QtWidgets.QFileDialog.AnyFile, dialog=None, parent=None, flags=QtCore.Qt.WindowFlags(0), **kwargs): QtWidgets.QWidget.__init__(self, parent, flags, **kwargs) self.__completer = QtWidgets.QCompleter(self) # @TODO: use QFileSystemModel instraed # model = QtWidgets.QFileSystemModel(self.__completer) model = QtWidgets.QDirModel(self.__completer) # model.setFilter(QtCore.QDir.AllEntries) # self.completer.setCompletionMode( # QtWidgets.QCompleter.InlineCompletion) self.__completer.setModel(model) self.lineEdit = QtWidgets.QLineEdit() self.lineEdit.setCompleter(self.__completer) if contents: self.lineEdit.setText(contents) icon = qtsupport.geticon('open.svg', __name__) self.button = QtWidgets.QPushButton( icon, '', toolTip=self.tr('select from file dialog')) layout = QtWidgets.QHBoxLayout() layout.addWidget(self.lineEdit) layout.addWidget(self.button) layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) self._mode = None self.mode = mode self.dialog = dialog # if not self.dialog: # self.dialog = get_filedialog(self) self.button.clicked.connect(self.choose)
def _setupBandItemActions(self, actionsgroup=None): if actionsgroup is None: actionsgroup = QtWidgets.QActionGroup(self) # open image view icon = qtsupport.geticon('open.svg', __name__) QtWidgets.QAction( icon, self.tr('&Open Image View'), actionsgroup, objectName='actionOpenImageView', shortcut=self.tr('Ctrl+O'), toolTip=self.tr('Open an image view'), statusTip=self.tr('Open a new image view'), triggered=self.openImageView) # @TODO: add a new action for newImageView # @TODO: Masked bands, Compute statistics, Compute histogram # @TODO: dataset --> Build overviews self._setupMajorObjectItemActions(actionsgroup) return actionsgroup
def _setupHelpActions(self): actionsgroup = QtWidgets.QActionGroup(self) # About icon = qtsupport.geticon('about.svg', __name__) QtWidgets.QAction( icon, self.tr('&About'), actionsgroup, objectName='aboutAction', toolTip=self.tr('Show program information'), statusTip=self.tr('Show program information'), triggered=lambda: self.aboutdialog.exec_()) # AboutQt icon = QtGui.QIcon.fromTheme(':qtlogo-64') QtWidgets.QAction( icon, self.tr('About &Qt'), actionsgroup, objectName='aboutQtAction', toolTip=self.tr('Show information about Qt'), statusTip=self.tr('Show information about Qt'), triggered=lambda: QtWidgets.QMessageBox.aboutQt(self)) return actionsgroup
class RubberBandMode(MouseMode): '''Mouse mode for rubber band selection. :SIGNALS: * :attr:`rubberBandSeclection` ''' dragmode = QtWidgets.QGraphicsView.RubberBandDrag cursor = QtCore.Qt.CrossCursor icon = qtsupport.geticon('area.svg', __name__) label = 'Rubber band' name = 'rubberband' #: SIGNAL: it is emitted when a rectangular area is selected #: #: :C++ signature: `void rubberBandSeclection(const QRectF&)` rubberBandSeclection = QtCore.Signal(QtCore.QRectF) def sceneEventFilter(self, obj, event): if event.type() == QtCore.QEvent.GraphicsSceneMouseRelease: p0 = event.buttonDownScenePos(QtCore.Qt.LeftButton) p1 = event.scenePos() rect = QtCore.QRectF(p0, p1).normalized() self.rubberBandSeclection.emit(rect) return True #return obj.eventFilter(obj, event) # @TODO: check #return QtWidgets.QGraphicsScene.eventFilter(self, obj, event) return False def scrollbarEventFilter(self, obj, event): # ignore wheel events if some button is pressed if ((event.type() == QtCore.QEvent.Wheel) and (event.buttons() != QtCore.Qt.NoButton)): return True else: return False
def __init__(self, contents='', mode=QtWidgets.QFileDialog.AnyFile, dialog=None, parent=None, flags=QtCore.Qt.WindowFlags(0), **kwargs): QtWidgets.QWidget.__init__(self, parent, flags, **kwargs) self.__completer = QtWidgets.QCompleter(self) # @TODO: use QFileSystemModel instraed #model = QtWidgets.QFileSystemModel(self.__completer) model = QtWidgets.QDirModel(self.__completer) #model.setFilter(QtCore.QDir.AllEntries) #self.completer.setCompletionMode( # QtWidgets.QCompleter.InlineCompletion) self.__completer.setModel(model) self.lineEdit = QtWidgets.QLineEdit() self.lineEdit.setCompleter(self.__completer) if contents: self.lineEdit.setText(contents) icon = qtsupport.geticon('open.svg', __name__) self.button = QtWidgets.QPushButton( icon, '', toolTip=self.tr('select from file dialog')) layout = QtWidgets.QHBoxLayout() layout.addWidget(self.lineEdit) layout.addWidget(self.button) layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) self._mode = None self.mode = mode self.dialog = dialog #~ if not self.dialog: #~ self.dialog = get_filedialog(self) self.button.clicked.connect(self.choose)
def createActions(self): style = QtWidgets.QApplication.style() icon = style.standardIcon(style.SP_FileIcon) self.newAct = QtWidgets.QAction(icon, self.tr('&New'), self, shortcut=self.tr('Ctrl+N'), statusTip=self.tr('Create a new file'), triggered=self.newFile) icon = style.standardIcon(style.SP_DialogOpenButton) self.openAct = QtWidgets.QAction( icon, self.tr('&Open...'), self, shortcut=self.tr('Ctrl+O'), statusTip=self.tr('Open an existing file'), triggered=self.open) icon = style.standardIcon(style.SP_DialogSaveButton) self.saveAct = QtWidgets.QAction( icon, self.tr('&Save'), self, shortcut=self.tr('Ctrl+S'), statusTip=self.tr('Save the document to disk'), triggered=self.save) self.saveAsAct = QtWidgets.QAction( self.tr('Save &As...'), self, statusTip=self.tr('Save the document under a new name'), triggered=self.saveAs) self.exitAct = QtWidgets.QAction( self.tr('E&xit'), self, shortcut=self.tr('Ctrl+Q'), statusTip=self.tr('Exit the application'), triggered=self.close) icon = geticon('cut.svg', 'gsdview') self.cutAct = QtWidgets.QAction( icon, self.tr('Cu&t'), self, shortcut=self.tr('Ctrl+X'), statusTip=self.tr("Cut the current selection's contents to the " "clipboard"), triggered=self.cut) icon = geticon('copy.svg', 'gsdview.gdalbackend') self.copyAct = QtWidgets.QAction( icon, self.tr('&Copy'), self, shortcut=self.tr("Ctrl+C"), statusTip=self.tr("Copy the current selection's contents to the " "clipboard"), triggered=self.copy) icon = geticon('paste.svg', 'gsdview') self.pasteAct = QtWidgets.QAction( icon, self.tr('&Paste'), self, shortcut=self.tr("Ctrl+V"), statusTip=self.tr("Paste the clipboard's contents into the " "current selection"), triggered=self.paste) self.aboutAct = QtWidgets.QAction( self.tr('&About'), self, statusTip=self.tr("Show the application's About box"), triggered=self.about) self.aboutQtAct = QtWidgets.QAction( self.tr('About &Qt'), self, statusTip=self.tr("Show the Qt library's About box"), triggered=QtWidgets.QApplication.aboutQt)
def init(app): import os import sys import logging from osgeo import gdal from gsdview import utils from gsdview import qtsupport from gsdview.gdalbackend import widgets from gsdview.gdalbackend import gdalsupport _log = logging.getLogger(__name__) # @TODO: check #UseExceptions() # set file dialog filters app.filedialog.setNameFilters(gdalsupport.gdalFilters()) # update versions info in about dialog app.aboutdialog.addSoftwareVersion('GDAL', gdal.VersionInfo('RELEASE_NAME'), 'http://www.gdal.org') # GDAL icon icon = qtsupport.geticon('GDALLogoColor.svg', __name__) # update the settings dialog #page = widgets.GDALPreferencesPage(app.preferencesdialog) page = widgets.BackendPreferencesPage(app.preferencesdialog) app.preferencesdialog.addPage(page, icon, 'GDAL') # add a new page in the about dialog page = widgets.GDALInfoWidget(app.aboutdialog) tabindex = app.aboutdialog.tabWidget.addTab(page, icon, 'GDAL') widget = app.aboutdialog.tabWidget.widget(tabindex) widget.setObjectName('gdalTab') # @TODO: check # register the backend app.backends.append(name) global _backendobj _backendobj = GDALBackend(app) # @TODO: fix #~ gdal.SetConfigOption('GDAL_PAM_ENABLED', 'YES') #~ gdal.SetConfigOption('GDAL_PAM_PROXY_DIR', #~ os.path.expanduser(os.path.join('~', '.gsdview', #~ 'cache'))) # @TODO: fix # @NOTE: explicitly disable GDAL exceptions due to bug #3077 # (http://trac.osgeo.org/gdal/ticket/3077) #UseExceptions() DontUseExceptions() # Fix path for GDAL tools if getattr(sys, 'frozen', False): from gsdview import appsite os.environ['PATH'] = os.pathsep.join( (appsite.GSDVIEWROOT, os.getenv('PATH', ''))) gdal.SetConfigOption('GDAL_DATA', os.path.join(appsite.GSDVIEWROOT, 'data')) # @TODO: check #if app.settings.value('GDAL_DATA').isValid(): # msg = app.tr('"GDAL_DATA" from the user configuration file ' # 'overrides the default value') # QtWidgets.QMessageBox.warning(app, app.tr('WARNING'), msg) elif sys.platform == 'darwin': gdaladdobin = utils.which('gdaladdo') if not gdaladdobin: frameworkroot = os.path.join(os.path.dirname(gdal.__file__), os.pardir, os.pardir, os.pardir) frameworkroot = os.path.abspath(frameworkroot) binpath = os.path.join(frameworkroot, 'unix', 'bin') PATH = os.getenv('PATH', '') if binpath not in PATH: PATH = os.pathsep.join((binpath, PATH)) os.environ['PATH'] = PATH _log.info('GDAL binary path added to system path: %s', binpath) #elif sys.platform[:3] == 'win': # gdaladdobin = utils.which('gdaladdo') # if not gdaladdobin: # pass return _backendobj
def update_view(self): self.pathListWidget.clear() for item in self.pluginmanager.paths: self.pathListWidget.addItem(item) self.pluginmanager.load(self.pluginmanager.allplugins, info_only=True) tablewidget = self.pluginsTableWidget tablewidget.clear() tablewidget.setRowCount(0) tablewidget.setHorizontalHeaderLabels([self.tr('Name'), self.tr('Description'), self.tr('Info'), self.tr('Active'), self.tr('Load on startup')]) for plugin in self.pluginmanager.allplugins: name = plugin short_description = tablewidget.tr('NOT AVAILABLE') disabled = False for dict_ in (self.pluginmanager.plugins, sys.modules): try: module = dict_[name] name = module.name short_description = module.short_description break except AttributeError as e: msg = str(e) if ("'name'" not in msg and "'short_description'" not in msg): raise disabled = True except KeyError: disabled = True index = tablewidget.rowCount() tablewidget.insertRow(index) # name/description tablewidget.setItem(index, 0, QtWidgets.QTableWidgetItem(name)) tablewidget.setItem(index, 1, QtWidgets.QTableWidgetItem(short_description)) # info icon = qtsupport.geticon('info.svg', __name__) w = QtWidgets.QPushButton( icon, '', tablewidget, toolTip=self.tr('Show plugin info.'), clicked=functools.partial(self.showPluginInfo, index)) #clicked=lambda index=index: self.showPluginInfo(index)) tablewidget.setCellWidget(index, 2, w) # active checked = bool(plugin in self.pluginmanager.plugins) w = QtWidgets.QCheckBox(tablewidget, checked=checked) tablewidget.setCellWidget(index, 3, w) # TODO: remove this block when plugins unloading will be # available if w.isChecked(): w.setEnabled(False) # autoload checked = bool(plugin in self.pluginmanager.autoload) w = QtWidgets.QCheckBox( tablewidget, checked=checked, toolTip=self.tr('Load on startup')) tablewidget.setCellWidget(index, 4, w) if disabled: for col in range(tablewidget.columnCount() - 1): item = tablewidget.item(index, col) if item: item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled) msg = tablewidget.tr("Plugin don't seems to be " "compatible with GSDView.") item.setToolTip(msg) else: w = tablewidget.cellWidget(index, col) w.setEnabled(False) tablewidget.resizeColumnsToContents()
class PointerMode(MouseMode): dragmode = QtWidgets.QGraphicsView.NoDrag cursor = None icon = qtsupport.geticon('arrow.svg', __name__) label = 'Pointer' name = 'pointer'
def update_view(self): self.pathListWidget.clear() for item in self.pluginmanager.paths: self.pathListWidget.addItem(item) self.pluginmanager.load(self.pluginmanager.allplugins, info_only=True) tablewidget = self.pluginsTableWidget tablewidget.clear() tablewidget.setRowCount(0) tablewidget.setHorizontalHeaderLabels([ self.tr('Name'), self.tr('Description'), self.tr('Info'), self.tr('Active'), self.tr('Load on startup') ]) for plugin in self.pluginmanager.allplugins: name = plugin short_description = tablewidget.tr('NOT AVAILABLE') disabled = False for dict_ in (self.pluginmanager.plugins, sys.modules): try: module = dict_[name] name = module.name short_description = module.short_description break except AttributeError as e: msg = str(e) if ("'name'" not in msg and "'short_description'" not in msg): raise disabled = True except KeyError: disabled = True index = tablewidget.rowCount() tablewidget.insertRow(index) # name/description tablewidget.setItem(index, 0, QtWidgets.QTableWidgetItem(name)) tablewidget.setItem(index, 1, QtWidgets.QTableWidgetItem(short_description)) # info icon = qtsupport.geticon('info.svg', __name__) w = QtWidgets.QPushButton(icon, '', tablewidget, toolTip=self.tr('Show plugin info.'), clicked=functools.partial( self.showPluginInfo, index)) #clicked=lambda index=index: self.showPluginInfo(index)) tablewidget.setCellWidget(index, 2, w) # active checked = bool(plugin in self.pluginmanager.plugins) w = QtWidgets.QCheckBox(tablewidget, checked=checked) tablewidget.setCellWidget(index, 3, w) # TODO: remove this block when plugins unloading will be # available if w.isChecked(): w.setEnabled(False) # autoload checked = bool(plugin in self.pluginmanager.autoload) w = QtWidgets.QCheckBox(tablewidget, checked=checked, toolTip=self.tr('Load on startup')) tablewidget.setCellWidget(index, 4, w) if disabled: for col in range(tablewidget.columnCount() - 1): item = tablewidget.item(index, col) if item: item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled) msg = tablewidget.tr("Plugin don't seems to be " "compatible with GSDView.") item.setToolTip(msg) else: w = tablewidget.cellWidget(index, col) w.setEnabled(False) tablewidget.resizeColumnsToContents()
def __init__(self, parent=None, flags=QtCore.Qt.WindowFlags(0), **kwargs): loglevel = kwargs.pop('loglevel', logging.NOTSET) _log.debug('Main window base classes initialization ...') QtWidgets.QApplication.setWindowIcon( qtsupport.geticon('GSDView.png', __name__)) super(GSDView, self).__init__(parent, flags, **kwargs) title = self.tr('GSDView Open Source Edition v. %s') % info.version self.setWindowTitle(title) self.setObjectName('gsdview-mainwin') # Dialogs _log.debug('Setting up file dialog ...') #: application global file dialog instance self.filedialog = QtWidgets.QFileDialog(self) self.filedialog.setFileMode(QtWidgets.QFileDialog.ExistingFile) self.filedialog.setViewMode(QtWidgets.QFileDialog.Detail) _log.debug('Setting up the about dialog ...') #: application global about dialog instance self.aboutdialog = AboutDialog(self) _log.debug('Setting up the preferences dialog ...') #: prefernces dialog instance self.preferencesdialog = PreferencesDialog(self, apply=self.applySettings) # Stop button _log.debug('Setting up the stop button ...') qstyle = QtWidgets.QApplication.style() icon = qstyle.standardIcon(QtWidgets.QStyle.SP_BrowserStop) #: stop button for external tools self.stopbutton = QtWidgets.QPushButton(icon, self.tr('Stop'), self) self.statusBar().addPermanentWidget(self.stopbutton) self.stopbutton.hide() # Progressbar _log.debug('Setting up the progress bar ...') #: application progress bar self.progressbar = QtWidgets.QProgressBar(self) self.progressbar.setTextVisible(True) self.statusBar().addPermanentWidget(self.progressbar) self.progressbar.hide() # Miscellanea _log.debug('Miscellanea setup ...') #: cache directory path self.cachedir = None # GraphicsViewMonitor and mouse manager _log.debug('Setting up "monitor" components ...') #: graphics scenes/views monitor self.monitor = graphicsview.GraphicsViewMonitor() #: mouse manager for graphics scenes/views self.mousemanager = mousemanager.MouseManager(self) self.mousemanager.mode = 'hand' # Plugin Manager #: backends list self.backends = [] #: plugin manager instance self.pluginmanager = pluginmanager.PluginManager(self, SYSPLUGINSDIR) self.preferencesdialog.addPage( pluginmanager.PluginManagerGui(self.pluginmanager, self), qtsupport.geticon('plugin.svg', __name__), label='Plugins') # Settings if not os.path.isdir(USERCONFIGDIR): os.makedirs(USERCONFIGDIR) # @TODO: fix filename _log.debug('Read application settings ...') #self.settings = QtCore.QSettings('gsdview-soft', 'gsdview', self) #self.settings = QtCore.QSettings(QtCore.QSettings.IniFormat, # QtCore.QSettings.UserScope, # 'gsdview', 'gsdview', self) cfgfile = os.path.join(USERCONFIGDIR, 'gsdview.ini') _log.info('Configuration file: "%s".', cfgfile) #: application settings self.settings = QtCore.QSettings(cfgfile, QtCore.QSettings.IniFormat, self) # Setup the log system and the external tools controller _log.debug('Complete logging setup...') # @TODO: logevel could be set from command line #: application standard logger self.logger = self.setupLogging(loglevel=loglevel) _log.debug('Setting up external tool controller ...') #: external tool controller self.controller = self.setupController(self.logger, self.statusBar(), self.progressbar) # Actions _log.debug('Setting up actions ...') #: actions associated to file menu self.fileActions = None #: settings actions self.settingsActions = None #: help actions self.helpActions = None self.setupActions() # File menu end toolbar self._addMenuFromActions(self.fileActions, self.tr('&File')) self._addToolBarFromActions(self.fileActions, self.tr('File toolbar')) # Image menu and toolbar self.imagemenu = self._addMenuFromActions(self.mousemanager.actions, self.tr('&Image')) self._addToolBarFromActions(self.mousemanager.actions, self.tr('Mouse toolbar')) # Tools menu self.toolsmenu = QtWidgets.QMenu(self.tr('&Tools'), self) self.menuBar().addMenu(self.toolsmenu) self.toolsmenu.hide() # Setup plugins _log.debug(self.tr('Setup plugins ...')) self.setupPlugins() # Settings menu end toolbar _log.debug(self.tr('Settings menu setup ...')) menu = self._addMenuFromActions(self.settingsActions, self.tr('&Settings')) self._addToolBarFromActions(self.settingsActions, self.tr('Settings toolbar')) #: settings sub-menu self.settings_submenu = QtWidgets.QMenu( self.tr('&View'), aboutToShow=self.updateSettingsMenu) menu.addSeparator() menu.addMenu(self.settings_submenu) _log.debug(self.tr('Window menu setup ...')) self.menuBar().addMenu(self.windowmenu) # Help menu end toolbar _log.debug('Help menu setup ...') self._addMenuFromActions(self.helpActions, self.tr('&Help')) self._addToolBarFromActions(self.helpActions, self.tr('Help toolbar')) # @NOTE: the window state setup must happen after the plugins loading _log.info('Load settings ...') self.loadSettings(loglevel=loglevel) # @TODO: pass cachedir self.treeview.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.treeview.customContextMenuRequested.connect(self.itemContextMenu) self.statusBar().showMessage('Ready')
def createActions(self): style = QtWidgets.QApplication.style() icon = style.standardIcon(style.SP_FileIcon) self.newAct = QtWidgets.QAction( icon, self.tr('&New'), self, shortcut=self.tr('Ctrl+N'), statusTip=self.tr('Create a new file'), triggered=self.newFile) icon = style.standardIcon(style.SP_DialogOpenButton) self.openAct = QtWidgets.QAction( icon, self.tr('&Open...'), self, shortcut=self.tr('Ctrl+O'), statusTip=self.tr('Open an existing file'), triggered=self.open) icon = style.standardIcon(style.SP_DialogSaveButton) self.saveAct = QtWidgets.QAction( icon, self.tr('&Save'), self, shortcut=self.tr('Ctrl+S'), statusTip=self.tr('Save the document to disk'), triggered=self.save) self.saveAsAct = QtWidgets.QAction( self.tr('Save &As...'), self, statusTip=self.tr('Save the document under a new name'), triggered=self.saveAs) self.exitAct = QtWidgets.QAction( self.tr('E&xit'), self, shortcut=self.tr('Ctrl+Q'), statusTip=self.tr('Exit the application'), triggered=self.close) icon = geticon('cut.svg', 'gsdview') self.cutAct = QtWidgets.QAction( icon, self.tr('Cu&t'), self, shortcut=self.tr('Ctrl+X'), statusTip=self.tr("Cut the current selection's contents to the " "clipboard"), triggered=self.cut) icon = geticon('copy.svg', 'gsdview.gdalbackend') self.copyAct = QtWidgets.QAction( icon, self.tr('&Copy'), self, shortcut=self.tr("Ctrl+C"), statusTip=self.tr("Copy the current selection's contents to the " "clipboard"), triggered=self.copy) icon = geticon('paste.svg', 'gsdview') self.pasteAct = QtWidgets.QAction( icon, self.tr('&Paste'), self, shortcut=self.tr("Ctrl+V"), statusTip=self.tr("Paste the clipboard's contents into the " "current selection"), triggered=self.paste) self.aboutAct = QtWidgets.QAction( self.tr('&About'), self, statusTip=self.tr("Show the application's About box"), triggered=self.about) self.aboutQtAct = QtWidgets.QAction( self.tr('About &Qt'), self, statusTip=self.tr("Show the Qt library's About box"), triggered=QtWidgets.QApplication.aboutQt)
def init(app): import os import sys import logging from osgeo import gdal from gsdview import utils from gsdview import qtsupport from gsdview.gdalbackend import widgets from gsdview.gdalbackend import gdalsupport _log = logging.getLogger(__name__) # @TODO: check #UseExceptions() # set file dialog filters app.filedialog.setNameFilters(gdalsupport.gdalFilters()) # update versions info in about dialog app.aboutdialog.addSoftwareVersion( 'GDAL', gdal.VersionInfo('RELEASE_NAME'), 'http://www.gdal.org') # GDAL icon icon = qtsupport.geticon('GDALLogoColor.svg', __name__) # update the settings dialog #page = widgets.GDALPreferencesPage(app.preferencesdialog) page = widgets.BackendPreferencesPage(app.preferencesdialog) app.preferencesdialog.addPage(page, icon, 'GDAL') # add a new page in the about dialog page = widgets.GDALInfoWidget(app.aboutdialog) tabindex = app.aboutdialog.tabWidget.addTab(page, icon, 'GDAL') widget = app.aboutdialog.tabWidget.widget(tabindex) widget.setObjectName('gdalTab') # @TODO: check # register the backend app.backends.append(name) global _backendobj _backendobj = GDALBackend(app) # @TODO: fix #~ gdal.SetConfigOption('GDAL_PAM_ENABLED', 'YES') #~ gdal.SetConfigOption('GDAL_PAM_PROXY_DIR', #~ os.path.expanduser(os.path.join('~', '.gsdview', #~ 'cache'))) # @TODO: fix # @NOTE: explicitly disable GDAL exceptions due to bug #3077 # (http://trac.osgeo.org/gdal/ticket/3077) #UseExceptions() DontUseExceptions() # Fix path for GDAL tools if getattr(sys, 'frozen', False): from gsdview import appsite os.environ['PATH'] = os.pathsep.join((appsite.GSDVIEWROOT, os.getenv('PATH', ''))) gdal.SetConfigOption('GDAL_DATA', os.path.join(appsite.GSDVIEWROOT, 'data')) # @TODO: check #if app.settings.value('GDAL_DATA').isValid(): # msg = app.tr('"GDAL_DATA" from the user configuration file ' # 'overrides the default value') # QtWidgets.QMessageBox.warning(app, app.tr('WARNING'), msg) elif sys.platform == 'darwin': gdaladdobin = utils.which('gdaladdo') if not gdaladdobin: frameworkroot = os.path.join(os.path.dirname(gdal.__file__), os.pardir, os.pardir, os.pardir) frameworkroot = os.path.abspath(frameworkroot) binpath = os.path.join(frameworkroot, 'unix', 'bin') PATH = os.getenv('PATH', '') if binpath not in PATH: PATH = os.pathsep.join((binpath, PATH)) os.environ['PATH'] = PATH _log.info('GDAL binary path added to system path: %s', binpath) #elif sys.platform[:3] == 'win': # gdaladdobin = utils.which('gdaladdo') # if not gdaladdobin: # pass return _backendobj