Skip to content
Snippets Groups Projects
widgets.py 7.18 KiB
Newer Older
  • Learn to ignore specific revisions
  • /***************************************************************************
    
                                  HUB TimeSeriesViewer
                                  -------------------
            begin                : 2017-08-04
            git sha              : $Format:%H$
            copyright            : (C) 2017 by HU-Berlin
            email                : benjamin.jakimow@geo.hu-berlin.de
    
     ***************************************************************************/
    
    
    /***************************************************************************
     *                                                                         *
     *   This program is free software; you can redistribute it and/or modify  *
     *   it under the terms of the GNU General Public License as published by  *
     *   the Free Software Foundation; either version 2 of the License, or     *
     *   (at your option) any later version.                                   *
     *                                                                         *
     ***************************************************************************/
    """
    # noinspection PyPep8Naming
    
    Benjamin Jakimow's avatar
    Benjamin Jakimow committed
    from __future__ import absolute_import, unicode_literals
    
    from qgis.core import *
    from qgis.gui import *
    
    from PyQt4 import uic
    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    
    from PyQt4.QtXml import *
    
    class VerticalLabel(QLabel):
        def __init__(self, text, orientation='vertical', forceWidth=True):
            QLabel.__init__(self, text)
            self.forceWidth = forceWidth
            self.orientation = None
            self.setOrientation(orientation)
    
        def setOrientation(self, o):
            if self.orientation == o:
                return
            self.orientation = o
            self.update()
            self.updateGeometry()
    
        def paintEvent(self, ev):
            p = QPainter(self)
            # p.setBrush(QtGui.QBrush(QtGui.QColor(100, 100, 200)))
            # p.setPen(QtGui.QPen(QtGui.QColor(50, 50, 100)))
            # p.drawRect(self.rect().adjusted(0, 0, -1, -1))
    
            # p.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255)))
    
            if self.orientation == 'vertical':
                p.rotate(-90)
                rgn = QRect(-self.height(), 0, self.height(), self.width())
            else:
                rgn = self.contentsRect()
            align = self.alignment()
            # align  = QtCore.Qt.AlignTop|QtCore.Qt.AlignHCenter
    
            self.hint = p.drawText(rgn, align, self.text())
            p.end()
    
            if self.orientation == 'vertical':
                self.setMaximumWidth(self.hint.height())
                self.setMinimumWidth(0)
                self.setMaximumHeight(16777215)
                if self.forceWidth:
                    self.setMinimumHeight(self.hint.width())
                else:
                    self.setMinimumHeight(0)
            else:
                self.setMaximumHeight(self.hint.height())
                self.setMinimumHeight(0)
                self.setMaximumWidth(16777215)
                if self.forceWidth:
                    self.setMinimumWidth(self.hint.width())
                else:
                    self.setMinimumWidth(0)
    
        def sizeHint(self):
            if self.orientation == 'vertical':
                if hasattr(self, 'hint'):
                    return QSize(self.hint.height(), self.hint.width())
                else:
                    return QSize(19, 50)
            else:
                if hasattr(self, 'hint'):
                    return QSize(self.hint.width(), self.hint.height())
                else:
                    return QSize(50, 19)
    
    
    
    
    
    from timeseriesviewer.utils import loadUI
    
    from timeseriesviewer.main import SpatialExtent, TsvMimeDataUtils
    
    def maxWidgetSizes(layout, onHint=True):
    
        assert isinstance(layout, QBoxLayout)
    
        p = layout.parentWidget()
        m = layout.contentsMargins()
    
        sizeX = 0
        sizeY = 0
        horizontal = isinstance(layout, QHBoxLayout)
    
        for item in [layout.itemAt(i) for i in range(layout.count())]:
            wid = item.widget()
    
            ly = item.layout()
    
                if onHint:
                    s = wid.sizeHint()
                else:
                    s = wid.size()
            elif ly:
                continue
            else:
    
                continue
            if horizontal:
                sizeX += s.width() + layout.spacing()
                sizeY = max([sizeY, s.height()])  + layout.spacing()
            else:
                sizeX = max([sizeX, s.width()])  + layout.spacing()
                sizeY += s.height()  + layout.spacing()
    
    
        return QSize(sizeX + m.left()+ m.right(),
                     sizeY + m.top() + m.bottom())
    
    
    
    
                        loadUI('aboutdialog.ui')):
    
        def __init__(self, parent=None):
            """Constructor."""
            super(AboutDialogUI, self).__init__(parent)
            # Set up the user interface from Designer.
            # After setupUI you can access any designer object by doing
            # self.<objectname>, and you can use autoconnect slots - see
            # http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
            # #widgets-and-dialogs-with-auto-connect
            self.setupUi(self)
    
            self.init()
    
        def init(self):
            self.mTitle = self.windowTitle()
            self.listWidget.currentItemChanged.connect(lambda: self.setAboutTitle())
            self.setAboutTitle()
    
            # page About
    
            from timeseriesviewer import PATH_LICENSE, VERSION, PATH_CHANGELOG
            self.labelVersion.setText('{}'.format(VERSION))
    
            # page Changed
            if os.path.isfile(PATH_CHANGELOG):
                import codecs
                txt = ''.join(codecs.open(PATH_CHANGELOG, encoding='utf-8').readlines())
                self.tbChanges.setText(txt)
    
            # page Licence
            if os.path.isfile(PATH_LICENSE):
                import codecs
                txt = ''.join(codecs.open(PATH_LICENSE, encoding='utf-8').readlines())
                self.tbLicense.setText(txt)
    
    
        def setAboutTitle(self, suffix=None):
            item = self.listWidget.currentItem()
    
            if item:
                title = '{} | {}'.format(self.mTitle, item.text())
            else:
                title = self.mTitle
            if suffix:
                title += ' ' + suffix
            self.setWindowTitle(title)
    
    
    
    Benjamin Jakimow's avatar
    Benjamin Jakimow committed
    
    
    class PropertyDialogUI(QDialog, loadUI('settingsdialog.ui')):
    
    
        def __init__(self, parent=None):
            super(PropertyDialogUI, self).__init__(parent)
            self.setupUi(self)
    
    
    
    if __name__ == '__main__':
        import site, sys
        #add site-packages to sys.path as done by enmapboxplugin.py
    
        from timeseriesviewer import DIR_SITE_PACKAGES
        site.addsitedir(DIR_SITE_PACKAGES)
    
        #prepare QGIS environment
        if sys.platform == 'darwin':
            PATH_QGS = r'/Applications/QGIS.app/Contents/MacOS'
            os.environ['GDAL_DATA'] = r'/usr/local/Cellar/gdal/1.11.3_1/share'
        else:
            # assume OSGeo4W startup
            PATH_QGS = os.environ['QGIS_PREFIX_PATH']
        assert os.path.exists(PATH_QGS)
    
        qgsApp = QgsApplication([], True)
        QApplication.addLibraryPath(r'/Applications/QGIS.app/Contents/PlugIns')
        QApplication.addLibraryPath(r'/Applications/QGIS.app/Contents/PlugIns/qgis')
        qgsApp.setPrefixPath(PATH_QGS, True)
        qgsApp.initQgis()
    
        #run tests