Пример #1
0
 def __init__(self, parent=None):
     super().__init__(
         parent, Qt.WindowSystemMenuHint | Qt.WindowTitleHint
         | Qt.WindowCloseButtonHint)
     self._layoutGran = QVBoxLayout()
     lblExplicacio = QLabel(
         'Trieu quines capes voleu carregar sobre el mapa')
     self._layoutGran.addWidget(lblExplicacio)
     fr = QFrame()
     sc = QScrollArea()
     sc.setWidget(fr)
     sc.setWidgetResizable(True)
     fr.setFrameShape(QFrame.Box)
     fr.setStyleSheet('background: white')
     self._layout = QVBoxLayout()
     fr.setLayout(self._layout)
     self._layoutGran.addWidget(sc)
     bAcceptar = QPushButton('Acceptar')
     bAcceptar.clicked.connect(self.accept)
     bCancelar = QPushButton('Cancelar')
     bCancelar.clicked.connect(self.reject)
     layBotons = QHBoxLayout()
     layBotons.addStretch()
     layBotons.addWidget(bAcceptar)
     layBotons.addWidget(bCancelar)
     self._layoutGran.addLayout(layBotons)
     self.setLayout(self._layoutGran)
     self.setWindowTitle('Tria de les subcapes a carregar')
Пример #2
0
    def __init__(self, summary):
        super().__init__()

        layout = QVBoxLayout()
        layout.setMargin(0)
        layout.addWidget(
            QLabel(
                f"<h3>{PlanetClient.getInstance().item_types_names()[summary['type']]}</h3>"
            ))
        for bundle in summary["bundles"]:
            frame = QFrame()
            framelayout = QVBoxLayout()
            framelayout.addWidget(
                IconLabel(f"{bundle['numitems']} items", NITEMS_ICON))
            framelayout.addWidget(QLabel(f"<b>{bundle['name']}</b>"))
            hlayout = QHBoxLayout()
            hlayout.setMargin(0)
            fileLabel = IconLabel(bundle["filetype"], FILETYPE_ICON)
            hlayout.addWidget(fileLabel)
            if bundle["udm"]:
                udmLabel = IconLabel("UDM2", UDM_ICON)
                hlayout.addWidget(udmLabel)
            if bundle["clipping"]:
                clipLabel = IconLabel("", CLIP_ICON)
                hlayout.addWidget(clipLabel)
            if bundle["harmonize"]:
                harmonizeLabel = IconLabel("", HARMONIZE_ICON)
                hlayout.addWidget(harmonizeLabel)
            hlayout.addStretch()
            framelayout.addLayout(hlayout)
            frame.setLayout(framelayout)
            frame.setFrameStyle(QFrame.Panel | QFrame.Raised)
            layout.addWidget(frame)
        layout.addStretch()
        self.setLayout(layout)
    def initGui(self):
        hlayout = QHBoxLayout()
        layout = QVBoxLayout()
        self.searchBox = QLineEdit()
        self.searchBox.returnPressed.connect(self.search)
        self.searchBox.setPlaceholderText("[Enter search string and press enter to search for maps]")
        hlayout.addWidget(self.searchBox)

        self.button = QToolButton()
        self.button.setText("Search")
        self.button.clicked.connect(self.search)
        self.button.adjustSize()
        self.searchBox.setFixedHeight(self.button.height())
        hlayout.addWidget(self.button)
        layout.addLayout(hlayout)

        w = QFrame()
        self.browser = QWebView()
        w.setStyleSheet("QFrame{border:1px solid rgb(0, 0, 0);}")
        innerlayout = QHBoxLayout()
        innerlayout.setSpacing(0)
        innerlayout.setMargin(0)
        innerlayout.addWidget(self.browser)
        w.setLayout(innerlayout)
        layout.addWidget(w)
        self.setLayout(layout)

        self.browser.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
        self.browser.settings().setUserStyleSheetUrl(QUrl("file://" + resourceFile("search.css").replace("\\", "/")))
        self.browser.linkClicked.connect(self.linkClicked)
        self.resize(600, 500)
        self.setWindowTitle("Search stories")
Пример #4
0
    def update_history_view(self):
        """Update the history view."""
        historic_folder = query_historic()
        files = os.listdir(historic_folder)

        self.dialog.list_historic.clear()

        for file in files[::-1]:
            file_path = join(historic_folder, file)
            with open(file_path, encoding='utf8') as json_file:
                data = json.load(json_file, object_hook=as_enum)
            name = data['file_name']

            item = QListWidgetItem(self.dialog.list_historic)
            self.dialog.list_historic.addItem(item)

            group = QFrame()
            group.setFrameStyle(QFrame.StyledPanel)
            group.setStyleSheet('QFrame { margin: 3px; }')
            group.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
            hbox = QHBoxLayout()
            vbox = QVBoxLayout()
            label_name = QLabel(name)
            label_name.setStyleSheet('font-weight: bold;')
            label_name.setWordWrap(True)
            vbox.addWidget(label_name)
            for label in data['description']:
                if not label:
                    label = tr('No description')
                real_label = QLabel(label)
                real_label.setWordWrap(True)
                vbox.addWidget(real_label)
            hbox.addItem(vbox)
            button_run = QPushButton()
            button_save = QPushButton()
            button_run.setIcon(QIcon(QgsApplication.iconPath("mActionStart.svg")))
            button_save.setIcon(QIcon(QgsApplication.iconPath("mActionFileSave.svg")))
            button_run.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
            button_save.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
            button_run.setToolTip(tr('Run the query'))
            button_save.setToolTip(tr('Save this query in a new preset'))
            hbox.addWidget(button_run)
            hbox.addWidget(button_save)
            group.setLayout(hbox)

            # Actions on click
            run = partial(self.run_saved_query, data)
            button_run.clicked.connect(run)
            save = partial(self.save_history_preset, data)
            button_save.clicked.connect(save)

            item.setSizeHint(group.minimumSizeHint())
            self.dialog.list_historic.setItemWidget(item, group)
Пример #5
0
    def __init__(self, table):
        QWidget.__init__(self)

        layout = QVBoxLayout()

        hlayout = QHBoxLayout()
        l = QLabel(table.name())
        font = l.font()
        font.setBold(True)
        l.setFont(font)

        hlayout.addWidget(l)
        open_table_btn = QToolButton()
        icon = QIcon(os.path.dirname(__file__) + "/mActionOpenTableGML.svg")
        open_table_btn.setIcon(icon)
        open_table_btn.resize(32, 32)
        open_table_btn.clicked.connect(
            lambda checked: self.linkActivated.emit(table.name())
        )
        hlayout.addWidget(open_table_btn)

        f = QFrame()
        f.setFrameStyle(QFrame.Panel | QFrame.Plain)
        f.setLineWidth(2.0)
        f.setLayout(hlayout)

        layout.addWidget(f)

        self.attribute_label = QLabel()
        names = [f.name() for f in table.columns()]
        names += [l.name() + "_id" for l in table.links() if l.max_occurs() == 1]
        names += [l.ref_table().name() + "_id" for l in table.back_links()]

        self.attribute_label.setText("\n".join(names))
        v2 = QVBoxLayout()
        v2.addWidget(self.attribute_label)

        self.attribute_frame = QFrame()
        self.attribute_frame.setFrameStyle(QFrame.Panel | QFrame.Plain)
        self.attribute_frame.setLineWidth(2.0)
        self.attribute_frame.setLayout(v2)
        layout.addWidget(self.attribute_frame)

        self.setLayout(layout)

        fm = QFontMetricsF(self.attribute_label.font())
        self.__font_height = fm.height()
        margins = layout.contentsMargins()

        self.attribute_x_offset = margins.left()
        self.attribute_x2_offset = margins.right()
Пример #6
0
    def setup_default_preset(self):
        """Setup the display of presets"""
        preset_folder = resources_path('map_preset')
        folders = os.listdir(preset_folder)

        for folder_name in folders:
            file_path = join(preset_folder, folder_name, folder_name + '.json')
            with open(file_path, encoding='utf8') as json_file:
                data = json.load(json_file, object_hook=as_enum)

            item = QListWidgetItem(self.dialog.list_default_mp)
            item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable
                          | Qt.ItemIsEnabled)
            self.dialog.list_default_mp.addItem(item)

            widget = QFrame()
            widget.setFrameStyle(QFrame.StyledPanel)
            widget.setStyleSheet('QFrame { margin: 3px; };')
            widget.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
            hbox = QHBoxLayout()
            vbox = QVBoxLayout()
            picture = QLabel()
            icon_path = resources_path('map_preset', folder_name,
                                       folder_name + '_icon.png')
            if not os.path.isfile(icon_path):
                icon_path = resources_path('icons', 'QuickOSM.svg')
            icon = QPixmap(icon_path)
            icon.scaled(QSize(150, 250), Qt.KeepAspectRatio)
            picture.setPixmap(icon)
            picture.setStyleSheet(
                'max-height: 150px; max-width: 250px; margin-right: 50px;')
            hbox.addWidget(picture)
            title = QLabel(data['file_name'])
            title.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
            title.setStyleSheet('font: bold 20px; margin-bottom: 25px;')
            vbox.addWidget(title)
            for label in data['description']:
                if not label:
                    label = tr('No description')
                real_label = QLabel(label)
                real_label.setWordWrap(True)
                vbox.addWidget(real_label)
            hbox.addItem(vbox)
            widget.setLayout(hbox)

            item.setSizeHint(widget.minimumSizeHint())
            self.dialog.list_default_mp.setItemWidget(item, widget)
Пример #7
0
class HtmlViewerWidget(QWidget):
    def __init__(self, parent):
        super(HtmlViewerWidget, self).__init__(parent)
        self.setLayout(QGridLayout())
        self.layout().setContentsMargins(0, 0, 0, 0)
        self.view = QWebView()
        self.view.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
        self.frame = QFrame()
        self.frame.setLayout(QGridLayout())
        self.frame.layout().setContentsMargins(0, 0, 0, 0)

        self.toolbar = QToolBar()
        self.spacer = QWidget()
        self.spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.copyAction = self.toolbar.addAction(QIcon(":/icons/clipboard"),
                                                 "Copy Text")
        self.label = QLabel()
        self.closeAction = QPushButton(QIcon(":/icons/cancel"), "Close", self)
        self.spaceraction = self.toolbar.insertWidget(None, self.spacer)
        self.labelaction = self.toolbar.insertWidget(self.spaceraction,
                                                     self.label)
        self.closeAction.pressed.connect(self.close)
        self.copyAction.triggered.connect(self.copy_text)
        self.layout().addWidget(self.frame)
        self.frame.layout().addWidget(self.toolbar)
        self.frame.layout().addWidget(self.view)
        self.frame.layout().addWidget(self.closeAction)

        self.effect = QGraphicsOpacityEffect()
        self.label.setGraphicsEffect(self.effect)
        self.anim = QPropertyAnimation(self.effect, "opacity".encode("utf-8"))
        self.anim.setDuration(2000)
        self.anim.setStartValue(1.0)
        self.anim.setEndValue(0.0)
        self.anim.setEasingCurve(QEasingCurve.OutQuad)

    def copy_text(self):
        self.label.setText("Copied to clipboard")
        text = self.view.page().mainFrame().toPlainText()
        QApplication.clipboard().setText(text)
        self.anim.stop()
        self.anim.start()

    def showHTML(self, template, level, **data):
        html = templates.render_tample(template, **data)
        self.view.setHtml(html, templates.baseurl)
Пример #8
0
    def draw(self, layout: QLayout, edit: bool = False):
        '''
        draw parameter in given layout

        Parameters
        ----------
        layout : QBoxLayout
            layout to append the drawn parameter to
        edit : bool, optional
            edit mode displaying the label and input of parameter if True,
            else label and (uneditable) value, by default False
        '''
        if edit and not self.input:
            return
        self.row = QHBoxLayout()
        label = QLabel(self.label)
        spacer = QFrame()
        spacer_layout = QHBoxLayout()
        spacer_layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding))
        spacer.setLayout(spacer_layout)
        # dotted line in preview
        if not edit:
            spacer.setFrameShape(QFrame.StyledPanel)
            spacer.setStyleSheet('border-width: 1px; border-style: none; '
                                 'border-bottom-style: dotted;'
                                 'border-color: grey;')
        if isinstance(layout, QGridLayout):
            n_rows = layout.rowCount()
            layout.addWidget(label, n_rows, 0)
            layout.addWidget(spacer, n_rows, 1)
            layout.addLayout(self.row, n_rows, 2)
        else:
            self.row.addWidget(label)
            self.row.addWidget(spacer)
            layout.addLayout(self.row)
        if edit:
            self.input.draw(self.row, unit=self.unit)
        else:
            self.row.addWidget(self._value_label)
            if self.unit:
                unit_label = QLabel(self.unit)
                self.row.addWidget(unit_label)
Пример #9
0
    def show(self, *args, title: str = 'Parameter einstellen',
             scrollable: bool = False):
        '''
        render parameters and elements in parent

        Parameters
        ----------
        args : optional
            arguments for appending parameter layout to parent
            (like x, y if parent is grid layout)
        title : str, optional
            title of the parameter dialog, defaults to 'Parameter einstellen'
        scrollable : bool, optional
            a scrollbar will be added to both preview and dialog if True,
            recommended if there are a lot of parameters, defaults to not
            scrollable
        '''
        if self.parent is None:
            raise Exception("can't render Params object with no parent set")

        # Debug: function to automatically write a help file with all params
        # with empty texts, should be removed in production
        if (settings.DEBUG and getattr(self, 'help_file', None) and
            not os.path.exists(self.help_file)):
            if not os.path.exists(self.HELP_PATH):
                os.mkdir(self.HELP_PATH)
            with open(self.help_file, 'w') as json_file:
                json.dump(self.help_dict, json_file, indent=4)

        self.dialog = ParamsDialog(parent=None,
                                   help_text=self.help_dict['beschreibung'],
                                   title=title)

        self.parent.addLayout(self.layout, *args)

        if scrollable:
            frame = QFrame()
            scroll_area = QScrollArea()
            layout = QVBoxLayout()
            layout.setSpacing(5)
            frame.setLayout(layout)
            scroll_area.setWidget(frame)
            scroll_area.setWidgetResizable(True)
            scroll_area.setFixedHeight(400)
            self.layout.addWidget(scroll_area)
        else:
            layout = self.layout

        for element in self._elements:
            if isinstance(element, QLayoutItem):
                layout.addItem(element)
            # overview
            elif not getattr(element, 'hide_in_overview', None):
                element.draw(layout)
            self.dialog.draw(element)

        if not self.editable:
            return

        row = QHBoxLayout()
        button = QPushButton(self.button_label)
        icon = QIcon(os.path.join(settings.IMAGE_PATH, 'iconset_mob',
                                  '20190619_iconset_mob_edit_1.png'))
        button.setIcon(icon)
        tool_tip = self.help_dict.get('tooltip', None)
        button.setToolTip(tool_tip)
        row.addItem(
            QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Minimum))
        row.addWidget(button)
        self.layout.addItem(
            QSpacerItem(10, 10, QSizePolicy.Fixed, QSizePolicy.Minimum))
        self.layout.addLayout(row)

        button.clicked.connect(self.show_dialog)
Пример #10
0
    def update_personal_preset_view(self):
        """Update the presets displayed."""
        preset_folder = query_preset()
        files = filter(
            lambda folder: os.path.isdir(join(preset_folder, folder)),
            os.listdir(preset_folder))

        self.dialog.list_personal_preset_mp.clear()

        for file in files:
            file_path = join(preset_folder, file, file + '.json')
            with open(file_path, encoding='utf8') as json_file:
                data = json.load(json_file, object_hook=as_enum)
            name = data['file_name']

            item = QListWidgetItem(self.dialog.list_personal_preset_mp)
            item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable
                          | Qt.ItemIsEnabled)
            self.dialog.list_personal_preset_mp.addItem(item)

            preset = QFrame()
            preset.setObjectName('FramePreset')
            preset.setFrameStyle(QFrame.StyledPanel)
            preset.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
            hbox = QHBoxLayout()
            vbox = QVBoxLayout()
            label_name = QLabel(name)
            label_name.setStyleSheet('font-weight: bold;')
            label_name.setWordWrap(True)
            vbox.addWidget(label_name)
            for label in data['description']:
                if not label:
                    label = tr('No description')
                real_label = QLabel(label)
                real_label.setWordWrap(True)
                vbox.addWidget(real_label)
            hbox.addItem(vbox)
            button_edit = QPushButton()
            button_remove = QPushButton()
            button_edit.setIcon(
                QIcon(QgsApplication.iconPath("mActionToggleEditing.svg")))
            button_remove.setIcon(
                QIcon(QgsApplication.iconPath('symbologyRemove.svg')))
            button_edit.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
            button_remove.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
            button_edit.setToolTip(tr('Edit the preset'))
            button_remove.setToolTip(tr('Delete the preset'))
            hbox.addWidget(button_edit)
            hbox.addWidget(button_remove)
            if data['advanced']:
                self.listAdvanced.append(True)
                preset.setStyleSheet('#FramePreset { margin: 3px;'
                                     ' border: 3px solid ' +
                                     self.advanced_selected + ';'
                                     ' border-width: 1px 1px 1px 4px;}')
            else:
                self.listAdvanced.append(False)
                preset.setStyleSheet('#FramePreset { margin: 3px;'
                                     ' border: 3px solid ' +
                                     self.basic_selected + ';'
                                     ' border-width: 1px 1px 1px 4px;}')
            preset.setLayout(hbox)

            # Actions on click
            remove = partial(self.verification_remove_preset, item, name)
            button_remove.clicked.connect(remove)
            edit = partial(self.edit_preset, data)
            button_edit.clicked.connect(edit)

            item.setSizeHint(preset.minimumSizeHint())
            self.dialog.list_personal_preset_mp.setItemWidget(item, preset)

        self.listAdvanced.append(False)
Пример #11
0
class TableWidget(QWidget):

    linkActivated = pyqtSignal(str)

    def __init__(self, table):
        QWidget.__init__(self)

        layout = QVBoxLayout()

        hlayout = QHBoxLayout()
        l = QLabel(table.name())
        font = l.font()
        font.setBold(True)
        l.setFont(font)

        hlayout.addWidget(l)
        open_table_btn = QToolButton()
        icon = QIcon(os.path.dirname(__file__) + "/mActionOpenTableGML.svg")
        open_table_btn.setIcon(icon)
        open_table_btn.resize(32, 32)
        open_table_btn.clicked.connect(
            lambda checked: self.linkActivated.emit(table.name())
        )
        hlayout.addWidget(open_table_btn)

        f = QFrame()
        f.setFrameStyle(QFrame.Panel | QFrame.Plain)
        f.setLineWidth(2.0)
        f.setLayout(hlayout)

        layout.addWidget(f)

        self.attribute_label = QLabel()
        names = [f.name() for f in table.columns()]
        names += [l.name() + "_id" for l in table.links() if l.max_occurs() == 1]
        names += [l.ref_table().name() + "_id" for l in table.back_links()]

        self.attribute_label.setText("\n".join(names))
        v2 = QVBoxLayout()
        v2.addWidget(self.attribute_label)

        self.attribute_frame = QFrame()
        self.attribute_frame.setFrameStyle(QFrame.Panel | QFrame.Plain)
        self.attribute_frame.setLineWidth(2.0)
        self.attribute_frame.setLayout(v2)
        layout.addWidget(self.attribute_frame)

        self.setLayout(layout)

        fm = QFontMetricsF(self.attribute_label.font())
        self.__font_height = fm.height()
        margins = layout.contentsMargins()

        self.attribute_x_offset = margins.left()
        self.attribute_x2_offset = margins.right()

    def attributeCoords(self, idx):
        # returns the box coordinates of the idx-th attribute
        offset_y = self.attribute_label.y() + self.attribute_frame.y()
        offset_x = self.attribute_x_offset
        x = self.x() + offset_x
        w = self.width() - offset_x - self.attribute_x2_offset
        y = self.y() + offset_y + self.__font_height * idx
        h = self.__font_height
        return (x, y, w, h)