Python源码示例:PyQt5.QtCore.Qt.UserRole()

示例1
def __init__(self, parent = None) -> None:
        super().__init__(parent)

        self._metadata = None  # type: Optional[List[Dict[str, Union[str, List[str], int]]]]

        self.addRoleName(Qt.UserRole + 1, "id")
        self.addRoleName(Qt.UserRole + 2, "name")
        self.addRoleName(Qt.UserRole + 3, "email")
        self.addRoleName(Qt.UserRole + 4, "website")
        self.addRoleName(Qt.UserRole + 5, "package_count")
        self.addRoleName(Qt.UserRole + 6, "package_types")
        self.addRoleName(Qt.UserRole + 7, "icon_url")
        self.addRoleName(Qt.UserRole + 8, "description")

        # List of filters for queries. The result is the union of the each list of results.
        self._filter = {}  # type: Dict[str, str] 
示例2
def _update_data(self, data_info):
        sorted_keys = list(sorted(data_info.get_map_names()))

        if len(data_info.get_map_names()):
            self.general_info_nmr_maps.setText(str(len(data_info.get_map_names())))
        else:
            self.general_info_nmr_maps.setText('0')

        with blocked_signals(self.general_map_selection):
            self.general_map_selection.clear()
            self.general_map_selection.addItems(sorted_keys)
            for index, map_name in enumerate(sorted_keys):
                item = self.general_map_selection.item(index)
                item.setData(Qt.UserRole, map_name)

        with blocked_signals(self.mask_name):
            self.mask_name.clear()
            self.mask_name.insertItem(0, '-- None --')
            self.mask_name.insertItems(1, sorted_keys) 
示例3
def onAdvScanUpdateSSIDs(self, wirelessNetworks):
        rowPosition = self.networkTable.rowCount()
        
        if rowPosition > 0:
            # Range goes to last # - 1
            for curRow in range(0, rowPosition):
                try:
                    curData = self.networkTable.item(curRow, 2).data(Qt.UserRole+1)
                except:
                    curData = None
                    
                if (curData):
                    # We already have the network.  just update it
                    for curKey in wirelessNetworks.keys():
                        curNet = wirelessNetworks[curKey]
                        if (curData.macAddr == curNet.macAddr) and (curData.channel == curNet.channel):
                            # See if we had an unknown SSID
                            if curData.ssid.startswith('<Unknown') and (not curNet.ssid.startswith('<Unknown')):
                                curData.ssid = curNet.ssid
                                self.networkTable.item(curRow, 2).setText(curData.ssid)
                                curSeries = self.networkTable.item(curRow, 2).data(Qt.UserRole)
                                curSeries.setName(curData.ssid) 
示例4
def onCopyNet(self):
        self.updateLock.acquire()
        
        curRow = self.networkTable.currentRow()
        curCol = self.networkTable.currentColumn()
        
        if curRow == -1 or curCol == -1:
            self.updateLock.release()
            return
        
        if curCol != 11:
            curText = self.networkTable.item(curRow, curCol).text()
        else:
            curNet = self.networkTable.item(curRow, 2).data(Qt.UserRole+1)
            curText = 'Last Recorded GPS Coordinates:\n' + str(curNet.gps)
            curText += 'Strongest Signal Coordinates:\n'
            curText += 'Strongest Signal: ' + str(curNet.strongestsignal) + '\n'
            curText += str(curNet.strongestgps)
            
        clipboard = QApplication.clipboard()
        clipboard.setText(curText)
        
        self.updateLock.release() 
示例5
def onDeleteNet(self):
        self.updateLock.acquire()
        
        curRow = self.networkTable.currentRow()
        
        if curRow == -1:
            self.updateLock.release()
            return
        
        curNet = self.networkTable.item(curRow, 2).data(Qt.UserRole+1)
        curSeries = self.networkTable.item(curRow, 2).data(Qt.UserRole)

        if curNet and curSeries:
            if (curNet.channel < 15):
                self.chart24.removeSeries(curSeries)
            else:
                self.chart5.removeSeries(curSeries)
            
        self.networkTable.removeRow(curRow)
        
        self.updateLock.release() 
示例6
def get_item(self, path: List[str], item_name: str):
        parents = [None]

        for i, name in enumerate(path + [item_name]):
            parent_model = self if i == 0 else parents[-1]
            items = self.findItems(name, Qt.MatchExactly | Qt.MatchRecursive)
            target_item = None

            if not items:   # create new item if it does not exist
                target_item = self._create_item(parent_model, name, {Qt.UserRole: "", Qt.UserRole+1: ""})
            else:
                for item in items: # check found items with corresponding parent
                    if item.parent() == parents[-1]:
                        target_item = item
                if target_item is None:
                    target_item = self._create_item(parent_model, name, {Qt.UserRole: "", Qt.UserRole + 1: ""})

            parents.append(target_item)
        return parents[-1] 
示例7
def data(self, qindex:QModelIndex, role=None):
        if role == Qt.DisplayRole or role == Qt.EditRole:
            entry = self.entries[qindex.row()]
            attr = self.columns[qindex.column()]
            value = getattr(entry, attr)
            if attr in ("gmd_name_index", "gmd_description_index"):
                return get_t9n(self.model, "t9n", value)
            elif attr == "kire_id":
                kire_model = self.model.get_relation_data("kire")
                if kire_model is None:
                    return None
                else:
                    return kire_model.entries[value]
            return value
        elif role == Qt.UserRole:
            entry = self.entries[qindex.row()]
            return entry 
示例8
def prompt_extractor(self, item):
        extractor = extractors[item.data(Qt.UserRole)]
        inputs = []
        if not assert_installed(self.view, **extractor.get('depends', {})):
            return
        
        if not extractor.get('pick_url', False):
            files, mime = QFileDialog.getOpenFileNames()
            for path in files:
                inputs.append((path, Path(path).stem))
        else:
            text, good = QInputDialog.getText(self.view, ' ', 'Input an URL:')
            if text:
                url = urlparse(text)
                inputs.append((url.geturl(), url.netloc))
        
        if inputs:
            wait = QProgressDialog('Extracting .proto structures...', None, 0, 0)
            wait.setWindowTitle(' ')
            self.set_view(wait)
            
            self.worker = Worker(inputs, extractor)
            self.worker.progress.connect(self.extraction_progress)
            self.worker.finished.connect(self.extraction_done)
            self.worker.start() 
示例9
def _settings_str(self):
        """Returns a human readable settings representation for logging purposes."""
        settings = "Automatically save changes: {}, " \
            "Show tray icon: {}, " \
            "Allow keyboard navigation: {}, " \
            "Sort by usage count: {}, " \
            "Enable undo using backspace: {}, " \
            "Tray icon theme: {}, " \
            "Disable Capslock: {}".format(
               self.autosave_checkbox.isChecked(),
               self.show_tray_checkbox.isChecked(),
               self.allow_kb_nav_checkbox.isChecked(),
               self.sort_by_usage_checkbox.isChecked(),
               self.enable_undo_checkbox.isChecked(),
               self.system_tray_icon_theme_combobox.currentData(Qt.UserRole),
               self.disable_capslock_checkbox.isChecked()
            )
        return settings 
示例10
def _on_modify_condition(self, num_row):
        item = self._breakpoints_model.item(num_row, 2)
        data = item.data(Qt.UserRole + 2)
        if data is None:
            data = ''
        ptr = self._breakpoints_model.item(num_row, 0).text()
        accept, input_ = InputMultilineDialog().input(
            'Condition for breakpoint %s' % ptr, input_content=data)
        if accept:
            what = utils.parse_ptr(ptr)
            if what == 0:
                what = self._breakpoints_model.item(num_row, 2).data(Qt.UserRole + 2)
            if self._app_window.dwarf.dwarf_api('setBreakpointCondition', [what, input_.replace('\n', '')]):
                item.setData(input_, Qt.UserRole + 2)
                if not item.text():
                    item.setText('ƒ')
                item.setToolTip(input_)
                self.onBreakpointChanged.emit(ptr)

    # + button 
示例11
def _on_native_contextmenu(self, pos):
        index = self._nativectx_list.indexAt(pos).row()
        glbl_pt = self._nativectx_list.mapToGlobal(pos)
        context_menu = QMenu(self)
        if index != -1:
            item = self._nativectx_model.item(index, 1)
            dec = self._nativectx_model.item(index, 2)
            telescope = self._nativectx_model.item(index, 3)
            # show contextmenu
            if self._nativectx_model.item(index, 0).data(Qt.UserRole + 1):
                context_menu.addAction('Jump to {0}'.format(item.text()), lambda: self._app_window.jump_to_address(item.text()))
                context_menu.addSeparator()
            # copy menu
            context_sub_menu = QMenu('Copy', context_menu)
            context_sub_menu.addAction('Value', lambda: utils.copy_str_to_clipboard(item.text()))
            if dec.text():
                context_sub_menu.addAction('Decimal', lambda: utils.copy_str_to_clipboard(dec.text()))
            if telescope.text():
                context_sub_menu.addAction('Telescope', lambda: utils.copy_str_to_clipboard(telescope.text()))
            context_menu.addMenu(context_sub_menu)

            context_menu.exec_(glbl_pt) 
示例12
def __init__(self, parent = None):
        super().__init__(parent)

        self.addRoleName(Qt.UserRole + 1, "name")
        self.addRoleName(Qt.UserRole + 2, "brand")
        self.addRoleName(Qt.UserRole + 3, "colors") 
示例13
def __init__(self, parent = None):
        super().__init__(parent)

        self.addRoleName(Qt.UserRole + 1, "name")
        self.addRoleName(Qt.UserRole + 2, "material_types")

        self._update() 
示例14
def __init__(self, parent = None):
        super().__init__(parent)

        self._metadata = None

        self.addRoleName(Qt.UserRole + 1, "id")
        self.addRoleName(Qt.UserRole + 2, "type")
        self.addRoleName(Qt.UserRole + 3, "name")
        self.addRoleName(Qt.UserRole + 4, "version")
        self.addRoleName(Qt.UserRole + 5, "author_id")
        self.addRoleName(Qt.UserRole + 6, "author_name")
        self.addRoleName(Qt.UserRole + 7, "author_email")
        self.addRoleName(Qt.UserRole + 8, "description")
        self.addRoleName(Qt.UserRole + 9, "icon_url")
        self.addRoleName(Qt.UserRole + 10, "image_urls")
        self.addRoleName(Qt.UserRole + 11, "download_url")
        self.addRoleName(Qt.UserRole + 12, "last_updated")
        self.addRoleName(Qt.UserRole + 13, "is_bundled")
        self.addRoleName(Qt.UserRole + 14, "is_active")
        self.addRoleName(Qt.UserRole + 15, "is_installed")  # Scheduled pkgs are included in the model but should not be marked as actually installed
        self.addRoleName(Qt.UserRole + 16, "has_configs")
        self.addRoleName(Qt.UserRole + 17, "supported_configs")
        self.addRoleName(Qt.UserRole + 18, "download_count")
        self.addRoleName(Qt.UserRole + 19, "tags")
        self.addRoleName(Qt.UserRole + 20, "links")
        self.addRoleName(Qt.UserRole + 21, "website")
        self.addRoleName(Qt.UserRole + 22, "login_required")
        self.addRoleName(Qt.UserRole + 23, "average_rating")
        self.addRoleName(Qt.UserRole + 24, "num_ratings")
        self.addRoleName(Qt.UserRole + 25, "user_rating")

        # List of filters for queries. The result is the union of the each list of results.
        self._filter = {}  # type: Dict[str, str] 
示例15
def __init__(self, parent = None):
        super().__init__(parent)

        self._configs = None

        self.addRoleName(Qt.UserRole + 1, "machine")
        self.addRoleName(Qt.UserRole + 2, "print_core")
        self.addRoleName(Qt.UserRole + 3, "build_plate")
        self.addRoleName(Qt.UserRole + 4, "support_material")
        self.addRoleName(Qt.UserRole + 5, "quality") 
示例16
def paint(self, painter, option, idx):
        new_idx = idx.sibling(idx.row(), 0)
        item = self.model.itemFromIndex(new_idx)
        if item and item.data(Qt.UserRole) in self.added_node_list:
            option.font.setWeight(QFont.Bold)
        QStyledItemDelegate.paint(self, painter, option, idx) 
示例17
def select_maps_context_menu(self, position):
        global_position = self.general_map_selection.mapToGlobal(position)

        def get_header_action(parent, map_name):
            label = QLabel(map_name)

            font = label.font()
            font.setBold(True)
            label.setFont(font)
            label.setStyleSheet('color: black; margin:5px; margin-left: 15px;')

            action = QWidgetAction(parent)
            action.setDisabled(True)
            action.setDefaultWidget(label)

            return action

        if self.general_map_selection.count():
            row = self.general_map_selection.indexAt(position)
            if row:
                element = self.general_map_selection.item(row.row())
                if element:
                    map_name = element.data(Qt.UserRole)
                    file_path = self._controller.get_model().get_data().get_file_path(map_name)

                    menu = QMenu()
                    menu.addAction(get_header_action(menu, map_name))
                    menu.addSeparator()

                    show_in_folder = menu.addAction('&Show in folder', lambda:
                        QDesktopServices.openUrl(QUrl.fromLocalFile(os.path.dirname(file_path))))
                    if file_path is None:
                        show_in_folder.setEnabled(False)

                    menu.addAction('Use as &mask', lambda: self._controller.apply_action(SetGeneralMask(map_name)))
                    menu.addAction('R&emove', lambda: self._controller.apply_action(
                        NewDataAction(self._controller.get_model().get_data().get_updated(removals=[map_name]))))
                    menu.exec(global_position) 
示例18
def _reorder_maps(self):
        items = [self.general_display_order.item(ind) for ind in range(self.general_display_order.count())]
        map_names = [item.data(Qt.UserRole) for item in items]
        self._controller.apply_action(SetMapsToShow(map_names)) 
示例19
def _update_maps_to_show(self):
        current_model = self._controller.get_model()
        map_names = copy.copy(current_model.get_config().maps_to_show)

        for item in [self.general_map_selection.item(ind) for ind in range(self.general_map_selection.count())]:
            map_name = item.data(Qt.UserRole)

            if item.isSelected():
                if map_name not in map_names:
                    self._insert_alphabetically(map_name, map_names)
            else:
                if map_name in map_names:
                    map_names.remove(map_name)

        self._controller.apply_action(SetMapsToShow(map_names)) 
示例20
def __init__(self, controller, parent=None):
        super().__init__(parent)
        self.setupUi(self)

        self.map_specific_tab = MapSpecificOptions(controller, self)
        self.mapSpecificOptionsPosition.addWidget(self.map_specific_tab)

        self._controller = controller
        self._controller.model_updated.connect(self.model_updated)

        self.selectedMap.currentIndexChanged.connect(
            lambda ind: self._update_map_specifics(self.selectedMap.itemData(ind, Qt.UserRole))) 
示例21
def get_pipe(self):
        pipe = [] if self._app_mode else [self.inputBox.currentData()]
        for n in range(self.currentList.count()):
            pipe.append(self.currentList.item(n).data(Qt.UserRole))
        pipe.append(self.outputBox.currentData())

        return tuple(pipe) 
示例22
def __init_current_plugins(self, pipe):
        self.currentList.clear()

        # If not in app_mode, the first pipe element is the input
        # the last the output
        start = 0 if self._app_mode else 1
        for plugin in pipe[start:-1]:
            item = QListWidgetItem(
                translate('MediaElementName', elements.plugin_name(plugin)))
            item.setData(Qt.UserRole, plugin)
            self.currentList.addItem(item) 
示例23
def __init_available_plugins(self, pipe):
        self.availableList.clear()

        for plugin in elements.plugins():
            if plugin not in pipe:
                item = QListWidgetItem(
                    translate('MediaElementName', elements.plugin_name(plugin)))
                item.setData(Qt.UserRole, plugin)
                self.availableList.addItem(item) 
示例24
def add_cue(self, cue):
        item = QTreeWidgetItem()
        item.setTextAlignment(0, Qt.AlignCenter)

        for n, prop in enumerate(self._properties):
            try:
                item.setData(n, Qt.DisplayRole, getattr(cue, prop, 'Undefined'))
            except Exception as e:
                elogging.exception('Cannot display {0} property'.format(prop), e,
                                   dialog=False)

        self._cues[cue] = item
        item.setData(0, Qt.UserRole, cue)
        self.list.addTopLevelItem(item) 
示例25
def selected_cues(self):
        cues = []
        for item in self.list.selectedItems():
            cues.append(item.data(0, Qt.UserRole))
        return cues 
示例26
def __add_message(self, msg):
        if self.msgTypeCombo.currentData(Qt.UserRole) == msg.type:
            self.midiModel.appendRow(msg.type, msg.channel+1, msg.note,
                                     self._default_action) 
示例27
def __new_message(self):
        message_type = self.msgTypeCombo.currentData(Qt.UserRole)
        self.midiModel.appendRow(message_type, 1, 0, self._default_action) 
示例28
def test_dataUnhappy():
    model = createModel("single_setting.def.json")
    # Out of bounds
    assert model.data(model.index(250, 0), model.KeyRole) == QVariant()

    # Invalid index
    assert model.data(QModelIndex(), model.KeyRole) == QVariant()

    # Unknown role
    assert model.data(model.index(0, 0), Qt.UserRole + 100) == QVariant()

    empty_model = SettingDefinitionsModel()
    assert empty_model.data(model.index(0, 0), model.KeyRole) == QVariant() 
示例29
def renderClips(self, cliptimes: list) -> int:
        self.clear()
        externalCount = 0
        for index, clip in enumerate(cliptimes):
            chapterName, endItem = '', ''
            if isinstance(clip[1], QTime):
                endItem = clip[1].toString(self.parent.timeformat)
                self.parent.totalRuntime += clip[0].msecsTo(clip[1])
            listitem = QListWidgetItem(self)
            listitem.setToolTip('Drag to reorder clips')
            if len(clip[3]):
                listitem.setToolTip(clip[3])
                externalCount += 1
            if self.parent.createChapters:
                chapterName = clip[4] if clip[4] is not None else 'Chapter {}'.format(index + 1)
            listitem.setStatusTip('Reorder clips with mouse drag & drop or right-click menu on the clip to be moved')
            listitem.setTextAlignment(Qt.AlignVCenter)
            listitem.setData(Qt.DecorationRole + 1, clip[2])
            listitem.setData(Qt.DisplayRole + 1, clip[0].toString(self.parent.timeformat))
            listitem.setData(Qt.UserRole + 1, endItem)
            listitem.setData(Qt.UserRole + 2, clip[3])
            listitem.setData(Qt.UserRole + 3, chapterName)
            listitem.setFlags(Qt.ItemIsSelectable | Qt.ItemIsDragEnabled | Qt.ItemIsEnabled)
            self.addItem(listitem)
            if isinstance(clip[1], QTime) and not len(clip[3]):
                self.parent.seekSlider.addRegion(clip[0].msecsSinceStartOfDay(), clip[1].msecsSinceStartOfDay())
        return externalCount 
示例30
def onShowTelemetry(self):
        self.updateLock.acquire()
        
        curRow = self.networkTable.currentRow()
        
        if curRow == -1:
            self.updateLock.release()
            return
        
        curNet = self.networkTable.item(curRow, 2).data(Qt.UserRole+1)
        
        if curNet == None:
            self.updateLock.release()
            return
       
        if curNet.getKey() not in self.telemetryWindows.keys():
            telemetryWindow = TelemetryDialog()
            telemetryWindow.show()
            self.telemetryWindows[curNet.getKey()] = telemetryWindow
        else:
            telemetryWindow = self.telemetryWindows[curNet.getKey()]
        
        # Can also key off of self.telemetryWindow.isVisible()
        telemetryWindow.show()
        telemetryWindow.activateWindow()
        
        # Can do telemetry window updates after release
        self.updateLock.release()
        
        # User could have selected a different network.
        telemetryWindow.updateNetworkData(curNet)