def createDataItem(self, path, parentItem):
     if not parentItem:
         ri = MerginRootItem()
         sip.transferto(ri, None)
         return ri
     else:
         return None
Exemple #2
0
 def set_value(self, value, property='text'):
     property_setter = QQuickPropertySetter(self._target, property, value)
     sip.transferto(property_setter, self._target)
     try:
         pqaut.server.key_press.input(property_setter)
     except Exception as ex:
         logger.debug("error on  set value on ui thread: {}".format(ex))
    def createChildren(self):
        children = []

        DATASETS = dict(
            **self.STANDARD_DATASET,
            **self.LOCAL_JP_DATASET,
            **self.LOCAL_NL_DATASET,
            **self.LOCAL_UK_DATASET,
        )
        smanager = SettingsManager()
        selectedmaps = smanager.get_setting('selectedmaps')

        for key in DATASETS:
            if not key in selectedmaps:
                continue
            md_item = MapDataItem(self, key, DATASETS[key])
            sip.transferto(md_item, self)
            children.append(md_item)

        custommaps = smanager.get_setting('custommaps')
        for key in custommaps:
            md_item = MapDataItem(self, key, custommaps[key], editable=True)
            sip.transferto(md_item, self)
            children.append(md_item)

        return children
    def __init__(self, df, columns={}):
        super(rs.DataframeData, self).__init__()
        self.columns = columns
        self.position = 0
        self.df = df

        users = self._get_def_valarray('user')
        items = self._get_def_valarray('item')
        ids = list(df.index)
        scores = self._get_def_valarray('score', 'ones')
        times = self._get_def_valarray('time', 'arange')
        evals = self._get_def_valarray('eval', 'ones')
        categories = self._get_def_valarray('category', 'ones')

        indexes = np.arange(len(self.df))
        recdats = []
        for (_i, _user, _item, _id, _score, _time, _eval, _category) in zip(indexes, users, items, ids, scores, times, evals, categories):
            rd = rs.RecDat()
            rd.user = _user
            rd.item = _item
            rd.id = _id
            rd.score = _score
            rd.time = _time
            rd.eval = _eval
            rd.category = _category
            recdats.append(rd)
            sip.transferto(rd, None)
        self.add_recdats(recdats)
        super(rs.DataframeData, self).initialize()
 def createDataItem(self, path, parentItem):
     if not parentItem:
         ri = MerginRootItem(self.plugin)
         sip.transferto(ri, None)
         self.root_item = ri
         return ri
     else:
         return None
 def do(self):
     GeniusCtrl.Genius.log('Query device structure.')
     control = GeniusCtrl.SolverControl
     _simuSys = control.system()
     sip.transferto(_simuSys, None)  ## temporary workaround
     simuSys = GeniusLib.SimulationSystem(_simuSys)
     if simuSys:
         if re.match('xml', self.queryStr, re.I):
             self.result = simuSys.toXML()
         else:
             self.result = simuSys.toText()
Exemple #7
0
 def open(self):
     MODULE.info('Opening VNC connection to %s' % (self.ipAddress))
     self._vnc = italc.ItalcVncConnection()
     # transfer responsibility for cleaning self._vnc up from python garbarge collector to C++/QT (Bug #27534)
     sip.transferto(self._vnc, None)
     self._vnc.setHost(self.ipAddress)
     self._vnc.setPort(ITALC_VNC_PORT)
     self._vnc.setQuality(italc.ItalcVncConnection.ThumbnailQuality)
     self._vnc.setFramebufferUpdateInterval(int(1000 * ITALC_VNC_UPDATE))
     self._vnc.start()
     self._vnc.stateChanged.connect(self._stateChanged)
 def do(self):
     GeniusCtrl.Genius.log("Query device structure.")
     control = GeniusCtrl.SolverControl
     _simuSys = control.system()
     sip.transferto(_simuSys, None)  ## temporary workaround
     simuSys = GeniusLib.SimulationSystem(_simuSys)
     if simuSys:
         if re.match("xml", self.queryStr, re.I):
             self.result = simuSys.toXML()
         else:
             self.result = simuSys.toText()
    def createChildren(self):
        if not self.mc and self.error:
            error_item = QgsErrorItem(self, self.error, "/Mergin/error")
            error_item.setIcon(
                QIcon(os.path.join(icon_path,
                                   "exclamation-triangle-solid.svg")))
            sip.transferto(error_item, self)
            return [error_item]

        items = []
        my_projects = MerginGroupItem(self, "My projects", "created",
                                      "user-solid.svg", 1)
        my_projects.setState(QgsDataItem.Populated)
        my_projects.refresh()
        sip.transferto(my_projects, self)
        items.append(my_projects)

        shared_projects = MerginGroupItem(self, "Shared with me", "shared",
                                          "user-friends-solid.svg", 2)
        shared_projects.setState(QgsDataItem.Populated)
        shared_projects.refresh()
        sip.transferto(shared_projects, self)
        items.append(shared_projects)

        all_projects = MerginGroupItem(self, "Explore", None, "list-solid.svg",
                                       3)
        all_projects.setState(QgsDataItem.Populated)
        all_projects.refresh()
        sip.transferto(all_projects, self)
        items.append(all_projects)

        return items
    def createChildren(self):
        if self.error or self.mc is None:
            self.error = self.error if self.error else "Not configured!"
            error_item = QgsErrorItem(self, self.error, "Mergin/error")
            error_item.setIcon(QIcon(icon_path("exclamation-triangle-solid.svg")))
            sip.transferto(error_item, self)
            return [error_item]

        items = []
        my_projects = MerginGroupItem(self, "My projects", "created", "user-solid.svg", 1, self.plugin)
        my_projects.setState(QgsDataItem.Populated)
        my_projects.refresh()
        sip.transferto(my_projects, self)
        items.append(my_projects)

        shared_projects = MerginGroupItem(self, "Shared with me", "shared", "user-friends-solid.svg", 2, self.plugin)
        shared_projects.setState(QgsDataItem.Populated)
        shared_projects.refresh()
        sip.transferto(shared_projects, self)
        items.append(shared_projects)

        all_projects = MerginGroupItem(self, "Explore", None, "list-solid.svg", 3, self.plugin)
        all_projects.setState(QgsDataItem.Populated)
        all_projects.refresh()
        sip.transferto(all_projects, self)
        items.append(all_projects)

        return items
Exemple #11
0
    def createChildren(self):
        mc = self.parent().mc
        if not mc:
            error_item = QgsErrorItem(
                self, "Failed to login please check the configuration",
                "/Mergin/error")
            sip.transferto(error_item, self)
            return [error_item]
        try:
            projects = mc.projects_list(flag=self.filter)
        except URLError:
            error_item = QgsErrorItem(self,
                                      "Failed to get projects from server",
                                      "/Mergin/error")
            sip.transferto(error_item, self)
            return [error_item]
        except Exception as err:
            error_item = QgsErrorItem(self, "Error: {}".format(str(err)),
                                      "/Mergin/error")
            sip.transferto(error_item, self)
            return [error_item]

        items = []
        for project in projects:
            item = MerginProjectItem(self, project, mc)
            item.setState(QgsDataItem.Populated)  # make it non-expandable
            sip.transferto(item, self)
            items.append(item)
        return items
 def set_fetch_more_item(self):
     """Check if there are more projects to be fetched from Mergin service and set the fetch-more item."""
     if self.fetch_more_item is not None:
         try:
             self.removeChildItem(self.fetch_more_item)
         except RuntimeError:
             pass
         self.fetch_more_item = None
     fetched_count = len(self.projects)
     if fetched_count < self.total_projects_count:
         self.fetch_more_item = FetchMoreItem(self)
         self.fetch_more_item.setState(QgsDataItem.Populated)
         sip.transferto(self.fetch_more_item, self)
     group_name = f"{self.group_name} ({self.total_projects_count})"
     self.setName(group_name)
Exemple #13
0
def openFile(fileName, window, cmd = None):
    """
    Opens a file with command cmd (string, read from config)
    or with the KDE default application (via KRun).
    """
    if cmd:
        cmd, err = KShell.splitArgs(cmd)
        if err == KShell.NoError:
            cmd.append(fileName)
            try:
                Popen(cmd)
                return
            except OSError:
                pass
    # let C++ own the KRun object, it will delete itself.
    sip.transferto(KRun(KUrl.fromPath(fileName), window), None)
Exemple #14
0
 def openDirectory(self, path=None):
     """
     Opens a folder. If None, opes the document folder if any, or else
     the current working directory in the default KDE file manager.
     """
     if path is None:
         d = self.mainwin.currentDocument()
         if d.url().isEmpty():
             if d.localFileManager():
                 path = d.localFileManager().directory
             else:
                 path = self.mainwin.app.defaultDirectory() or os.getcwd()
         else:
             path = d.url().resolved(KUrl('.'))
     url = KUrl(path)
     url.adjustPath(KUrl.RemoveTrailingSlash)
     sip.transferto(KRun(url, self.mainwin), None) # C++ will delete it
Exemple #15
0
    def destroy_control(self, control):
        """ Destroys a specified GUI toolkit control.
        """
        # Block signals to prevent any editors from being updated (the control
        # will not be deleted immediately).
        control.blockSignals(True)

        # This may be called from within the finished() signal handler so we
        # need to do the delete after the handler has returned.
        control.hide()
        control.deleteLater()

        # PyQt v4.3.1 and earlier deleteLater() didn't transfer ownership to
        # C++, which is necessary for the QObject system to garbage collect it.
        if qt_api == 'pyqt':
            if QtCore.PYQT_VERSION < 0x040302:
                import sip
                sip.transferto(control, None)
 def createChildren(self):
     if not self.projects:
         error = self.fetch_projects()
         if error is not None:
             return error
     items = []
     for project in self.projects:
         project_name = posixpath.join(project["namespace"], project["name"])  # posix path for server API calls
         local_proj_path = mergin_project_local_path(project_name)
         if local_proj_path is None or not os.path.exists(local_proj_path):
             item = MerginRemoteProjectItem(self, project, self.project_manager)
             item.setState(QgsDataItem.Populated)  # make it non-expandable
         else:
             item = MerginLocalProjectItem(self, project, self.project_manager)
         sip.transferto(item, self)
         items.append(item)
     self.set_fetch_more_item()
     if self.fetch_more_item is not None:
         items.append(self.fetch_more_item)
     return items
Exemple #17
0
def inject_xml_tree_into_form(dialog, feature):
    """Function called on form opening to add a custom XML widget"""
    w = dialog.findChild(QPushButton, "_xml_widget_")
    if w is not None:
        return
    l = __find_label_layout(dialog, "fid")
    if l is None:
        return

    w = xml_tree_widget.XMLTreeWidget(dialog)
    w.setObjectName("_xml_widget_")
    w.updateFeature(feature)
    lbl = QLabel("XML", dialog)
    l.addWidget(lbl, l.rowCount() - 1, 0)
    l.addWidget(w, l.rowCount() - 1, 1)
    l.setRowStretch(l.rowCount() - 1, 2)

    # the tree widget must not be garbage collected yet
    # since we want its Python slots to be called on signals
    # we then transfer its ownership to a C++ object that lives longer
    import sip
    sip.transferto(w, dialog)
 def fetch_projects(self, page=1, per_page=PROJS_PER_PAGE):
     """Get paginated projects list from Mergin service. If anything goes wrong, return an error item."""
     if self.project_manager is None:
         error_item = QgsErrorItem(self, "Failed to log in. Please check the configuration", "/Mergin/error")
         sip.transferto(error_item, self)
         return [error_item]
     try:
         resp = self.project_manager.mc.paginated_projects_list(
             flag=self.filter, page=page, per_page=per_page, order_params="namespace_asc,name_asc")
         self.projects += resp["projects"]
         self.total_projects_count = int(resp["count"]) if is_number(resp["count"]) else 0
     except URLError:
         error_item = QgsErrorItem(self, "Failed to get projects from server", "/Mergin/error")
         sip.transferto(error_item, self)
         return [error_item]
     except Exception as err:
         error_item = QgsErrorItem(self, "Error: {}".format(str(err)), "/Mergin/error")
         sip.transferto(error_item, self)
         return [error_item]
     return None
 def createDataItem(self, path, parentItem):
     root = RootCollection()
     sip.transferto(root, None)
     return root