Пример #1
0
 def setHeaderName(self):
     for idx in range(len(headerIndex)):
         self.setHeaderData(headerIndex[idx], Qt.Horizontal,
                            QVariant(headerData[idx]))
Пример #2
0
 def hints(self):
     return QVariant(
         [int(digit) - 1 for digit in self._square.possible_digits])
Пример #3
0
 def headerData(self, p_int, Qt_Orientation, int_role=None):
     if int_role == Qt.DisplayRole and Qt_Orientation == Qt.Horizontal:
         if p_int < len(self.head_name):
             return self.head_name[p_int]
     return QVariant()
Пример #4
0
    def data(self, index, role):
        if role == Qt.DisplayRole:
            return "({},{})".format(index.row(), index.column())

        return QVariant()
Пример #5
0
 def _save_settings(self):
     setting = QSettings()
     setting.setValue('DB/init_data', QVariant(self.init_data))
Пример #6
0
 def data(self, index, role):
     if not index.isValid():
         return QVariant()
     return self._items[index.row()][self._role_names[role].decode("utf-8")]
Пример #7
0
    def cmdHandler(self):
        while self.udpsock.hasPendingDatagrams():
            data, host, port = self.udpsock.readDatagram(self.udpsock.pendingDatagramSize())
            # print("DATA: ", data)
            lines = data.splitlines()
            for line in lines:
                # print("Line:", line)
                (command, value) = line.decode('utf_8').split(':', 1)
                command = str(command)
                value = str(value)
                # print("command: >" + command + "<")
                # print("value: >" + value + "<")
                if command == "NOW":
                    self.setCurrentSongText(value)
                if command == "NEXT":
                    self.setNewsText(value)
                if command == "LED1":
                    if value == "OFF":
                        self.ledLogic(1, False)
                    else:
                        self.ledLogic(1, True)
                if command == "LED2":
                    if value == "OFF":
                        self.ledLogic(2, False)
                    else:
                        self.ledLogic(2, True)
                if command == "LED3":
                    if value == "OFF":
                        self.ledLogic(3, False)
                    else:
                        self.ledLogic(3, True)
                if command == "LED4":
                    if value == "OFF":
                        self.ledLogic(4, False)
                    else:
                        self.ledLogic(4, True)
                if command == "WARN":
                    if value:
                        self.showWarning(value)
                    else:
                        self.hideWarning()

                if command == "AIR1":
                    if value == "OFF":
                        self.setAIR1(False)
                    else:
                        self.setAIR1(True)

                if command == "AIR2":
                    if value == "OFF":
                        self.setAIR2(False)
                    else:
                        self.setAIR2(True)

                if command == "AIR3":
                    if value == "OFF":
                        self.stopAIR3()
                    if value == "ON":
                        self.startAIR3()
                    if value == "RESET":
                        self.radioTimerReset()
                    if value == "TOGGLE":
                        self.radioTimerStartStop()

                if command == "AIR3TIME":
                    self.radioTimerSet(int(value))

                if command == "AIR4":
                    if value == "OFF":
                        self.setAIR4(False)
                    if value == "ON":
                        self.setAIR4(True)
                    if value == "RESET":
                        self.streamTimerReset()

                if command == "CMD":
                    if value == "REBOOT":
                        self.reboot_host()
                    if value == "SHUTDOWN":
                        self.shutdown_host()
                    if value == "QUIT":
                        QApplication.quit()

                if command == "CONF":
                    # split group, config and values and apply them
                    (group, paramvalue) = value.split(':', 1)
                    (param, content) = paramvalue.split('=', 1)
                    # print "CONF:", param, content
                    if group == "General":
                        if param == "stationname":
                            self.settings.StationName.setText(content)
                        if param == "slogan":
                            self.settings.Slogan.setText(content)
                        if param == "stationcolor":
                            self.settings.setStationNameColor(self.settings.getColorFromName(content))
                        if param == "slogancolor":
                            self.settings.setSloganColor(self.settings.getColorFromName(content))

                    if group == "LED1":
                        if param == "used":
                            self.settings.LED1.setChecked(QVariant(content).toBool())
                        if param == "text":
                            self.settings.LED1Text.setText(content)
                        if param == "activebgcolor":
                            self.settings.setLED1BGColor(self.settings.getColorFromName(content))
                        if param == "activetextcolor":
                            self.settings.setLED1FGColor(self.settings.getColorFromName(content))
                        if param == "autoflash":
                            self.settings.LED1Autoflash.setChecked(QVariant(content).toBool())
                        if param == "timedflash":
                            self.settings.LED1Timedflash.setChecked(QVariant(content).toBool())

                    if group == "LED2":
                        if param == "used":
                            self.settings.LED2.setChecked(QVariant(content).toBool())
                        if param == "text":
                            self.settings.LED2Text.setText(content)
                        if param == "activebgcolor":
                            self.settings.setLED2BGColor(self.settings.getColorFromName(content))
                        if param == "activetextcolor":
                            self.settings.setLED2FGColor(self.settings.getColorFromName(content))
                        if param == "autoflash":
                            self.settings.LED2Autoflash.setChecked(QVariant(content).toBool())
                        if param == "timedflash":
                            self.settings.LED2Timedflash.setChecked(QVariant(content).toBool())

                    if group == "LED3":
                        if param == "used":
                            self.settings.LED3.setChecked(QVariant(content).toBool())
                        if param == "text":
                            self.settings.LED3Text.setText(content)
                        if param == "activebgcolor":
                            self.settings.setLED3BGColor(self.settings.getColorFromName(content))
                        if param == "activetextcolor":
                            self.settings.setLED3FGColor(self.settings.getColorFromName(content))
                        if param == "autoflash":
                            self.settings.LED3Autoflash.setChecked(QVariant(content).toBool())
                        if param == "timedflash":
                            self.settings.LED3Timedflash.setChecked(QVariant(content).toBool())

                    if group == "LED4":
                        if param == "used":
                            self.settings.LED4.setChecked(QVariant(content).toBool())
                        if param == "text":
                            self.settings.LED4Text.setText(content)
                        if param == "activebgcolor":
                            self.settings.setLED4BGColor(self.settings.getColorFromName(content))
                        if param == "activetextcolor":
                            self.settings.setLED4FGColor(self.settings.getColorFromName(content))
                        if param == "autoflash":
                            self.settings.LED4Autoflash.setChecked(QVariant(content).toBool())
                        if param == "timedflash":
                            self.settings.LED4Timedflash.setChecked(QVariant(content).toBool())

                    if group == "Clock":
                        if param == "digital":
                            if content == "True":
                                self.settings.clockDigital.setChecked(True)
                                self.settings.clockAnalog.setChecked(False)
                            if content == "False":
                                self.settings.clockAnalog.setChecked(False)
                                self.settings.clockDigital.setChecked(True)
                        if param == "showseconds":
                            if content == "True":
                                self.settings.showSeconds.setChecked(True)
                            if content == "False":
                                self.settings.showSeconds.setChecked(False)
                        if param == "digitalhourcolor":
                            self.settings.setDigitalHourColor(self.settings.getColorFromName(content))
                        if param == "digitalsecondcolor":
                            self.settings.setDigitalSecondColor(self.settings.getColorFromName(content))
                        if param == "digitaldigitcolor":
                            self.settings.setDigitalDigitColor(self.settings.getColorFromName(content))
                        if param == "logopath":
                            self.settings.setLogoPath(content)

                    if group == "Network":
                        if param == "udpport":
                            self.settings.udpport.setText(content)

                    if group == "CONF":
                        if param == "APPLY":
                            if content == "TRUE":
                                # apply and save settings
                                self.settings.applySettings()
Пример #8
0
 def headerData(self, section, orientation, role):
     if role != Qt.DisplayRole or orientation != Qt.Horizontal:
         return QVariant()
     return self._header[section]
Пример #9
0
 def data(self, index, role):
     if not index.isValid():
         return QVariant()
     elif role != Qt.DisplayRole:
         return QVariant()
     return QVariant(self.rows_data[index.row()][index.column()])
Пример #10
0
 def data(self, index: QModelIndex, role: int = ...) -> typing.Any:
     if role != Qt.DisplayRole:
         return QVariant()
     return self.rows[index.row()][index.column()]
Пример #11
0
 def __showInList(self, node):
     if node is None:
         return
     item = QListWidgetItem(node.name)
     item.setData(Qt.UserRole, QVariant(str(node.id)))
     self.uiList.addItem(item)
Пример #12
0
    def load_data(self):
        self.window.mode_comboBox.setItemData(0, QVariant(1 | 32), Qt.UserRole - 1)
        self.window.mode_comboBox.setItemData(1, QVariant(1 | 32), Qt.UserRole - 1)
        self.window.mode_comboBox.setItemData(2, QVariant(1 | 32), Qt.UserRole - 1)
        Dialog = QFileDialog()
        file_names, filetype = Dialog.getOpenFileNames(self.window,
                                                       "选取文件",
                                                       # 获得当前路径
                                                       os.getcwd(),  # 起始路径
                                                       "CSV文件 (*.csv);;所有文件 (*)")  # 设置文件扩展名过滤,用双分号间隔
        if file_names == []:
            print("\n取消选择")
            Dialog.deleteLater()
            sip.delete(Dialog)
            gc.collect()

        else:
            """
            如果选择单个文件则判断是合并的周级数据还是天级数据
                周级数据:大文件模式
                天级数据:小文件绘图模式
            如果选择多个文件
                多个文件:多文件模式
            """
            if len(file_names) == 1:
                """
               得到文件的大小 单位 kb
               1M = 1024 kb
               300M = 307200 kb
               如果文件小于300M则选择小文件绘图模式 否则大文件模式
               """
                self.need_deal_data = file_names[0]
                self.window.select_project_comboBox.setEnabled(True)
                file_size = os.path.getsize(self.need_deal_data)
                file_size = float(file_size) / float(1024 * 1024)  # M
                if file_size <= 300:
                    # 设置模式为小文件绘图模式,1,2 选项不可选
                    self.window.mode_comboBox.setItemData(1, 0, Qt.UserRole - 1)
                    self.window.mode_comboBox.setItemData(2, 0, Qt.UserRole - 1)
                    # 设置模式1
                    self.mode = 1
                    self.window.mode_comboBox.setCurrentIndex(0)
                    print("mode1")

                else:
                    self.need_deal_data = file_names[0]
                    self.window.select_project_comboBox.setEnabled(True)
                    # 设置模式为大文件,0,2 选项不可选
                    self.window.mode_comboBox.setItemData(0, 0, Qt.UserRole - 1)
                    self.window.mode_comboBox.setItemData(2, 0, Qt.UserRole - 1)
                    # 设置模式2
                    self.mode = 2
                    self.window.mode_comboBox.setCurrentIndex(1)
                    print("mode2")

            else:
                self.window.select_project_comboBox.setEnabled(True)
                # 还未设计多文件选择模式
                self.need_deal_data = file_names
                # 设置模式为多文件模式,0,2 选项不可选
                self.window.mode_comboBox.setItemData(0, 0, Qt.UserRole - 1)
                self.window.mode_comboBox.setItemData(1, 0, Qt.UserRole - 1)
                # 设置模式3
                self.mode = 3
                print("mode3")
            # 设置选择下拉框可见
            Dialog.deleteLater()
            sip.delete(Dialog)
            gc.collect()
Пример #13
0
 def data(self, index, role=Qt.DisplayRole):
     current = self.filtered_titles if self.filtered_titles != None else self.titles
     if role == Qt.DisplayRole:
         return QVariant(current[index.row()])
     else:
         return QVariant()
Пример #14
0
 def headerData(self, section, orientation, role=Qt.DisplayRole):
     if role == Qt.TextAlignmentRole:
         if orientation == Qt.Horizontal:
             return QVariant(int(Qt.AlignCenter | Qt.AlignVCenter))
         return QVariant(int(Qt.AlignRight | Qt.AlignVCenter))
     if role != Qt.DisplayRole:
         return QVariant()
     if role == Qt.DisplayRole:
         if orientation == Qt.Horizontal:
             if section == STATUS:
                 return QVariant(headerData[STATUS])
             elif section == ID:
                 return QVariant(headerData[ID])
             elif section == PATTERN:
                 return QVariant(headerData[PATTERN])
             elif section == POSITION:
                 return QVariant(headerData[POSITION])
             elif section == REASON:
                 return QVariant(headerData[REASON])
             elif section == ROOT:
                 return QVariant(headerData[ROOT])
             elif section == SITUATION:
                 return QVariant(headerData[SITUATION])
             elif section == RECORD_TIME:
                 return QVariant(headerData[RECORD_TIME])
Пример #15
0
 def test_get_badindex(self):
     self.addroles_auto()
     self.adddata()
     self.assertEqual(self.testmodel.get(-1), QVariant())
     self.assertEqual(self.testmodel.get(100), QVariant())
Пример #16
0
    def headerData(self, section, orientation, role=None):
        headers = ["Имя"]
        if orientation == Qt.Horizontal and section < len(headers):
            return QVariant(headers[section])

        return QVariant()
Пример #17
0
 def data(self, index, role):
     if role == Qt.DisplayRole:
         return QVariant(db[index.row()].name)
     return QVariant()
Пример #18
0
def _as_uint32(x: int) -> QVariant:
    """Convert the given int to an uint32 for DBus."""
    variant = QVariant(x)
    successful = variant.convert(QVariant.UInt)
    assert successful
    return variant
Пример #19
0
    def edit(self):

        logging.debug('edit() called BinanceOHLC')

        # interval-str, inteval-index, symbol_txt, log-state
        interval_str, interval_index, symbol_txt, log_state = self.config

        self.binance_ohlc_layout = QVBoxLayout()
        self.confirm_button = QPushButton(QC.translate('', 'Ok'))

        self.interval_txt = QLabel()
        self.interval_txt.setText(QC.translate('', 'Choose the OHLC interval'))

        # https://github.com/sammchardy/python-binance/blob/master/binance/client.py
        self.selectInterval = QComboBox()
        self.selectInterval.addItem(QC.translate('', '1 Minute'),
                                    QVariant('1m'))
        self.selectInterval.addItem(QC.translate('', '3 Minutes'),
                                    QVariant('3m'))
        self.selectInterval.addItem(QC.translate('', '5 Minutes'),
                                    QVariant('5m'))
        self.selectInterval.addItem(QC.translate('', '15 Minutes'),
                                    QVariant('15m'))
        self.selectInterval.addItem(QC.translate('', '30 Minutes'),
                                    QVariant('30m'))
        self.selectInterval.addItem(QC.translate('', '1 Hour'), QVariant('1h'))
        self.selectInterval.addItem(QC.translate('', '2 Hours'),
                                    QVariant('2h'))
        self.selectInterval.addItem(QC.translate('', '4 Hours'),
                                    QVariant('4h'))
        self.selectInterval.addItem(QC.translate('', '6 Hours'),
                                    QVariant('6h'))
        self.selectInterval.addItem(QC.translate('', '8 Hours'),
                                    QVariant('8h'))
        self.selectInterval.addItem(QC.translate('', '12 Hours'),
                                    QVariant('12h'))
        self.selectInterval.addItem(QC.translate('', '1 Day'), QVariant('1d'))
        self.selectInterval.setCurrentIndex(interval_index)

        self.symbol_txt = QLabel()
        self.symbol_txt.setText(QC.translate('', 'Enter currency pair'))

        self.symbol_input = QLineEdit()
        self.symbol_input.setPlaceholderText(QC.translate('', 'e.g. "XMRBTC"'))

        if symbol_txt:
            self.symbol_input.setText(symbol_txt)

        self.help_txt = QWidget()
        self.help_txt_layout = QVBoxLayout(self.help_txt)

        self.help_txt_1 = QLabel()
        self.help_txt_1.setText(
            QC.translate(
                '', 'Outputs a Pandas dataframe in the following format:'))

        self.help_txt_2 = QLabel()
        self.help_txt_2.setText('\r\n')

        self.help_txt_3 = QLabel()
        self.help_txt_3.setText(QC.translate('','open_time [Unix, 10 digits], open, high, low, close,\r\nvolume, close_time [Unix, 10 digits], quote_assetv,\r\n' \
            'trades, taker_b_asset_v, taker_b_asset_v, datetime'))

        self.help_txt_layout.addWidget(self.help_txt_1)
        self.help_txt_layout.addWidget(self.help_txt_2)
        self.help_txt_layout.addWidget(self.help_txt_3)

        # hier logging option einfügen
        self.log_line = QWidget()
        self.ask_for_logging = QLabel()
        self.ask_for_logging.setText(QC.translate('', 'Log output?'))
        self.log_checkbox = QCheckBox()
        self.log_line_layout = QHBoxLayout(self.log_line)
        self.log_line_layout.addWidget(self.ask_for_logging)
        self.log_line_layout.addWidget(self.log_checkbox)
        self.log_line_layout.addStretch(1)

        if log_state:
            self.log_checkbox.setChecked(True)

        self.binance_ohlc_edit = ElementEditor(self)
        self.binance_ohlc_edit.setWindowTitle(
            QC.translate('', 'Edit OHLC query'))

        # signals and slots
        self.confirm_button.clicked.connect(self.binance_ohlc_edit.closeEvent)
        self.binance_ohlc_edit.window_closed.connect(self.edit_done)

        self.binance_ohlc_layout.addWidget(self.interval_txt)
        self.binance_ohlc_layout.addWidget(self.selectInterval)
        self.binance_ohlc_layout.addWidget(self.symbol_txt)
        self.binance_ohlc_layout.addWidget(self.symbol_input)
        self.binance_ohlc_layout.addWidget(self.log_line)
        self.binance_ohlc_layout.addStretch(1)
        self.binance_ohlc_layout.addWidget(self.help_txt)
        self.binance_ohlc_layout.addWidget(self.confirm_button)
        self.binance_ohlc_edit.setLayout(self.binance_ohlc_layout)
        self.binance_ohlc_edit.show()
Пример #20
0
 def data(self, index, role):
     if index.isValid() and role == Qt.DisplayRole:
         return QVariant(self.listdata[index.row()])
     else:
         return QVariant()
Пример #21
0
 def data(self, index: QModelIndex, role: Qt.ItemDataRole) -> QVariant:
     # note: this method is performance-critical.
     # it is called a lot, and so must run extremely fast.
     assert index.isValid()
     col = index.column()
     tx_item = self.transactions.value_from_pos(index.row())
     tx_hash = tx_item['txid']
     conf = tx_item['confirmations']
     txpos = tx_item['txpos_in_block'] or 0
     height = tx_item['height']
     try:
         status, status_str = self.tx_status_cache[tx_hash]
     except KeyError:
         tx_mined_info = self.tx_mined_info_from_tx_item(tx_item)
         status, status_str = self.parent.wallet.get_tx_status(
             tx_hash, tx_mined_info)
     if role == Qt.UserRole:
         # for sorting
         d = {
             HistoryColumns.STATUS_ICON:
             # height breaks ties for unverified txns
             # txpos breaks ties for verified same block txns
             (status, conf, -height, -txpos),
             HistoryColumns.STATUS_TEXT:
             status_str,
             HistoryColumns.DIP2:
             tx_item.get('dip2', ''),
             HistoryColumns.DESCRIPTION:
             tx_item['label'],
             HistoryColumns.COIN_VALUE:
             tx_item['value'].value,
             HistoryColumns.RUNNING_COIN_BALANCE:
             tx_item['balance'].value,
             HistoryColumns.FIAT_VALUE:
             tx_item['fiat_value'].value
             if 'fiat_value' in tx_item else None,
             HistoryColumns.FIAT_ACQ_PRICE:
             tx_item['acquisition_price'].value
             if 'acquisition_price' in tx_item else None,
             HistoryColumns.FIAT_CAP_GAINS:
             tx_item['capital_gain'].value
             if 'capital_gain' in tx_item else None,
             HistoryColumns.TXID:
             tx_hash,
         }
         return QVariant(d[col])
     if role not in (Qt.DisplayRole, Qt.EditRole):
         if col == HistoryColumns.STATUS_ICON and role == Qt.DecorationRole:
             return QVariant(read_QIcon(TX_ICONS[status]))
         elif col == HistoryColumns.STATUS_ICON and role == Qt.ToolTipRole:
             return QVariant(
                 str(conf) + _(" confirmation" +
                               ("s" if conf != 1 else "")))
         elif col != HistoryColumns.DESCRIPTION and role == Qt.TextAlignmentRole:
             return QVariant(Qt.AlignRight | Qt.AlignVCenter)
         elif col != HistoryColumns.DESCRIPTION and role == Qt.FontRole:
             monospace_font = QFont(MONOSPACE_FONT)
             return QVariant(monospace_font)
         elif col == HistoryColumns.DESCRIPTION and role == Qt.DecorationRole \
                 and self.parent.wallet.invoices.paid.get(tx_hash):
             return QVariant(read_QIcon("seal"))
         elif col == HistoryColumns.DIP2 and role == Qt.ForegroundRole:
             dip2_brush = QBrush(QColor("#1c75bc"))
             return QVariant(dip2_brush)
         elif col in (HistoryColumns.DESCRIPTION, HistoryColumns.COIN_VALUE) \
                 and role == Qt.ForegroundRole and tx_item['value'].value < 0:
             red_brush = QBrush(QColor("#BC1E1E"))
             return QVariant(red_brush)
         elif col == HistoryColumns.FIAT_VALUE and role == Qt.ForegroundRole \
                 and not tx_item.get('fiat_default') and tx_item.get('fiat_value') is not None:
             blue_brush = QBrush(QColor("#1E1EFF"))
             return QVariant(blue_brush)
         return QVariant()
     if col == HistoryColumns.STATUS_TEXT:
         return QVariant(status_str)
     elif col == HistoryColumns.DIP2:
         return QVariant(tx_item.get('dip2', ''))
     elif col == HistoryColumns.DESCRIPTION:
         return QVariant(tx_item['label'])
     elif col == HistoryColumns.COIN_VALUE:
         value = tx_item['value'].value
         v_str = self.parent.format_amount(value,
                                           is_diff=True,
                                           whitespaces=True)
         return QVariant(v_str)
     elif col == HistoryColumns.RUNNING_COIN_BALANCE:
         balance = tx_item['balance'].value
         balance_str = self.parent.format_amount(balance, whitespaces=True)
         return QVariant(balance_str)
     elif col == HistoryColumns.FIAT_VALUE and 'fiat_value' in tx_item:
         value_str = self.parent.fx.format_fiat(tx_item['fiat_value'].value)
         return QVariant(value_str)
     elif col == HistoryColumns.FIAT_ACQ_PRICE and \
             tx_item['value'].value < 0 and 'acquisition_price' in tx_item:
         # fixme: should use is_mine
         acq = tx_item['acquisition_price'].value
         return QVariant(self.parent.fx.format_fiat(acq))
     elif col == HistoryColumns.FIAT_CAP_GAINS and 'capital_gain' in tx_item:
         cg = tx_item['capital_gain'].value
         return QVariant(self.parent.fx.format_fiat(cg))
     elif col == HistoryColumns.TXID:
         return QVariant(tx_hash)
     return QVariant()
Пример #22
0
    def data(self, index: QModelIndex, role: Qt.ItemDataRole) -> QVariant:
        assert index.isValid()
        col = index.column()
        tx_item = index.internalPointer()
        tx_hash = tx_item['txid']
        conf = tx_item['confirmations']
        islock = tx_item['islock']
        is_parent = ('group_label' in tx_item)
        if is_parent and tx_hash in self.expanded_groups:
            expanded = True
        else:
            expanded = False

        if not is_parent:
            tx_group_icon = None
        elif not expanded:
            tx_group_icon = self.tx_group_expand_icn
        else:
            tx_group_icon = self.tx_group_collapse_icn
        try:
            status, status_str = self.tx_status_cache[tx_hash]
        except KeyError:
            tx_mined_info = self.tx_mined_info_from_tx_item(tx_item)
            status, status_str = self.parent.wallet.get_tx_status(
                tx_hash, tx_mined_info, islock)

        if role not in (Qt.DisplayRole, Qt.EditRole):
            if col == HistoryColumns.TX_GROUP and role == Qt.DecorationRole:
                if tx_group_icon:
                    return QVariant(tx_group_icon)
            if col == HistoryColumns.STATUS and role == Qt.DecorationRole:
                return QVariant(read_QIcon(TX_ICONS[status]))
            elif col == HistoryColumns.STATUS and role == Qt.ToolTipRole:
                if tx_item['height'] == TX_HEIGHT_LOCAL:
                    msg = _(
                        "This transaction is only available on your local machine.\n"
                        "The currently connected server does not know about it.\n"
                        "You can either broadcast it now, or simply remove it."
                    )
                    return QVariant(msg)
                c = str(conf) + _(' confirmation' + ('s' if conf != 1 else ''))
                if conf < 6 and islock:
                    res = 'InstantSend, %s' % c
                else:
                    res = c
                return QVariant(res)
            elif col not in [HistoryColumns.DESCRIPTION, HistoryColumns.DIP2
                             ] and role == Qt.TextAlignmentRole:
                return QVariant(int(Qt.AlignRight | Qt.AlignVCenter))
            elif col != HistoryColumns.DESCRIPTION and role == Qt.FontRole:
                monospace_font = QFont(MONOSPACE_FONT)
                return QVariant(monospace_font)
            #elif col == HistoryColumns.DESCRIPTION and role == Qt.DecorationRole \
            #        and self.parent.wallet.invoices.paid.get(tx_hash):
            #    return QVariant(read_QIcon("seal"))
            elif col == HistoryColumns.DIP2 and role == Qt.ForegroundRole:
                dip2_brush = QBrush(QColor("#1c75bc"))
                return QVariant(dip2_brush)
            elif (col in (HistoryColumns.DESCRIPTION, HistoryColumns.AMOUNT)
                  and role == Qt.ForegroundRole):
                if is_parent and not expanded:
                    value = tx_item['group_value'].value
                else:
                    value = tx_item['value'].value
                if value < 0:
                    red_brush = QBrush(QColor("#BC1E1E"))
                    return QVariant(red_brush)
            elif col == HistoryColumns.FIAT_VALUE and role == Qt.ForegroundRole \
                    and not tx_item.get('fiat_default') and tx_item.get('fiat_value') is not None:
                blue_brush = QBrush(QColor("#1E1EFF"))
                return QVariant(blue_brush)
            return QVariant()
        if col == HistoryColumns.STATUS:
            return QVariant(status_str)
        elif col == HistoryColumns.DIP2:
            if is_parent and not expanded:
                return QVariant(tx_item.get('group_tx_type', ''))
            else:
                return QVariant(tx_item.get('tx_type', ''))
        elif col == HistoryColumns.DESCRIPTION:
            if is_parent and not expanded:
                return QVariant(tx_item['group_label'])
            else:
                return QVariant(tx_item['label'])
        elif col == HistoryColumns.AMOUNT:
            if is_parent and not expanded:
                value = tx_item['group_value'].value
            else:
                value = tx_item['value'].value
            v_str = self.parent.format_amount(value,
                                              is_diff=True,
                                              whitespaces=True)
            return QVariant(v_str)
        elif col == HistoryColumns.BALANCE:
            if is_parent and not expanded:
                balance = tx_item['group_balance'].value
            else:
                balance = tx_item['balance'].value
            balance_str = self.parent.format_amount(balance, whitespaces=True)
            return QVariant(balance_str)
        elif col == HistoryColumns.FIAT_VALUE and 'fiat_value' in tx_item:
            if is_parent and not expanded:
                return
            value_str = self.parent.fx.format_fiat(tx_item['fiat_value'].value)
            return QVariant(value_str)
        elif col == HistoryColumns.FIAT_ACQ_PRICE and \
                tx_item['value'].value < 0 and 'acquisition_price' in tx_item:
            if is_parent and not expanded:
                return
            # fixme: should use is_mine
            acq = tx_item['acquisition_price'].value
            return QVariant(self.parent.fx.format_fiat(acq))
        elif col == HistoryColumns.FIAT_CAP_GAINS and 'capital_gain' in tx_item:
            if is_parent and not expanded:
                return
            cg = tx_item['capital_gain'].value
            return QVariant(self.parent.fx.format_fiat(cg))
        elif col == HistoryColumns.TXID:
            return QVariant(tx_hash)
        return QVariant()
Пример #23
0
 def data(self, index, role=None):
     if not index.isValid() or role != Qt.DisplayRole:
         return QVariant()
     return qGray(self.modelImage.pixel(index.column(), index.row()))
Пример #24
0
 def updateTable(self):
     self.beginResetModel()
     self.endResetModel()
     return QVariant()
Пример #25
0
 def headerData(self, col, orientation, role=None):
     if orientation == Qt.Horizontal and role == Qt.DisplayRole:
         return QVariant(self.headerdata[col])
     return QVariant()
Пример #26
0
 def data(self, index, role):
     if role == Qt.DisplayRole or role == Qt.EditRole:  # <--
         # See https://stackoverflow.com/a/8480223
         return self._data.get_data(index.row(), index.column())
     return QVariant()
Пример #27
0
 def cells(self):
     return QVariant(self._cells)
 def data(self, index, role):
     if role == Qt.DisplayRole:
         return self.data.get_data(index.row(), index.column())
     return QVariant()
Пример #29
0
    def data(self, index, role=Qt.DisplayRole):

        if role == Qt.EditRole:
            return self.arraydata[index.row()][index.column()]

        elif role == Qt.DecorationRole and index.column() == 18:
            value = self.arraydata[index.row()][index.column()]
            return QIcon(os.path.join(ICONPATH, "tool_pos_{}.png".format(value)))

        elif role == Qt.DisplayRole:
            value = self.arraydata[index.row()][index.column()]
            col = index.column()
            if isinstance(value, float):
                if value == 0.0:
                    tmpl = lambda s: self.zero_text_template % s
                    return tmpl(value)
                elif col in(16,17):
                    tmpl = lambda s: self.degree_text_template % s
                    return tmpl(value)
                elif self.metric_display:
                    tmpl = lambda s: self.metric_text_template % s
                else:
                    tmpl = lambda s: self.imperial_text_template % s
                if self.metric_display != INFO.MACHINE_IS_METRIC:
                    value = INFO.convert_units(value)
                if col in(3,4):
                    if self.diameter_display:
                        value *=2
                        self.headerdata[3] = 'X D'
                        self.headerdata[4] = 'X Wear D'
                    else:
                        self.headerdata[3] = 'X R'
                        self.headerdata[4] = 'X Wear R'
                return tmpl(value)

            if isinstance(value, str):
                return '%s' % value
            # Default (anything not captured above: e.g. int)
            return value

        elif role == Qt.BackgroundRole:
            value = self.arraydata[index.row()][index.column()]
            if (isinstance(value, int) or isinstance(value, float) or
                  isinstance(value, str), isinstance(value, QCheckBox)):
                if self.arraydata[index.row()][1] == self.parent().current_tool:
                    return QColor(self._highlightcolor)
                elif self.arraydata[index.row()][0].isChecked():
                    return QColor(self._selectedcolor)
                else:
                    return QVariant()
            
        elif role == Qt.CheckStateRole:
            if index.column() == 0:
                # print(">>> data() row,col = %d, %d" % (index.row(), index.column()))
                if self.arraydata[index.row()][index.column()].isChecked():
                    return Qt.Checked
                else:
                    return Qt.Unchecked

        elif role == Qt.ForegroundRole:
            value = self.arraydata[index.row()][index.column()]

            if ((isinstance(value, int) or isinstance(value, float))
                and value < 0 ):
                return QColor('red')

        return QVariant()
Пример #30
0
 def data(self, index, role):
     if index.isValid() and role == Qt.DisplayRole:
         return QVariant(str(self.points[index.row()]))
     if index.isValid() and role == Qt.UserRole:
         return self.points[index.row()].x, self.points[index.row()].y
     return QVariant()