Ejemplo n.º 1
0
    def set_value_at(self, x, y, value): # Set item value at position (x,y). This is used to reference a board made of 9 different widgets.
        nvalue = str(value)
        newItem = QTableWidgetItem(nvalue)
        current_value = self.get_value_at(x, y)
        if current_value != 0:
            newItem.setTextColor(QColor("green"))

        horizontal = int(y / 3)
        horizontalIndex = y % 3
        vertical = int(x / 3)
        verticalIndex = x % 3

        if vertical == 0:
            if horizontal == 0:
                self.topLeft.setItem(verticalIndex, horizontalIndex, newItem)
            elif horizontal == 1:
                self.topMiddle.setItem(verticalIndex, horizontalIndex, newItem)
            else:
                self.topRight.setItem(verticalIndex, horizontalIndex, newItem)
        elif vertical == 1:
            if horizontal == 0:
                self.middleLeft.setItem(verticalIndex, horizontalIndex, newItem)
            elif horizontal == 1:
                self.middleMiddle.setItem(verticalIndex, horizontalIndex, newItem)
            else:
                self.middleRight.setItem(verticalIndex, horizontalIndex, newItem)
        else:
            if horizontal == 0:
                self.bottomLeft.setItem(verticalIndex, horizontalIndex, newItem)
            elif horizontal == 1:
                self.bottomMiddle.setItem(verticalIndex, horizontalIndex, newItem)
            else:
                self.bottomRight.setItem(verticalIndex, horizontalIndex, newItem)
Ejemplo n.º 2
0
 def set_position_slot(self, positions: list):
     self.position_table.setRowCount(0)
     barpos = self.position_table.verticalScrollBar().value()
     row = 0
     x = sorted(positions, key=operator.itemgetter('local_symbol'))
     for p in x:
         self.position_table.insertRow(row)
         for i, col in enumerate(position_table_column):
             if col != 'operator':
                 if col == 'position_profit':
                     new = float(p[col])
                     it = QTableWidgetItem(str(new))
                     if new > 0:
                         it.setTextColor(QColor('red'))
                     elif new < 0:
                         it.setTextColor(QColor('green'))
                     self.position_table.setItem(row, i, it)
                 else:
                     self.position_table.setItem(
                         row, i, QTableWidgetItem(str(p[col])))
             else:
                 btn = QPushButton('平仓')
                 btn.clicked.connect(self.close_position)
                 self.position_table.setCellWidget(row, i, btn)
     self.position_table.verticalScrollBar().setValue(barpos)
Ejemplo n.º 3
0
 def set_item_value(self, item, value):  # Color item
     if (hasattr(item, 'text')):
         if item.text() != ' ' and item.text() != '':
             item.setText(value)
         else:
             item.setText(value)
             item.setTextColor(QColor("green"))
     else:
         item = QTableWidgetItem(value)
         item.setTextColor(QColor("green"))
Ejemplo n.º 4
0
 def add_row(self,
             row: int,
             item_text: str,
             item_text_color: QColor = color.TABLE_CODE_TEXT_COLOR,
             item_background_color=color.TABLE_CODE_BACKGROUND_COLOR,
             header_text: str = ''):
     self.table_widget.setRowCount(row + 1)
     table_header = QTableWidgetItem(header_text)
     self.table_widget.setVerticalHeaderItem(row, table_header)
     table_item = QTableWidgetItem(item_text)
     table_item.setTextColor(item_text_color)
     table_item.setFlags(table_item.flags() ^ Qt.ItemIsEditable)
     table_item.setBackgroundColor(item_background_color)
     self.table_widget.setItem(row, 0, table_item)
Ejemplo n.º 5
0
 def showOneDay(self, columnNumber, pickle_file, theDay):
     #在特定列显示特定项目的任务
     f = open(pickle_file, 'rb')
     all_list = pickle.load(f)
     review_dict = all_list[1]
     study_dict = all_list[0]
     if theDay in study_dict:
         if 0 >= self.ui.tableWidget.rowCount():
             self.ui.tableWidget.insertRow(0)
         newItem = QTableWidgetItem(study_dict[theDay][0:-1])
         newItem.setTextColor(QColor(200, 111, 100))
         self.ui.tableWidget.setItem(0, columnNumber, newItem)
     if theDay in review_dict:
         rowNumber = 1
         for task in review_dict[theDay]:
             if rowNumber >= self.ui.tableWidget.rowCount():
                 self.ui.tableWidget.insertRow(rowNumber)
             if task:
                 self.ui.tableWidget.setItem(rowNumber, columnNumber,
                                             QTableWidgetItem(task[0:-1]))
                 rowNumber = rowNumber + 1
Ejemplo n.º 6
0
def display_active_table_on_data_display(self):
    # class props needed
    data_to_display = self.data_to_display_on_tab1.copy()
    table_name = self.table_on_target
    self.ui.label_table_on_display.setText(table_name)
    # headers
    fields = self.headers_for_tab1
    self.ui.tableWidget_table_display.setColumnCount(len(fields))
    tableHeadersWidgets_list = list((QTableWidgetItem() for n in fields))

    for index, field in enumerate(fields):
        tableHeadersWidgets_list[index].setText(field)
        self.ui.tableWidget_table_display.setHorizontalHeaderItem(
            index, tableHeadersWidgets_list[index])

    # table build process
    self.ui.tableWidget_table_display.setRowCount(0)
    for i_row, row in enumerate(data_to_display):
        self.ui.tableWidget_table_display.insertRow(i_row)
        for i_col, item_data in enumerate(row):
            item__ = QTableWidgetItem(str(item_data))
            if i_row % 2 == 0:
                item__.setBackgroundColor(QColor(220, 230, 255))
            try:
                negative_value = item_data < 0
                if negative_value:
                    item__.setBackgroundColor(QColor(120, 0, 0))
                    item__.setTextColor(QColor(255, 255, 255))
                    item__.setFont(QFont(weight=5))
            except:
                pass
            finally:
                item__.setText(
                    get_format_of_field(
                        table_name,
                        self.ui.tableWidget_table_display.horizontalHeaderItem(
                            i_col).text())(item_data))
                self.ui.tableWidget_table_display.setItem(i_row, i_col, item__)
    # print('debug: table {} displayed...'.format(table_name))
    return
Ejemplo n.º 7
0
    def populateTable(self, path):
        "fill file table with file names"
        self.showFolder(path)

        names = []
        for n in os.listdir(path):
            if os.path.isdir(os.path.join(path, n)): continue  # folder
            names.append(n)

        self.folderTable.clearContents()
        self.folderTable.setRowCount(len(names))
        self.folderTable.setColumnCount(1)

        if not names:  # no files in this folder, inform user
            self.setMessage('This folder has no files')
            return

        self.folderTable.blockSignals(True)
        selEnab = Qt.ItemIsSelectable | Qt.ItemIsEnabled
        for i, n in enumerate(names):
            item = QTableWidgetItem()
            item.setText(n)
            item.setToolTip(n)
            item.setFlags(selEnab)

            # color code encrypted/decrypted files
            if n in self.encrypted:
                item.setTextColor(QColor(211, 70, 0))
                # allowed encrypted filenames to be changed
                item.setFlags(selEnab | Qt.ItemIsEditable)
            if n in self.decrypted:
                item.setForeground(QColor(0, 170, 255))
            self.folderTable.setItem(i, 0, item)
        if len(names) > 5:
            self.setMessage('{:,} files'.format(len(names)), 7)
        self.folderTable.blockSignals(False)
        return
Ejemplo n.º 8
0
    def set_item_slot(self, tick: dict):
        local_symbol = tick['local_symbol']
        if local_symbol not in self.cur_ticks:
            return
        if local_symbol not in self.cur_row_map:  # 不在table ,插入row
            self.cur_row_map.append(local_symbol)
            self.tableWidget.insertRow(self.item_row)
            self.insert_(self.item_row, tick)
            self.item_row += 1

        else:  # 已在table中 ,更新对应row
            row = self.cur_row_map.index(local_symbol)
            for i, col in enumerate(market_table_column):
                try:
                    if col == "last_price":  # 对最新价动态颜色表示涨跌
                        old = self.tableWidget.item(row, i)
                        if old:  # 非空
                            old = float(old.text())
                            new = float(tick[col])
                            difference = new - old
                            item = QTableWidgetItem(str(new))
                            if difference > 0:  # 涨
                                item.setTextColor(QColor('red'))
                            elif difference < 0:  # 跌
                                item.setTextColor(QColor('green'))
                            else:
                                continue
                        else:  # None
                            item = QTableWidgetItem(str(tick[col]))
                    elif col == "inc_day_interest":
                        data = tick['open_interest'] - tick['pre_open_interest']
                        item = QTableWidgetItem(str(data))
                        # item.setTextColor()
                    # elif col == "inc_now_interest": # 现增仓
                    #     item = ''
                    elif col == "limit":  # 涨跌
                        data = tick['last_price'] - tick['pre_close']
                        item = QTableWidgetItem(str(data))
                    elif col == "limit1":  # 涨幅
                        data = (tick['last_price'] -
                                tick['pre_close'] / tick['pre_close']) * 0.01
                        item = QTableWidgetItem(str(data))
                    else:
                        item = QTableWidgetItem(str(tick.get(col, "---")))
                except (ValueError, ZeroDivisionError) as e:
                    item = QTableWidgetItem(str(tick.get(col, "---")))
                if item.text().isdigit():
                    item.setText("%0.2f" % float(item.text()))
                if col in yellow:
                    item.setTextColor(QColor(199, 199, 9))
                self.tableWidget.setItem(row, i, item)
Ejemplo n.º 9
0
 def insert_(self, row, tick):
     for i, col in enumerate(market_table_column):
         item = QTableWidgetItem(str(tick.get(col, "---")))
         if col in yellow:
             item.setTextColor(QColor(199, 199, 9))
         self.tableWidget.setItem(row, i, item)
Ejemplo n.º 10
0
class MainTable(QTableWidget):
    def __init__(self):
        super().__init__()
        self.initTable()

    def initTable(self):
        #Формирование базовой таблицы
        self.header = [
            'Составляющие затрат', 'Номер расценки', 'Единица измерения',
            'Базовая величина затрат, тыс.руб./ед.изм.', 'Количество ед.',
            'Коэффициент приведения затрат к уровню цен субъекта',
            'Базовые затраты в уровнях цен субъекта РФ, тыс.руб.',
            'Текущие затраты в уровнях цен субъекта РФ, тыс.руб.', 'Del'
        ]
        self.setColumnCount(9)
        self.setRowCount(1)
        for i in range(0, len(self.header)):
            self.setHorizontalHeaderItem(i, QTableWidgetItem(self.header[i]))
        stylesheet = "::section{Background-color:rgb(176,224,230);border-radius:2px;}"
        self.horizontalHeader().setStyleSheet(stylesheet)
        self.resizeColumnsToContents()

        #Формирование сигналов
        self.cellClicked.connect(self.deleteClicked)

    #Добавление строк по клику
    def update_table(self, items):
        self.make_closebutton()
        text = self.make_numbertext(items)
        self.row = self.rowCount() - 1
        self.setItem(self.row, 3, QTableWidgetItem(items[0]))
        self.setItem(self.row, 4, QTableWidgetItem(items[3]))
        self.setItem(self.row, 5, QTableWidgetItem(
            items[4]))  #Добавить критерии выбора региональных коэффициентов
        self.setItem(self.row, 6, QTableWidgetItem(self.calculate(items)[0]))
        self.setItem(self.row, 7, QTableWidgetItem(self.calculate(items)[1]))
        self.setItem(self.row, 1, QTableWidgetItem(text))
        self.setItem(self.row, 8, self.closebut)
        self.insertRow(self.row + 1)

    #Пересчет при изменении значений
    def recalculation(self, data):
        for i in range(len(data[0])):
            cost = float(data[0][i])
            count = float(data[1][i])
            koef = float(data[2][i])
            calc = str(round(cost * count * koef, 1))
            self.setItem(i, 6, QTableWidgetItem(calc.replace('.', ',')))
            self.setItem(
                i, 7,
                QTableWidgetItem(
                    str(round(float(calc) * 1.2, 1)).replace('.', ',')))

    #Удаление строки
    def deleteClicked(self, row, col):
        if col == 8:
            self.removeRow(row)
            self.row += 1

    #Текст для категории
    def make_numbertext(self, items):
        if len(items[2]) > 5:
            return items[2][:5] + '-' + items[1]
        else:
            return items[2]

    #Расчет стоимости
    def calculate(self, items):
        cost = float(items[0].replace(',', '.'))
        count = float(items[3].replace(',', '.'))
        k = float(items[4].replace(',', '.'))
        current_cost = str(round(cost * count * k, 11))
        future_cost = str(round(float(current_cost) * 1.2, 1))
        return [current_cost.replace('.', ','), future_cost.replace('.', ',')]

    #Рисует крестик для удаления строки
    def make_closebutton(self):
        self.closebut = QTableWidgetItem('X')
        self.closebut.setBackgroundColor(QColor(240, 240, 240))
        self.closebut.setFont(QFont('Helvetica [Cronyx]', 18, QFont.ExtraBold))
        self.closebut.setTextColor(QColor(255, 11, 21))
        self.closebut.setTextAlignment(4)