コード例 #1
0
class GwAction:
    def __init__(self, icon_path, action_name, text, toolbar, action_group):

        self.iface = global_vars.iface
        self.canvas = global_vars.canvas
        self.schema_name = global_vars.schema_name
        self.settings = global_vars.giswater_settings
        self.plugin_dir = global_vars.plugin_dir
        self.project_type = global_vars.project_type

        icon = None
        if os.path.exists(icon_path):
            icon = QIcon(icon_path)

        self.action = None
        if icon is None:
            self.action = QAction(text, action_group)
        else:
            self.action = QAction(icon, text, action_group)

        self.action.setObjectName(action_name)
        self.action.setProperty('action_group', action_group)
        self.action.setCheckable(False)
        self.action.triggered.connect(self.clicked_event)

        if toolbar is None:
            return

        toolbar.addAction(self.action)

    def clicked_event(self):

        tools_qgis.show_message("Action has no function!!", "INFO")
コード例 #2
0
ファイル: mainwindow.py プロジェクト: transformaps/Roam
    def add_plugin_pages(self, pages) -> None:
        """
        Add pages from the plugin to the side pabel.
        :param pages: List of plugin page classes to create and attach to the side panel.
        """
        def safe_connect(method, to):
            try:
                method.connect(to)
            except AttributeError:
                pass

        for PageClass in pages:
            action = QAction(self.menutoolbar)
            text = PageClass.title.ljust(13)
            action.setIconText(text)
            action.setIcon(QIcon(PageClass.icon))
            action.setCheckable(True)
            if PageClass.projectpage:
                action.setVisible(False)
                self.projectbuttons.append(action)
                self.menutoolbar.insertAction(self.spaceraction, action)
            else:
                self.menutoolbar.insertAction(self.actionProject, action)

            pagewidget = PageClass(plugins.api, self)

            safe_connect(RoamEvents.selectionchanged,
                         pagewidget.selection_changed)
            safe_connect(RoamEvents.projectloaded, pagewidget.project_loaded)

            pageindex = self.stackedWidget.insertWidget(-1, pagewidget)
            action.setProperty('page', pageindex)
            self.pluginactions.append(action)
            self.menuGroup.addAction(action)
コード例 #3
0
    def _fill_arc_menu(self):
        """ Fill add arc menu """

        # disconnect and remove previuos signals and actions
        actions = self.menu.actions()
        for action in actions:
            action.disconnect()
            self.menu.removeAction(action)
            del action
        action_group = self.action.property('action_group')

        # Update featurecatvalues
        global_vars.feature_cat = tools_gw.manage_feature_cat()

        # Get list of different arc types
        features_cat = global_vars.feature_cat
        if features_cat is not None:
            list_feature_cat = tools_os.get_values_from_dictionary(
                features_cat)
            for feature_cat in list_feature_cat:
                if feature_cat.feature_type.upper() == 'ARC':
                    obj_action = QAction(str(feature_cat.id), action_group)
                    obj_action.setObjectName(feature_cat.id)
                    obj_action.setProperty('action_group', action_group)
                    if f"{feature_cat.shortcut_key}" not in global_vars.shortcut_keys:
                        obj_action.setShortcut(
                            QKeySequence(str(feature_cat.shortcut_key)))
                    try:
                        obj_action.setShortcutVisibleInContextMenu(True)
                    except Exception:
                        pass
                    self.menu.addAction(obj_action)
                    obj_action.triggered.connect(
                        partial(self.info_feature.add_feature, feature_cat))
                    obj_action.triggered.connect(
                        partial(self._save_last_selection, self.menu,
                                feature_cat))
コード例 #4
0
    def _get_layers_from_coordinates(self, point, rb_list, tab_type=None):

        cursor = QCursor()
        x = cursor.pos().x()
        y = cursor.pos().y()
        click_point = QPoint(x + 5, y + 5)

        visible_layers = tools_qgis.get_visible_layers(as_str_list=True)
        scale_zoom = self.iface.mapCanvas().scale()

        # Get layers under mouse clicked
        extras = f'"pointClickCoords":{{"xcoord":{point.x()}, "ycoord":{point.y()}}}, '
        extras += f'"visibleLayers":{visible_layers}, '
        extras += f'"zoomScale":{scale_zoom} '
        body = tools_gw.create_body(extras=extras)
        json_result = tools_gw.execute_procedure(
            'gw_fct_getlayersfromcoordinates',
            body,
            rubber_band=self.rubber_band)
        if not json_result or json_result['status'] == 'Failed':
            return False

        # hide QMenu identify if no feature under mouse
        len_layers = len(json_result['body']['data']['layersNames'])
        if len_layers == 0:
            return False

        self.icon_folder = self.plugin_dir + '/icons/'

        # Right click main QMenu
        main_menu = QMenu()

        # Create one menu for each layer
        for layer in json_result['body']['data']['layersNames']:
            layer_name = tools_qgis.get_layer_by_tablename(layer['layerName'])
            icon_path = self.icon_folder + layer['icon'] + '.png'
            if os.path.exists(str(icon_path)):
                icon = QIcon(icon_path)
                sub_menu = main_menu.addMenu(icon, layer_name.name())
            else:
                sub_menu = main_menu.addMenu(layer_name.name())
            # Create one QAction for each id
            for feature in layer['ids']:
                if 'label' in feature:
                    label = str(feature['label'])
                else:
                    label = str(feature['id'])
                action = QAction(label, None)
                action.setProperty('feature_id', str(feature['id']))
                sub_menu.addAction(action)
                action.triggered.connect(
                    partial(self._get_info_from_selected_id, action, tab_type))
                action.hovered.connect(
                    partial(self._draw_by_action, feature, rb_list))

        main_menu.addSeparator()
        # Identify all
        cont = 0
        for layer in json_result['body']['data']['layersNames']:
            cont += len(layer['ids'])
        action = QAction(f'Identify all ({cont})', None)
        action.hovered.connect(
            partial(self._identify_all, json_result, rb_list))
        main_menu.addAction(action)
        main_menu.addSeparator()
        main_menu.exec_(click_point)