프로젝트

일반

사용자정보

개정판 9358b7d1

ID9358b7d172cb49ad118b2d761968fb3424db9e6c
상위 cce7850b
하위 9a1af0f8

백흠경이(가) 약 4년 전에 추가함

issue #1048: fixed 2 columns in StreamData View

Change-Id: Icbd7b41e33bc10d1b17ced8a26e242509e6ce642

차이점 보기:

HYTOS/HYTOS/AppDocData.py
1701 1701

  
1702 1702
        return unitsList
1703 1703

  
1704
    def getHMBDisplayNameAndUnitsExpression(self):
1705
        res = []
1704
    def getHMBDisplayNameAndUnitsExpression(self) -> QStandardItemModel:
1705
        res = QStandardItemModel(0, 2)
1706 1706

  
1707 1707
        if self.activeDrawing:
1708
            conn = sqlite3.connect(self.activeDrawing.path)
1709
            conn.execute('PRAGMA foreign_keys = ON')
1710
            with conn:
1708
            with sqlite3.connect(self.activeDrawing.path) as conn:
1709
                conn.execute('PRAGMA foreign_keys = ON')
1711 1710
                cursor = conn.cursor()
1712 1711
                sql = """SELECT dn.DISPLAY_NAME
1713 1712
                                , hu.Units_Expression
......
1720 1719
                    cursor.execute(sql)
1721 1720
                    rows = cursor.fetchall()
1722 1721
                    for row in rows:
1723
                        res.append((row[0], row[1]))
1722
                        items = [QStandardItem(row[0]), QStandardItem(row[1])]
1723
                        items[0].setTextAlignment(Qt.AlignLeft | Qt.AlignVCenter)
1724
                        items[0].setBackground(QColor(51, 153, 102))
1725
                        items[0].setEditable(False)
1726
                        items[1].setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
1727
                        items[1].setBackground(QColor(204, 255, 204))
1728
                        items[1].setEditable(False)
1729

  
1730
                        res.appendRow(items)
1731
                        # res.append((row[0], row[1]))
1724 1732
                except Exception as ex:
1725 1733
                    from App import App
1726 1734

  
1727
                    message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1728
                                                                   sys.exc_info()[-1].tb_lineno)
1735
                    message = f'error occurred({ex}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:' \
1736
                              f'{sys.exc_info()[-1].tb_lineno}'
1729 1737
                    App.mainWnd().addMessage.emit(MessageType.Error, message)
1730 1738

  
1731 1739
        return res
HYTOS/HYTOS/CopyStreamData.py
110 110
            app_doc_data = AppDocData.instance()
111 111

  
112 112
            column_infos = app_doc_data.getHMBDisplayNameAndUnitsExpression()
113
            count = len(column_infos)
113
            count = column_infos.rowCount()
114 114
            self.ui.tableWidget_StreamData.setRowCount(count)
115
            if len(column_infos) > 0:
115
            if column_infos.columnCount() > 0:
116 116
                self.ui.tableWidget_StreamData.setColumnCount(3)
117 117
            else:
118 118
                self.ui.tableWidget_StreamData.setColumnCount(0)
......
156 156
            self.ui.tableWidget_StreamData.horizontalHeader().setVisible(False)
157 157
            self.ui.tableWidget_StreamData.horizontalHeader().setStretchLastSection(True)
158 158

  
159
            rowIndex = 0
160
            for columnInfo in column_infos:
161
                name = columnInfo[0]
162
                unit = self.convertToUnits(columnInfo[1])
159
            for row in range(column_infos.rowCount()):
160
                name = column_infos.item(row, 0).text()
161
                unit = self.convertToUnits(column_infos.item(row, 1).text())
163 162

  
164
                self.ui.tableWidget_StreamData.setItem(rowIndex, 0,
163
                self.ui.tableWidget_StreamData.setItem(row + 1, 0,
165 164
                                                       set_item_properties(name,
166 165
                                                                           QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter,
167
                                                                           QColor(51, 153,
168
                                                                                               102)))  # QColor(230, 230, 230)))
166
                                                                           QColor(51, 153, 102)))  # QColor(230, 230, 230)))
169 167

  
170
                self.ui.tableWidget_StreamData.setItem(rowIndex, 1,
168
                self.ui.tableWidget_StreamData.setItem(row + 1, 1,
171 169
                                                       set_item_properties(unit,
172 170
                                                                           QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter,
173
                                                                           QColor(204, 255,
174
                                                                                               204)))  # QColor(230, 230, 230)))
175

  
176
                rowIndex += 1
171
                                                                           QColor(204, 255, 204)))  # QColor(230, 230, 230)))
177 172

  
178 173
            self.ui.tableWidget_StreamData.resizeColumnsToContents()
179 174
            self.ui.tableWidget_StreamData.resizeRowsToContents()
......
181 176
        except Exception as ex:
182 177
            from App import App
183 178
            from AppDocData import MessageType
184
            message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
185
                                                           sys.exc_info()[-1].tb_lineno)
179
            message = f'error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:' \
180
                      f'{sys.exc_info()[-1].tb_lineno}'
186 181
            App.mainWnd().addMessage.emit(MessageType.Error, message)
187 182

  
188 183
    def init_stream_no(self):
HYTOS/HYTOS/FreezeTableWidget.py
1
# -*- coding: utf-8 -*-
2
""" This is FreezeTableWidget module """
3

  
4
from PyQt5.QtCore import *
5
from PyQt5.QtGui import *
6
from PyQt5.QtWidgets import *
7

  
8

  
9
class FreezeTableWidget(QTableView):
10
    def __init__(self, parent=None, fixed_col_count=1, *args):
11
        QTableView.__init__(self, parent, *args)
12

  
13
        self._fixed_col_count = fixed_col_count
14

  
15
        self.frozenTableView = QTableView(self)
16

  
17
        self.frozenTableView.verticalHeader().hide()
18
        self.frozenTableView.setFocusPolicy(Qt.NoFocus)
19
        self.frozenTableView.setStyleSheet('''border: none; background-color: #CCC''')
20
        self.frozenTableView.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
21
        self.frozenTableView.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
22
        self.frozenTableView.horizontalHeader().setSectionResizeMode(QHeaderView.Fixed)
23

  
24
        self.viewport().stackUnder(self.frozenTableView)
25

  
26
        self.setShowGrid(True)
27

  
28
        hh = self.horizontalHeader()
29
        hh.setDefaultAlignment(Qt.AlignCenter)
30
        hh.setStretchLastSection(True)
31

  
32
        self.resizeColumnsToContents()
33

  
34
        vh = self.verticalHeader()
35
        vh.setDefaultSectionSize(25)
36
        vh.setDefaultAlignment(Qt.AlignCenter)
37
        vh.setVisible(True)
38
        self.frozenTableView.verticalHeader().setDefaultSectionSize(vh.defaultSectionSize())
39

  
40
        self.frozenTableView.show()
41
        self.updateFrozenTableGeometry()
42

  
43
        self.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel)
44
        self.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
45
        self.frozenTableView.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
46

  
47
        # connect the headers and scrollbars of both table view's together
48
        self.horizontalHeader().sectionResized.connect(self.updateSectionWidth)
49
        self.verticalHeader().sectionResized.connect(self.updateSectionHeight)
50
        self.frozenTableView.verticalScrollBar().valueChanged.connect(self.verticalScrollBar().setValue)
51
        self.verticalScrollBar().valueChanged.connect(self.frozenTableView.verticalScrollBar().setValue)
52

  
53
    @property
54
    def fixed_col_count(self):
55
        return self._fixed_col_count
56

  
57
    @fixed_col_count.setter
58
    def fixed_col_count(self, value):
59
        self._fixed_col_count = value
60

  
61
    def setModel(self, model: QAbstractTableModel):
62
        QTableView.setModel(self, model)
63
        self.frozenTableView.setModel(model)
64
        self.frozenTableView.verticalHeader().hide()
65
        self.frozenTableView.setFocusPolicy(Qt.NoFocus)
66

  
67
        cols = model.columnCount()
68
        for col in range(cols):
69
            if col not in range(self._fixed_col_count):
70
                self.frozenTableView.setColumnHidden(col, True)
71
            else:
72
                self.frozenTableView.setColumnWidth(col, self.columnWidth(col))
73

  
74
    def updateSectionWidth(self, logicalIndex, oldSize, newSize):
75
        if logicalIndex in range(self._fixed_col_count):
76
            self.frozenTableView.setColumnWidth(logicalIndex, newSize)
77
            self.updateFrozenTableGeometry()
78

  
79
    def updateSectionHeight(self, logicalIndex, oldSize, newSize):
80
        self.frozenTableView.setRowHeight(logicalIndex, newSize)
81

  
82
    def resizeEvent(self, event):
83
        QTableView.resizeEvent(self, event)
84
        self.updateFrozenTableGeometry()
85

  
86
    def scrollTo(self, index, hint):
87
        if index.column() >= self._fixed_col_count:
88
            QTableView.scrollTo(self, index, hint)
89

  
90
    def updateFrozenTableGeometry(self):
91
        frozen_width = sum([self.frozenTableView.columnWidth(col) for col in range(self._fixed_col_count)])
92
        if self.verticalHeader().isVisible():
93
            self.frozenTableView.setGeometry(self.verticalHeader().width() + self.frameWidth(),
94
                                             self.frameWidth(), frozen_width,
95
                                             self.viewport().height() + self.horizontalHeader().height())
96
        else:
97
            self.frozenTableView.setGeometry(self.frameWidth(),
98
                                             self.frameWidth(), frozen_width,
99
                                             self.viewport().height() + self.horizontalHeader().height())
100

  
101
    def moveCursor(self, cursorAction, modifiers):
102
        current = QTableView.moveCursor(self, cursorAction, modifiers)
103
        x = self.visualRect(current).topLeft().x()
104
        frozen_width = sum([self.frozenTableView.columnWidth(col) for col in range(self._fixed_col_count)])
105
        if cursorAction == self.MoveLeft:
106
            if current.column() >= self._fixed_col_count and x < frozen_width:
107
                new_value = self.horizontalScrollBar().value() + x - frozen_width
108
                self.horizontalScrollBar().setValue(new_value)
109
            elif current.column() < self._fixed_col_count:
110
                current = self.model().index(current.row(), current.column() + 1)
111
        elif cursorAction == self.MoveHome:
112
            new_value = self.horizontalScrollBar().value() + x - frozen_width
113
            self.horizontalScrollBar().setValue(new_value)
114
            current = self.model().index(current.row(), self._fixed_col_count)
115

  
116
        return current
117

  
HYTOS/HYTOS/MainWindow.py
7 7
from functools import partial
8 8

  
9 9
# from openpyxl.drawing import colors
10
from FreezeTableWidget import FreezeTableWidget
11

  
10 12
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
11 13
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '\\Commands')
12 14
import CreateCommand
......
53 55
        return False
54 56

  
55 57

  
56
def set_item_properties(name, alignment, backgroundcolor=None, foregroundcolor=None):
58
def set_item_properties(name: str, alignment, backgroundcolor=None, foregroundcolor=None) -> QStandardItem:
57 59
    if name is None:
58 60
        name = ''
59 61

  
62
    item = QStandardItem(str(name))
63
    item.setTextAlignment(alignment)
64
    if backgroundcolor:
65
        item.setBackground(backgroundcolor)
66
    if foregroundcolor:
67
        item.setForeground(foregroundcolor)  # QBrush(QColor(255, 0, 0)))
68
    return item
69

  
70
    """
60 71
    item = QTableWidgetItem(str(name))
61 72
    item.setTextAlignment(alignment)
62 73
    if backgroundcolor:
......
64 75
    if foregroundcolor:
65 76
        item.setForeground(foregroundcolor)  # QBrush(QColor(255, 0, 0)))
66 77
    return item
78
    """
67 79

  
68 80

  
69 81
def convert_to_fixed_point(value):
......
121 133
            changed = editor.currentText()
122 134
        else:
123 135
            changed = editor.text()
124
        item = editor.parentWidget().parentWidget().item(index.row(), index.column())
136
        item = editor.parentWidget().parentWidget().model().item(index.row(), index.column())
125 137
        value = item.data(Qt.UserRole)
126 138

  
127 139
        value_changed = False
......
135 147
        """clear value of other side"""
136 148
        if value_changed:
137 149
            if index.row() == 4:
138
                item = editor.parentWidget().parentWidget().item(5, index.column())
150
                item = editor.parentWidget().parentWidget().model().item(5, index.column())
139 151
                item.setText('')
140 152
                item.setBackground(Qt.magenta)
141 153
            elif index.row() == 5:
142
                item = editor.parentWidget().parentWidget().item(4, index.column())
154
                item = editor.parentWidget().parentWidget().model().item(4, index.column())
143 155
                item.setText('')
144 156
                item.setBackground(Qt.magenta)
145 157

  
......
166 178
        try:
167 179
            super(self.__class__, self).__init__()
168 180
            self.setupUi(self)
181
            self.tableWidgetHMB = FreezeTableWidget(self, 2)
182
            self.horizontalLayoutStreamData.addWidget(self.tableWidgetHMB)
169 183

  
170 184
            self._label_mouse = QLabel(self.statusbar)
171 185
            self._label_mouse.setText(self.tr(f'mouse pos : ({0},{0})'))
......
310 324
    def on_sync_stream_data(self):
311 325
        """
312 326
        sync stream data
313
        @return:
327
        @return: None
314 328
        """
315 329

  
316 330
        drawing = AppDocData.instance().activeDrawing
......
318 332
            return
319 333

  
320 334
        try:
321
            for col in range(2, self.tableWidgetHMB.columnCount()):
335
            model = self.tableWidgetHMB.model()
336
            for col in range(2, model.columnCount()):
322 337
                hmb = None
323 338
                if self.tableWidgetHMB.isColumnHidden(col):
324 339
                    continue
325 340

  
326
                components_uid = self.tableWidgetHMB.item(1, col).text()
341
                components_uid = model.item(1, col).text()
327 342
                hmb = drawing.hmbTable.get_hmb_data(components_uid)
328 343

  
329 344
                for row in range(2, 23):
330
                    item = self.tableWidgetHMB.item(row, col)
345
                    item = model.item(row, col)
331 346
                    if Qt.magenta != item.background():
332 347
                        continue
333 348

  
......
389 404
            self.addMessage.emit(MessageType.Error, message)
390 405

  
391 406
    def clearlogs(self):
407
        """
408
        @brief: clear logs
409
        @return: None
410
        """
392 411
        try:
393 412
            self.listWidgetLogs.clear()
394 413
        except Exception as ex:
395
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
396
                                                           sys.exc_info()[-1].tb_lineno)
414
            message = f'error occurred({ex}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:' \
415
                      f'{sys.exc_info()[-1].tb_lineno}'
397 416
            self.addMessage.emit(MessageType.Error, message)
398 417
        finally:
399 418
            logs = self.listWidgetLogs.count()
......
542 561
        app_doc_data = AppDocData.instance()
543 562

  
544 563
        column_infos = app_doc_data.getHMBDisplayNameAndUnitsExpression()
564
        self.tableWidgetHMB.setModel(column_infos)
565

  
566
        """
545 567
        count = len(column_infos)
546 568
        self.tableWidgetHMB.setRowCount(count)
547 569
        if len(column_infos) > 0:
548 570
            self.tableWidgetHMB.setColumnCount(2)
549 571
        else:
550 572
            self.tableWidgetHMB.setColumnCount(0)
573
        """
551 574

  
552 575
        self.tableWidgetHMB.hideRow(0)  # UID
553 576
        self.tableWidgetHMB.hideRow(1)  # Components_UID
......
586 609
        # self.tableWidgetHMB.setEditTriggers(QAbstractItemView.NoEditTriggers)
587 610
        self.tableWidgetHMB.verticalHeader().setVisible(False)
588 611

  
589
        col_names = ['Stream No.', 'Unit']
590
        self.tableWidgetHMB.setHorizontalHeaderLabels(col_names)
612
        col_names = ['Stream No.\n', 'Unit\n']
613
        column_infos.setHorizontalHeaderLabels(col_names)
614
        # self.tableWidgetHMB.setHorizontalHeaderLabels(col_names)
591 615

  
616
        """
592 617
        rowIndex = 0
593 618
        for columnInfo in column_infos:
594 619
            name = columnInfo[0]
......
600 625
                                                                         QColor(204, 255, 204)))
601 626

  
602 627
            rowIndex += 1
628
        """
603 629

  
604 630
        self.tableWidgetHMB.resizeColumnsToContents()
605 631
        self.tableWidgetHMB.resizeRowsToContents()
......
2738 2764
        try:
2739 2765
            hmbs = drawing.hmbTable._hmbs
2740 2766
            if hmbs is not None:
2741
                self.tableWidgetHMB.setColumnCount(2)
2767
                model = self.tableWidgetHMB.model()
2768
                model.setColumnCount(2)
2769
                # self.tableWidgetHMB.setColumnCount(2)
2742 2770

  
2743
                col_names = ['Stream No.', 'Unit']
2771
                col_names = ['Stream No.\n', 'Unit\n']
2744 2772
                _hmbs = sorted(hmbs, key=lambda hmb: hmb.stream_no)
2745 2773
                for hmb in _hmbs:
2746
                    columnCount = self.tableWidgetHMB.columnCount()
2747
                    self.tableWidgetHMB.setColumnCount(columnCount + 1)
2774
                    columnCount = model.columnCount()
2775
                    # self.tableWidgetHMB.setColumnCount(columnCount + 1)
2748 2776
                    col_names.append(str(hmb.stream_no) + '\n(' + str(hmb.stream_no_text if hmb.stream_no_text else hmb._stream_no) + ')')
2749 2777

  
2750
                    self.tableWidgetHMB.setItem(0, columnCount, set_item_properties(hmb.uid,
2751
                                                                                    Qt.AlignHCenter | Qt.AlignVCenter))
2752
                    self.tableWidgetHMB.setItem(1, columnCount, set_item_properties(hmb.components_uid,
2753
                                                                                    Qt.AlignHCenter | Qt.AlignVCenter))
2754
                    self.tableWidgetHMB.setItem(2, columnCount, set_item_properties(hmb.stream_no,
2755
                                                                                    Qt.AlignHCenter | Qt.AlignVCenter))
2778
                    item = set_item_properties(hmb.uid, Qt.AlignHCenter | Qt.AlignVCenter)
2779
                    model.setItem(0, columnCount, item)
2780
                    item = set_item_properties(hmb.components_uid, Qt.AlignHCenter | Qt.AlignVCenter)
2781
                    model.setItem(1, columnCount, item)
2782
                    item = set_item_properties(hmb.stream_no, Qt.AlignHCenter | Qt.AlignVCenter)
2783
                    model.setItem(2, columnCount, item)
2756 2784
                    item = set_item_properties(hmb.phase_type, Qt.AlignHCenter | Qt.AlignVCenter)
2757
                    item.setData(Qt.UserRole, hmb.phase_type)
2758
                    self.tableWidgetHMB.setItem(3, columnCount, item)
2785
                    item.setData(hmb.phase_type, Qt.UserRole)
2786
                    model.setItem(3, columnCount, item)
2759 2787

  
2760 2788
                    item = set_item_properties(convert_to_fixed_point(hmb.flowrate_mass), Qt.AlignHCenter | Qt.AlignVCenter)
2761
                    item.setData(Qt.UserRole, hmb.flowrate_mass)
2762
                    self.tableWidgetHMB.setItem(4, columnCount, item)
2789
                    item.setData(hmb.flowrate_mass, Qt.UserRole)
2790
                    model.setItem(4, columnCount, item)
2763 2791

  
2764 2792
                    item = set_item_properties(convert_to_fixed_point(hmb.flowrate_volume), Qt.AlignHCenter | Qt.AlignVCenter)
2765 2793
                    item.setData(Qt.UserRole, hmb.flowrate_volume)
......
2767 2795
                    if hmb.phase_type == 'Vapor':
2768 2796
                        item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)
2769 2797
                    """
2770
                    self.tableWidgetHMB.setItem(5, columnCount, item)
2798
                    model.setItem(5, columnCount, item)
2771 2799

  
2772 2800
                    item = set_item_properties(convert_to_fixed_point(hmb.density), Qt.AlignHCenter | Qt.AlignVCenter)
2773
                    item.setData(Qt.UserRole, hmb.density)
2774
                    self.tableWidgetHMB.setItem(6, columnCount, item)
2801
                    item.setData(hmb.density, Qt.UserRole)
2802
                    model.setItem(6, columnCount, item)
2775 2803

  
2776 2804
                    item = set_item_properties(convert_to_fixed_point(hmb.viscosity), Qt.AlignHCenter | Qt.AlignVCenter)
2777
                    item.setData(Qt.UserRole, hmb.viscosity)
2778
                    self.tableWidgetHMB.setItem(7, columnCount, item)
2805
                    item.setData(hmb.viscosity, Qt.UserRole)
2806
                    model.setItem(7, columnCount, item)
2779 2807

  
2780 2808
                    item = set_item_properties(convert_to_fixed_point(hmb.temperature), Qt.AlignHCenter | Qt.AlignVCenter)
2781
                    item.setData(Qt.UserRole, hmb.temperature)
2782
                    self.tableWidgetHMB.setItem(8, columnCount, item)
2809
                    item.setData(hmb.temperature, Qt.UserRole)
2810
                    model.setItem(8, columnCount, item)
2783 2811

  
2784 2812
                    item = set_item_properties(convert_to_fixed_point(hmb.molecular_weight), Qt.AlignHCenter | Qt.AlignVCenter)
2785
                    item.setData(Qt.UserRole, hmb.molecular_weight)
2786
                    self.tableWidgetHMB.setItem(9, columnCount, item)
2813
                    item.setData(hmb.molecular_weight, Qt.UserRole)
2814
                    model.setItem(9, columnCount, item)
2787 2815

  
2788 2816
                    item = set_item_properties(convert_to_fixed_point(hmb.specific_heat_ratio), Qt.AlignHCenter | Qt.AlignVCenter)
2789
                    item.setData(Qt.UserRole, hmb.specific_heat_ratio)
2790
                    self.tableWidgetHMB.setItem(10, columnCount, item)
2817
                    item.setData(hmb.specific_heat_ratio, Qt.UserRole)
2818
                    model.setItem(10, columnCount, item)
2791 2819

  
2792 2820
                    item = set_item_properties(convert_to_fixed_point(hmb.compress_factor), Qt.AlignHCenter | Qt.AlignVCenter)
2793
                    item.setData(Qt.UserRole, hmb.compress_factor)
2794
                    self.tableWidgetHMB.setItem(11, columnCount, item)
2821
                    item.setData(hmb.compress_factor, Qt.UserRole)
2822
                    model.setItem(11, columnCount, item)
2795 2823

  
2796 2824
                    item = set_item_properties(convert_to_fixed_point(hmb.nominal_pipe_size), Qt.AlignHCenter | Qt.AlignVCenter)
2797
                    item.setData(Qt.UserRole, hmb.nominal_pipe_size)
2798
                    self.tableWidgetHMB.setItem(12, columnCount, item)
2825
                    item.setData(hmb.nominal_pipe_size, Qt.UserRole)
2826
                    model.setItem(12, columnCount, item)
2799 2827

  
2800 2828
                    item = set_item_properties(convert_to_fixed_point(hmb.inside_pipe_size), Qt.AlignHCenter | Qt.AlignVCenter)
2801
                    item.setData(Qt.UserRole, hmb.inside_pipe_size)
2802
                    self.tableWidgetHMB.setItem(13, columnCount, item)
2829
                    item.setData(hmb.inside_pipe_size, Qt.UserRole)
2830
                    model.setItem(13, columnCount, item)
2803 2831

  
2804 2832
                    item = set_item_properties(convert_to_fixed_point(hmb.schedule_no), Qt.AlignHCenter | Qt.AlignVCenter)
2805
                    item.setData(Qt.UserRole, hmb.schedule_no)
2806
                    self.tableWidgetHMB.setItem(14, columnCount, item)
2833
                    item.setData(hmb.schedule_no, Qt.UserRole)
2834
                    model.setItem(14, columnCount, item)
2807 2835

  
2808 2836
                    item = set_item_properties(convert_to_fixed_point(hmb.straight_length), Qt.AlignHCenter | Qt.AlignVCenter)
2809
                    item.setData(Qt.UserRole, hmb.straight_length)
2810
                    self.tableWidgetHMB.setItem(15, columnCount, item)
2837
                    item.setData(hmb.straight_length, Qt.UserRole)
2838
                    model.setItem(15, columnCount, item)
2811 2839

  
2812 2840
                    item = set_item_properties(convert_to_fixed_point(hmb.equivalent_length), Qt.AlignHCenter | Qt.AlignVCenter)
2813
                    item.setData(Qt.UserRole, hmb.equivalent_length)
2814
                    self.tableWidgetHMB.setItem(16, columnCount, item)
2841
                    item.setData(hmb.equivalent_length, Qt.UserRole)
2842
                    model.setItem(16, columnCount, item)
2815 2843

  
2816 2844
                    item = set_item_properties(convert_to_fixed_point(hmb.equivalent_length_input), Qt.AlignHCenter | Qt.AlignVCenter)
2817
                    item.setData(Qt.UserRole, hmb.equivalent_length_input)
2818
                    self.tableWidgetHMB.setItem(17, columnCount, item)
2845
                    item.setData(hmb.equivalent_length_input, Qt.UserRole)
2846
                    model.setItem(17, columnCount, item)
2819 2847

  
2820 2848
                    item = set_item_properties(convert_to_fixed_point(hmb.fitting_length), Qt.AlignHCenter | Qt.AlignVCenter)
2821
                    item.setData(Qt.UserRole, hmb.fitting_length)
2822
                    self.tableWidgetHMB.setItem(18, columnCount, item)
2849
                    item.setData(hmb.fitting_length, Qt.UserRole)
2850
                    model.setItem(18, columnCount, item)
2823 2851

  
2824 2852
                    item = set_item_properties(convert_to_fixed_point(hmb.fitting_K), Qt.AlignHCenter | Qt.AlignVCenter)
2825
                    item.setData(Qt.UserRole, hmb.fitting_K)
2826
                    self.tableWidgetHMB.setItem(19, columnCount, item)
2853
                    item.setData(hmb.fitting_K, Qt.UserRole)
2854
                    model.setItem(19, columnCount, item)
2827 2855

  
2828 2856
                    item = set_item_properties(convert_to_fixed_point(hmb.equivalent_length_cal), Qt.AlignHCenter | Qt.AlignVCenter)
2829
                    item.setData(Qt.UserRole, hmb.equivalent_length_cal)
2830
                    self.tableWidgetHMB.setItem(20, columnCount, item)
2857
                    item.setData(hmb.equivalent_length_cal, Qt.UserRole)
2858
                    model.setItem(20, columnCount, item)
2831 2859

  
2832 2860
                    item = set_item_properties(convert_to_fixed_point(hmb.roughness), Qt.AlignHCenter | Qt.AlignVCenter)
2833
                    item.setData(Qt.UserRole, hmb.roughness)
2834
                    self.tableWidgetHMB.setItem(21, columnCount, item)
2861
                    item.setData(hmb.roughness, Qt.UserRole)
2862
                    model.setItem(21, columnCount, item)
2835 2863

  
2836 2864
                    item = set_item_properties(convert_to_fixed_point(hmb.limitation_velocity), Qt.AlignHCenter | Qt.AlignVCenter)
2837
                    item.setData(Qt.UserRole, hmb.limitation_velocity)
2838
                    self.tableWidgetHMB.setItem(22, columnCount, item)
2865
                    item.setData(hmb.limitation_velocity, Qt.UserRole)
2866
                    model.setItem(22, columnCount, item)
2839 2867

  
2840 2868
                    item = set_item_properties(convert_to_fixed_point(hmb.limitation_pressure_drop), Qt.AlignHCenter | Qt.AlignVCenter)
2841
                    item.setData(Qt.UserRole, hmb.limitation_pressure_drop)
2842
                    self.tableWidgetHMB.setItem(23, columnCount, item)
2843

  
2844
                    self.tableWidgetHMB.setItem(24, columnCount, set_item_properties(None,
2845
                                                                                     Qt.AlignHCenter | Qt.AlignVCenter,
2846
                                                                                     QColor(153, 204, 255)))
2847

  
2848
                    self.tableWidgetHMB.setItem(25, columnCount,
2849
                                                set_item_properties(convert_to_fixed_point(hmb.velocity),
2850
                                                                    Qt.AlignHCenter | Qt.AlignVCenter))
2851
                    self.tableWidgetHMB.setItem(26, columnCount,
2852
                                                set_item_properties(convert_to_fixed_point(hmb.reynolds),
2853
                                                                    Qt.AlignHCenter | Qt.AlignVCenter))
2854
                    self.tableWidgetHMB.setItem(27, columnCount,
2855
                                                set_item_properties(convert_to_fixed_point(hmb.friction_factor),
2856
                                                                    Qt.AlignHCenter | Qt.AlignVCenter))
2857
                    self.tableWidgetHMB.setItem(28, columnCount,
2858
                                                set_item_properties(convert_to_fixed_point(hmb.pressure_drop),
2859
                                                                    Qt.AlignHCenter | Qt.AlignVCenter))
2860
                    self.tableWidgetHMB.setItem(29, columnCount,
2861
                                                set_item_properties(convert_to_fixed_point(hmb.pressure_drop_friction),
2862
                                                                    Qt.AlignHCenter | Qt.AlignVCenter))
2863
                    self.tableWidgetHMB.setItem(30, columnCount,
2864
                                                set_item_properties(convert_to_fixed_point(hmb.pressure_drop_static),
2865
                                                                    Qt.AlignHCenter | Qt.AlignVCenter))
2866
                    self.tableWidgetHMB.setItem(31, columnCount,
2867
                                                set_item_properties(
2868
                                                    convert_to_fixed_point(hmb.pressure_pipe_end_point),
2869
                                                    Qt.AlignHCenter | Qt.AlignVCenter))
2870
                    self.tableWidgetHMB.setItem(32, columnCount, set_item_properties(convert_to_fixed_point(hmb.power),
2871
                                                                                     Qt.AlignHCenter | Qt.AlignVCenter))
2872

  
2873
                    if hmb.isDeleted: self.tableWidgetHMB.hideColumn(columnCount)
2874

  
2875
                self.tableWidgetHMB.setHorizontalHeaderLabels(col_names)
2869
                    item.setData(hmb.limitation_pressure_drop, Qt.UserRole)
2870
                    model.setItem(23, columnCount, item)
2871

  
2872
                    item = set_item_properties(None, Qt.AlignHCenter | Qt.AlignVCenter, QColor(153, 204, 255))
2873
                    model.setItem(24, columnCount, item)
2874

  
2875
                    item = set_item_properties(convert_to_fixed_point(hmb.velocity), Qt.AlignHCenter | Qt.AlignVCenter)
2876
                    model.setItem(25, columnCount, item)
2877

  
2878
                    item = set_item_properties(convert_to_fixed_point(hmb.reynolds), Qt.AlignHCenter | Qt.AlignVCenter)
2879
                    model.setItem(26, columnCount, item)
2880

  
2881
                    item = set_item_properties(convert_to_fixed_point(hmb.friction_factor), Qt.AlignHCenter | Qt.AlignVCenter)
2882
                    model.setItem(27, columnCount, item)
2883

  
2884
                    item = set_item_properties(convert_to_fixed_point(hmb.pressure_drop), Qt.AlignHCenter | Qt.AlignVCenter)
2885
                    model.setItem(28, columnCount, item)
2886

  
2887
                    item = set_item_properties(convert_to_fixed_point(hmb.pressure_drop_friction), Qt.AlignHCenter | Qt.AlignVCenter)
2888
                    model.setItem(29, columnCount, item)
2889

  
2890
                    item = set_item_properties(convert_to_fixed_point(hmb.pressure_drop_static), Qt.AlignHCenter | Qt.AlignVCenter)
2891
                    model.setItem(30, columnCount, item)
2892

  
2893
                    item = set_item_properties(convert_to_fixed_point(hmb.pressure_pipe_end_point), Qt.AlignHCenter | Qt.AlignVCenter)
2894
                    model.setItem(31, columnCount, item)
2895

  
2896
                    item = set_item_properties(convert_to_fixed_point(hmb.power), Qt.AlignHCenter | Qt.AlignVCenter)
2897
                    model.setItem(32, columnCount, item)
2898

  
2899
                    if hmb.isDeleted:
2900
                        self.tableWidgetHMB.hideColumn(columnCount)
2901

  
2902
                model.setHorizontalHeaderLabels(col_names)
2903
                self.tableWidgetHMB.setModel(model)
2876 2904

  
2877 2905
                self.tableWidgetHMB.resizeColumnsToContents()
2878 2906
                self.tableWidgetHMB.resizeRowsToContents()
......
3107 3135
        return itemList
3108 3136

  
3109 3137
    def add_data(self, table_widget, name, value, unit, separation=None, is_cell_merge=None, foregroundcolor=None):
3138
        def make_table_widget_item(name: str, alignment, backgroundcolor=None, foregroundcolor=None) -> QTableWidgetItem:
3139
            if name is None:
3140
                name = ''
3141

  
3142
            item = QTableWidgetItem(str(name))
3143
            item.setTextAlignment(alignment)
3144
            if backgroundcolor:
3145
                item.setBackground(backgroundcolor)
3146
            if foregroundcolor:
3147
                item.setForeground(foregroundcolor)  # QBrush(QColor(255, 0, 0)))
3148
            return item
3149

  
3110 3150
        row = table_widget.rowCount()
3111 3151
        table_widget.setRowCount(row + 1)
3112 3152

  
3113 3153
        if separation:
3114 3154
            if is_cell_merge:
3115 3155
                table_widget.setSpan(row, 0, 1, 3)
3116
                table_widget.setItem(row, 0, set_item_properties(name,
3117
                                                                 Qt.AlignLeft | Qt.AlignVCenter,
3118
                                                                 QColor(153, 204, 255), foregroundcolor))
3156
                table_widget.setItem(row, 0, make_table_widget_item(name, Qt.AlignLeft | Qt.AlignVCenter,
3157
                                                                    QColor(153, 204, 255), foregroundcolor))
3119 3158
            else:
3120
                table_widget.setItem(row, 0, set_item_properties(name,
3121
                                                                 Qt.AlignLeft | Qt.AlignVCenter,
3122
                                                                 QColor(153, 204, 255), foregroundcolor))
3123
                table_widget.setItem(row, 1, set_item_properties(value,
3124
                                                                 Qt.AlignHCenter | Qt.AlignVCenter,
3125
                                                                 QColor(153, 204, 255), foregroundcolor))
3126
                table_widget.setItem(row, 2, set_item_properties(unit,
3127
                                                                 Qt.AlignHCenter | Qt.AlignVCenter,
3128
                                                                 QColor(153, 204, 255), foregroundcolor))
3159
                table_widget.setItem(row, 0, make_table_widget_item(name, Qt.AlignLeft | Qt.AlignVCenter,
3160
                                                                    QColor(153, 204, 255), foregroundcolor))
3161
                table_widget.setItem(row, 1, make_table_widget_item(value, Qt.AlignHCenter | Qt.AlignVCenter,
3162
                                                                    QColor(153, 204, 255), foregroundcolor))
3163
                table_widget.setItem(row, 2, make_table_widget_item(unit, Qt.AlignHCenter | Qt.AlignVCenter,
3164
                                                                    QColor(153, 204, 255), foregroundcolor))
3129 3165
        else:
3130 3166
            if is_cell_merge:
3131 3167
                table_widget.setSpan(row, 0, 1, 3)
3132
                table_widget.setItem(row, 0, set_item_properties(name,
3133
                                                                 Qt.AlignLeft | Qt.AlignVCenter, None,
3134
                                                                 foregroundcolor))
3168
                table_widget.setItem(row, 0, make_table_widget_item(name, Qt.AlignLeft | Qt.AlignVCenter,
3169
                                                                    None, foregroundcolor))
3135 3170
            else:
3136
                table_widget.setItem(row, 0, set_item_properties(name,
3137
                                                                 Qt.AlignLeft | Qt.AlignVCenter, None,
3138
                                                                 foregroundcolor))
3139
                table_widget.setItem(row, 1, set_item_properties(value,
3140
                                                                 Qt.AlignRight | Qt.AlignVCenter, None,
3141
                                                                 foregroundcolor))
3142
                table_widget.setItem(row, 2, set_item_properties(unit,
3143
                                                                 Qt.AlignLeft | Qt.AlignVCenter, None,
3144
                                                                 foregroundcolor))
3171
                table_widget.setItem(row, 0, make_table_widget_item(name, Qt.AlignLeft | Qt.AlignVCenter,
3172
                                                                    None, foregroundcolor))
3173
                table_widget.setItem(row, 1, make_table_widget_item(value, Qt.AlignRight | Qt.AlignVCenter,
3174
                                                                    None, foregroundcolor))
3175
                table_widget.setItem(row, 2, make_table_widget_item(unit, Qt.AlignLeft | Qt.AlignVCenter,
3176
                                                                    None, foregroundcolor))
3145 3177

  
3146 3178
        table_widget.resizeRowsToContents()
3147 3179
        table_widget.resizeColumnsToContents()
HYTOS/HYTOS/MainWindow_UI.py
1 1
# -*- coding: utf-8 -*-
2 2

  
3
# Form implementation generated from reading ui file '.\UI\MainWindow.ui'
3
# Form implementation generated from reading ui file '.\HYTOS\UI\MainWindow.ui'
4 4
#
5
# Created by: PyQt5 UI code generator 5.13.1
5
# Created by: PyQt5 UI code generator 5.15.2
6 6
#
7
# WARNING! All changes made in this file will be lost!
7
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
8
# run again.  Do not edit this file unless you know what you are doing.
8 9

  
9 10

  
10 11
from PyQt5 import QtCore, QtGui, QtWidgets
......
81 82
        self.gridLayout_5.setObjectName("gridLayout_5")
82 83
        self.gridLayout_8 = QtWidgets.QGridLayout()
83 84
        self.gridLayout_8.setObjectName("gridLayout_8")
84
        self.tableWidgetHMB = QtWidgets.QTableWidget(self.tabStreamData)
85
        self.tableWidgetHMB.setObjectName("tableWidgetHMB")
86
        self.tableWidgetHMB.setColumnCount(0)
87
        self.tableWidgetHMB.setRowCount(0)
88
        self.gridLayout_8.addWidget(self.tableWidgetHMB, 0, 3, 1, 1)
89 85
        self.verticalLayout_3 = QtWidgets.QVBoxLayout()
90 86
        self.verticalLayout_3.setObjectName("verticalLayout_3")
91 87
        self.toolButtonSyncStreamData = QtWidgets.QToolButton(self.tabStreamData)
......
105 101
        spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
106 102
        self.verticalLayout_3.addItem(spacerItem)
107 103
        self.gridLayout_8.addLayout(self.verticalLayout_3, 0, 1, 1, 1)
104
        self.horizontalLayoutStreamData = QtWidgets.QHBoxLayout()
105
        self.horizontalLayoutStreamData.setObjectName("horizontalLayoutStreamData")
106
        self.gridLayout_8.addLayout(self.horizontalLayoutStreamData, 0, 2, 1, 1)
108 107
        self.gridLayout_5.addLayout(self.gridLayout_8, 0, 0, 1, 1)
109 108
        self.tabWidget.addTab(self.tabStreamData, "")
110 109
        self.tabLoop = QtWidgets.QWidget()
HYTOS/HYTOS/StreamDataDialog.py
598 598

  
599 599
        dlg = QCopyStreamData()
600 600
        (isAccepted, components_uid) = dlg.show_dialog(self.item)
601
        if isAccepted == True:
601
        if isAccepted:
602 602
            self.load_hmb(components_uid)
603 603

  
604 604
    def mixed_type_calculation(self):
HYTOS/HYTOS/UI/MainWindow.ui
119 119
        <layout class="QGridLayout" name="gridLayout_5">
120 120
         <item row="0" column="0">
121 121
          <layout class="QGridLayout" name="gridLayout_8">
122
           <item row="0" column="3">
123
            <widget class="QTableWidget" name="tableWidgetHMB"/>
124
           </item>
125 122
           <item row="0" column="1">
126 123
            <layout class="QVBoxLayout" name="verticalLayout_3">
127 124
             <item>
......
167 164
             </item>
168 165
            </layout>
169 166
           </item>
167
           <item row="0" column="2">
168
            <layout class="QHBoxLayout" name="horizontalLayoutStreamData"/>
169
           </item>
170 170
          </layout>
171 171
         </item>
172 172
        </layout>

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)