Exemplo n.º 1
0
    def paint(self, painter, option, index):
        """
        """
        origRect = QtCore.QRect(option.rect)
        if self._view.showGrid():
            # remove 1 pixel from right and bottom edge of rect, to
            # make room for drawing grid
            option.rect.setRight(option.rect.right() - 1)
            option.rect.setBottom(option.rect.bottom() - 1)

        # paint the item
        Delegate.paint(self, painter, option, index)

        # draw the vertical grid lines (horizontal lines are painted
        # in TreeView.drawRow())
        if self._view.showGrid():
            painter.save()
            gridHint = QtGui.QApplication.style().styleHint(
                QtGui.QStyle.SH_Table_GridLineColor, option, self._view, None)
            # must ensure that the value is positive before
            # constructing a QColor from it
            # http://www.riverbankcomputing.com/pipermail/pyqt/2010-February/025893.html
            gridColor = QtGui.QColor.fromRgb(gridHint & 0xffffffff)
            painter.setPen(QtGui.QPen(gridColor, 0, QtCore.Qt.SolidLine))
            # paint the vertical line
            painter.drawLine(origRect.right(), origRect.top(),
                             origRect.right(), origRect.bottom())
            painter.restore()
    def __init__(self, parent):
        super().__init__(parent)

        self.__parent__ = parent
        self.parent_model = parent.model
        self.partslist = parent.partslist
        self.rank_title = 'rank'
        self.quantities_key = 'quantity'
        self.key_column = 'key'

        self.ui = Ui_Dialog()
        self.ui.setupUi(self)

        # list view
        self.model_rank = Model(self, Item(), Column())
        self.ui.listView.setModel(self.model_rank)
        self.ui.listView.setItemDelegate(Delegate())

        # list view 2
        self.model_quantity = Model(self, Item(), Column())
        self.ui.listView_2.setModel(self.model_quantity)
        self.ui.listView_2.setItemDelegate(Delegate())

        # list view 3
        self.model_key = Model(self, Item(), Column())
        self.ui.listView_3.setModel(self.model_key)
        self.ui.listView_3.setItemDelegate(Delegate())

        # table view
        self.model_csv = Model(self, Item(), Column())
        self.ui.tableView.setModel(self.model_csv)
        self.ui.tableView.setItemDelegate(Delegate())

        self.ui.pushButton.clicked.connect(self.open_file)
Exemplo n.º 3
0
    def sizeHint(self, option, index):
        """
        :parameters:
            option :QStyleOptionViewItem
                drawing parameters
            index : QModelIndex
                index of item
        """
        # TODO: speed this up, by caching more?
        widget = self._view.indexWidget(index)
        if widget:
            hint = widget.sizeHint()
            gridSize = 1 if self._view.showGrid() else 0
            return QtCore.QSize(hint.width(), hint.height() + gridSize)

        hint = Delegate.sizeHint(self, option, index)

        if self._view.showGrid():
            if self.MARGIN is None:
                self.MARGIN = QtGui.QApplication.style().pixelMetric(
                    QtGui.QStyle.PM_HeaderMargin, None)
            margin = self.MARGIN
            minimumHeight = max(QtGui.QApplication.globalStrut().height(),
                                option.fontMetrics.height() + margin)
            return QtCore.QSize(hint.width(), max(hint.height(),
                                                  minimumHeight))

        return hint
Exemplo n.º 4
0
    def __init__(self, app):
        super().__init__()

        self.copy_data = None
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.resize(800, 600)

        self.model = Model(self, Item(),
                           Column(['File name', 'Resolution', 'Settings']))

        self.ui.tableView.setModel(self.model)
        self.ui.tableView.setItemDelegate(Delegate())
        self.ui.tableView.clicked.connect(self.tableview_clicked)
        self.ui.tableView.customContextMenuRequested.connect(
            self.context_menu_tableview)

        self.tool_bar = ToolBar(self.ui.toolBar)
        self.ui.toolBar.addWidget(self.tool_bar)

        self.tool_bar.ui.toolButton.clicked.connect(self.open_files)
        self.tool_bar.ui.toolButton_3.clicked.connect(
            self.ui.image_view.recognize)
        self.tool_bar.ui.toolButton_4.clicked.connect(self.split_cells)
        self.tool_bar.ui.toolButton_5.clicked.connect(
            self.ui.image_view.graphics_view_update)
        self.tool_bar.ui.toolButton_6.clicked.connect(
            self.ui.image_view.graphics_view_update)
        self.tool_bar.ui.toolButton_7.clicked.connect(
            self.ui.image_view.graphics_view_update)
        self.tool_bar.ui.toolButton_8.clicked.connect(self.ocr)
Exemplo n.º 5
0
    def __init__(self, parent):
        super().__init__(parent)

        self.ui = Ui_Form()
        self.ui.setupUi(self)

        self.model = Model( self, Item(), Column(['column']) )

        self.ui.listView.setModel(self.model)
        self.ui.listView.setItemDelegate( Delegate() )
        self.ui.listView.clicked.connect(self.listview_clicked)
        self.ui.listView.customContextMenuRequested.connect(self.context_menu)
        self.ui.listView.keyReleaseEvent = self.lsitview_keyReleaseEvent
        
        self.ui.graphicsView.setScene( QtWidgets.QGraphicsScene(self.ui.graphicsView) )
Exemplo n.º 6
0
    def __init__(self, parent):
        super().__init__(parent)

        self.parent = parent

        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.model = Model(self, Item(), Column())
        self.ui.listView.setModel(self.model)
        self.ui.listView.setItemDelegate(Delegate())
        self.ui.listView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.ui.listView.customContextMenuRequested.connect(self.context_menu)

        self.model.insertColumn(0)
        self.model.setHeaderData(0, QtCore.Qt.Horizontal, 'column')

        # get all columns from parent model
        all_columns = []

        def recursion(item):
            for key in item.data().keys():
                if not key in all_columns:
                    all_columns.append(key)
            for child in item.children():
                recursion(child)

        recursion(parent.model.root())

        # get shown columns at treeview
        column_list = range(parent.model.columnCount())
        columns = [
            parent.model.headerData(i, QtCore.Qt.Horizontal)
            for i in column_list
        ]

        self.model.insertRows(0, len(all_columns))

        selection_model = self.ui.listView.selectionModel()
        for row, column in enumerate(all_columns):
            index = self.model.index(row, 0)
            self.model.setData(index, column)

            if column in columns:
                selection_model.select(index,
                                       QtCore.QItemSelectionModel.Select)

        self.ui.lineEdit.setText(parent.partslist.get('key_column'))
        self.ui.lineEdit_2.setText(parent.partslist.get('quantity_column'))
Exemplo n.º 7
0
    def __init__(self):
        super().__init__()

        # Устанаваливаем свойства окна
        self.setGeometry(500, 100, 600, 750)
        self.setWindowTitle('Task 2')
        # Создаем экземпляр делегата
        self.combobox = Delegate()
        # Создаем кнопки
        self.randomButton = QPushButton('Random')
        self.saveButton = QPushButton('Save')
        self.loadButton = QPushButton('Load')
        # Передаем данные в экземпляр для обработки данных
        self.back = Data(data)
        # Пересчитываем данные во 2, 3 столбцах
        self.back.calcData()
        # Получаем данные
        self.backData = self.back.get_data()
        # Создаем экземпляр модели
        self.model = TableModel(self.backData)
        # Создаем виджет таблицы и подключаем модель
        self.view = QTableView(self)
        self.view.setModel(self.model)
        # Устанавливаем делегат на 4 столбец
        self.view.setItemDelegateForColumn(3, self.combobox)
        # Устанавливаем минимальную ширину столбцов
        self.view.horizontalHeader().setMinimumSectionSize(137)
        # Создаем виджет графика
        self.plot = pg.PlotWidget()
        self.plot.setBackground('w')
        # Создаем вертикальный и горизонтальный контейнеры и распологаем виджеты
        self.layout = QVBoxLayout(self)
        self.layoutHor = QHBoxLayout(self)
        self.layout.addLayout(self.layoutHor)
        self.layoutHor.addWidget(self.randomButton)
        self.layoutHor.addWidget(self.saveButton)
        self.layoutHor.addWidget(self.loadButton)
        self.layout.addWidget(self.view)
        self.layout.addWidget(self.plot)
        self.show()
        # Устанавливаем сигналы на кнопки и изменение данных в таблице
        self.model.dataChanged.connect(self.back.calcData)
        self.saveButton.clicked.connect(self.save)
        self.loadButton.clicked.connect(self.load)
        self.randomButton.clicked.connect(self.back.randomize)
        self.view.horizontalHeader().sectionClicked.connect(self.graphic)
Exemplo n.º 8
0
    def __init__(self, app):
        super().__init__()

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.model = Model(self, Item(), Column())

        self.ui.treeView.setModel(self.model)
        self.ui.treeView.setItemDelegate(Delegate())
        self.ui.treeView.customContextMenuRequested.connect(self.contextMenu)

        self.ui.actionAppendChild.triggered.connect(self.append_child)
        self.ui.actionDelete.triggered.connect(self.remove_items)
        self.ui.actionImportJSON.triggered.connect(
            lambda: ImporterJson(self).open())
        self.ui.actionImportCSV.triggered.connect(
            lambda: ImporterCSV(self).exec())
        self.ui.actionExportJSON.triggered.connect(
            lambda: ImporterJson(self).save())
        self.ui.actionExportCSV.triggered.connect(
            lambda: ImporterCSV(self).save())
        self.ui.actionSettings.triggered.connect(lambda: Settings(self).exec())
        self.ui.actionOpen.triggered.connect(self.open)
        self.ui.actionSave.triggered.connect(self.save)
        self.ui.actionImpoertImage.triggered.connect(
            lambda: importer_image(self))

        self.ui.toolButton.clicked.connect(self.append_child)
        self.ui.toolButton_2.clicked.connect(self.remove_items)
        self.ui.toolButton_3.clicked.connect(self.ui.treeView.expandAll)
        self.ui.toolButton_4.clicked.connect(self.search_and_replace)

        self.ui.treeView.clicked.connect(self.tree_view_clicked)

        self.partslist = {
            'root_item': self.model.root(),
            'pixmaps': {},
            'key_column': None,
            'quantity_column': None
        }
Exemplo n.º 9
0
    def __init__(self, app):
        super().__init__()

        self.copy_data = None
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.resize(800, 600)

        self.model = Model(self, Item(), Column(['File name', 'Resolution']))
        #self.model = Model( self, Item(), Column(['File name', 'Resolution', 'Settings']) )

        self.ui.tableView.setModel(self.model)
        self.ui.tableView.setItemDelegate(Delegate())
        self.ui.tableView.clicked.connect(self.tableview_clicked)
        self.ui.tableView.customContextMenuRequested.connect(
            self.context_menu_tableview)

        self.tool_bar = ToolBar(self.ui.toolBar)
        self.ui.toolBar.addWidget(self.tool_bar)

        self.tool_bar.ui.toolButton.clicked.connect(self.open_files)
        self.tool_bar.ui.toolButton_2.clicked.connect(self.save_file)
        self.tool_bar.ui.toolButton_3.clicked.connect(self.recognize)
        self.tool_bar.ui.toolButton_4.clicked.connect(self.crop_by_rects)
        self.tool_bar.ui.toolButton_5.clicked.connect(
            self.graphics_view_update)
        self.tool_bar.ui.toolButton_6.clicked.connect(
            self.graphics_view_update)
        self.tool_bar.ui.toolButton_7.clicked.connect(
            self.graphics_view_update)
        self.tool_bar.ui.toolButton_8.clicked.connect(self.ocr)
        self.tool_bar.ui.toolButton_9.clicked.connect(self.crop_by_crops)

        self.ui.image_view.ui.graphicsView.mouse_left_released.connect(
            self.append_rect)
        self.tool_bar.slider_changed.connect(self.slider_changed_event)

        self.progress_bar = QtWidgets.QProgressBar(self.ui.statusbar)
        self.ui.statusbar.addWidget(self.progress_bar)
        self.progress_bar.hide()
        self.progress_bar.setMinimum(0)
Exemplo n.º 10
0
    def __init__(self, parent):
        super().__init__(parent)

        self.ui = Ui_Form()
        self.ui.setupUi(self)

        self.model = Model( self, Item(), Column(['column']) )

        self.ui.listView.setModel(self.model)
        self.ui.listView.setItemDelegate( Delegate() )
        self.ui.listView.clicked.connect(self.listview_clicked)
        self.ui.listView.customContextMenuRequested.connect(self.context_menu)
        self.ui.listView.keyReleaseEvent = self.lsitview_keyReleaseEvent

        self.ui.horizontalSlider.valueChanged.connect(self.slider_changed)
        self.ui.horizontalSlider_2.valueChanged.connect(self.slider_changed)
        self.ui.horizontalSlider_3.valueChanged.connect(self.slider_changed)

        self.ui.lineEdit.returnPressed.connect(self.lineedit_changed)
        self.ui.lineEdit_2.returnPressed.connect(self.lineedit_changed)
        self.ui.lineEdit_3.returnPressed.connect(self.lineedit_changed)

        self.ui.graphicsView.setScene( QtWidgets.QGraphicsScene(self.ui.graphicsView) )
Exemplo n.º 11
0
 def __init__(self, client):
   Delegate.__init__(self)
   self.client = client
Exemplo n.º 12
0
 def __init__(self, client):
   Delegate.__init__(self)
   self.client = client
Exemplo n.º 13
0
    def __init__(self, parent=None):
        super().__init__(parent)
        # Варианты выбора для ячеек с Combobox
        choices = ['0', '1', '2', '3', '4', '5']
        # номер столбца с QComboBox
        cbox_column = 1

        # Получение данные через класс Backend
        self.backend = Backend(raw_data, 8, 4)
        # Вычисление столбца суммы и накопления
        self.backend.recalculate()
        # Получение ссылки на numpy array
        self.backend_data = self.backend.get_data()

        # Создание модели
        self.model = Model(self.backend_data)
        # изменение данных в модели вызывет перерасчет через метод recalc
        self.model.c.data_changed.connect(self.recalc)

        # создание виджетов таблицы
        self.table_data = QtWidgets.QTableView()
        # подключиние модели к таблице
        self.table_data.setModel(self.model)
        # Установка делегата на второй столбец таблицы
        self.table_data.setItemDelegateForColumn(cbox_column,
                                                 Delegate(self, choices))
        # получаем модель выделения
        self.selectionModel = self.table_data.selectionModel()
        # событие происходящее выделением столбца целчком по шапке таблицы
        self.table_data.horizontalHeader().sectionClicked.connect(
            self.draw_graph)

        # сделать Combobox редактируемым одним щелчком во 2(1) столбце
        for row in range(self.backend_data.shape[0]):
            self.table_data.openPersistentEditor(
                self.model.index(row, cbox_column))

        # создаем виджет графика
        self.matplotlib_widget = MatplotlibWidget(self)

        # Создать кнопки и повесить на них события
        btnLoad = QtWidgets.QPushButton('Load')
        btnSave = QtWidgets.QPushButton('Save')
        btnSave.clicked.connect(lambda: Save()(self.backend_data))
        btnLoad.clicked.connect(self.load_data)

        # btnSave.clicked.connect(app.exit)
        # создаем лайаут для вертикального размещения виджетов
        self.layoutVertical = QtWidgets.QVBoxLayout(self)
        # добавляем виджеты в лайаут
        self.layoutVertical.addWidget(self.table_data)
        self.layoutVertical.addWidget(btnLoad)
        self.layoutVertical.addWidget(btnSave)

        self.layoutVertical.addWidget(self.matplotlib_widget)
        # x = [1, 2, 3, 4, 5]
        # y = [10, 20, 30, 40, 50]
        # self.matplotlib_widget.draw_plot(x, y)

        self.setWindowTitle('Тестовое задание')
        self.setGeometry(50, 50, 800, 800)
        self.show()