コード例 #1
0
    def _create_status_lights(self, layout):
        # Create a frame to hold the register's bits
        status_frame = QFrame(self)
        layout.addWidget(status_frame)
        layout.setAlignment(status_frame, Qt.AlignBottom)
        status_layout = QGridLayout(status_frame)
        status_layout.setSpacing(0)
        status_layout.setMargin(0)
        status_frame.setLayout(status_layout)
        status_frame.setFrameStyle(QFrame.StyledPanel | QFrame.Raised)

        # Add indicators for each status in the register, from MSB to LSB
        for col, stat in enumerate(STATUS_INDS.keys()):
            check = QCheckBox(status_frame)
            check.setFixedSize(30, 20)
            check.setStyleSheet(
                'QCheckBox::indicator{subcontrol-position:center;}')
            check.stateChanged.connect(lambda state: self._update_status())
            status_layout.addWidget(check, 0, col)
            status_layout.setAlignment(check, Qt.AlignCenter)
            self._status_cmp_switches[stat] = check

            check = QCheckBox(status_frame)
            check.setFixedSize(30, 20)
            check.setStyleSheet(
                'QCheckBox::indicator{subcontrol-position:center;}')
            check.stateChanged.connect(lambda state: self._update_status())
            status_layout.addWidget(check, 1, col)
            status_layout.setAlignment(check, Qt.AlignCenter)
            self._status_ign_switches[stat] = check
コード例 #2
0
    def _create_reg(self, frame, layout, col, width, cmp_switches,
                    ign_switches, cmp_fn, ign_fn):
        # Add indicators for each bit in the register, from MSB to LSB
        for i in range(width, 0, -1):
            check = QCheckBox(frame)
            check.setFixedSize(20, 20)
            check.setStyleSheet(
                'QCheckBox::indicator{subcontrol-position:center;}')
            check.stateChanged.connect(cmp_fn)
            layout.addWidget(check, 0, col)
            layout.setAlignment(check, Qt.AlignCenter)
            cmp_switches.append(check)

            check = QCheckBox(frame)
            check.setFixedSize(20, 20)
            check.setStyleSheet(
                'QCheckBox::indicator{subcontrol-position:center;}')
            check.stateChanged.connect(ign_fn)
            layout.addWidget(check, 1, col)
            layout.setAlignment(check, Qt.AlignCenter)
            ign_switches.append(check)

            col += 1

            # Add separators between each group of 3 bits
            if (i < 16) and (i > 1) and ((i % 3) == 1):
                sep = QFrame(frame)
                sep.setFrameStyle(QFrame.VLine | QFrame.Raised)
                layout.addWidget(sep, 0, col, 2, 1)
                col += 1

        return col
コード例 #3
0
 def createSBoard(self):
     wid = QFrame(self)
     wid.setFrameStyle(QFrame.Box)
     wid.setLineWidth(2)
     gridlayout = QGridLayout()
     gridlayout.setSpacing(0)
     label_list = []
     for i in range(3):
         for j in range(3):
             #label_list.append(QPushButton("{},{}".format(i,j),self))
             qcb = QComboBox(self)
             qcb.addItems([str(i) for i in range(1, 10)])
             label_list.append(qcb)
             label_list[-1].setFixedSize(50, 50)
             #label_list[-1].setAlignment(Qt.AlignCenter)
             #label_list[-1].setFrameStyle(QFrame.Box)
             #label_list[-1].setLineWidth(1)
             gridlayout.addWidget(label_list[-1], i, j)
     wid.setLayout(gridlayout)
     return wid
コード例 #4
0
    def _setup_ui(self):
        # Set up our basic layout
        layout = QHBoxLayout(self)
        self.setLayout(layout)
        layout.setSpacing(3)
        layout.setMargin(1)

        bit_frame = QFrame(self)
        layout.addWidget(bit_frame)
        bit_layout = QGridLayout(bit_frame)
        bit_layout.setSpacing(1)
        bit_layout.setMargin(0)
        bit_frame.setLayout(bit_layout)
        bit_frame.setFrameStyle(QFrame.StyledPanel | QFrame.Raised)

        col = 0
        col = self._create_reg(bit_frame, bit_layout, col, 16,
                               self._w_cmp_switches, self._w_ign_switches,
                               self._update_val_box, self._send_ign_val)
        sep = QFrame(bit_frame)
        sep.setFrameStyle(QFrame.VLine | QFrame.Raised)
        bit_layout.addWidget(sep, 0, col, 2, 1)
        self._create_reg(bit_frame, bit_layout, col + 1, 2,
                         self._par_cmp_switches, self._par_ign_switches,
                         self._send_parity, self._send_parity)

        # Create a value box for displaying the overall decoded valess
        self._val_box = QLineEdit(self)
        layout.addWidget(self._val_box)
        self._val_box.setMaximumSize(52, 32)
        self._val_box.setText('00000')
        self._val_box.setValidator(RegValidator(0o77777))
        self._val_box.returnPressed.connect(self._update_cmp_switches)
        font = QFont('Monospace')
        font.setStyleHint(QFont.TypeWriter)
        font.setPointSize(10)
        self._val_box.setFont(font)
        self._val_box.setAlignment(Qt.AlignCenter)

        # Add some spacing to account for lack of parity indicators
        layout.addSpacing(40)
コード例 #5
0
ファイル: ui2.py プロジェクト: NCarrez/Python
def build_adminpanelwidget():
    widget = QFrame()
    widget.setFrameStyle(QFrame.Panel | QFrame.Raised)
    # widget = QWidget()
    # widget.setStyleSheet(
    #    "background-color: rgb(255,0,0); margin:5px; border:1px solid rgb(0, 255, 0); "
    # )
    # widget.setStyle(QStyle.PE_FrameWindow)
    widget.layout = QVBoxLayout()
    widget.we_username = QLineEdit("username")
    widget.wl_username = QLabel("username")
    widget.wl_username.setBuddy(widget.we_username)
    widget.we_username.setReadOnly(True)

    widget.pas_layout = QHBoxLayout()
    widget.we_password = QLineEdit("password")
    widget.wl_password = QLabel("password")
    widget.wl_password.setBuddy(widget.we_password)
    widget.we_password.setReadOnly(True)
    widget.we_password.setEchoMode(QLineEdit.Password)
    widget.reveal = QPushButton("Reveal")

    widget.btn_layout = QHBoxLayout()
    widget.update = QPushButton("Update")
    widget.delete = QPushButton("Delete")

    widget.layout.addWidget(widget.wl_username)
    widget.layout.addWidget(widget.we_username)
    widget.layout.addWidget(widget.wl_password)
    widget.layout.insertLayout(-1, widget.pas_layout)
    widget.pas_layout.addWidget(widget.we_password)
    widget.pas_layout.addWidget(widget.reveal)
    widget.layout.addStretch()
    widget.layout.insertLayout(-1, widget.btn_layout)
    widget.btn_layout.addWidget(widget.update)
    widget.btn_layout.addWidget(widget.delete)
    widget.setLayout(widget.layout)
    return widget
    pass
コード例 #6
0
class MainWindow(QMainWindow):
    def __init__(self,*args,**kwargs):
        super(MainWindow,self).__init__(*args,**kwargs)
        self.ventanaHelp = HelpContentWindow()
        self.ventana = AddProductWindow(self)
        self.menuBar = QMenuBar(self)
        self.setMenuBar(self.menuBar)
        help_menu = self.menuBar.addMenu('&Ayuda')
        help_content = QAction('&Contenido',self)
        help_acerca = QAction('&Acerca de',self)
        help_menu.addAction(help_content)
        help_menu.addAction(help_acerca)
        help_content.triggered.connect(self.help_content_triggered)
        focus_in_signal = Signal()
        self.majorLayout = QHBoxLayout()
        self.layout = QVBoxLayout()
        self.table = QTableView()
        self.marco = QFrame()
        self.marco.setFrameStyle(QFrame.Box)
        self.marco.setLayout(self.layout)
        self.inputCommands = LineEdit()
        self.inputCommands.setText('Ingrese un comando')
        self.inputCommands.focus_in_signal.connect(self.focus_in_command)
        self.layout.addWidget(self.inputCommands)
        self.inputCommands.returnPressed.connect(self.command_agrega_producto)
        self.inputCommands.hide()
        self.input = QLineEdit()
        self.layout.addWidget(self.table)
        self.layout.addWidget(self.input)
        self.majorLayout.addWidget(self.marco)
        self.total = QLabel()
        self.total.setText('Total: 0.00')
        self.total.setStyleSheet("{padding:0 50; margin:0 100;}")
        self.majorLayout.addWidget(self.total)
        widget = QWidget()
        widget.setLayout(self.majorLayout)
        self.datos =[
            ['ABCZ-1234', 'Paño esponja', 130.50],
            ['XYZC-2345', 'Escoba', 140.30],
            ]
        self.datosAnexos = [
            ['ABCZ-1234', 'Paño esponja', 130.50],
            ['XYZC-2345', 'Escoba', 140.30],
            ['WXYZ-1234', 'Limpiador de pisos', 150.00],
            ['ABCD-1234', 'Bote de basura grande', 1000.00]
            ]
        self.model = TableModel(self.datos, ['SKU', 'Artículo', 'Precio'])
        self.table.setModel(self.model)
        self.table.setColumnWidth(1,315)
        self.setCentralWidget(widget)
        self.input.returnPressed.connect(self.add_datos)
        self.calculate_total()

    def help_content_triggered(self):
        self.ventanaHelp.display_help()

    def add_datos(self):
        texto = self.input.text()
        valor = self.method_in(self.datosAnexos, texto)
        if(valor is None):
            self.marco.setStyleSheet("QFrame{border: 1px solid red;}")
            self.input.setStyleSheet("border: 1px solid red;")
            self.inputCommands.setText('Ingrese un comando')
            self.inputCommands.show()
        else:
            self.marco.setStyleSheet("QFrame{border: 1px solid black;}")
            self.input.setStyleSheet("border: 1px solid black;")
            self.datos.append(valor)
            self.table.model().layoutChanged.emit()
            self.calculate_total()
            self.inputCommands.hide()

    def calculate_total(self):
        agregado = 0.0
        for dato in self.datos:
            agregado += dato[2]
        self.total.setText('Total: ' + '{:.2f}'.format(agregado))

    def method_in(self, data, text):
        for element in data:
            if element[0].casefold() == text.casefold():
                return element
        return None
        
    def focus_in_command(self):
        self.inputCommands.setText('')

    def command_agrega_producto(self):
        valor = self.elige_comando(1)
        print(valor)
        if(valor == self.inputCommands.text()):
            self.ventana.display_info()
        else:
            print('Comando incorrecto')

    def comando_agregar(self):
        return 'A'

    def elige_comando(self, argument):
        return {
            1: lambda: self.comando_agregar(),
        }.get(argument, lambda: 'Opción inválida')()
コード例 #7
0
    def _create_reg(self, width, cmp_switches, ign_switches):
        # Create a widget to hold the register's bits
        reg_widget = QWidget(self)
        reg_layout = QVBoxLayout(reg_widget)
        reg_widget.setLayout(reg_layout)
        reg_layout.setSpacing(0)
        reg_layout.setMargin(0)

        # Create a widget to hold the register's value and ignore textboxes
        values = QWidget(reg_widget)
        v_layout = QHBoxLayout(values)
        values.setLayout(v_layout)
        v_layout.setSpacing(1)
        v_layout.setMargin(0)
        reg_layout.addWidget(values)
        reg_layout.setAlignment(values, Qt.AlignRight)

        # Create textboxes to show the register's value and ignore mask in octal
        n_digits = int((width + 2) / 3)
        if n_digits == 1:
            value_width = 25
        elif n_digits == 2:
            value_width = 30
        else:
            value_width = 45

        reg_value = QLineEdit(values)
        reg_value.setMaximumSize(value_width, 32)
        reg_value.setText(n_digits * '0')
        reg_value.setAlignment(Qt.AlignCenter)
        reg_value.setValidator(RegValidator(2**width - 1))
        reg_value.setMaxLength(n_digits)
        reg_value.returnPressed.connect(
            lambda b=reg_value, s=cmp_switches: self._update_switches(b, s))
        v_layout.addWidget(reg_value)

        ign_value = QLineEdit(values)
        ign_value.setMaximumSize(value_width, 32)
        ign_value.setText(n_digits * '0')
        ign_value.setAlignment(Qt.AlignCenter)
        ign_value.setValidator(RegValidator(2**width - 1))
        ign_value.setMaxLength(n_digits)
        ign_value.returnPressed.connect(
            lambda b=ign_value, s=ign_switches: self._update_switches(b, s))
        v_layout.addWidget(ign_value)

        font = QFont('Monospace')
        font.setStyleHint(QFont.TypeWriter)
        font.setPointSize(10)
        reg_value.setFont(font)
        ign_value.setFont(font)

        # Create a frame to hold the register's bits
        bit_frame = QFrame(reg_widget)
        bit_layout = QGridLayout(bit_frame)
        bit_layout.setSpacing(1)
        bit_layout.setMargin(0)
        bit_frame.setLayout(bit_layout)
        bit_frame.setFrameStyle(QFrame.StyledPanel | QFrame.Raised)

        # Add indicators for each bit in the register, from MSB to LSB
        col = 0
        for i in range(width, 0, -1):
            check = QCheckBox(bit_frame)
            check.setFixedSize(20, 20)
            check.setStyleSheet(
                'QCheckBox::indicator{subcontrol-position:center;}')
            check.stateChanged.connect(
                lambda state, b=reg_value, s=cmp_switches: self.
                _update_reg_box(state, b, s))
            bit_layout.addWidget(check, 0, col)
            bit_layout.setAlignment(check, Qt.AlignCenter)
            cmp_switches.append(check)

            check = QCheckBox(bit_frame)
            check.setFixedSize(20, 20)
            check.setStyleSheet(
                'QCheckBox::indicator{subcontrol-position:center;}')
            check.stateChanged.connect(
                lambda state, b=ign_value, s=ign_switches: self.
                _update_reg_box(state, b, s))
            bit_layout.addWidget(check, 1, col)
            bit_layout.setAlignment(check, Qt.AlignCenter)
            ign_switches.append(check)

            col += 1

            # Add separators between each group of 3 bits
            if (i > 1) and ((i % 3) == 1):
                sep = QFrame(bit_frame)
                sep.setFrameStyle(QFrame.VLine | QFrame.Raised)
                bit_layout.addWidget(sep, 0, col, 2, 1)
                col += 1

        reg_layout.addWidget(bit_frame)

        return reg_widget, reg_value, ign_value
コード例 #8
0
    def _create_reg(self, ind_list, name, width, color):
        # Create a widget to hold the register's bits
        reg_widget = QWidget(self)
        reg_layout = QVBoxLayout(reg_widget)
        reg_widget.setLayout(reg_layout)
        reg_layout.setSpacing(0)
        reg_layout.setMargin(0)

        # Create a widget to hold the register's label and value textbox
        label_value = QWidget(reg_widget)
        lv_layout = QHBoxLayout(label_value)
        label_value.setLayout(lv_layout)
        lv_layout.setSpacing(1)
        lv_layout.setMargin(0)
        reg_layout.addWidget(label_value)

        # Create a label to show the register's name
        reg_label = QLabel(name, label_value)
        reg_label.setAlignment(Qt.AlignCenter)
        font = reg_label.font()
        font.setPointSize(8)
        reg_label.setFont(font)
        lv_layout.addWidget(reg_label)

        # Create a textbox to show the register's value in octal
        n_digits = int((width + 2) / 3)
        if n_digits == 1:
            value_width = 25
        elif n_digits == 2:
            value_width = 30
        else:
            value_width = 45

        reg_value = QLineEdit(label_value)
        reg_value.setReadOnly(True)
        reg_value.setMaximumSize(value_width, 32)
        reg_value.setText(n_digits * '0')
        font = QFont('Monospace')
        font.setStyleHint(QFont.TypeWriter)
        font.setPointSize(10)
        reg_value.setFont(font)
        reg_value.setAlignment(Qt.AlignCenter)
        lv_layout.addWidget(reg_value)

        # Create a frame to hold the register's bits
        bit_frame = QFrame(reg_widget)
        bit_layout = QHBoxLayout(bit_frame)
        bit_layout.setSpacing(1)
        bit_layout.setMargin(0)
        bit_frame.setLayout(bit_layout)
        bit_frame.setFrameStyle(QFrame.StyledPanel | QFrame.Raised)

        # Add indicators for each bit in the register, from MSB to LSB
        for i in range(width, 0, -1):
            ind = Indicator(bit_frame, color)
            ind.setFixedSize(20, 32)
            bit_layout.addWidget(ind)
            ind_list.insert(0, ind)

            # Add separators between each group of 3 bits
            if (i > 1) and ((i % 3) == 1):
                sep = QFrame(bit_frame)
                sep.setFrameStyle(QFrame.VLine | QFrame.Raised)
                bit_layout.addWidget(sep)

        reg_layout.addWidget(bit_frame)

        return reg_widget, reg_value
コード例 #9
0
ファイル: register.py プロジェクト: rzinkstok/fpga_agc
    def _setup_ui(self, name, color):
        # Set up the overall horizontal layout
        layout = QHBoxLayout(self)
        self.setLayout(layout)
        layout.setSpacing(3)
        layout.setMargin(1)

        # Construct a frame to hold the 16 indicators
        bit_frame = QFrame(self)
        bit_frame.setStyleSheet("QFrame { color: #666 }")
        bit_layout = QHBoxLayout(bit_frame)
        bit_layout.setSpacing(1)
        bit_layout.setContentsMargins(1, 0, 2, 0)
        bit_frame.setLayout(bit_layout)
        bit_frame.setFrameStyle(QFrame.Panel | QFrame.Plain)

        layout.addWidget(bit_frame)

        # Add sensed and generated parity bits, if this register has them
        if self._has_parity:
            for i in range(2, 0, -1):
                ind = ApolloIndicator(bit_frame, QColor(220, 240, 0))
                ind.setFixedSize(20, 32)
                bit_layout.addWidget(ind)
                self._parity_inds.insert(0, ind)

            sep = QFrame(bit_frame)
            sep.setFrameStyle(QFrame.VLine | QFrame.Plain)
            bit_layout.addWidget(sep)

        # Add the 16 bit indicators to the frame, from 16 to 1.
        for i in range(16, 0, -1):
            if (i == 15):
                indcolor = QColor(220, 240, 0)
            else:
                indcolor = color
            ind = ApolloIndicator(bit_frame, indcolor)
            ind.setFixedSize(20, 32)
            bit_layout.addWidget(ind)
            self._indicators.insert(0, ind)

            # Add separators between every group of 3 bits (except between
            # bits 15 and 16).
            if (i < 16) and (i > 1) and ((i % 3) == 1):
                sep = QFrame(bit_frame)
                sep.setFrameStyle(QFrame.VLine | QFrame.Plain)
                bit_layout.addWidget(sep)

        # Add a box to display the octal decoded value in
        self._value_box = QLineEdit(self)
        self._value_box.setFixedSize(70, 32)
        self._value_box.setReadOnly(True)
        self._value_box.setAlignment(Qt.AlignCenter)
        self._value_box.setText('00000')
        self._value_box.setStyleSheet("QLineEdit { color: #555; }")
        layout.addWidget(self._value_box)

        # Add a label showing the name of the register
        label = QLabel(name, self)
        label.setFixedWidth(20)
        layout.addWidget(label)
コード例 #10
0
ファイル: main.py プロジェクト: BubaDubaKuba/sergey
    def initUI(self):
        """Функция инициализации всех виджетов
        (вызывать её не надо)"""

        # showMaximized() изменяет размер окна на максимальный.
        self.showMaximized()
        # Присваиваем названию окна строку "SERGEY APP!!!".
        self.setWindowTitle("SERGEY APP!!!")
        # Должно менять иконку приложения (Почему-то не работает).
        self.setWindowIcon(QIcon("icon.ico"))

        # QWebEngineView - класс библиотеки, с помощью которого можно
        # отображать Web страницы (сайты из интернета или
        # просто локальные файлы HTML).
        # Иницилиализируем его, передавая обьект нашего главного класса.
        self.web = QWebEngineView(self)
        # Получаем абсолютный путь файла
        # map2.html (почему-то QWebEngineView
        # загружает только абсолютные пути файла).
        file_path = os.path.abspath(
            os.path.join(os.path.dirname(__file__), "index.html"))
        self.web.setPage(WebPage(self.web))
        self.web.load(QUrl.fromLocalFile(file_path))

        def ready(retVal):
            print("Returned:", retVal)

        def loadFinished(ok):
            if ok:
                #self.web.page().runJavaScript("bruhmoment()", ready)
                pass

        self.web.loadFinished.connect(loadFinished)

        self.jsChannel = QWebChannel()
        self.jsHandler = CallHandler()
        self.jsChannel.registerObject("jsHandler", self.jsHandler)
        self.web.page().setWebChannel(self.jsChannel)

        input_frame = QFrame(self)
        input_frame.setFrameStyle(QFrame.Box)

        inputgrid = QGridLayout(input_frame)

        inputButtonTexts = ["Привет!", "Квест", "Пока!"]
        buttons = []
        for i in range(len(inputButtonTexts)):
            buttons.append(InputButton(inputButtonTexts[i], input_frame, self))
            inputgrid.addWidget(buttons[i], 0, i, 1, 1)

        self.inputbox = QLineEdit(input_frame)
        self.inputbox.returnPressed.connect(self.sendMsg)
        inputgrid.addWidget(self.inputbox, 1, 0, 1, -1)

        self.chat = Chat()

        # QGridLayout - один из макетных классов, которые помогает управлять
        # положением виджетов. Этот класс управляет положениями виджетов
        # с помощью "таблицы", например как в Excel.
        # Виджеты могут занимать несколько "клеток" в таблице.
        # Пример макета:
        # +------------+----------------+
        # |   Кнопка   |                |
        # +------------+  Что-то еще... |
        # |            |                |
        # | Поле ввода +----------------+
        # |            | Какой-то текст |
        # +------------+----------------+
        main_layout = QGridLayout(self)

        # Добавляем все наши виджеты (кнопки, веб страницы и т.д.)
        main_layout.addWidget(self.chat, 0, 0, 80, 60)
        main_layout.addWidget(input_frame, 80, 0, 20, 60)
        main_layout.addWidget(self.web, 0, 60, 100, 40)
コード例 #11
0
class RenameOptionsView(QWidget):
    """View responsible for holding renaming options.
    
    Attributes:
        layout (QVBoxLayout): Main layout of view.
        frame_layout (QVBoxLayout: Layout of frame which holds options.
        frame (QFrame): Frame surrounding options.
        prefix_h_layout (QHBoxLayout): Layout holding prefix options.
        complete_rename_h_layout (QHBoxLayout): Layout holding complete rename options.
        search_and_replace_h_layout (QHBoxLayout): Layout holding search and replace options.
        renumber_h_layout (QHBoxLayout): Layout holding renumber options.
        remove_ext_h_layout (QHBoxLayout): Layout holding remove options.
        change_ext_h_layout (QHBoxLayout): Layout holding change extension options.
        create_backup_h_layout (QHBoxLayout): Layout holding backup options.
        preview_h_layout (QHBoxLayout): Layout holding preview options.
        start_lbl (QLabel): Label for renumbering start.
        padding_lbl (QLabel): Label for renumbering padding.
        add_prefix_cb (QCheckBox): Used to signify the user wants to add a prefix to the renaming.
        prefix (QLineEdit): prefix to add.
        complete_rename_cb (QCheckBox): Used to signify the user wants to completely rename the file.
        new_name (QLineEdit): New name used when renaming.
        search_and_replace_cb (QCheckBox): Used to signify the user wants to partially rename files.
        find (QLineEdit): When searching and replacing this is what the user wants to search for.
        replace (QLineEdit): When searching and replacing this is what the user wants to replace with.
        renumber_cb (QCheckBox): Used to signify the user wants to renumber while renaming.
        start_num (QSpinBox): Number to start with when renumbering files.
        padding (QComboBox): Padding to apply to renaming when renumbering files.
        dot_cb (QCheckBox): When checked a dot will be used to separate the renumber from the name.
        remove_ext_cb (QCheckBox): Used to signify the user wants to remove extensions when renaming.
        backup_files_cb (QCheckBox): Used to signify the user wants to backup old files before renaming.
        change_ext_cb (QCheckBox): Used to signify the user wants to change the extension while renaming.
        change_ext (QLineEdit): New extension to add to the renamed file.
        preview_cb (QCheckBox): Used to signify the user wants to preview the rename before renaming.
    """
    def __init__(self):
        super(RenameOptionsView, self).__init__()
        self.layout = QVBoxLayout()
        self.frame_layout = QVBoxLayout()
        self.options_lbl = QLabel(prefs.OPTIONS)
        self.frame = QFrame()
        self.prefix_h_layout = QHBoxLayout()
        self.complete_rename_h_layout = QHBoxLayout()
        self.search_and_replace_h_layout = QHBoxLayout()
        self.renumber_h_layout = QHBoxLayout()
        self.remove_ext_h_layout = QHBoxLayout()
        self.change_ext_h_layout = QHBoxLayout()
        self.create_backup_h_layout = QHBoxLayout()
        self.preview_h_layout = QHBoxLayout()
        self.start_lbl = QLabel(prefs.START_NUM)
        self.padding_lbl = QLabel(prefs.PADDING)
        self.add_prefix_cb = QCheckBox(prefs.PREFIX)
        self.prefix = QLineEdit(prefs.PREFIX_DEFAULT)
        self.complete_rename_cb = QCheckBox(prefs.COMPLETE_RENAME)
        self.new_name = QLineEdit(prefs.COMPLETE_RENAME_DEFAULT)
        self.search_and_replace_cb = QCheckBox(prefs.SEARCH_AND_REPLACE)
        self.find = QLineEdit(prefs.SEARCH_AND_REPLACE_DEFAULT)
        self.replace = QLineEdit(prefs.REPLACE_WITH_DEFAULT)
        self.renumber_cb = QCheckBox(prefs.RENUMBER)
        self.start_num = QSpinBox()
        self.padding = QComboBox()
        self.dot_cb = QCheckBox(prefs.USE_DOT)
        self.remove_ext_cb = QCheckBox(prefs.REMOVE_EXT)
        self.backup_files_cb = QCheckBox(prefs.BACKUP)
        self.change_ext_cb = QCheckBox(prefs.CHANGE_EXT)
        self.change_ext = QLineEdit(prefs.CHANGE_EXT_DEFAULT)
        self.preview_cb = QCheckBox(prefs.PREVIEW)

        self._configure()

    def _configure(self) -> None:
        """Configure the RenameOptionsView."""
        self.frame.setLayout(self.frame_layout)
        self.frame.setFrameStyle(QFrame.StyledPanel | QFrame.Sunken)
        self.layout.addWidget(self.options_lbl)
        self.layout.addWidget(self.frame)
        self.add_prefix_cb.setToolTip(prefs.PREFIX_TOOLTIP)
        self.prefix.setDisabled(True)
        self.prefix.setMaximumWidth(prefs.PREFIX_WIDTH)
        self.prefix.setMinimumWidth(prefs.PREFIX_WIDTH)
        self.complete_rename_cb.setToolTip(prefs.COMPLETE_RENAME_TOOLTIP)
        self.new_name.setDisabled(True)
        self.new_name.setMaximumWidth(prefs.NEW_NAME_WIDTH)
        self.new_name.setMinimumWidth(prefs.NEW_NAME_WIDTH)
        self.search_and_replace_cb.setToolTip(prefs.SEARCH_AND_REPLACE_TOOLTIP)
        self.find.setDisabled(True)
        self.find.setMinimumWidth(prefs.FIND_WIDTH)
        self.find.setMaximumWidth(prefs.FIND_WIDTH)
        self.replace.setDisabled(True)
        self.replace.setMaximumWidth(prefs.REPLACE_WIDTH)
        self.replace.setMinimumWidth(prefs.REPLACE_WIDTH)
        self.renumber_cb.setToolTip(prefs.RENUMBER_TOOLTIP)
        self.start_num.setToolTip(prefs.START_NUM_TOOLTIP)
        self.start_num.setDisabled(True)
        self.start_num.setValue(prefs.START_NUM_DEFAULT)
        self.start_num.setMinimumWidth(prefs.START_NUM_MIN_WIDTH)
        self.padding.setToolTip(prefs.PADDING_TOOLTIP)
        self.padding.setDisabled(True)
        self.padding.addItems([str(x) for x in range(10)])
        self.padding.setCurrentIndex(4)
        self.padding.setMinimumWidth(prefs.PADDING_MIN_WIDTH)
        self.dot_cb.setToolTip(prefs.USE_DOT_TOOLTIP)
        self.dot_cb.setDisabled(True)
        self.dot_cb.setChecked(True)
        self.dot_cb.setMinimumWidth(prefs.DOT_WIDTH)
        self.dot_cb.setMaximumWidth(prefs.DOT_WIDTH)
        self.remove_ext_cb.setToolTip(prefs.REMOVE_EXT_TOOLTIP)
        self.change_ext.setToolTip(prefs.CHANGE_EXT_TOOLTIP)
        self.change_ext.setDisabled(True)
        self.backup_files_cb.setToolTip(prefs.BACKUP_TOOLTIP)
        self.backup_files_cb.setChecked(True)
        self.preview_cb.setToolTip(prefs.PREVIEW_TOOLTIP)
        self.preview_cb.setChecked(True)

        self.prefix_h_layout.addWidget(self.add_prefix_cb)
        self.prefix_h_layout.addWidget(self.prefix)
        self.frame_layout.addLayout(self.prefix_h_layout)

        self.complete_rename_h_layout.addWidget(self.complete_rename_cb)
        self.complete_rename_h_layout.addWidget(self.new_name)
        self.frame_layout.addLayout(self.complete_rename_h_layout)

        self.search_and_replace_h_layout.addWidget(self.search_and_replace_cb)
        self.search_and_replace_h_layout.addWidget(self.find)
        self.search_and_replace_h_layout.addWidget(self.replace)
        self.frame_layout.addLayout(self.search_and_replace_h_layout)

        self.renumber_h_layout.addWidget(self.renumber_cb)
        self.renumber_h_layout.addStretch(1)
        self.renumber_h_layout.addWidget(self.start_lbl)
        self.renumber_h_layout.addWidget(self.start_num)
        self.renumber_h_layout.addSpacerItem(QSpacerItem(*prefs.SPACER_SIZE))
        self.renumber_h_layout.addWidget(self.padding_lbl)
        self.renumber_h_layout.addWidget(self.padding)
        self.renumber_h_layout.addSpacerItem(QSpacerItem(*prefs.SPACER_SIZE))
        self.renumber_h_layout.addWidget(self.dot_cb)
        self.frame_layout.addLayout(self.renumber_h_layout)

        self.change_ext_h_layout.addWidget(self.change_ext_cb)
        self.change_ext_h_layout.addWidget(self.change_ext)
        self.frame_layout.addLayout(self.change_ext_h_layout)

        self.remove_ext_h_layout.addWidget(self.remove_ext_cb)
        self.frame_layout.addLayout(self.remove_ext_h_layout)

        self.create_backup_h_layout.addWidget(self.backup_files_cb)
        self.frame_layout.addLayout(self.create_backup_h_layout)

        self.preview_h_layout.addWidget(self.preview_cb)
        self.frame_layout.addLayout(self.preview_h_layout)

        self.frame_layout.addSpacerItem(QSpacerItem(*prefs.SPACER_SIZE))

        self.setLayout(self.layout)

    def disable_change_ext(self) -> None:
        """Disable change extension."""
        self.change_ext.setDisabled(True)

    def disable_dot(self) -> None:
        """Disable dot checkbox."""
        self.dot_cb.setDisabled(True)

    def disable_find(self) -> None:
        """Disable find."""
        self.find.setDisabled(True)

    def disable_new_name(self) -> None:
        """Disable new name."""
        print("disable new name")
        self.new_name.setDisabled(True)

    def disable_padding(self) -> None:
        """Disable padding."""
        self.padding.setDisabled(True)

    def disable_prefix(self) -> None:
        """Disable prefix."""
        self.prefix.setDisabled(True)

    def disable_start_num(self) -> None:
        """Disable start num."""
        self.start_num.setDisabled(True)

    def disable_replace(self) -> None:
        """Disable replace."""
        self.replace.setDisabled(True)

    def enable_change_ext(self) -> None:
        """Disable change extension."""
        self.change_ext.setDisabled(False)

    def enable_dot(self) -> None:
        """Enable dot checkbox."""
        self.dot_cb.setEnabled(True)

    def enable_find(self) -> None:
        """Enable find."""
        self.find.setEnabled(True)

    def enable_new_name(self) -> None:
        """Enable new name."""
        print("enable new name.")
        self.new_name.setEnabled(True)

    def enable_padding(self) -> None:
        """Enable padding."""
        self.padding.setEnabled(True)

    def enable_prefix(self) -> None:
        """Enable prefix."""
        self.prefix.setEnabled(True)

    def enable_replace(self) -> None:
        """Enable replace."""
        self.replace.setEnabled(True)

    def enable_start_num(self) -> None:
        """Enable start num."""
        self.start_num.setEnabled(True)

    def get_add_prefix(self) -> bool:
        """Return if end user wants to add a prefix and it is not the default value."""
        result = self.get_prefix_checked()
        if result and self.get_prefix() == prefs.PREFIX_DEFAULT:
            result = False
        return result

    def get_do_backup(self) -> bool:
        """Return if end user wants to backup files."""
        return self.backup_files_cb.isChecked()

    def get_change_ext(self) -> bool:
        """Return if the change extension checkbox is checked."""
        return self.change_ext_cb.isChecked()

    def get_do_complete_rename(self) -> bool:
        """Get if end user wants to completely rename."""
        return self.complete_rename_cb.isChecked()

    def get_dot(self) -> str:
        """Return dot string based on end users configuration.

        Note:
            If the end user has not enable using dot separators an empty string will be returned.
        """
        return "." if self.get_do_dot() else ""

    def get_do_dot(self) -> bool:
        """Return if the end user wants to use dot separators when renaming."""
        return self.dot_cb.isChecked()

    def get_do_change_ext(self) -> bool:
        """Return if the end user wants to change the extension."""
        result = self.change_ext_cb.isChecked()
        if self.get_new_ext() == prefs.CHANGE_EXT_DEFAULT:
            return False
        return result

    def get_do_padding(self) -> bool:
        """Return if the end user wants to add padding."""
        return False if self.get_padding() == 0 else True

    def get_do_preview(self) -> bool:
        """Return if the end user wants to preview changes."""
        return self.preview_cb.isChecked()

    def get_do_rename(self) -> bool:
        """Return if end user wants to rename the full item and it is not the default value."""
        result = self.complete_rename_cb.isChecked()
        if result and self.get_new_name() == prefs.COMPLETE_RENAME_DEFAULT:
            result = False
        return result

    def get_do_renumber(self) -> bool:
        """Return if the end user wants to renumber."""
        return self.renumber_cb.isChecked()

    def get_do_search(self) -> bool:
        """Return if end user wants to perform a search and replace AND it is not the default values respectfully.

        Note:
            If you only want to know if search and replace is checked use get_search_and_replace.
        """
        result = self.search_and_replace_cb.isChecked()
        if result and (self.get_find() == prefs.SEARCH_AND_REPLACE_DEFAULT
                       or self.get_replace() == prefs.REPLACE_WITH_DEFAULT):
            result = False
        return result

    def get_do_search_and_replace(self) -> bool:
        """Return if end user wants to perform a search and replace."""
        return self.search_and_replace_cb.isChecked()

    def get_find(self) -> str:
        """Return find value."""
        return str(self.find.text())

    def get_new_ext(self) -> str:
        """Return new ext."""
        return str(self.change_ext.text())

    def get_new_name(self) -> str:
        """Return new_name value."""
        return str(self.new_name.text())

    def get_padding(self) -> int:
        """Return the current padding value."""
        return int(self.padding.currentText())

    def get_prefix_checked(self) -> bool:
        """Return if the prefix checkbox is checked."""
        return self.add_prefix_cb.isChecked()

    def get_prefix(self) -> str:
        """Return the current prefix value end user has entered."""
        return str(self.prefix.text())

    def get_remove_ext(self) -> bool:
        """Return if end user has checked the remove extension checkbox."""
        return self.remove_ext_cb.isChecked()

    def get_replace(self) -> str:
        """Return the current replace value end user has entered."""
        return str(self.replace.text())

    def get_start_num(self) -> int:
        """Return start number from view."""
        return int(self.start_num.value())

    def set_change_ext_style(self, style: str) -> None:
        """Set style of change extension.

        Args:
            style: Style sheet applied to change extension.
        """
        self.change_ext.setStyleSheet(style)

    def set_disabled(self) -> None:
        """Disable View."""
        self.setDisabled(True)

    def set_enable(self) -> None:
        """Enable View."""
        self.setEnabled(True)

    def set_find(self, value: str) -> None:
        """Set the value of find.

        Args:
            value: Value applied to find
        """
        self.find.setText(value)

    def set_find_style(self, style: str) -> None:
        """Set style of find.

        Args:
            style: Style sheet applied to find.
        """
        self.find.setStyleSheet(style)

    def set_new_name(self, value: str) -> None:
        """Set the value of new name.

        Args:
            value: Value applied to new_name
        """
        self.new_name.setText(value)

    def set_new_name_style(self, style: str) -> None:
        """Set style of new_name.
        
        Args:
            style: Style sheet applied to new_name.
        """
        self.new_name.setStyleSheet(style)

    def set_prefix(self, value: str) -> None:
        """Set the value of prefix.

        Args:
            value: Value applied to prefix
        """
        self.prefix.setText(value)

    def set_prefix_style(self, style: str) -> None:
        """Set style of prefix.

        Args:
            style: Style sheet applied to prefix.
        """
        self.prefix.setStyleSheet(style)

    def set_remove_ext(self, state: bool) -> None:
        """Set the remove_ext checkbox as checked or unchecked.

        Args:
            state: Check state of remove_ext.
        """
        self.remove_ext_cb.setCheckState(Qt.Checked if state else Qt.Unchecked)

    def set_replace(self, value: str) -> None:
        """Set the value of replace.

        Args:
            value: Value applied to replace
        """
        self.replace.setText(value)

    def set_replace_style(self, style: str) -> None:
        """Set style of replace.

        Args:
            style: Style sheet applied to replace.
        """
        self.replace.setStyleSheet(style)
コード例 #12
0
    def _setup_ui(self):
        self.setStyleSheet("QFrame { color: #666; }")
        layout = QVBoxLayout(self)
        self.setLayout(layout)
        layout.setMargin(0)
        layout.setSpacing(0)

        if self.include_values:
            # Value boxes
            vw = QWidget(self)
            vl = QHBoxLayout()
            vl.setSpacing(2)
            vl.setContentsMargins(0, 0, 0, 2)
            vw.setLayout(vl)
            layout.addWidget(vw)
            layout.setAlignment(vw, Qt.AlignRight)

            # Create textboxes to show the register's value and ignore mask in octal
            n_digits = int((self.width + 2) / 3)
            if n_digits == 1:
                value_width = 25
            elif n_digits == 2:
                value_width = 30
            else:
                value_width = 45

            self.reg_box = QLineEdit(vw)
            self.reg_box.setFixedSize(value_width, 32)
            self.reg_box.setText(n_digits * '0')
            self.reg_box.setAlignment(Qt.AlignCenter)
            self.reg_box.setValidator(OctalValidator(2**self.width - 1))
            self.reg_box.setMaxLength(n_digits)
            self.reg_box.returnPressed.connect(self._update_reg_switches)
            vl.addWidget(self.reg_box)

            self.ign_box = QLineEdit(vw)
            self.ign_box.setMaximumSize(value_width, 32)
            self.ign_box.setText(n_digits * '0')
            self.ign_box.setAlignment(Qt.AlignCenter)
            self.ign_box.setValidator(OctalValidator(2**self.width - 1))
            self.ign_box.setMaxLength(n_digits)
            self.ign_box.returnPressed.connect(self._update_ign_switches)
            vl.addWidget(self.ign_box)

        # Switches
        ssf = QFrame(self)
        ssf.setFrameStyle(QFrame.Panel | QFrame.Plain)
        ssf.setStyleSheet(
            'QCheckBox::indicator { subcontrol-position: center; }')

        ssl = QHBoxLayout()
        ssl.setSpacing(1)
        ssl.setContentsMargins(1, 0, 2, 0)
        ssf.setLayout(ssl)
        layout.addWidget(ssf)
        layout.setAlignment(ssf, Qt.AlignRight)

        for i in range(self.width, 0, -1):
            sw = QWidget(ssf)
            sl = QVBoxLayout()
            sl.setSpacing(1)
            sl.setContentsMargins(0, 1, 0, 1)
            sw.setLayout(sl)

            s1 = QCheckBox(sw)
            s1.setFixedSize(self.item_width, 20)
            sl.addWidget(s1)
            sl.setAlignment(s1, Qt.AlignCenter)
            s1.stateChanged.connect(self._update_reg_value)
            self._reg_switches.insert(0, s1)

            s2 = QCheckBox(sw)
            s2.setFixedSize(self.item_width, 20)
            sl.addWidget(s2)
            sl.setAlignment(s2, Qt.AlignCenter)
            s2.stateChanged.connect(self._update_ign_value)
            self._ign_switches.insert(0, s2)

            ssl.addWidget(sw)

            # Add separators between each group of 3 bits
            if self.separators and i in [17, 13, 10, 7, 4]:
                sep = QFrame(ssf)
                sep.setFrameStyle(QFrame.VLine | QFrame.Plain)
                ssl.addWidget(sep)
コード例 #13
0
    def _setup_ui(self):
        layout = QVBoxLayout(self)
        self.setLayout(layout)
        layout.setMargin(1)
        layout.setSpacing(1)

        s1_s2 = QWidget(self)
        s1_s2_layout = QHBoxLayout(s1_s2)
        s1_s2.setLayout(s1_s2_layout)
        s1_s2_layout.setMargin(1)
        s1_s2_layout.setSpacing(0)
        self._s1 = QRadioButton('S1', s1_s2)
        font = self._s1.font()
        font.setPointSize(7)
        font.setBold(True)
        self._s1.setFont(font)
        self._s1.setLayoutDirection(Qt.RightToLeft)
        self._s1.setChecked(True)
        self._s2 = QRadioButton('S2', s1_s2)
        self._s2.setFont(font)
        self._s2.toggled.connect(lambda s: self._send_mode(s))
        s1_s2_layout.addWidget(self._s1)
        s1_s2_layout.setAlignment(self._s1, Qt.AlignLeft)
        s1_s2_layout.addWidget(self._s2)
        s1_s2_layout.setAlignment(self._s2, Qt.AlignLeft)

        layout.addWidget(s1_s2)
        layout.setAlignment(s1_s2, Qt.AlignRight)

        write_w_box = QGroupBox('WRITE W', self)
        write_w_layout = QGridLayout(write_w_box)
        write_w_box.setLayout(write_w_layout)
        write_w_layout.setMargin(1)
        write_w_layout.setSpacing(1)

        row = 0
        col = 0
        for label, mode in WRITE_W_POSITIONS.items():
            pos = QRadioButton(label, write_w_box)
            pos.setFont(font)
            if label == 'ALL':
                pos.setChecked(True)
            pos.pressed.connect(lambda m=mode: self._update_mode(m))
            write_w_layout.addWidget(pos, row, col)
            col += 1
            if row == 0 or col >= 3:
                col = 0
                row += 1

        layout.addWidget(write_w_box)

        switch_frame = QFrame(self)
        switch_frame.setFrameStyle(QFrame.StyledPanel | QFrame.Raised)
        switch_layout = QGridLayout(switch_frame)
        switch_layout.setMargin(1)
        switch_layout.setSpacing(1)
        switch_frame.setLayout(switch_layout)

        layout.addWidget(switch_frame)

        row = self._add_switches(switch_frame, switch_layout, TIME_SWITCHES,
                                 self._time_switches, self._send_times, row)
        sep = QFrame(switch_frame)
        sep.setFrameStyle(QFrame.HLine | QFrame.Raised)
        switch_layout.addWidget(sep, row, 0, 1, 6)
        row += 1

        self._add_switches(switch_frame, switch_layout, PULSE_SWITCHES,
                           self._pulse_switches, self._send_pulses, row)
コード例 #14
0
ファイル: register.py プロジェクト: rzinkstok/fpga_agc
    def __init__(self, parent, name, width, color, include_value=True):
        super().__init__(parent)
        self.indicators = []
        self.value = 0

        reg_layout = QVBoxLayout(self)
        self.setLayout(reg_layout)
        reg_layout.setSpacing(0)
        reg_layout.setContentsMargins(0, 0, 0, 0)

        if include_value:
            # Create a widget to hold the register's bits
            # Create a widget to hold the register's label and value textbox
            #label_value = QWidget(self)
            lv_layout = QHBoxLayout()
            #label_value.setLayout(lv_layout)
            lv_layout.setSpacing(1)
            lv_layout.setContentsMargins(0, 0, 0, 0)
            reg_layout.addLayout(lv_layout)
            reg_layout.addSpacing(1)

            # Create a label to show the register's name
            reg_label = QLabel(name, self)
            reg_label.setFixedHeight(32)
            reg_label.setAlignment(Qt.AlignCenter | Qt.AlignVCenter)
            lv_layout.addWidget(reg_label)

            # Create a textbox to show the register's value in octal
            n_digits = int((width + 2) / 3)
            if n_digits == 1:
                value_width = 25
            elif n_digits == 2:
                value_width = 30
            else:
                value_width = 45

            self.value_box = QLineEdit(self)
            self.value_box.setMaximumSize(value_width, 32)
            self.value_box.setReadOnly(True)
            self.value_box.setAlignment(Qt.AlignCenter)
            self.value_box.setText(n_digits * '0')
            self.value_box.setStyleSheet("QLineEdit { color: #555; }")
            lv_layout.addWidget(self.value_box)

        # Create a frame to hold the register's bits
        bit_frame = QFrame(self)
        bit_layout = QHBoxLayout(bit_frame)
        bit_layout.setSpacing(1)
        bit_layout.setContentsMargins(1, 0, 2, 0)
        bit_frame.setLayout(bit_layout)
        bit_frame.setFrameStyle(QFrame.StyledPanel | QFrame.Plain)
        reg_layout.addWidget(bit_frame)
        reg_layout.setAlignment(bit_frame, Qt.AlignRight)

        # Add indicators for each bit in the register, from MSB to LSB
        for i in range(width, 0, -1):
            ind = ApolloIndicator(bit_frame, color)
            ind.setFixedSize(20, 32)
            bit_layout.addWidget(ind)
            self.indicators.insert(0, ind)

            # Add separators between each group of 3 bits
            if (i > 1) and ((i % 3) == 1):
                sep = QFrame(bit_frame)
                sep.setFrameStyle(QFrame.VLine | QFrame.Plain)
                sep.setStyleSheet("QFrame { color: #666; } ")
                bit_layout.addWidget(sep)
コード例 #15
0
class Card(QWidget):
    def __init__(self, parent: QWidget, card_details: Dict[str, Any]):
        super().__init__()
        if parent is not None:
            self.setParent(parent)
        self.model = create_card(card_details)
        self.setupUi()

    def get_card_background_colour(self):
        if isinstance(self.model, SpellCard):
            return QColor(CardColours[CardType.SPELL])
        elif isinstance(self.model, TrapCard):
            return QColor(CardColours[CardType.TRAP])
        else:
            pass

    def setupUi(self):
        self.main_layout = QVBoxLayout()

        self.name_attr_layout = QHBoxLayout()
        self.name_label = QLabel(self.model.name)
        font = self.name_label.font()
        font.setBold(True)
        font.setCapitalization(QFont.AllUppercase)
        font.setPointSize(12)
        self.name_label.setFont(font)
        self.name_label.setMargin(5)
        pixmap = get_attr_icon(self.model.attribute)
        self.attr_icon = QLabel()
        self.attr_icon.setPixmap(pixmap)
        self.attr_icon.setAlignment(Qt.AlignRight)
        self.name_attr_layout.addWidget(self.name_label)
        self.name_attr_layout.addWidget(self.attr_icon)
        self.main_layout.addLayout(self.name_attr_layout)

        self.level_layout = QHBoxLayout()
        self.main_layout.addLayout(self.level_layout)

        self.picture_frame = QFrame()
        self.picture_frame.setFixedSize(250, 250)
        self.picture_frame.setFrameStyle(QFrame.Box | QFrame.Plain)
        self.picture_frame.setFrameShadow(QFrame.Shadow.Raised)
        self.picture_frame.setLineWidth(1)
        self.picture_frame.setContentsMargins(0, 0, 0, 0)
        self.picture_frame.setLayout(QGridLayout())
        self.image_holder = QLabel()

        pixmap = self._get_card_image()
        self.image_holder.setPixmap(
            pixmap.scaled(
                self.picture_frame.width(),
                self.picture_frame.height(),
                Qt.KeepAspectRatio,
            ))

        self.picture_frame.layout().addWidget(self.image_holder)

        self.main_layout.addWidget(self.picture_frame)

        # Card sets here?

        self.desc_group_box = QGroupBox()
        self.desc_group_box.setMaximumWidth(250)
        self.set_up_group_box()
        self.main_layout.addWidget(self.desc_group_box)

        self.id_label = QLabel(self.model.id)
        self.id_label.setAlignment(Qt.AlignLeft)
        self.id_label.setMargin(5)
        self.main_layout.addWidget(self.id_label)

        self.setLayout(self.main_layout)

        pal = QPalette()
        pal.setColor(QPalette.Background, self.get_card_background_colour())
        self.setAutoFillBackground(True)
        self.setPalette(pal)

    def _get_card_image(self):
        image_name = self.model.img_url.split("/")[-1]

        if os.path.exists(self.get_image_path(image_name)):
            image = Image.open(self.get_image_path(image_name))
        else:
            image_data = requests.get(self.model.img_url).content
            image = Image.open(BytesIO(image_data))
            image.save(self.get_image_path(image_name))
        image = image.crop((44, 106, 380, 438))  # this is about correct
        data = image.tobytes("raw", "RGB")
        qimage = QImage(data, image.size[0], image.size[1],
                        QImage.Format_RGB888)
        pixmap = QPixmap.fromImage(qimage)
        return pixmap

    def get_image_path(self, image_name):
        return os.path.join(os.getcwd(), "images", image_name)

    def set_up_group_box(self):
        self.desc_group_box.setLayout(QVBoxLayout())
        self.desc_label = QLabel(self.model.desc)
        self.desc_label.setWordWrap(True)
        self.desc_group_box.layout().addWidget(self.desc_label)
        if isinstance(self.model, (MonsterCard)):
            self.desc_group_box.setTitle(self.get_group_box_title())
            line = QFrame()
            line.setFrameShape((QFrame.HLine))
            line.setFrameShadow(QFrame.Sunken)
            self.desc_group_box.layout().addWidget(line)
            label = QLabel(
                f"ATK/{self.model.attack}  DEF/{self.model.defence}")
            label.setAlignment(Qt.AlignRight)
            self.desc_group_box.layout().addWidget(label)

    def get_group_box_title(self):
        return "[TEST/TEST]"
コード例 #16
0
ファイル: settings.py プロジェクト: cernyd/newnigma
    def generate_components(self, reflectors, rotors, rotor_n, charset):
        """Generates currently displayed components based on Enigma model
        :param reflectors: {str} Reflector labels
        :param rotors: {[str, str, str]} Rotor labels
        :param rotor_n: {int} Number of rotors the Enigma model has
        """
        # REFLECTOR SETTINGS ===================================================
        spacing = 15
        style = "font-size: 18px; text-align: center;"

        reflector_frame = QFrame(self.__settings_frame)
        reflector_frame.setFrameStyle(QFrame.StyledPanel | QFrame.Plain)

        reflector_layout = QVBoxLayout(reflector_frame)
        reflector_layout.setSpacing(spacing)
        reflector_layout.addWidget(
            QLabel("REFLECTOR", reflector_frame, styleSheet=style),
            alignment=Qt.AlignHCenter,
        )

        self.__reflector_group = QButtonGroup(reflector_frame)
        reflector_layout.setAlignment(Qt.AlignTop)

        for i, model in enumerate(reflectors):
            radio = QRadioButton(model, reflector_frame)
            radio.setToolTip(
                "Reflector is an Enigma component that \nreflects "
                "letters from the rotors back to the lightboard")
            self.__reflector_group.addButton(radio)
            self.__reflector_group.setId(radio, i)
            reflector_layout.addWidget(radio, alignment=Qt.AlignTop)

        reflector_layout.addStretch()
        reflector_layout.addWidget(self.__ukwd_button)

        self.__reflector_group.button(0).setChecked(True)
        self.__reflector_group.buttonClicked.connect(self.refresh_ukwd)
        self.__settings_layout.addWidget(reflector_frame)

        # ROTOR SETTINGS =======================================================

        self.__rotor_selectors = []
        self.__ring_selectors = []
        self.__rotor_frames = []

        for rotor in range(rotor_n):
            rotor_frame = QFrame(self.__settings_frame)
            rotor_frame.setFrameStyle(QFrame.StyledPanel | QFrame.Plain)
            rotor_layout = QVBoxLayout(rotor_frame)
            rotor_layout.setAlignment(Qt.AlignTop)
            rotor_layout.setSpacing(spacing)
            rotor_frame.setLayout(rotor_layout)

            # ROTOR RADIOS =====================================================

            label = QLabel(SELECTOR_LABELS[-rotor_n:][rotor],
                           rotor_frame,
                           styleSheet=style)
            label.setToolTip(SELECTOR_TOOLTIPS[-rotor_n:][rotor])

            rotor_layout.addWidget(label, alignment=Qt.AlignHCenter)

            button_group = QButtonGroup(rotor_frame)

            final_rotors = rotors

            if "Beta" in rotors:
                logging.info(
                    "Enigma M4 rotors detected, adjusting radiobuttons...")
                if rotor == 0:
                    final_rotors = ["Beta", "Gamma"]
                else:
                    final_rotors.remove("Beta")
                    final_rotors.remove("Gamma")

            for i, model in enumerate(final_rotors):
                radios = QRadioButton(model, rotor_frame)
                button_group.addButton(radios)
                button_group.setId(radios, i)
                rotor_layout.addWidget(radios, alignment=Qt.AlignTop)

            button_group.button(0).setChecked(True)

            # RINGSTELLUNG =====================================================

            combobox = QComboBox(rotor_frame)
            for i, label in enumerate(LABELS[:len(charset)]):
                combobox.addItem(label, i)

            h_rule = QFrame(rotor_frame)
            h_rule.setFrameShape(QFrame.HLine)
            h_rule.setFrameShadow(QFrame.Sunken)

            self.__ring_selectors.append(combobox)
            self.__rotor_selectors.append(button_group)

            rotor_layout.addStretch()
            rotor_layout.addWidget(h_rule)
            rotor_layout.addWidget(
                QLabel("RING SETTING", rotor_frame, styleSheet=style),
                alignment=Qt.AlignHCenter,
            )
            rotor_layout.addWidget(combobox)

            self.__settings_layout.addWidget(rotor_frame)
            self.__rotor_frames.append(rotor_frame)
コード例 #17
0
    def _setup_ui(self, name, color):
        # Set up the overall horizontal layout
        layout = QHBoxLayout(self)
        self.setLayout(layout)
        layout.setSpacing(3)
        layout.setMargin(1)

        # Construct a frame to hold the 16 indicators
        bit_frame = QFrame(self)
        bit_layout = QHBoxLayout(bit_frame)
        bit_layout.setSpacing(1)
        bit_layout.setMargin(0)
        bit_frame.setLayout(bit_layout)
        bit_frame.setFrameStyle(QFrame.StyledPanel | QFrame.Raised)

        layout.addWidget(bit_frame)

        # Add the 16 bit indicators to the frame, from 16 to 1.
        for i in range(16, 0, -1):
            ind = Indicator(bit_frame, color)
            ind.setFixedSize(20, 32)
            bit_layout.addWidget(ind)
            self._indicators.insert(0, ind)

            # Add separators between every group of 3 bits (except between
            # bits 15 and 16).
            if (i < 16) and (i > 1) and ((i % 3) == 1):
                sep = QFrame(bit_frame)
                sep.setFrameStyle(QFrame.VLine | QFrame.Raised)
                bit_layout.addWidget(sep)

        # Add sensed and generated parity bits, if this register has them
        if self._has_parity:
            sep = QFrame(bit_frame)
            sep.setFrameStyle(QFrame.VLine | QFrame.Raised)
            bit_layout.addWidget(sep)

            for i in range(2, 0, -1):
                ind = Indicator(bit_frame, QColor(220, 240, 0))
                ind.setFixedSize(20, 32)
                bit_layout.addWidget(ind)
                self._parity_inds.insert(0, ind)

        # Add a box to display the octal decoded value in
        self._value_box = QLineEdit()
        self._value_box.setMaximumSize(52, 32)
        self._value_box.setReadOnly(True)
        self._value_box.setAlignment(Qt.AlignCenter)
        self._value_box.setText('00000')

        font = QFont('Monospace')
        font.setStyleHint(QFont.TypeWriter)
        font.setPointSize(10)
        self._value_box.setFont(font)

        layout.addWidget(self._value_box)

        # Add a label showing the name of the register
        label = QLabel(name, self)
        font = label.font()
        font.setPointSize(14)
        font.setBold(True)
        label.setFont(font)
        label.setMinimumWidth(20)

        layout.addWidget(label)

        # If parity was not included, fill up the equivalent space
        if not self._has_parity:
            layout.addSpacing(62)
        else:
            layout.addSpacing(17)