Exemplo n.º 1
0
    def __init__(self):
        QWidget.__init__(self)
        self.items = 0

        # Example data
        self._data = {
            "Water": 24.5,
            "Electricity": 55.1,
            "Rent": 850.0,
            "Supermarket": 230.4,
            "Internet": 29.99,
            "Spätkauf": 21.85,
            "BVG Ticket": 60.0,
            "Coffee": 22.45,
            "Meetup": 0.0
        }

        # Left
        self.table = QTableWidget()
        self.table.setColumnCount(2)
        self.table.setHorizontalHeaderLabels(["Description", "Quantity"])
        self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)

        # QWidget Layout
        self.layout = QHBoxLayout()

        self.layout.addWidget(self.table)

        # Set the layout to the QWidget
        self.setLayout(self.layout)

        # Fill example data
        self.fill_table()
Exemplo n.º 2
0
    def __init__(self, app: "MainWindow", parent=None):
        super(FormationExtrapolator, self).__init__(parent)
        self.app = app

        self.setWindowTitle(self.app.settings.WINDOW_TITLE)
        self.setWindowIcon(QIcon(self.app.settings.WINDOW_ICON))

        layout = QVBoxLayout()

        self.table = QTableWidget(10, 5)
        self.table.setMinimumWidth(500)
        self.table.setMinimumHeight(500)
        self.table.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.table.setFocusPolicy(Qt.NoFocus)
        self.table.setSelectionMode(QAbstractItemView.NoSelection)
        self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.table.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
        labels = ["Formation\nAccumulator", "Formation ID", "Enemies", "Enemy\nFormation", "Preemptable"]
        for i in range(len(labels)):
            self.table.setHorizontalHeaderItem(i, QTableWidgetItem(labels[i]))
            for j in range(self.table.rowCount()):
                self.table.setCellWidget(j, i, QLabel())
        for i in range(self.table.rowCount()):
            self.table.setVerticalHeaderItem(i, QTableWidgetItem(""))
        layout.addWidget(self.table)

        self.setLayout(layout)
        self.show()
Exemplo n.º 3
0
    def __init__(self) -> None:
        super().__init__()
        self.resize(500, 300)

        # 非组件对象
        self.values = {}
        self.ut = UpdateValues()
        # 界面组件对象

        self.centralwidget = QWidget(self)
        self.table = QTableWidget(self.centralwidget)
        self.startButton = QPushButton(self.centralwidget, text='开始')
        self.stopButton = QPushButton(self.centralwidget, text='停止')
        self.stopButton.setDisabled(True)
        self.table.setColumnCount(3)
        self.table.setHorizontalHeaderItem(0, QTableWidgetItem('GID'))
        self.table.setHorizontalHeaderItem(2, QTableWidgetItem('name'))
        self.table.setHorizontalHeaderItem(1, QTableWidgetItem('speed'))
        self.table.horizontalHeader().setStretchLastSection(True)
        self.table.setRowCount(1)

        self.layout = QGridLayout(self.centralwidget)

        self.layout.addWidget(self.startButton)
        self.layout.addWidget(self.stopButton)
        self.layout.addWidget(self.table)

        self.setCentralWidget(self.centralwidget)

        self.ut.resultReady.connect(self.on_changeValue)
        self.startButton.clicked.connect(self.changeValue)
        self.stopButton.clicked.connect(self.stopUpdate)
Exemplo n.º 4
0
    def initUI(self):
        self.setWindowTitle("QTableWidget demo")
        self.resize(500, 300);
        conLayout = QHBoxLayout()
        self.tableWidget = QTableWidget()
        self.tableWidget.setRowCount(5)
        self.tableWidget.setColumnCount(3)
        conLayout.addWidget(self.tableWidget)

        self.tableWidget.setHorizontalHeaderLabels(['姓名', '性别', '体重'])
        self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)

        newItem = QTableWidgetItem("张三")
        self.tableWidget.setItem(0, 0, newItem)

        newItem = QTableWidgetItem("男")
        self.tableWidget.setItem(0, 1, newItem)

        newItem = QTableWidgetItem("160")
        self.tableWidget.setItem(0, 2, newItem)
        # 表格中第二行记录
        newItem = QTableWidgetItem("李四")
        self.tableWidget.setItem(1, 0, newItem)

        newItem = QTableWidgetItem("女")
        self.tableWidget.setItem(1, 1, newItem)

        newItem = QTableWidgetItem("170")
        self.tableWidget.setItem(1, 2, newItem)

        self.tableWidget.setContextMenuPolicy(Qt.CustomContextMenu)  ######允许右键产生子菜单
        self.tableWidget.customContextMenuRequested.connect(self.generateMenu)  ####右键菜单
        self.setLayout(conLayout)
Exemplo n.º 5
0
    def __init__(self):
        QWidget.__init__(self)
        self.items = 0

        # Example data
        self._data = {
            "Water": 24.5,
            "Electricity": 55.1,
            "Rent": 850.0,
            "Supermarket": 230.4,
            "Internet": 29.99,
            "Spätkauf": 21.85,
            "BVG Ticket": 60.0,
            "Coffee": 22.45,
            "Meetup": 0.0
        }

        # Left
        self.table = QTableWidget()
        self.table.setColumnCount(2)
        self.table.setHorizontalHeaderLabels(["Description", "Quantity"])
        self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)

        # Right
        self.description = QLineEdit()
        self.quantity = QLineEdit()
        self.add = QPushButton("Add")
        self.clear = QPushButton("Clear")
        self.quit = QPushButton("Quit")

        self.right = QVBoxLayout()
        self.right.setContentsMargins(10, 10, 10, 10)
        self.right.addWidget(QLabel("Description"))
        self.right.addWidget(self.description)
        self.right.addWidget(QLabel("Quantity"))
        self.right.addWidget(self.quantity)
        self.right.addWidget(self.add)
        self.right.addStretch()
        self.right.addWidget(self.quit)

        # QWidget Layout
        self.layout = QHBoxLayout()

        self.layout.addWidget(self.table)
        self.layout.addLayout(self.right)

        # Set the layout to the QWidget
        self.setLayout(self.layout)

        # Signals and Slots
        self.add.clicked.connect(self.add_element)
        self.quit.clicked.connect(self.quit_application)
        self.clear.clicked.connect(self.clear_table)

        # Fill example data
        self.fill_table()
Exemplo n.º 6
0
def download_table_to_json(qtable: QtWidgets.QTableWidget, dest) -> None:
    result = {}
    for row in range(qtable.rowCount()):
        row_header = qtable.verticalHeaderItem(row).text()
        result[row_header] = {}
        for column in range(qtable.columnCount()):
            column_header = qtable.horizontalHeaderItem(column).text()
            result[row_header][column_header] = qtable.item(row, column).text()

    with open(dest, 'w') as f:
        json.dump(result, f)
Exemplo n.º 7
0
 def __init__(self, parent):
     super().__init__(parent)
     self.setLayout(QVBoxLayout(self))
     self.label_workouts = QLabel("Workouts", self)
     self.layout().addWidget(self.label_workouts)
     self.table_workouts = QTableWidget(self)
     self.layout().addWidget(self.table_workouts)
     self.frame_hline = HLineSunken(self)
     self.layout().addWidget(self.frame_hline)
     self.label_performed_exercises = QLabel(
         "Performed Exercises: Double click a line in the "
         "workouts table!", self)
     self.layout().addWidget(self.label_performed_exercises)
     self.table_performed_exercises = QTableWidget(self)
     self.layout().addWidget(self.table_performed_exercises)
Exemplo n.º 8
0
class App(widgets.QWidget):
    def __init__(self):
        super().__init__()
        self.button = widgets.QPushButton('Request from webservice')
        self.text = widgets.QLabel('aiplayground',
                                   alignment=core.Qt.AlignCenter)
        self.layout = widgets.QVBoxLayout()
        self.layout.addWidget(self.text)
        self.layout.addWidget(self.button)
        self.setLayout(self.layout)
        self.button.clicked.connect(self.magic)
        self.api_url = 'http://www.lennartberning.de/aiplayground/api/moods?'

    def createTable(self, data):
        #Not proud about the following, but it serves the purpose...
        data = data.strip('][').split(',')
        self.tableWidget = QTableWidget()
        self.tableWidget.setColumnCount(3)
        self.tableWidget.setRowCount(len(data) / 3)
        self.tableWidget.setHorizontalHeaderLabels(
            ['Mood', 'Is-Positive', 'Timestamp'])
        p = 0
        for r, list in enumerate(data):
            for i in range(3):
                if p < len(data):
                    self.tableWidget.setItem(
                        r, i,
                        QTableWidgetItem(
                            re.sub('[""]', '',
                                   data[p]).replace('[', '').replace(']', '')))
                p = p + 1
        self.tableWidget.show()

    @core.Slot()
    def magic(self):
        response = self.call_webservice(self.api_url, 'sentiment', 0)
        self.text.setText(str(response.status_code))
        self.createTable(response.text)

    @staticmethod
    def call_webservice(api_url, key, direction):
        url = '{0}{1}={2}'.format(api_url, key, direction)
        r = requests.get(url)
        if r.status_code == 200:
            return r
        else:
            return 'Error contacting webservice. Please check connectivity!'
Exemplo n.º 9
0
def update_hints_text(
    game: RandovaniaGame,
    hint_item_names_tree_widget: QtWidgets.QTableWidget,
):
    item_database = default_database.item_database_for_game(game)

    rows = []

    for item in item_database.major_items.values():
        rows.append((
            item.name,
            item.item_category.hint_details[1],
            item.item_category.general_details[1],
            item.broad_category.hint_details[1],
        ))

    for name, item_category, broad_category in _GAME_SPECIFIC.get(
            game, lambda: [])():
        rows.append((
            name,
            item_category.hint_details[1],
            item_category.general_details[1],
            broad_category.hint_details[1],
        ))

    for ammo in item_database.ammo.values():
        rows.append((
            ammo.name,
            ammo.item_category.hint_details[1],
            ammo.item_category.general_details[1],
            ammo.broad_category.hint_details[1],
        ))

    hint_item_names_tree_widget.setSortingEnabled(False)
    hint_item_names_tree_widget.setRowCount(len(rows))
    for i, elements in enumerate(rows):
        for j, element in enumerate(elements):
            hint_item_names_tree_widget.setItem(
                i, j, QtWidgets.QTableWidgetItem(element))

    for i in range(4):
        hint_item_names_tree_widget.resizeColumnToContents(i)

    hint_item_names_tree_widget.setSortingEnabled(True)
Exemplo n.º 10
0
 def createTable(self, data):
     #Not proud about the following, but it serves the purpose...
     data = data.strip('][').split(',')
     self.tableWidget = QTableWidget()
     self.tableWidget.setColumnCount(3)
     self.tableWidget.setRowCount(len(data) / 3)
     self.tableWidget.setHorizontalHeaderLabels(
         ['Mood', 'Is-Positive', 'Timestamp'])
     p = 0
     for r, list in enumerate(data):
         for i in range(3):
             if p < len(data):
                 self.tableWidget.setItem(
                     r, i,
                     QTableWidgetItem(
                         re.sub('[""]', '',
                                data[p]).replace('[', '').replace(']', '')))
             p = p + 1
     self.tableWidget.show()
Exemplo n.º 11
0
    def __init__(self):
        self.db = ClientesDB()
        QWidget.__init__(self)
        Font = QFont()
        Font.setBold(True)  # Labels em Negrito

        # Entry:
        self.entry_nome = QLineEdit()
        self.entry_nome.setText("Nome para Busca")

        # Botões
        self.button_busca = QPushButton("&Busca")
        self.button_busca.clicked.connect(self.buscar)
        self.button_busca.setShortcut("Ctrl+B")
        self.button_limpar = QPushButton("Limpar")
        self.button_limpar.clicked.connect(self.limpar)
        self.button_limpar.setShortcut("ESC")

        # Tabela
        self.clientes = 0
        self.tabela_clientes = QTableWidget()
        self.tabela_clientes.setColumnCount(4)
        self.tabela_clientes.setHorizontalHeaderLabels([
            "Nome",
            "Número",
            "CPF",
            "Endereço",
        ])
        self.tabela_clientes.horizontalHeader().setSectionResizeMode(
            QHeaderView.ResizeToContents)
        self.tabela_clientes.horizontalHeader().setStretchLastSection(True)
        self.tabela_clientes.resizeColumnsToContents()
        self.tabela_clientes.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.tabela_clientes.itemDoubleClicked.connect(self.info_cliente)

        #Leiaute:
        self.layout = QVBoxLayout()
        self.layout_busca = QHBoxLayout()
        self.layout_busca.addWidget(self.entry_nome)
        self.layout_busca.addWidget(self.button_busca)
        self.layout.addLayout(self.layout_busca)
        self.layout.addWidget(self.tabela_clientes)
        self.setLayout(self.layout)
Exemplo n.º 12
0
 def __init__(self, title, parent):
     super().__init__(title, parent)
     self.__layout = QGridLayout(self)
     self.setLayout(self.__layout)
     self.combobox_category = ComboboxCategory(self)
     self.__layout.addWidget(self.combobox_category, 0, 0)
     self.combobox_muscles = ComboboxMuscles(self)
     self.__layout.addWidget(self.combobox_muscles, 0, 1)
     self.combobox_difficulty = ComboboxDifficulty(self)
     self.__layout.addWidget(self.combobox_difficulty, 0, 2)
     self.table_available_exercises = QTableWidget(self)
     self.__layout.addWidget(self.table_available_exercises, 1, 0, 1, 3)
Exemplo n.º 13
0
    def __init__(self, parent, onset, duration, description):
        super().__init__(parent)
        self.setWindowTitle("Edit Annotations")

        self.table = QTableWidget(len(onset), 3)

        for row, annotation in enumerate(zip(onset, duration, description)):
            self.table.setItem(row, 0, IntTableWidgetItem(annotation[0]))
            self.table.setItem(row, 1, IntTableWidgetItem(annotation[1]))
            self.table.setItem(row, 2, QTableWidgetItem(annotation[2]))

        self.table.setHorizontalHeaderLabels(["Onset", "Duration", "Type"])
        self.table.horizontalHeader().setStretchLastSection(True)
        self.table.verticalHeader().setVisible(False)
        self.table.setShowGrid(False)
        self.table.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.table.setSortingEnabled(True)
        self.table.sortByColumn(0, Qt.AscendingOrder)

        vbox = QVBoxLayout(self)
        vbox.addWidget(self.table)
        hbox = QHBoxLayout()
        self.add_button = QPushButton("+")
        self.remove_button = QPushButton("-")
        buttonbox = QDialogButtonBox(QDialogButtonBox.Ok
                                     | QDialogButtonBox.Cancel)
        hbox.addWidget(self.add_button)
        hbox.addWidget(self.remove_button)
        hbox.addStretch()
        hbox.addWidget(buttonbox)
        vbox.addLayout(hbox)
        buttonbox.accepted.connect(self.accept)
        buttonbox.rejected.connect(self.reject)
        self.table.itemSelectionChanged.connect(self.toggle_buttons)
        self.remove_button.clicked.connect(self.remove_event)
        self.add_button.clicked.connect(self.add_event)
        self.toggle_buttons()
        self.resize(500, 500)
Exemplo n.º 14
0
 def __init__(self):
     super().__init__()
     self.setWindowTitle("Example")
     self.layout = QGridLayout()
     self.layout.setContentsMargins(6, 6, 6, 6)
     self.layout.addWidget(QTableWidget(), 0, 0, 1, 3)
     self.loading_bar = QProgressBar()
     self.loading_bar.setTextVisible(False)
     self.loading_bar.setValue(25)
     self.layout.addWidget(self.loading_bar, 1, 0, 1, 1)
     self.refresh_btn = FixedWindowsButton("Refresh")
     self.layout.addWidget(self.refresh_btn, 1, 1, 1, 1)
     self.execute_btn = FixedWindowsButton("Execute")
     self.layout.addWidget(self.execute_btn, 1, 2, 1, 1)
     self.setLayout(self.layout)
Exemplo n.º 15
0
    def create_table(self, group_name):
        table = QTableWidget(0, len(self.table_headers))
        table.setHorizontalHeaderLabels(self.table_headers)
        table.resizeColumnsToContents()

        layout = QVBoxLayout()
        layout.addWidget(QLabel(group_name))
        layout.addWidget(table)

        self.layout.addLayout(layout)

        return table
Exemplo n.º 16
0
class AnnotationsDialog(QDialog):
    def __init__(self, parent, onset, duration, description):
        super().__init__(parent)
        self.setWindowTitle("Edit Annotations")

        self.table = QTableWidget(len(onset), 3)

        for row, annotation in enumerate(zip(onset, duration, description)):
            self.table.setItem(row, 0, IntTableWidgetItem(annotation[0]))
            self.table.setItem(row, 1, IntTableWidgetItem(annotation[1]))
            self.table.setItem(row, 2, QTableWidgetItem(annotation[2]))

        self.table.setHorizontalHeaderLabels(["Onset", "Duration", "Type"])
        self.table.horizontalHeader().setStretchLastSection(True)
        self.table.verticalHeader().setVisible(False)
        self.table.setShowGrid(False)
        self.table.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.table.setSortingEnabled(True)
        self.table.sortByColumn(0, Qt.AscendingOrder)

        vbox = QVBoxLayout(self)
        vbox.addWidget(self.table)
        hbox = QHBoxLayout()
        self.add_button = QPushButton("+")
        self.remove_button = QPushButton("-")
        buttonbox = QDialogButtonBox(QDialogButtonBox.Ok
                                     | QDialogButtonBox.Cancel)
        hbox.addWidget(self.add_button)
        hbox.addWidget(self.remove_button)
        hbox.addStretch()
        hbox.addWidget(buttonbox)
        vbox.addLayout(hbox)
        buttonbox.accepted.connect(self.accept)
        buttonbox.rejected.connect(self.reject)
        self.table.itemSelectionChanged.connect(self.toggle_buttons)
        self.remove_button.clicked.connect(self.remove_event)
        self.add_button.clicked.connect(self.add_event)
        self.toggle_buttons()
        self.resize(500, 500)

    @Slot()
    def toggle_buttons(self):
        """Toggle + and - buttons."""
        n_items = len(self.table.selectedItems())
        if n_items == 3:  # one row (3 items) selected
            self.add_button.setEnabled(True)
            self.remove_button.setEnabled(True)
        elif n_items > 3:  # more than one row selected
            self.add_button.setEnabled(False)
            self.remove_button.setEnabled(True)
        else:  # no rows selected
            self.add_button.setEnabled(False)
            self.remove_button.setEnabled(False)

    def add_event(self):
        current_row = self.table.selectedIndexes()[0].row()
        pos = int(self.table.item(current_row, 0).data(Qt.DisplayRole))
        self.table.setSortingEnabled(False)
        self.table.insertRow(current_row)
        self.table.setItem(current_row, 0, IntTableWidgetItem(pos))
        self.table.setItem(current_row, 1, IntTableWidgetItem(0))
        self.table.setItem(current_row, 2, QTableWidgetItem("New Annotation"))
        self.table.setSortingEnabled(True)

    def remove_event(self):
        rows = {index.row() for index in self.table.selectedIndexes()}
        self.table.clearSelection()
        for row in sorted(rows, reverse=True):
            self.table.removeRow(row)
Exemplo n.º 17
0
class MainWindow(QMainWindow):
    def open_formation_extrapolator(self):
        self.formation_extrapolator_windows.append(
            formation_extrapolator.FormationExtrapolator(self))

    def open_formation_list(self):
        self.formation_list_windows.append(formation_list.FormationList(self))

    def update_formation_windows(self):
        for window in self.formation_extrapolator_windows:
            window.update_display()

    def disconnect(self):
        self.hook.stop()

    def connect_pc(self):
        if self.hook.running:
            box = QMessageBox()
            box.setIcon(QMessageBox.Information)
            box.setWindowTitle("Already Connected")
            box.setText("Already connected. Disconnect first.")
            box.setStandardButtons(QMessageBox.Ok)
            box.exec_()
            return
        pid = hook.get_pc_process_id()
        if pid is None:
            box = QMessageBox()
            box.setIcon(QMessageBox.Information)
            box.setWindowTitle("FF7 PC Not Detected")
            box.setText("FF7 PC was not detected.")
            box.setStandardButtons(QMessageBox.Ok)
            box.exec_()
            return
        self.hook.hooked_platform = hook.Hook.PC_PLATFORM
        self.hook.hooked_process_id = pid
        self.hook.start()

    def connect_emulator(self):
        if self.hook.running:
            box = QMessageBox()
            box.setIcon(QMessageBox.Information)
            box.setWindowTitle("Already Connected")
            box.setText("Already connected. Disconnect first.")
            box.setStandardButtons(QMessageBox.Ok)
            box.exec_()
            return
        pids = hook.get_emu_process_ids()
        if len(pids) == 0:
            box = QMessageBox()
            box.setIcon(QMessageBox.Information)
            box.setWindowTitle("No Emulators Detected")
            box.setText("No emulators that can be connected to were detected.")
            box.setStandardButtons(QMessageBox.Ok)
            box.exec_()
            return
        ConnectEmuDialog(pids, self).exec_()

    def on_close(self):
        self.stepgraph.stop()
        self.disconnect()
        try:
            self.master.destroy()
        except Exception:
            pass

    def __init__(self, _settings: settings.Settings, parent=None):
        super(MainWindow, self).__init__(parent)

        self.formation_extrapolator_windows = []
        self.formation_list_windows = []

        self.settings = _settings

        self.stepgraph = stepgraph.Stepgraph(self)

        self.hook = hook.Hook(self)

        self.current_step_state: State = State(field_id=117,
                                               step=Step(0, 0),
                                               danger=0,
                                               step_fraction=0,
                                               formation_value=0)

        self.setWindowTitle(self.settings.WINDOW_TITLE)
        self.setWindowIcon(QIcon(self.settings.WINDOW_ICON))

        menubar = QMenuBar()

        menu_file = QMenu("File")

        menu_file_exit = QAction("Exit", self)
        menu_file_exit.triggered.connect(exit)
        menu_file.addAction(menu_file_exit)

        menu_connect = QMenu("Connect")

        menu_connect_connect_emulator = QAction("Connect to Emulator", self)
        menu_connect_connect_emulator.triggered.connect(self.connect_emulator)
        menu_connect.addAction(menu_connect_connect_emulator)

        menu_connect_connect_pc = QAction("Connect to PC", self)
        menu_connect_connect_pc.triggered.connect(self.connect_pc)
        menu_connect.addAction(menu_connect_connect_pc)

        menu_connect.addSeparator()

        menu_connect_disconnect = QAction("Disconnect", self)
        menu_connect_disconnect.triggered.connect(self.disconnect)
        menu_connect.addAction(menu_connect_disconnect)

        menu_window = QMenu("Window")

        menu_window_toggle_stepgraph = QAction("Toggle Stepgraph", self)
        menu_window_toggle_stepgraph.triggered.connect(self.stepgraph.toggle)
        menu_window.addAction(menu_window_toggle_stepgraph)

        menu_window_open_formation_window = QAction("Open Formation Window",
                                                    self)
        menu_window_open_formation_window.triggered.connect(
            self.open_formation_extrapolator)
        menu_window.addAction(menu_window_open_formation_window)

        menubar.addMenu(menu_file)
        menubar.addMenu(menu_connect)
        menubar.addMenu(menu_window)

        # self.master.config(menu=menubar)
        self.setMenuBar(menubar)

        main_frame = QFrame()
        layout = QVBoxLayout()

        rows = [
            "Step ID", "Step Fraction", "Offset", "Danger",
            "Formation Accumulator", "Field ID", "Table Index",
            "Danger Divisor Multiplier", "Lure Rate", "Preempt Rate",
            "Last Encounter Formation"
        ]

        self.memory_view = QTableWidget(len(rows), 2)
        self.memory_view.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.memory_view.setFocusPolicy(Qt.NoFocus)
        self.memory_view.setSelectionMode(QAbstractItemView.NoSelection)
        self.memory_view.setHorizontalHeaderItem(0,
                                                 QTableWidgetItem("Address"))
        self.memory_view.setHorizontalHeaderItem(
            1, QTableWidgetItem("        Value        "))
        self.memory_view.horizontalHeader().setSectionResizeMode(
            QHeaderView.Stretch)
        self.memory_view.verticalHeader().setSectionResizeMode(
            QHeaderView.ResizeToContents)
        for rowNum in range(len(rows)):
            self.memory_view.setVerticalHeaderItem(rowNum,
                                                   QTableWidgetItem(""))
            _l = QLabel(" " + rows[rowNum] + " ")
            _l.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
            self.memory_view.setCellWidget(rowNum, 0, _l)
            _l = QLabel("")
            _l.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
            self.memory_view.setCellWidget(rowNum, 1, _l)
        self.memory_view.resizeColumnsToContents()
        self.memory_view.setMinimumHeight(350)
        self.memory_view.setMinimumWidth(300)
        layout.addWidget(self.memory_view)

        self.connected_text = QLabel(self.settings.DISCONNECTED_TEXT)
        self.connected_text.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        layout.addWidget(self.connected_text)

        main_frame.setLayout(layout)

        self.setCentralWidget(main_frame)

        self.setMinimumHeight(420)
Exemplo n.º 18
0
    def __init__(self, _settings: settings.Settings, parent=None):
        super(MainWindow, self).__init__(parent)

        self.formation_extrapolator_windows = []
        self.formation_list_windows = []

        self.settings = _settings

        self.stepgraph = stepgraph.Stepgraph(self)

        self.hook = hook.Hook(self)

        self.current_step_state: State = State(field_id=117,
                                               step=Step(0, 0),
                                               danger=0,
                                               step_fraction=0,
                                               formation_value=0)

        self.setWindowTitle(self.settings.WINDOW_TITLE)
        self.setWindowIcon(QIcon(self.settings.WINDOW_ICON))

        menubar = QMenuBar()

        menu_file = QMenu("File")

        menu_file_exit = QAction("Exit", self)
        menu_file_exit.triggered.connect(exit)
        menu_file.addAction(menu_file_exit)

        menu_connect = QMenu("Connect")

        menu_connect_connect_emulator = QAction("Connect to Emulator", self)
        menu_connect_connect_emulator.triggered.connect(self.connect_emulator)
        menu_connect.addAction(menu_connect_connect_emulator)

        menu_connect_connect_pc = QAction("Connect to PC", self)
        menu_connect_connect_pc.triggered.connect(self.connect_pc)
        menu_connect.addAction(menu_connect_connect_pc)

        menu_connect.addSeparator()

        menu_connect_disconnect = QAction("Disconnect", self)
        menu_connect_disconnect.triggered.connect(self.disconnect)
        menu_connect.addAction(menu_connect_disconnect)

        menu_window = QMenu("Window")

        menu_window_toggle_stepgraph = QAction("Toggle Stepgraph", self)
        menu_window_toggle_stepgraph.triggered.connect(self.stepgraph.toggle)
        menu_window.addAction(menu_window_toggle_stepgraph)

        menu_window_open_formation_window = QAction("Open Formation Window",
                                                    self)
        menu_window_open_formation_window.triggered.connect(
            self.open_formation_extrapolator)
        menu_window.addAction(menu_window_open_formation_window)

        menubar.addMenu(menu_file)
        menubar.addMenu(menu_connect)
        menubar.addMenu(menu_window)

        # self.master.config(menu=menubar)
        self.setMenuBar(menubar)

        main_frame = QFrame()
        layout = QVBoxLayout()

        rows = [
            "Step ID", "Step Fraction", "Offset", "Danger",
            "Formation Accumulator", "Field ID", "Table Index",
            "Danger Divisor Multiplier", "Lure Rate", "Preempt Rate",
            "Last Encounter Formation"
        ]

        self.memory_view = QTableWidget(len(rows), 2)
        self.memory_view.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.memory_view.setFocusPolicy(Qt.NoFocus)
        self.memory_view.setSelectionMode(QAbstractItemView.NoSelection)
        self.memory_view.setHorizontalHeaderItem(0,
                                                 QTableWidgetItem("Address"))
        self.memory_view.setHorizontalHeaderItem(
            1, QTableWidgetItem("        Value        "))
        self.memory_view.horizontalHeader().setSectionResizeMode(
            QHeaderView.Stretch)
        self.memory_view.verticalHeader().setSectionResizeMode(
            QHeaderView.ResizeToContents)
        for rowNum in range(len(rows)):
            self.memory_view.setVerticalHeaderItem(rowNum,
                                                   QTableWidgetItem(""))
            _l = QLabel(" " + rows[rowNum] + " ")
            _l.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
            self.memory_view.setCellWidget(rowNum, 0, _l)
            _l = QLabel("")
            _l.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
            self.memory_view.setCellWidget(rowNum, 1, _l)
        self.memory_view.resizeColumnsToContents()
        self.memory_view.setMinimumHeight(350)
        self.memory_view.setMinimumWidth(300)
        layout.addWidget(self.memory_view)

        self.connected_text = QLabel(self.settings.DISCONNECTED_TEXT)
        self.connected_text.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        layout.addWidget(self.connected_text)

        main_frame.setLayout(layout)

        self.setCentralWidget(main_frame)

        self.setMinimumHeight(420)
Exemplo n.º 19
0
class Widget(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        self.items = 0

        # Example data
        self._data = {
            "Water": 24.5,
            "Electricity": 55.1,
            "Rent": 850.0,
            "Supermarket": 230.4,
            "Internet": 29.99,
            "Spätkauf": 21.85,
            "BVG Ticket": 60.0,
            "Coffee": 22.45,
            "Meetup": 0.0
        }

        # Left
        self.table = QTableWidget()
        self.table.setColumnCount(2)
        self.table.setHorizontalHeaderLabels(["Description", "Quantity"])
        self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)

        # Chart
        self.chart_view = QChartView()
        self.chart_view.setRenderHint(QPainter.Antialiasing)

        # Right
        self.description = QLineEdit()
        self.quantity = QLineEdit()
        self.add = QPushButton("Add")
        self.clear = QPushButton("Clear")
        self.quit = QPushButton("Quit")
        self.plot = QPushButton("Plot")

        # Disabling 'Add' button
        self.add.setEnabled(False)

        self.right = QVBoxLayout()
        self.right.setContentsMargins(10, 10, 10, 10)
        self.right.addWidget(QLabel("Description"))
        self.right.addWidget(self.description)
        self.right.addWidget(QLabel("Quantity"))
        self.right.addWidget(self.quantity)
        self.right.addWidget(self.add)
        self.right.addWidget(self.plot)
        self.right.addWidget(self.chart_view)
        self.right.addWidget(self.clear)
        self.right.addWidget(self.quit)

        # QWidget Layout
        self.layout = QHBoxLayout()

        self.layout.addWidget(self.table)
        self.layout.addLayout(self.right)

        # Set the layout to the QWidget
        self.setLayout(self.layout)

        # Signals and Slots
        self.add.clicked.connect(self.add_element)
        self.quit.clicked.connect(self.quit_application)
        self.plot.clicked.connect(self.plot_data)
        self.clear.clicked.connect(self.clear_table)
        self.description.textChanged[str].connect(self.check_disable)
        self.quantity.textChanged[str].connect(self.check_disable)

        # Fill example data
        self.fill_table()

    @Slot()
    def add_element(self):
        des = self.description.text()
        qty = self.quantity.text()

        self.table.insertRow(self.items)
        self.table.setItem(self.items, 0, QTableWidgetItem(des))
        self.table.setItem(self.items, 1, QTableWidgetItem(qty))

        self.description.setText("")
        self.quantity.setText("")

        self.items += 1

    @Slot()
    def check_disable(self, s):
        if not self.description.text() or not self.quantity.text():
            self.add.setEnabled(False)
        else:
            self.add.setEnabled(True)

    @Slot()
    def plot_data(self):
        # Get table information
        series = QPieSeries()
        for i in range(self.table.rowCount()):
            text = self.table.item(i, 0).text()
            number = float(self.table.item(i, 1).text())
            series.append(text, number)

        chart = QChart()
        chart.addSeries(series)
        chart.legend().setAlignment(Qt.AlignLeft)
        self.chart_view.setChart(chart)

    @Slot()
    def quit_application(self):
        QApplication.quit()

    def fill_table(self, data=None):
        data = self._data if not data else data
        for desc, price in data.items():
            self.table.insertRow(self.items)
            self.table.setItem(self.items, 0, QTableWidgetItem(desc))
            self.table.setItem(self.items, 1, QTableWidgetItem(str(price)))
            self.items += 1

    @Slot()
    def clear_table(self):
        self.table.setRowCount(0)
        self.items = 0
Exemplo n.º 20
0
    def initUI(self):
        self.setWindowTitle("QTableWidget 例子")
        self.resize(430, 230);
        conLayout = QHBoxLayout()
        tableWidget = QTableWidget()
        tableWidget.setRowCount(4)
        tableWidget.setColumnCount(3)
        conLayout.addWidget(tableWidget)

        tableWidget.setHorizontalHeaderLabels(['姓名', '性别', '体重(kg)'])

        newItem = QTableWidgetItem("张三")
        newItem.setForeground(QBrush(QColor(255, 0, 0)))
        tableWidget.setItem(0, 0, newItem)

        newItem = QTableWidgetItem("男")
        newItem.setForeground(QBrush(QColor(255, 0, 0)))
        tableWidget.setItem(0, 1, newItem)

        newItem = QTableWidgetItem("160")
        newItem.setForeground(QBrush(QColor(255, 0, 0)))
        tableWidget.setItem(0, 2, newItem)

        self.setLayout(conLayout)
Exemplo n.º 21
0
    def setupUi(self, MainWindow):
        if not MainWindow.objectName():
            MainWindow.setObjectName(u"MainWindow")
        MainWindow.resize(1020, 588)
        self.actionSave = QAction(MainWindow)
        self.actionSave.setObjectName(u"actionSave")
        self.actionExit = QAction(MainWindow)
        self.actionExit.setObjectName(u"actionExit")
        self.actionExit_2 = QAction(MainWindow)
        self.actionExit_2.setObjectName(u"actionExit_2")
        self.openini = QAction(MainWindow)
        self.openini.setObjectName(u"openini")
        self.openjson = QAction(MainWindow)
        self.openjson.setObjectName(u"openjson")
        self.main_widget = QWidget(MainWindow)
        self.main_widget.setObjectName(u"main_widget")
        self.ini_widget = QWidget(self.main_widget)
        self.ini_widget.setObjectName(u"ini_widget")
        self.ini_widget.setGeometry(QRect(670, 10, 341, 551))
        self.initable = QTableWidget(self.ini_widget)
        if (self.initable.columnCount() < 2):
            self.initable.setColumnCount(2)
        self.initable.setObjectName(u"initable")
        self.initable.setEnabled(True)
        self.initable.setGeometry(QRect(10, 60, 321, 451))
        font = QFont()
        self.initable.setFont(font)
        self.initable.setEditTriggers(QAbstractItemView.DoubleClicked)
        self.initable.setDragEnabled(False)
        self.initable.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.initable.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.initable.setWordWrap(False)
        self.initable.setRowCount(0)
        self.initable.setColumnCount(2)
        self.initable.horizontalHeader().setDefaultSectionSize(110)
        self.initable.horizontalHeader().setProperty("showSortIndicator",
                                                     False)
        self.initable.horizontalHeader().setStretchLastSection(True)
        self.initable.verticalHeader().setDefaultSectionSize(21)
        self.inilabel = QLabel(self.ini_widget)
        self.inilabel.setObjectName(u"inilabel")
        self.inilabel.setGeometry(QRect(10, 10, 181, 16))
        self.inipath = QTextBrowser(self.ini_widget)
        self.inipath.setObjectName(u"inipath")
        self.inipath.setEnabled(True)
        self.inipath.setGeometry(QRect(10, 30, 321, 22))
        self.inipath.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.iniapply = QPushButton(self.ini_widget)
        self.iniapply.setObjectName(u"iniapply")
        self.iniapply.setEnabled(True)
        self.iniapply.setGeometry(QRect(250, 520, 80, 21))
        self.inidel = QPushButton(self.ini_widget)
        self.inidel.setObjectName(u"inidel")
        self.inidel.setEnabled(False)
        self.inidel.setGeometry(QRect(10, 520, 80, 21))
        self.iniadd = QPushButton(self.ini_widget)
        self.iniadd.setObjectName(u"iniadd")
        self.iniadd.setEnabled(False)
        self.iniadd.setGeometry(QRect(100, 520, 80, 21))
        self.json_widget = QWidget(self.main_widget)
        self.json_widget.setObjectName(u"json_widget")
        self.json_widget.setGeometry(QRect(0, 10, 661, 551))
        self.checkBox = QCheckBox(self.json_widget)
        self.checkBox.setObjectName(u"checkBox")
        self.checkBox.setEnabled(True)
        self.checkBox.setGeometry(QRect(20, 100, 131, 20))
        self.checkBox.setChecked(True)
        self.delentry = QPushButton(self.json_widget)
        self.delentry.setObjectName(u"delentry")
        self.delentry.setEnabled(False)
        self.delentry.setGeometry(QRect(10, 520, 80, 21))
        self.remote = QLineEdit(self.json_widget)
        self.remote.setObjectName(u"remote")
        self.remote.setEnabled(True)
        self.remote.setGeometry(QRect(20, 130, 601, 22))
        self.textBrowser = QTextBrowser(self.json_widget)
        self.textBrowser.setObjectName(u"textBrowser")
        self.textBrowser.setEnabled(True)
        self.textBrowser.setGeometry(QRect(20, 30, 601, 22))
        self.textBrowser.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.addButton = QPushButton(self.json_widget)
        self.addButton.setObjectName(u"addButton")
        self.addButton.setEnabled(True)
        self.addButton.setGeometry(QRect(280, 160, 61, 22))
        self.table = QTableWidget(self.json_widget)
        if (self.table.columnCount() < 2):
            self.table.setColumnCount(2)
        self.table.setObjectName(u"table")
        self.table.setEnabled(True)
        self.table.setGeometry(QRect(10, 200, 641, 311))
        self.table.setFont(font)
        self.table.setEditTriggers(QAbstractItemView.DoubleClicked)
        self.table.setDragEnabled(False)
        self.table.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.table.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.table.setWordWrap(False)
        self.table.setRowCount(0)
        self.table.setColumnCount(2)
        self.table.horizontalHeader().setDefaultSectionSize(80)
        self.table.horizontalHeader().setProperty("showSortIndicator", False)
        self.table.horizontalHeader().setStretchLastSection(True)
        self.table.verticalHeader().setDefaultSectionSize(21)
        self.path = QLineEdit(self.json_widget)
        self.path.setObjectName(u"path")
        self.path.setEnabled(True)
        self.path.setGeometry(QRect(20, 70, 531, 22))
        self.apply = QPushButton(self.json_widget)
        self.apply.setObjectName(u"apply")
        self.apply.setEnabled(True)
        self.apply.setGeometry(QRect(570, 520, 80, 21))
        self.label = QLabel(self.json_widget)
        self.label.setObjectName(u"label")
        self.label.setGeometry(QRect(20, 10, 181, 16))
        self.browse = QPushButton(self.json_widget)
        self.browse.setObjectName(u"browse")
        self.browse.setGeometry(QRect(560, 70, 61, 22))
        MainWindow.setCentralWidget(self.main_widget)
        self.menubar = QMenuBar(MainWindow)
        self.menubar.setObjectName(u"menubar")
        self.menubar.setGeometry(QRect(0, 0, 1020, 19))
        self.File = QMenu(self.menubar)
        self.File.setObjectName(u"File")
        self.menuOpen = QMenu(self.File)
        self.menuOpen.setObjectName(u"menuOpen")
        MainWindow.setMenuBar(self.menubar)

        self.menubar.addAction(self.File.menuAction())
        self.File.addAction(self.menuOpen.menuAction())
        self.File.addAction(self.actionSave)
        self.File.addSeparator()
        self.File.addAction(self.actionExit_2)
        self.menuOpen.addAction(self.openini)
        self.menuOpen.addAction(self.openjson)

        self.retranslateUi(MainWindow)

        QMetaObject.connectSlotsByName(MainWindow)
Exemplo n.º 22
0
    def initUI(self):
        self.setWindowTitle("QTableWidget 例子")
        self.resize(430, 230)
        conLayout = QHBoxLayout()
        tableWidget = QTableWidget()
        tableWidget.setRowCount(4)
        tableWidget.setColumnCount(3)
        conLayout.addWidget(tableWidget)

        tableWidget.setHorizontalHeaderLabels(['姓名', '性别', '体重(kg)'])

        newItem = QTableWidgetItem("张三")
        newItem.setFont(QFont("Times", 12, QFont.Black))
        tableWidget.setItem(0, 0, newItem)

        newItem = QTableWidgetItem("男")
        newItem.setFont(QFont("Times", 12, QFont.Black))
        tableWidget.setItem(0, 1, newItem)

        newItem = QTableWidgetItem("160")
        newItem.setFont(QFont("Times", 12, QFont.Black))
        tableWidget.setItem(0, 2, newItem)

        self.setLayout(conLayout)
Exemplo n.º 23
0
class FormationExtrapolator(QDialog):

    def update_display(self):
        field = self.app.current_step_state.field()
        preempt_rate = self.app.current_step_state.preempt_rate
        table = self.app.current_step_state.table_index
        old_fmaccum = self.app.current_step_state.formation_value
        last_formation = self.app.current_step_state.last_encounter_formation
        for i in range(10):
            formation_data = formations.encounter_on_formation(field=field, formation=old_fmaccum,
                                                               preempt_rate=preempt_rate, table=table)
            formation_type = formation_data[2]
            if formation_type == "Normal":
                if formation_data[0] == last_formation:
                    formation = formation_data[1]
                    new_fmaccum = old_fmaccum + 3
                else:
                    formation = formation_data[0]
                    new_fmaccum = old_fmaccum + 2
                preemptable = "Yes" if constants.FORMATION_PREEMPTABLE_MAP[formation] == 1 else "No"
            else:
                formation = formation_data[0]
                new_fmaccum = old_fmaccum + 1
                preemptable = "---"
            enemy_names = [constants.ENEMY_DATA[str(en)]["name"] for en in
                           constants.ENCOUNTER_DATA[str(formation)]["enemies"]]
            self.table.cellWidget(i, 0).setText(" " + str(old_fmaccum) + " -> " + str(new_fmaccum))
            self.table.cellWidget(i, 1).setText(" " + str(formation))
            self.table.cellWidget(i, 2).setText(" " + "\n ".join(enemy_names))
            self.table.cellWidget(i, 3).setText(" " + formation_type)
            self.table.cellWidget(i, 4).setText(" " + preemptable)

            old_fmaccum = new_fmaccum
            last_formation = formation
        self.table.resizeRowsToContents()

    def __init__(self, app: "MainWindow", parent=None):
        super(FormationExtrapolator, self).__init__(parent)
        self.app = app

        self.setWindowTitle(self.app.settings.WINDOW_TITLE)
        self.setWindowIcon(QIcon(self.app.settings.WINDOW_ICON))

        layout = QVBoxLayout()

        self.table = QTableWidget(10, 5)
        self.table.setMinimumWidth(500)
        self.table.setMinimumHeight(500)
        self.table.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.table.setFocusPolicy(Qt.NoFocus)
        self.table.setSelectionMode(QAbstractItemView.NoSelection)
        self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.table.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
        labels = ["Formation\nAccumulator", "Formation ID", "Enemies", "Enemy\nFormation", "Preemptable"]
        for i in range(len(labels)):
            self.table.setHorizontalHeaderItem(i, QTableWidgetItem(labels[i]))
            for j in range(self.table.rowCount()):
                self.table.setCellWidget(j, i, QLabel())
        for i in range(self.table.rowCount()):
            self.table.setVerticalHeaderItem(i, QTableWidgetItem(""))
        layout.addWidget(self.table)

        self.setLayout(layout)
        self.show()
Exemplo n.º 24
0
class Table(QWidget):

    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle("QTableWidget demo")
        self.resize(500, 300);
        conLayout = QHBoxLayout()
        self.tableWidget = QTableWidget()
        self.tableWidget.setRowCount(5)
        self.tableWidget.setColumnCount(3)
        conLayout.addWidget(self.tableWidget)

        self.tableWidget.setHorizontalHeaderLabels(['姓名', '性别', '体重'])
        self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)

        newItem = QTableWidgetItem("张三")
        self.tableWidget.setItem(0, 0, newItem)

        newItem = QTableWidgetItem("男")
        self.tableWidget.setItem(0, 1, newItem)

        newItem = QTableWidgetItem("160")
        self.tableWidget.setItem(0, 2, newItem)
        # 表格中第二行记录
        newItem = QTableWidgetItem("李四")
        self.tableWidget.setItem(1, 0, newItem)

        newItem = QTableWidgetItem("女")
        self.tableWidget.setItem(1, 1, newItem)

        newItem = QTableWidgetItem("170")
        self.tableWidget.setItem(1, 2, newItem)

        self.tableWidget.setContextMenuPolicy(Qt.CustomContextMenu)  ######允许右键产生子菜单
        self.tableWidget.customContextMenuRequested.connect(self.generateMenu)  ####右键菜单
        self.setLayout(conLayout)

    def generateMenu(self, pos):
        print(pos)
        row_num = -1
        for i in self.tableWidget.selectionModel().selection().indexes():
            row_num = i.row()
        menu = QMenu()
        item1 = menu.addAction(u"选项一")
        item2 = menu.addAction(u"选项二")
        item3 = menu.addAction(u"选项三")
        action = menu.exec_(self.tableWidget.mapToGlobal(pos))
        if action == item1:
            print('您选了选项一,当前行文字内容是:', self.tableWidget.item(row_num, 0).text(),
                  self.tableWidget.item(row_num, 1).text(), self.tableWidget.item(row_num, 2).text())

        elif action == item2:
            print('您选了选项二,当前行文字内容是:', self.tableWidget.item(row_num, 0).text(),
                  self.tableWidget.item(row_num, 1).text(), self.tableWidget.item(row_num, 2).text())

        elif action == item3:
            print('您选了选项三,当前行文字内容是:', self.tableWidget.item(row_num, 0).text(),
                  self.tableWidget.item(row_num, 1).text(), self.tableWidget.item(row_num, 2).text())
        else:
            return
Exemplo n.º 25
0
class Widget(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        self.items = 0

        # Example data
        self._data = {
            "Water": 24.5,
            "Electricity": 55.1,
            "Rent": 850.0,
            "Supermarket": 230.4,
            "Internet": 29.99,
            "Spätkauf": 21.85,
            "BVG Ticket": 60.0,
            "Coffee": 22.45,
            "Meetup": 0.0
        }

        # Left
        self.table = QTableWidget()
        self.table.setColumnCount(2)
        self.table.setHorizontalHeaderLabels(["Description", "Quantity"])
        self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)

        # Right
        self.description = QLineEdit()
        self.quantity = QLineEdit()
        self.add = QPushButton("Add")
        self.clear = QPushButton("Clear")
        self.quit = QPushButton("Quit")

        self.right = QVBoxLayout()
        self.right.setContentsMargins(10, 10, 10, 10)
        self.right.addWidget(QLabel("Description"))
        self.right.addWidget(self.description)
        self.right.addWidget(QLabel("Quantity"))
        self.right.addWidget(self.quantity)
        self.right.addWidget(self.add)
        self.right.addStretch()
        self.right.addWidget(self.clear)
        self.right.addWidget(self.quit)

        # QWidget Layout
        self.layout = QHBoxLayout()

        self.layout.addWidget(self.table)
        self.layout.addLayout(self.right)

        # Set the layout to the QWidget
        self.setLayout(self.layout)

        # Fill example data
        self.fill_table()

    def fill_table(self, data=None):
        data = self._data if not data else data
        for desc, price in data.items():
            self.table.insertRow(self.items)
            self.table.setItem(self.items, 0, QTableWidgetItem(desc))
            self.table.setItem(self.items, 1, QTableWidgetItem(str(price)))
            self.items += 1
Exemplo n.º 26
0
class Widget(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        self.items = 0

        # Left
        self.table = QTableWidget()
        self.table.setColumnCount(2)
        self.table.setHorizontalHeaderLabels(["Description", "Quantity"])
        self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)

        # Chart
        self.chart_view = QChartView()
        self.chart_view.setRenderHint(QPainter.Antialiasing)

        # Right
        self.description = QLineEdit()
        self.quantity = QLineEdit()
        self.add = QPushButton("Add")
        self.clear = QPushButton("Clear")
        self.quit = QPushButton("Quit")
        self.plot = QPushButton("Plot")

        # Disabling 'Add' button
        self.add.setEnabled(False)

        self.right = QVBoxLayout()
        self.right.setContentsMargins(10, 10, 10, 10)

        self.right_top = QGridLayout()

        self.right_top.addWidget(QLabel("Description"), 0, 0, 1, 1)
        self.right_top.addWidget(self.description, 0, 1, 1, 3)
        self.right_top.addWidget(QLabel("Quantity"), 1, 0, 1, 1)
        self.right_top.addWidget(self.quantity, 1, 1, 1, 1)
        self.right_top.addWidget(self.add, 1, 2, 1, 2)

        self.right.addLayout(self.right_top)
        self.right.addWidget(self.chart_view)

        self.right_bottom = QGridLayout()
        self.right_bottom.addWidget(self.plot, 0, 0, 1, 2)
        self.right_bottom.addWidget(self.clear, 1, 0)
        self.right_bottom.addWidget(self.quit, 1, 1)

        self.right.addLayout(self.right_bottom)

        # QWidget Layout
        self.layout = QHBoxLayout()

        self.layout.addWidget(self.table)
        self.layout.addLayout(self.right)

        # Set the layout to the QWidget
        self.setLayout(self.layout)

        # Signals and Slots
        self.add.clicked.connect(self.add_element)
        self.quit.clicked.connect(self.quit_application)
        self.plot.clicked.connect(self.plot_data)
        self.clear.clicked.connect(self.clear_table)
        self.description.textChanged[str].connect(self.check_disable)
        self.quantity.textChanged[str].connect(self.check_disable)

    @Slot()
    def add_element(self):
        des = self.description.text()
        qty = self.quantity.text()

        self.table.insertRow(self.items)
        self.table.setItem(self.items, 0, QTableWidgetItem(des))
        self.table.setItem(self.items, 1, QTableWidgetItem(qty))

        self.description.setText("")
        self.quantity.setText("")

        self.items += 1

    @Slot()
    def check_disable(self, s):
        if not self.description.text() or not self.quantity.text():
            self.add.setEnabled(False)
        else:
            self.add.setEnabled(True)

    @Slot()
    def plot_data(self):
        # Get table information
        series = QBarSeries()
        for i in range(self.table.rowCount()):
            text = self.table.item(i, 0).text()
            number = float(self.table.item(i, 1).text())

            bar_set = QBarSet(text)
            bar_set.append(number)

            series.append(bar_set)

        chart = QChart()
        chart.addSeries(series)
        chart.legend().setAlignment(Qt.AlignLeft)
        self.chart_view.setChart(chart)

    @Slot()
    def quit_application(self):
        QApplication.quit()

    @Slot()
    def clear_table(self):
        self.table.setRowCount(0)
        self.items = 0
Exemplo n.º 27
0
    def __init__(self):
        QWidget.__init__(self)
        self.items = 0

        # Left
        self.table = QTableWidget()
        self.table.setColumnCount(2)
        self.table.setHorizontalHeaderLabels(["Description", "Quantity"])
        self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)

        # Chart
        self.chart_view = QChartView()
        self.chart_view.setRenderHint(QPainter.Antialiasing)

        # Right
        self.description = QLineEdit()
        self.quantity = QLineEdit()
        self.add = QPushButton("Add")
        self.clear = QPushButton("Clear")
        self.quit = QPushButton("Quit")
        self.plot = QPushButton("Plot")

        # Disabling 'Add' button
        self.add.setEnabled(False)

        self.right = QVBoxLayout()
        self.right.setContentsMargins(10, 10, 10, 10)

        self.right_top = QGridLayout()

        self.right_top.addWidget(QLabel("Description"), 0, 0, 1, 1)
        self.right_top.addWidget(self.description, 0, 1, 1, 3)
        self.right_top.addWidget(QLabel("Quantity"), 1, 0, 1, 1)
        self.right_top.addWidget(self.quantity, 1, 1, 1, 1)
        self.right_top.addWidget(self.add, 1, 2, 1, 2)

        self.right.addLayout(self.right_top)
        self.right.addWidget(self.chart_view)

        self.right_bottom = QGridLayout()
        self.right_bottom.addWidget(self.plot, 0, 0, 1, 2)
        self.right_bottom.addWidget(self.clear, 1, 0)
        self.right_bottom.addWidget(self.quit, 1, 1)

        self.right.addLayout(self.right_bottom)

        # QWidget Layout
        self.layout = QHBoxLayout()

        self.layout.addWidget(self.table)
        self.layout.addLayout(self.right)

        # Set the layout to the QWidget
        self.setLayout(self.layout)

        # Signals and Slots
        self.add.clicked.connect(self.add_element)
        self.quit.clicked.connect(self.quit_application)
        self.plot.clicked.connect(self.plot_data)
        self.clear.clicked.connect(self.clear_table)
        self.description.textChanged[str].connect(self.check_disable)
        self.quantity.textChanged[str].connect(self.check_disable)
Exemplo n.º 28
0
    def initUI(self):
        self.setWindowTitle("QTableWidget 例子")
        self.resize(430, 300);
        conLayout = QHBoxLayout()
        tableWidget = QTableWidget()
        tableWidget.setRowCount(4)
        tableWidget.setColumnCount(3)
        conLayout.addWidget(tableWidget)

        tableWidget.setHorizontalHeaderLabels(['姓名', '性别', '体重(kg)'])

        newItem = QTableWidgetItem("张三")
        tableWidget.setItem(0, 0, newItem)

        comBox = QComboBox()
        comBox.addItem("男")
        comBox.addItem("女")
        comBox.setStyleSheet("QComboBox{margin:3px};")
        tableWidget.setCellWidget(0, 1, comBox)

        searchBtn = QPushButton("修改")
        searchBtn.setDown(True)
        searchBtn.setStyleSheet("QPushButton{margin:3px};")
        tableWidget.setCellWidget(0, 2, searchBtn)

        self.setLayout(conLayout)
Exemplo n.º 29
0
    :param str code:
    :return:
    """
    code_hex = code.replace('#', '')
    rgb = tuple(int(code_hex[i:i + 2], 16) for i in (0, 2, 3))
    return QColor.fromRgb(rgb[0], rgb[1], rgb[2])


if __name__ == '__main__':
    colors = [("Red", "#FF0000"), ("Green", "#00FF00"), ("Blue", "#0000FF"),
              ("Black", "#000000"), ("White", "#FFFFFF"),
              ("Electric Green", "#41CD52"), ("Dark Blue", "#222840"),
              ("Yellow", "#F9E56d")]
    app = QApplication()
    table = QTableWidget()
    table.setRowCount(len(colors))
    table.setColumnCount(len(colors[0]) + 1)
    table.setHorizontalHeaderLabels(['Name', 'Hex Code', 'Color'])

    for i, (name, code) in enumerate(colors):
        item_name = QTableWidgetItem(name)
        item_code = QTableWidgetItem(code)
        item_color = QTableWidgetItem()
        item_color.setBackground(get_rgb_from_hex(code))
        table.setItem(i, 0, item_name)
        table.setItem(i, 1, item_code)
        table.setItem(i, 2, item_color)
    table.show()
    sys.exit(app.exec_())
Exemplo n.º 30
0
    def setupUi(self, stepData):
        if not stepData.objectName():
            stepData.setObjectName(u"stepData")
        stepData.setEnabled(True)
        stepData.setMaximumSize(QSize(410, 16777215))
        self.stepsTab = QWidget()
        self.stepsTab.setObjectName(u"stepsTab")
        sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.stepsTab.sizePolicy().hasHeightForWidth())
        self.stepsTab.setSizePolicy(sizePolicy)
        self.stepsTab.setMinimumSize(QSize(200, 278))
        self.stepsTab.setAutoFillBackground(False)
        self.verticalLayout_2 = QVBoxLayout(self.stepsTab)
        self.verticalLayout_2.setObjectName(u"verticalLayout_2")
        self.verticalLayout_2.setContentsMargins(-1, 11, -1, -1)
        self.stepsTable = QTableWidget(self.stepsTab)
        self.stepsTable.setObjectName(u"stepsTable")

        self.verticalLayout_2.addWidget(self.stepsTable)

        self.stepButtons = QHBoxLayout()
        self.stepButtons.setObjectName(u"stepButtons")
        self.stepDownBtn = QPushButton(self.stepsTab)
        self.stepDownBtn.setObjectName(u"stepDownBtn")

        self.stepButtons.addWidget(self.stepDownBtn)

        self.stepUpBtn = QPushButton(self.stepsTab)
        self.stepUpBtn.setObjectName(u"stepUpBtn")

        self.stepButtons.addWidget(self.stepUpBtn)

        self.removeStepBtn = QPushButton(self.stepsTab)
        self.removeStepBtn.setObjectName(u"removeStepBtn")

        self.stepButtons.addWidget(self.removeStepBtn)

        self.addStepBtn = QPushButton(self.stepsTab)
        self.addStepBtn.setObjectName(u"addStepBtn")

        self.stepButtons.addWidget(self.addStepBtn)

        self.runBtn = QPushButton(self.stepsTab)
        self.runBtn.setObjectName(u"runBtn")
        sizePolicy1 = QSizePolicy(QSizePolicy.MinimumExpanding,
                                  QSizePolicy.Fixed)
        sizePolicy1.setHorizontalStretch(0)
        sizePolicy1.setVerticalStretch(0)
        sizePolicy1.setHeightForWidth(
            self.runBtn.sizePolicy().hasHeightForWidth())
        self.runBtn.setSizePolicy(sizePolicy1)
        self.runBtn.setMinimumSize(QSize(0, 0))
        font = QFont()
        font.setBold(False)
        self.runBtn.setFont(font)
        self.runBtn.setCheckable(False)
        self.runBtn.setFlat(False)

        self.stepButtons.addWidget(self.runBtn)

        self.verticalLayout_2.addLayout(self.stepButtons)

        stepData.addTab(self.stepsTab, "")
        self.templatesTab = QWidget()
        self.templatesTab.setObjectName(u"templatesTab")
        sizePolicy2 = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Preferred)
        sizePolicy2.setHorizontalStretch(0)
        sizePolicy2.setVerticalStretch(0)
        sizePolicy2.setHeightForWidth(
            self.templatesTab.sizePolicy().hasHeightForWidth())
        self.templatesTab.setSizePolicy(sizePolicy2)
        self.verticalLayout_19 = QVBoxLayout(self.templatesTab)
        self.verticalLayout_19.setObjectName(u"verticalLayout_19")
        self.treeWidget = QTreeWidget(self.templatesTab)
        __qtreewidgetitem = QTreeWidgetItem()
        __qtreewidgetitem.setText(0, u"1")
        self.treeWidget.setHeaderItem(__qtreewidgetitem)
        self.treeWidget.setObjectName(u"treeWidget")
        sizePolicy3 = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Expanding)
        sizePolicy3.setHorizontalStretch(0)
        sizePolicy3.setVerticalStretch(0)
        sizePolicy3.setHeightForWidth(
            self.treeWidget.sizePolicy().hasHeightForWidth())
        self.treeWidget.setSizePolicy(sizePolicy3)

        self.verticalLayout_19.addWidget(self.treeWidget)

        stepData.addTab(self.templatesTab, "")
        self.optionsTab = QWidget()
        self.optionsTab.setObjectName(u"optionsTab")
        sizePolicy4 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
        sizePolicy4.setHorizontalStretch(0)
        sizePolicy4.setVerticalStretch(0)
        sizePolicy4.setHeightForWidth(
            self.optionsTab.sizePolicy().hasHeightForWidth())
        self.optionsTab.setSizePolicy(sizePolicy4)
        self.optionsTab.setAutoFillBackground(True)
        self.verticalLayout_17 = QVBoxLayout(self.optionsTab)
        self.verticalLayout_17.setObjectName(u"verticalLayout_17")
        self.stepOptionsTable = QTableWidget(self.optionsTab)
        self.stepOptionsTable.setObjectName(u"stepOptionsTable")

        self.verticalLayout_17.addWidget(self.stepOptionsTable)

        stepData.addTab(self.optionsTab, "")

        self.retranslateUi(stepData)

        stepData.setCurrentIndex(2)

        QMetaObject.connectSlotsByName(stepData)