def __init__(self) -> None: QWidget.__init__(self) # self.index stores the index of the latest item which is clicked self.index = None self.model = QStandardItemModel() file_view = QListView() file_view.setModel(self.model) file_view.setEditTriggers(QAbstractItemView.NoEditTriggers) file_view.clicked.connect(self.onClicked) file_view.doubleClicked.connect(self.onDoubleClicked) open_file_button = QPushButton('Open') open_file_button.clicked.connect(self.onOpenFile) preview_file_button = QPushButton('Preview') preview_file_button.clicked.connect(self.onPreviewFile) layout = QGridLayout() layout.addWidget(file_view, 0, 0, 1, 2) layout.addWidget(open_file_button, 1, 0, 1, 1) layout.addWidget(preview_file_button, 1, 1, 1, 1) layout.setMargin(0) self.setLayout(layout)
def __init__(self, path, settings, session): QWidget.__init__(self) ABookCore.__init__(self, path, settings, session) self.signal = CourseTreeWidgetSignals() self.selectedList = [] self.treeWidget = QTreeWidget() self.treeWidget.setHeaderLabels(['Name', "Course ID", "Chapter ID"]) self.treeWidget.itemChanged.connect(self.checkbox_toggled) self.treeWidget.clicked.connect(self.loadResourceList) self.addDownloadTaskButton = QPushButton("Add to Downloader") self.addDownloadTaskButton.clicked.connect(self.addDownloadTask) self.importCourseButton = QPushButton("Import Courses") self.importCourseButton.clicked.connect(self.startImportCourseWidget) main_layout = QGridLayout() main_layout.addWidget(self.treeWidget, 0, 0, 1, 2) main_layout.addWidget(self.importCourseButton, 1, 0) main_layout.addWidget(self.addDownloadTaskButton, 1, 1) main_layout.setMargin(0) self.setLayout(main_layout) if settings['first_launch'] is True: settings['first_launch'] = False self.importCourseButton.click() else: self.createTreeRoot()
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
def __init__(self): super().__init__() self.id = 1 self.TASKID = 0 self.FILENAME = 1 self.PROGRESSBAR = 2 self.SPEED = 3 self.STATUS = 4 self.URL = 5 self.FILEPATH = 6 self.CANCEL = 7 self.RETRY = 8 self.DELETE = 9 self.signals = FileDownloaderSignals() self.tableWidget = QTableWidget() self.startDownloadButton = QPushButton('Start Download') self.clearListButton = QPushButton('Clear Download List') self.hideFinishedCheckBox = QCheckBox('Hide Finished') self.startDownloadButton.clicked.connect(self.startDownload) self.clearListButton.clicked.connect(self.clearDownloadList) self.hideFinishedCheckBox.clicked.connect(self.hideFinished) self.createTable() layout = QGridLayout() layout.addWidget(self.tableWidget, 0, 0, 1, 2) layout.addWidget(self.hideFinishedCheckBox, 1, 0, 1, 1) layout.addWidget(self.startDownloadButton, 2, 0, 1, 1) layout.addWidget(self.clearListButton, 2, 1, 1, 1) layout.setMargin(0) self.setLayout(layout) self.resize(1920, 1080)
def _setup_ui(self): self.setFrameStyle(QFrame.StyledPanel | QFrame.Raised) layout = QGridLayout(self) self.setLayout(layout) layout.setMargin(1) layout.setHorizontalSpacing(10) layout.setVerticalSpacing(1) self._create_header('MONITOR', layout, 0) self._mon_temp = self._create_meas('TEMP', layout, 1, 0, True) self._vccint = self._create_meas('VCCINT', layout, 2, 0, False) self._vccaux = self._create_meas('VCCAUX', layout, 3, 0, False) self._p3v3io = self._create_meas('+3V3IO', layout, 4, 0, False) self._create_header('AGC', layout, 2) self._agc_temp = self._create_meas('TEMP', layout, 1, 2, True) self._bplssw = self._create_meas('BPLSSW', layout, 2, 2, False) self._p4sw = self._create_meas('+4SW', layout, 3, 2, False) label = QLabel('MEASUREMENTS', self) font = label.font() font.setPointSize(12) font.setBold(True) label.setFont(font) label.setAlignment(Qt.AlignCenter) layout.addWidget(label, 4, 2, 1, 2, Qt.AlignRight)
def makeDisplay(self): layout = QGridLayout(self) wordLabel = QLabel(self) self.wordLabel = wordLabel font = wordLabel.font() font.setPointSize(32) font.setBold(True) wordLabel.setFont(font) layout.addWidget(wordLabel, 0, 0, 1, 6) layout.setMargin(10) group = QButtonGroup(self) self.group = group self.buttons = [] for i in range(4): scoreButton = QPushButton(self, text=str(i)) scoreButton.setCheckable(True) if i == 0: scoreButton.setChecked(True) scoreButton.setMaximumWidth(40) group.addButton(scoreButton, i) layout.addWidget(scoreButton, 1, i) self.buttons.append(scoreButton) self.modelSimilarity = QLabel(self, text='') layout.addWidget(self.modelSimilarity, 2, 0) self.setLayout(layout)
def _setup_ui(self): self.setFrameStyle(QFrame.StyledPanel | QFrame.Raised) layout = QHBoxLayout(self) self.setLayout(layout) # Create a group box for the inhibit switches nh_group = QGroupBox('INH', self) nh_group.setAlignment(Qt.AlignCenter) layout.addWidget(nh_group) layout.setAlignment(nh_group, Qt.AlignTop) layout.setMargin(1) layout.setSpacing(1) # Set up a grid layout to hold the labels, switches, and indicators nh_layout = QGridLayout(nh_group) nh_group.setLayout(nh_layout) nh_layout.setMargin(1) nh_layout.setSpacing(1) # Construct the inhibit indicators and switches col = 0 for switch, msg in INH_SWITCHES.items(): self._create_inh_control(switch, nh_group, nh_layout, col) ind = self._inh_inds[-1] self._inh_switches[-1].stateChanged.connect( lambda on, ind=ind, msg=msg: self._set_inh(ind, msg, on)) col += 1 sl_group = QWidget(self) layout.addWidget(sl_group) sl_layout = QVBoxLayout(sl_group) sl_group.setLayout(sl_layout) sl_layout.setMargin(1) sl_layout.setSpacing(1) sl_layout.addSpacing(4) stat_group = QWidget(sl_group) sl_layout.addWidget(stat_group) stat_layout = QGridLayout(stat_group) stat_layout.setMargin(3) stat_layout.setSpacing(3) col = 0 for name, label in STATUS_INDS.items(): self._status_inds[name] = self._create_status_light( label, stat_group, stat_layout, col) col += 1 label = QLabel('CONTROL', sl_group) font = label.font() font.setPointSize(12) font.setBold(True) label.setFont(font) label.setAlignment(Qt.AlignCenter) sl_layout.addWidget(label)
def initUI(self): layout = QGridLayout(self) # layout.setContentsMargins(10, 5, 10, 5) layout.setMargin(0) self.setLayout(layout) layout.addWidget(self.log_box) self.log_box.setAcceptRichText(True) self.log_box.setReadOnly(True) self.log_box.setLineWrapMode(QTextEdit.LineWrapMode.NoWrap) self.log_box.setStyleSheet("QTextEdit{" "background-color:white;" "}")
class MainWidget(QWidget): def __init__(self): QWidget.__init__(self) self.layout = QGridLayout(self) self.layout.addWidget(self.DrawNE555(), 0, 0, 2, 1) self.layout.setMargin(0) self.layout.setSpacing(0) self.OpWidget = Opreator() self.layout.addWidget(self.OpWidget) def DrawNE555(self): d = schemdraw.Drawing() IC555def = elm.Ic(pins=[ elm.IcPin(name='TRG', side='left', pin='2'), elm.IcPin(name='THR', side='left', pin='6'), elm.IcPin(name='DIS', side='left', pin='7'), elm.IcPin(name='CTL', side='right', pin='5'), elm.IcPin(name='OUT', side='right', pin='3'), elm.IcPin(name='RST', side='top', pin='4'), elm.IcPin(name='Vcc', side='top', pin='8'), elm.IcPin(name='GND', side='bot', pin='1'), ], edgepadW=.5, edgepadH=1, pinspacing=2, leadlen=1, label='555') T = d.add(IC555def) BOT = d.add(elm.Ground(xy=T.GND)) d.add(elm.Dot) d.add(elm.Resistor(endpts=[T.DIS, T.THR], label='Rb')) d.add(elm.Resistor('u', xy=T.DIS, label='Ra', rgtlabel='+Vcc')) d.add(elm.Line(endpts=[T.THR, T.TRG])) d.add( elm.Capacitor('d', xy=T.TRG, toy=BOT.start, label='C', l=d.unit / 2)) d.add(elm.Line('r', tox=BOT.start)) d.add(elm.Capacitor('d', xy=T.CTL, toy=BOT.start, botlabel='.01$\mu$F')) d.add(elm.Dot(xy=T.DIS)) d.add(elm.Dot(xy=T.THR)) d.add(elm.Dot(xy=T.TRG)) d.add(elm.Line(endpts=[T.RST, T.Vcc])) d.add(elm.Dot) d.add(elm.Line('u', l=d.unit / 4, rgtlabel='+Vcc')) d.add(elm.Resistor('r', xy=T.OUT, label='330')) d.add(elm.LED(flip=True, d='down', toy=BOT.start)) d.add(elm.Line('l', tox=BOT.start)) return FigureCanvas(d.draw(show=False).getfig())
def _setup_ui(self): self.setFrameStyle(QFrame.StyledPanel | QFrame.Raised) # Set up our basic layout layout = QGridLayout(self) self.setLayout(layout) layout.setSpacing(1) layout.setMargin(1) for bank in range(0o10): sw = self._create_bank_switch('E%o' % bank, layout, 0, bank, 1) sw.stateChanged.connect(self._update_ems_banks) self._bank_switches.append(sw) for col in range(0o10, 0o22): s = QSpacerItem(20, 20) layout.addItem(s, 1, col) label = QLabel('EMS', self) font = label.font() font.setPointSize(12) font.setBold(True) label.setFont(font) label.setAlignment(Qt.AlignCenter) layout.addWidget(label, 5, 16, 2, 2, Qt.AlignCenter) b = self._create_button('ALL', layout, 5, 1, 3) b.pressed.connect(lambda: self._set_all(True)) b = self._create_button('NONE', layout, 5, 3, 2) b.pressed.connect(lambda: self._set_all(False)) self._ems_sel = QRadioButton('EMS', self) self._ems_sel.setLayoutDirection(Qt.RightToLeft) layout.addWidget(self._ems_sel, 5, 6, 2, 3) layout.setAlignment(self._ems_sel, Qt.AlignRight) self._agc_sel = QRadioButton('AGC', self) self._agc_sel.setChecked(True) layout.addWidget(self._agc_sel, 5, 8, 2, 3) layout.setAlignment(self._agc_sel, Qt.AlignCenter) font.setPointSize(7) self._ems_sel.setFont(font) self._agc_sel.setFont(font) b = self._create_button('PAD', layout, 5, 11, 2) b.pressed.connect(self._load_pad) b = self._create_button('LOAD', layout, 5, 12, 3) b.pressed.connect(self._load_core) b = self._create_button('DUMP', layout, 5, 14, 2) b.pressed.connect(self._dump_core)
def _setup_ui(self): self.setFrameStyle(QFrame.StyledPanel | QFrame.Raised) # Set up our basic layout layout = QGridLayout(self) self.setLayout(layout) layout.setSpacing(1) layout.setMargin(1) for bank in range(0o44): col = bank % 18 row = int(bank / 18) * 2 sw = self._create_bank_switch('%o' % bank, layout, row, col, 1) sw.stateChanged.connect( lambda state, bank=bank: self._update_crs_bank(bank)) self._bank_switches.append(sw) self._aux_switch = self._create_bank_switch('44-77', layout, 5, 0, 2) label = QLabel('CRS', self) font = label.font() font.setPointSize(12) font.setBold(True) label.setFont(font) label.setAlignment(Qt.AlignCenter) layout.addWidget(label, 5, 16, 2, 2, Qt.AlignCenter) b = self._create_button('ALL', layout, 5, 1, 3) b.pressed.connect(lambda: self._set_all(True)) b = self._create_button('NONE', layout, 5, 3, 2) b.pressed.connect(lambda: self._set_all(False)) self._crs_sel = QRadioButton('CRS', self) self._crs_sel.setLayoutDirection(Qt.RightToLeft) layout.addWidget(self._crs_sel, 5, 6, 2, 3) layout.setAlignment(self._crs_sel, Qt.AlignRight) self._agc_sel = QRadioButton('AGC', self) self._agc_sel.setChecked(True) layout.addWidget(self._agc_sel, 5, 8, 2, 3) layout.setAlignment(self._agc_sel, Qt.AlignCenter) font.setPointSize(7) self._crs_sel.setFont(font) self._agc_sel.setFont(font) b = self._create_button('LOAD', layout, 5, 12, 3) b.pressed.connect(self._load_rope) b = self._create_button('DUMP', layout, 5, 14, 2) b.pressed.connect(self._dump_rope)
def _create_switch_group(self, layout, group_name, button3, switch1, switch2, switch3): group_box = QGroupBox(group_name, self) layout.addWidget(group_box) group_layout = QGridLayout(group_box) group_box.setLayout(group_layout) group_layout.setMargin(0) group_layout.setSpacing(0) l = QLabel('S', group_box) l.setAlignment(Qt.AlignCenter) font = l.font() font.setPointSize(7) font.setBold(True) l.setFont(font) l.setMinimumWidth(30) group_layout.addWidget(l, 0, 0, Qt.AlignBottom) l = QLabel('PRESET', group_box) l.setAlignment(Qt.AlignCenter) l.setFont(font) l.setMinimumWidth(30) group_layout.addWidget(l, 0, 1, Qt.AlignBottom) l = QLabel(button3, group_box) l.setAlignment(Qt.AlignCenter) l.setFont(font) l.setMinimumWidth(30) group_layout.addWidget(l, 0, 2, Qt.AlignBottom) b1 = QPushButton(group_box) b1.setFixedSize(20, 20) group_layout.addWidget(b1, 1, 0, Qt.AlignCenter) b2 = QPushButton(group_box) b2.setFixedSize(20, 20) group_layout.addWidget(b2, 1, 1, Qt.AlignCenter) b3 = QPushButton(group_box) b3.setFixedSize(20, 20) group_layout.addWidget(b3, 1, 2, Qt.AlignCenter) s1 = self._create_switch(group_box, group_layout, 0, switch1) s2 = self._create_switch(group_box, group_layout, 1, switch2) s3 = self._create_switch(group_box, group_layout, 2, switch3) return b1, b2, b3, s1, s2, s3
class MainWidget(QWidget): def __init__(self): QWidget.__init__(self) self.layout = QGridLayout(self) # # self.imgwidget = QLabel(self) # Plot RC filter rc = schemdraw.Drawing() rc.add(elm.Resistor(d='right', label='R', lftlabel='In', rgtlabel='Out')) rc.add(elm.Capacitor(d='down', label='C')) rc.add(elm.Ground(d='right')) rc.draw(show=False) rccanvas = FigureCanvas(rc.draw(show=False).getfig()) self.layout.addWidget(rccanvas,0,0,2,1) self.layout.setMargin(0) self.layout.setSpacing(0) self.InputWidget=Opreator() self.layout.addWidget(self.InputWidget)
def grid_layout_build(variables_list): grid = QGridLayout() grid.setSpacing(16) grid.setMargin(8) # grid.setAlignment(Qt.AlignTop) row = 0 for name, value in variables_list.items(): if name.startswith("UI_"): name = name.replace("UI_", "").replace("_", " ").capitalize() grid.addWidget(QLabel(f"{name}:"), row, 0, alignment = Qt.AlignTop) grid.addWidget(get_widget_by_type(value), row, 1, alignment = Qt.AlignTop) row += 1 return grid
def __init__(self, root_path) -> None: QWidget.__init__(self) # self.index stores the index of the latest item which is clicked # self.root_path is the path to the folder currently showing self.index = None self.root_path = os.path.abspath(root_path) self.dir_view = QTreeView() self.model = QFileSystemModel(self.dir_view) self.model.setRootPath(self.root_path) self.dir_view.clicked.connect(self.onFileItemClicked) self.dir_view.doubleClicked.connect(self.onFileItemDoubleClicked) self.dir_view.setModel(self.model) self.dir_view.setRootIndex(self.model.index(self.root_path)) open_button = QPushButton("Open") open_button.clicked.connect(self.openFile) open_in_file_explorer_button = QPushButton("Open in File Explorer") open_in_file_explorer_button.clicked.connect(self.openInFileExplorer) self.root_path_line_edit = QLineEdit(self.root_path) self.root_path_line_edit.returnPressed.connect( self.onChangeLineEditReturned) self.root_path_line_edit.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) self.root_path_line_edit.adjustSize() change_path_button = QPushButton('Change Directory') change_path_button.clicked.connect(self.onChangeButtonClicked) addressCompleter = QCompleter() addressCompleter.setModel(self.model) self.root_path_line_edit.setCompleter(addressCompleter) # Set layout layout = QGridLayout() layout.addWidget(self.root_path_line_edit, 0, 0, 1, 1) layout.addWidget(change_path_button, 0, 1, 1, 1) layout.addWidget(self.dir_view, 1, 0, 1, 2) layout.addWidget(open_button, 2, 0, 1, 1) layout.addWidget(open_in_file_explorer_button, 2, 1, 1, 1) layout.setMargin(0) self.setLayout(layout)
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)
def generate_layout(self): layout = QGridLayout() layout.setMargin(7) layout.setHorizontalSpacing(7) layout.setVerticalSpacing(7) inner_layouts = [] for row, col in itertools.product(range(3), range(3)): inner_layout = QGridLayout() inner_layout.setMargin(0) inner_layout.setHorizontalSpacing(3) inner_layout.setVerticalSpacing(3) inner_layouts.append(inner_layout) layout.addLayout(inner_layout, row, col) for cell in range(len(self.cells)): row = int(cell / 9) col = int(cell % 9) band = int(row / 3) stack = int(col / 3) box = int(band * 3 + stack) minirow = int(row % 3) minicol = int(col % 3) inner_layouts[box].addWidget(self.cells[cell], minirow, minicol) self.setLayout(layout)
def _setup_ui(self): self.setFrameStyle(QFrame.StyledPanel | QFrame.Raised) layout = QGridLayout(self) self.setLayout(layout) layout.setMargin(1) layout.setSpacing(1) # Construct the stop indicators and switches col = 0 for l, n in STOP_CONDS.items(): self._create_stop_cond(l, n, layout, col) col += 1 label = QLabel('COMP STOP', self) font = label.font() font.setPointSize(12) font.setBold(True) label.setFont(font) label.setAlignment(Qt.AlignCenter) layout.addWidget(label, 3, 0, 1, 4, Qt.AlignRight) self._s1 = QRadioButton('S1', self) self._s1.setLayoutDirection(Qt.RightToLeft) layout.addWidget(self._s1, 3, 5, 1, 2) layout.setAlignment(self._s1, Qt.AlignRight) self._s1.setChecked(True) self._s1.toggled.connect(self._set_stop_conds) self._s2 = QRadioButton('S2', self) layout.addWidget(self._s2, 3, 6, 1, 2) layout.setAlignment(self._s2, Qt.AlignRight) font.setPointSize(7) self._s1.setFont(font) self._s2.setFont(font)
def _setup_ui(self): self.setFrameStyle(QFrame.StyledPanel | QFrame.Raised) layout = QGridLayout(self) self.setLayout(layout) layout.setMargin(1) layout.setSpacing(1) # Construct the alarm indicators col = 0 for n, c in ALARMS.items(): self._create_alarm(n, c, layout, col) col += 1 check = QCheckBox(self) check.setFixedSize(20, 20) check.setStyleSheet( 'QCheckBox::indicator{subcontrol-position:center;}') layout.addWidget(check, 2, 2) layout.setAlignment(check, Qt.AlignCenter) check.stateChanged.connect( lambda state: self._usbif.send(um.WriteControlDoscal(bool(state)))) check = QCheckBox(self) check.setFixedSize(20, 20) check.setStyleSheet( 'QCheckBox::indicator{subcontrol-position:center;}') layout.addWidget(check, 2, 3) layout.setAlignment(check, Qt.AlignCenter) check.stateChanged.connect( lambda state: self._usbif.send(um.WriteControlDbltst(bool(state)))) b = QPushButton(self) b.setFixedSize(20, 20) layout.addWidget(b, 2, 8, 1, 2) layout.setAlignment(b, Qt.AlignCenter) label = QLabel('RESET', self) label.setAlignment(Qt.AlignRight) font = label.font() font.setPointSize(8) font.setBold(True) label.setFont(font) label.setMinimumWidth(30) layout.addWidget(label, 2, 7, 1, 2) layout.setAlignment(label, Qt.AlignCenter) b.pressed.connect(lambda: self._reset_alarms()) label = QLabel('TEST', self) label.setAlignment(Qt.AlignRight) font = label.font() font.setPointSize(8) font.setBold(True) label.setFont(font) label.setMinimumWidth(30) layout.addWidget(label, 2, 1, 1, 1) layout.setAlignment(label, Qt.AlignRight) label = QLabel('ALARMS', self) font = label.font() font.setPointSize(12) font.setBold(True) label.setFont(font) label.setAlignment(Qt.AlignCenter) layout.addWidget(label, 2, len(ALARMS) - 4, 1, 4, Qt.AlignRight)
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
def get_widget_by_type(obj): if type(obj) == int: widget = QSpinBox() widget.setRange(INT_RANGE_MIN, INT_RANGE_MAX) widget.setSingleStep(INT_RANGE_STEP) widget.setValue(obj) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) elif type(obj) == float: widget = QDoubleSpinBox() widget.setRange(FLOAT_RANGE_MIN, FLOAT_RANGE_MAX) widget.setSingleStep(FLOAT_RANGE_STEP) widget.setValue(obj) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) elif type(obj) == str: widget = QLineEdit() widget.setText(obj) elif type(obj) == bool: widget = QCheckBox() widget.setChecked(obj) elif type(obj) == list: widget = QComboBox() widget.addItems(obj) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) elif type(obj) == tuple: widget = QFrame() if len(obj) <= 3: box = QHBoxLayout() else: box = QVBoxLayout() box.setMargin(0) for item in obj: value_widget = QLabel(f"{item}") value_widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) value_widget.setObjectName("tuple") box.addWidget(value_widget) widget.setLayout(box) elif type(obj) == dict: widget = QFrame() # If less than 3 items, lay it out horizontally else vertically # if len(obj) <= 3: # box = QHBoxLayout() # else: # box = QVBoxLayout() # box.setMargin(0) grid = QGridLayout() grid.setMargin(0) row = 0 for key in obj: label = QLabel(f"{key.capitalize()}:") grid.addWidget(label, row, 0) value_widget = get_widget_by_type(obj[key]) value_widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) grid.addWidget(value_widget, row, 1) try: value_widget.setRange(INT_RANGE_MIN, INT_RANGE_MAX) value_widget.setSingleStep(INT_RANGE_STEP) value_widget.setValue(obj[key]) except: pass row += 1 widget.setLayout(grid) # TODO: Lists inside of lists. Should probably use QTreeView # elif type(obj) == list: # widget = [] # for l in obj: # widget.append(QComboBox()) # widget[-1].addItems(obj) # widget[-1].setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) return widget
class QUnitInfoWindow(QDialog): def __init__(self, game: Game, unit_type: Type[UnitType]) -> None: super(QUnitInfoWindow, self).__init__() self.setModal(True) self.game = game self.unit_type = unit_type self.setWindowTitle( f"Unit Info: {db.unit_get_expanded_info(self.game.player_country, self.unit_type, 'name')}" ) self.setWindowIcon(QIcon("./resources/icon.png")) self.setMinimumHeight(570) self.setMaximumWidth(640) self.setWindowFlags(Qt.WindowStaysOnTopHint) self.initUi() def initUi(self): self.layout = QGridLayout() header = QLabel(self) header.setGeometry(0, 0, 720, 360) if ( dcs.planes.plane_map.get(self.unit_type.id) is not None or dcs.helicopters.helicopter_map.get(self.unit_type.id) is not None ): pixmap = AIRCRAFT_BANNERS.get(self.unit_type.id) elif dcs.vehicles.vehicle_map.get(self.unit_type.id) is not None: pixmap = VEHICLE_BANNERS.get(self.unit_type.id) if pixmap is None: pixmap = AIRCRAFT_BANNERS.get("Missing") header.setPixmap(pixmap.scaled(header.width(), header.height())) self.layout.addWidget(header, 0, 0) self.gridLayout = QGridLayout() # Build the topmost details grid. self.details_grid = QFrame() self.details_grid_layout = QGridLayout() self.details_grid_layout.setMargin(0) self.name_box = QLabel( f"<b>Name:</b> {db.unit_get_expanded_info(self.game.player_country, self.unit_type, 'manufacturer')} {db.unit_get_expanded_info(self.game.player_country, self.unit_type, 'name')}" ) self.name_box.setProperty("style", "info-element") self.country_box = QLabel( f"<b>Country of Origin:</b> {db.unit_get_expanded_info(self.game.player_country, self.unit_type, 'country-of-origin')}" ) self.country_box.setProperty("style", "info-element") self.role_box = QLabel( f"<b>Role:</b> {db.unit_get_expanded_info(self.game.player_country, self.unit_type, 'role')}" ) self.role_box.setProperty("style", "info-element") self.year_box = QLabel( f"<b>Variant Introduction:</b> {db.unit_get_expanded_info(self.game.player_country, self.unit_type, 'year-of-variant-introduction')}" ) self.year_box.setProperty("style", "info-element") self.details_grid_layout.addWidget(self.name_box, 0, 0) self.details_grid_layout.addWidget(self.country_box, 0, 1) self.details_grid_layout.addWidget(self.role_box, 1, 0) self.details_grid_layout.addWidget(self.year_box, 1, 1) self.details_grid.setLayout(self.details_grid_layout) self.gridLayout.addWidget(self.details_grid, 1, 0) # If it's an aircraft, include the task list. if ( dcs.planes.plane_map.get(self.unit_type.id) is not None or dcs.helicopters.helicopter_map.get(self.unit_type.id) is not None ): self.tasks_box = QLabel( f"<b>In-Game Tasks:</b> {self.generateAircraftTasks()}" ) self.tasks_box.setProperty("style", "info-element") self.gridLayout.addWidget(self.tasks_box, 2, 0) # Finally, add the description box. self.details_text = QTextBrowser() self.details_text.setProperty("style", "info-desc") self.details_text.setText( db.unit_get_expanded_info(self.game.player_country, self.unit_type, "text") ) self.gridLayout.addWidget(self.details_text, 3, 0) self.layout.addLayout(self.gridLayout, 1, 0) self.setLayout(self.layout) def generateAircraftTasks(self) -> str: aircraft_tasks = "" if self.unit_type in gen.flights.ai_flight_planner_db.CAP_CAPABLE: aircraft_tasks = ( aircraft_tasks + f"{FlightType.BARCAP}, {FlightType.ESCORT}, {FlightType.INTERCEPTION}, {FlightType.SWEEP}, {FlightType.TARCAP}, " ) if ( self.unit_type in gen.flights.ai_flight_planner_db.CAS_CAPABLE or self.unit_type in gen.flights.ai_flight_planner_db.TRANSPORT_CAPABLE ): aircraft_tasks = ( aircraft_tasks + f"{FlightType.CAS}, {FlightType.BAI}, {FlightType.OCA_AIRCRAFT}, " ) if self.unit_type in gen.flights.ai_flight_planner_db.SEAD_CAPABLE: aircraft_tasks = aircraft_tasks + f"{FlightType.SEAD}, " if self.unit_type in gen.flights.ai_flight_planner_db.DEAD_CAPABLE: aircraft_tasks = aircraft_tasks + f"{FlightType.DEAD}, " if self.unit_type in gen.flights.ai_flight_planner_db.ANTISHIP_CAPABLE: aircraft_tasks = aircraft_tasks + f"{FlightType.ANTISHIP}, " if self.unit_type in gen.flights.ai_flight_planner_db.RUNWAY_ATTACK_CAPABLE: aircraft_tasks = aircraft_tasks + f"{FlightType.OCA_RUNWAY}, " if ( self.unit_type in gen.flights.ai_flight_planner_db.STRIKE_CAPABLE or self.unit_type in gen.flights.ai_flight_planner_db.TRANSPORT_CAPABLE ): aircraft_tasks = aircraft_tasks + f"{FlightType.STRIKE}, " return aircraft_tasks[:-2]
class Header(QWidget): def __init__(self, song=None): super(Header, self).__init__() self.song = song self.settings = get_settings() self.layout = QGridLayout() self.layout.setMargin(0) self.layout.setContentsMargins(0, 0, 0, 25) self.setObjectName(u'header') self.setAttribute(Qt.WA_StyledBackground, True) self.setStyleSheet( css(''' #header { border-bottom: 1px solid {{backgroundColor}}; } ''', backgroundColor=colors.SECONDARY_COLOR)) self.left_container = QWidget() self.left_container.setStyleSheet( css('color: {{color}};', color=colors.GREY_COLOR)) self.left_container_layout = QHBoxLayout(alignment=Qt.AlignLeft) self.left_container_layout.setMargin(0) self.left_container.setLayout(self.left_container_layout) self.right_container = QWidget() self.right_container_layout = QHBoxLayout(alignment=Qt.AlignRight) self.right_container_layout.setMargin(0) self.right_container.setLayout(self.right_container_layout) self.layout.addWidget(self.left_container, 0, 0) self.layout.addWidget(self.right_container, 0, 1) # Info on the left songs_amount = len( self.song['songlist']) if self.song['full_release'] else len( [s for s in self.song['songlist'] if s['released']]) songs_text = pluralize('song', 'songs', songs_amount) info_text = '{} ยท {}'.format(self.song['genre'], songs_text).upper() self.left_container_layout.addWidget(QLabel(info_text)) # Download buttons on the right if 'download_links' in self.song: for item in self.song['download_links']: btn = IconButton(text=item['label'], icon='download', on_click=self.download(item)) self.right_container_layout.addWidget(btn) self.setLayout(self.layout) def download(self, link): def closure(): filename = replace_multiple(self.song['title'], ( (r'\s+', '_'), (r'[^\w]+', ''), (r'_+', '_'), )).lower() self.start_download_thread({ 'id': str(uuid4()), 'url': link['url'], 'retriable': False, 'title': self.song['title'], 'artwork_local_path': '{}/{}.jpg'.format(ARTWORK_DIR, filename), 'artwork_url': self.song['artwork'], 'quality': link['label'], 'filename': '{}.tar'.format(filename), 'basename': filename, 'location': self.settings['file_storage_location'], 'progress': 0, 'created': int(datetime.now().strftime('%s')) }) return closure def start_download_thread(self, item): logging.info('Starting download thread: {}'.format(item['id'])) thread_id = 'download_thread_{}'.format(item['id']) history = get_download_history() history.append(item) with open(DOWNLOAD_HISTORY_FILE, 'w') as f: json.dump(history, f) f.close() setattr(self, thread_id, RunThread(download_song, None, item))
class EECalculator(QMainWindow): def __init__(self, parent): QMainWindow.__init__(self) # TODO:use framelesswindow # self.setWindowFlags(Qt.FramelessWindowHint) self.InitUI() def RefreshWidgets(self,target,name): while target.count(): Child = target.takeAt(0) if Child.widget(): Child.widget().deleteLater() if name==modules[0]: target.addWidget(homepage.MainWidget()) if name==modules[1]: target.addWidget(rc.MainWidget()) if name==modules[2]: target.addWidget(tcap.MainWidget()) if name==modules[3]: target.addWidget(ne555.MainWidget()) def InitUI(self): # Set Window Size self.resize(800, 600) self.setMinimumSize(QSize(800, 600)) # Set Window Titile self.setWindowTitle("EE Calculator") # Create Main Widgets self.MainWidget = QWidget() self.MainLayout = QHBoxLayout(self.MainWidget) # Create Display Widgets self.DisplayWidget = QWidget(self.MainWidget) self.DisplayLayout = QGridLayout(self.DisplayWidget) # Create Menu Area&Widgets self.MenuScrollArea = QScrollArea(self.MainWidget) self.MenuScrollAreaContents = QWidget() self.MenuScrollAreaLayout = QVBoxLayout(self.MenuScrollAreaContents) ButtonList=[] i = 0 for module in modules: ButtonList.append(QPushButton(module)) ButtonList[i].setFixedWidth(198) ButtonList[i].setFixedHeight(66) ButtonList[i].clicked.connect(partial(self.RefreshWidgets,self.DisplayLayout,module)) self.MenuScrollAreaLayout.addWidget(ButtonList[i]) i += 1 self.MenuScrollAreaLayout.addStretch(1) # Setup Widget&LAyout self.MenuScrollArea.setFixedWidth(200) self.MenuScrollAreaLayout.setMargin(0) self.MenuScrollAreaLayout.setSpacing(0) self.DisplayLayout.setMargin(0) self.MainLayout.setMargin(0) self.MenuScrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.MenuScrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.MenuScrollArea.setWidget(self.MenuScrollAreaContents) self.DisplayLayout.addWidget(homepage.MainWidget()) self.MainLayout.addWidget(self.MenuScrollArea) self.MainLayout.addWidget(self.DisplayWidget) self.setCentralWidget(self.MainWidget)
def _setup_ui(self, color): # Set up our basic layout layout = QHBoxLayout(self) self.setLayout(layout) layout.setSpacing(3) layout.setMargin(1) # Construct register groups for BR, ST, and SQ br_frame, self._br_value = self._create_reg(self._br_inds, 'BR', 2, color) st_frame, self._st_value = self._create_reg(self._st_inds, 'ST', 3, color) sq_frame, self._sq_value = self._create_reg(self._sq_inds, 'SQ', 7, color) layout.addWidget(br_frame) layout.addWidget(st_frame) layout.addWidget(sq_frame) stat_group = QWidget(self) layout.addWidget(stat_group) stat_layout = QGridLayout(stat_group) stat_layout.setMargin(0) stat_layout.setSpacing(0) col = 0 for name, label in STATUS_INDS.items(): self._status_inds[name] = self._create_status_light( label, stat_group, stat_layout, col) col += 1 # Create a grouping widget for the I label and decoded instruction value box label_value = QWidget(self) lv_layout = QHBoxLayout(label_value) lv_layout.setSpacing(3) lv_layout.setMargin(1) lv_layout.setContentsMargins(0, 32, 0, 0) label_value.setLayout(lv_layout) layout.addWidget(label_value) # Create a value box for displaying the overall decoded instruction self._inst_value = QLineEdit(label_value) self._inst_value.setReadOnly(True) self._inst_value.setMaximumSize(65, 32) self._inst_value.setText('TC0') font = QFont('Monospace') font.setStyleHint(QFont.TypeWriter) font.setPointSize(10) self._inst_value.setFont(font) self._inst_value.setAlignment(Qt.AlignCenter) lv_layout.addWidget(self._inst_value) # Create a label to show 'I' label = QLabel('I', label_value) font = label.font() font.setPointSize(14) font.setBold(True) label.setFont(font) lv_layout.addWidget(label) # Add some spacing to account for lack of parity indicators layout.addSpacing(52)
def _setup_ui(self): self.setFrameStyle(QFrame.StyledPanel | QFrame.Raised) # Set up our basic layout layout = QVBoxLayout(self) self.setLayout(layout) layout.setSpacing(1) layout.setMargin(1) self._table = QTableWidget(TRACE_DEPTH, 6, self) layout.addWidget(self._table) for c, n in enumerate(['EB', 'FB', 'Z', 'I', 'S', 'W']): item = QTableWidgetItem(n) self._table.setHorizontalHeaderItem(c, item) font = self._table.horizontalHeader().font() font.setPointSize(8) font.setBold(True) item.setFont(font) self._table.horizontalHeader().setFont(font) self._table.verticalHeader().setFont(font) font.setBold(False) for r in range(TRACE_DEPTH): for c in range(6): item = QTableWidgetItem('') item.setFont(font) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsDragEnabled | Qt.ItemIsEnabled) self._table.setItem(r, c, item) self._table.setColumnWidth(0, 10) self._table.setColumnWidth(1, 10) for c in range(2, 6): self._table.horizontalHeader().setSectionResizeMode( c, QHeaderView.Stretch) self._table.resizeRowsToContents() self._table.verticalScrollBar().setValue( self._table.verticalScrollBar().maximum()) controls_widget = QWidget(self) layout.addWidget(controls_widget) controls_layout = QGridLayout(controls_widget) controls_layout.setSpacing(0) controls_layout.setMargin(0) b = self._create_button('DUMP', controls_layout, 1, 1) b.pressed.connect(self._dump_trace) b = self._create_button('SAVE', controls_layout, 1, 2) b.pressed.connect(self._save_trace) s = QSpacerItem(260, 20) controls_layout.addItem(s, 1, 3) label = QLabel('TRACE', controls_widget) font = label.font() font.setPointSize(12) font.setBold(True) label.setFont(font) label.setAlignment(Qt.AlignLeft) controls_layout.addWidget(label, 1, 4, 2, 1, Qt.AlignLeft)
class Randomizer(QWidget): """A game randomizer for selecting a random game to play from the user's collection. User can select which platforms to choose from. gamesData: Raw table data in list of dictionaries""" def __init__(self, gamesData: list, platformsData: list, genresData: list): super(Randomizer, self).__init__() self._consoleItems = platformsData self._genreItems = genresData self._gamesData = gamesData self._games = [] # For holding the games to randomize self._gameCount = 0 self._coverdir = path.join("data", "images", "covers") self.consoleLabel = QLabel("Platforms") self.consoleList = QListWidget() self.consoleList.addItems(self._consoleItems) self.consoleList.setSelectionMode(QAbstractItemView.MultiSelection) self.consoleList.setMaximumWidth(350) self.consoleList.itemClicked.connect(self._updateGameCount) self.genreLabel = QLabel("Genres") self.genreMatchExclusiveCB = QCheckBox("Match exclusive") self.genreMatchExclusiveCB.setToolTip( "Only match games which exclusively contain the selected genres.") self.genreMatchExclusiveCB.setChecked(False) self.genreMatchExclusiveCB.stateChanged.connect(self._updateGameCount) self.genreList = QListWidget() self.genreList.addItems(self._genreItems) self.genreList.setSelectionMode(QAbstractItemView.MultiSelection) self.genreList.setMaximumWidth(350) self.genreList.itemClicked.connect(self._updateGameCount) self.btnAll = QPushButton("Select All") self.btnAll.setMaximumSize(self.btnAll.sizeHint()) self.btnAll.clicked.connect(self.consoleList.selectAll) self.btnAll.clicked.connect(self.genreList.selectAll) self.btnAll.clicked.connect(self._updateGameCount) self.btnNone = QPushButton("Select None") self.btnNone.setMaximumSize(self.btnNone.sizeHint()) self.btnNone.clicked.connect(self.consoleList.clearSelection) self.btnNone.clicked.connect(self.genreList.clearSelection) self.btnNone.clicked.connect(self._updateGameCount) self._btnRnd = QPushButton("Randomize") self._btnRnd.setMaximumSize(self._btnRnd.sizeHint()) self._btnRnd.clicked.connect(self._randomize) self._lblFont = QFont() self._lblFont.setPointSize(14) self._lblFont.setBold(True) self._lblPlay = QLabel() self._lblPlay.setAlignment(Qt.AlignCenter) self._lblPlay.setFont(self._lblFont) self._lblTitle = QLabel() self._lblTitle.setAlignment(Qt.AlignCenter) self._lblTitle.setFont(self._lblFont) self._lblTitle.setWordWrap(True) # Cover image self._cover = QLabel() self._cover.setVisible(False) self._cover.setAlignment(Qt.AlignCenter) p = QPixmap(path.join(self._coverdir, "none.png")) w = self._cover.width() h = self._cover.height() self._cover.setPixmap( p.scaled(w, h, Qt.KeepAspectRatio, Qt.SmoothTransformation)) self._hboxButtons = QHBoxLayout() self._vboxLists = QVBoxLayout() self._vboxConsoles = QVBoxLayout() self._hboxGenres = QHBoxLayout() self._vboxGenres = QVBoxLayout() self._vboxResult = QVBoxLayout() self._grid = QGridLayout() self._hboxButtons.addWidget(self.btnAll, 0) self._hboxButtons.addWidget(self.btnNone, 0) self._hboxButtons.addWidget(self._btnRnd, 0) self._vboxConsoles.addWidget(self.consoleLabel, 0) self._vboxConsoles.addWidget(self.consoleList, 1) self._hboxGenres.addWidget(self.genreLabel, 0) self._hboxGenres.addWidget(self.genreMatchExclusiveCB, 0) self._vboxGenres.addWidget(self.genreList, 1) self._vboxLists.addSpacing(10) self._vboxLists.addLayout(self._vboxConsoles, 1) self._vboxLists.addSpacing(10) self._vboxLists.addLayout(self._hboxGenres, 0) self._vboxLists.addLayout(self._vboxGenres, 1) self._vboxResult.addStretch(3) self._vboxResult.addWidget(self._lblPlay, 0) self._vboxResult.addWidget(self._lblTitle, 0) self._vboxResult.addSpacing(50) self._vboxResult.addWidget(self._cover, 0) self._vboxResult.addStretch(3) self._grid.setMargin(0) self._grid.setSpacing(0) self._grid.addLayout(self._vboxLists, 0, 0) self._grid.addLayout(self._hboxButtons, 1, 0) self._grid.addLayout(self._vboxResult, 0, 1, 1, -1) self.widget = QWidget() self.widget.setLayout(self._grid) def _getSelectedItems(self) -> tuple: return [x.text() for x in self.consoleList.selectedItems() ], [x.text() for x in self.genreList.selectedItems()] def _randomize(self): platforms, genres = self._getSelectedItems() if len(self._games) > 0 and (len(platforms) > 0 or len(genres) > 0): choice = randint(0, len(self._games) - 1) self._lblPlay.setText("You will play:") self._lblTitle.setText( f"{self._games[choice]['name']}" if len(platforms) == 1 else f"{self._games[choice]['name']} [{self._games[choice]['platform']}]" ) # Cover image cover = str(self._games[choice]['id']) + ".jpg" if path.exists(path.join(self._coverdir, cover)): # Update cover image if the game has one pixmap = path.join(self._coverdir, cover) self._cover.setVisible(True) else: pixmap = path.join(self._coverdir, "none.png") self._cover.setVisible(False) p = QPixmap(pixmap) w = self._cover.width() h = self._cover.height() self._cover.setPixmap( p.scaled(w, h, Qt.KeepAspectRatio, Qt.SmoothTransformation)) elif len(self._games) == 0 and (len(platforms) > 0 or len(genres) > 0): self._lblPlay.setText("") self._lblTitle.setText("No games found with those criteria.") self._cover.setVisible(False) else: self._lblPlay.setText("") self._lblTitle.setText("Select at least one console or genre...") self._cover.setVisible(False) def _updateGameCount(self): platforms, genres = self._getSelectedItems() self._gameCount = 0 self._games = [] if len(platforms) > 0 or len(genres) > 0: for row in self._gamesData: if len(platforms) > 0 and len(genres) > 0: if row["platform"] in platforms: if self.genreMatchExclusiveCB.isChecked(): count = 0 for genre in row["genre"].split(", "): if genre in genres: count += 1 else: # Not exclusive count = 0 break if count == len(genres): self._gameCount += 1 self._games.append(row) else: for genre in row["genre"].split(", "): if genre in genres: self._gameCount += 1 self._games.append(row) break # We only need to match with one genre elif len(platforms) > 0 and len(genres) == 0: if row["platform"] in platforms: self._gameCount += 1 self._games.append(row) elif len(platforms) == 0 and len(genres) > 0: if self.genreMatchExclusiveCB.isChecked(): count = 0 for genre in row["genre"].split(", "): if genre in genres: count += 1 else: # Not exclusive count = 0 break if count == len(genres): self._gameCount += 1 self._games.append(row) else: for genre in row["genre"].split(", "): if genre in genres: self._gameCount += 1 self._games.append(row) break # We only need to match with one genre def gameCount(self) -> int: return self._gameCount def updateLists(self, gamesData: list, platformsData: list, genresData: list): self._gamesData = gamesData self._consoleItems = platformsData self._genreItems = genresData self.consoleList.clear() self.genreList.clear() self.consoleList.addItems(self._consoleItems) self.genreList.addItems(self._genreItems)
class QFileBrowse(QWidget): def __init__(self, subfolder_name='QR Codes', *args, **kwargs): super().__init__(*args, **kwargs) self.layout = QGridLayout() self.button = QPushButton("Change save location") self.subfolder = QCheckBox("Create subfolder") self.subfolder.stateChanged.connect(self.update_display) self.button.clicked.connect(self.browse) self.subfolder_name = subfolder_name self.dialog = QFileDialog() self._base_path = pathlib.Path(".").expanduser().resolve() # output path display self.path_display = QPlainTextEdit() # make bold font = self.path_display.font() font.setWeight(QFont.Bold) self.path_display.setFont(font) # configure height self.path_display.setFixedHeight(QFontMetrics(font).height() * 2) self.path_display.setLineWrapMode(QPlainTextEdit.NoWrap) # styles self.path_display.setReadOnly(True) self.path_display.setFrameStyle(QFrame.Box | QFrame.Sunken) self.path_display.setTextInteractionFlags(Qt.TextSelectableByMouse) self.path_display.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Fixed) self.path_display.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.path_display.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) # add widgets to layout self.layout.addWidget(self.button, 0, 0) self.layout.addWidget(self.subfolder, 0, 1) self.layout.addWidget(self.path_display, 1, 0, 1, 2) self.layout.setMargin(0) self.setLayout(self.layout) self.update_display() @property def save_path(self): if self.subfolder.isChecked(): return self._base_path / self.subfolder_name return self._base_path def browse(self): path = self.dialog.getExistingDirectory() if path != '': self._base_path = pathlib.Path(path).expanduser().resolve() self.update_display() def update_display(self): scrollbar = self.path_display.horizontalScrollBar() old_scroll = scrollbar.value() scrolled_to_end = old_scroll == scrollbar.maximum() self.path_display.setPlainText(str(self.save_path)) if scrolled_to_end: scrollbar.setValue(scrollbar.maximum()) else: scrollbar.setValue(old_scroll)
class QUnitInfoWindow(QDialog): def __init__(self, game: Game, unit_type: UnitType) -> None: super().__init__() self.setModal(True) self.game = game self.unit_type = unit_type self.name = unit_type.name self.setWindowTitle(f"Unit Info: {self.name}") self.setWindowIcon(QIcon("./resources/icon.png")) self.setMinimumHeight(570) self.setMaximumWidth(640) self.setWindowFlags(Qt.WindowStaysOnTopHint) self.layout = QGridLayout() header = QLabel(self) header.setGeometry(0, 0, 720, 360) pixmap = None if isinstance(self.unit_type, AircraftType): pixmap = AIRCRAFT_BANNERS.get(self.unit_type.dcs_id) elif isinstance(self.unit_type, GroundUnitType): pixmap = VEHICLE_BANNERS.get(self.unit_type.dcs_id) if pixmap is None: pixmap = AIRCRAFT_BANNERS.get("Missing") header.setPixmap(pixmap.scaled(header.width(), header.height())) self.layout.addWidget(header, 0, 0) self.gridLayout = QGridLayout() # Build the topmost details grid. self.details_grid = QFrame() self.details_grid_layout = QGridLayout() self.details_grid_layout.setMargin(0) self.name_box = QLabel( f"<b>Name:</b> {unit_type.manufacturer} {unit_type.name}") self.name_box.setProperty("style", "info-element") self.country_box = QLabel( f"<b>Country of Origin:</b> {unit_type.country_of_origin}") self.country_box.setProperty("style", "info-element") self.role_box = QLabel(f"<b>Role:</b> {unit_type.role}") self.role_box.setProperty("style", "info-element") self.year_box = QLabel( f"<b>Variant Introduction:</b> {unit_type.year_introduced}") self.year_box.setProperty("style", "info-element") self.details_grid_layout.addWidget(self.name_box, 0, 0) self.details_grid_layout.addWidget(self.country_box, 0, 1) self.details_grid_layout.addWidget(self.role_box, 1, 0) self.details_grid_layout.addWidget(self.year_box, 1, 1) self.details_grid.setLayout(self.details_grid_layout) self.gridLayout.addWidget(self.details_grid, 1, 0) # If it's an aircraft, include the task list. if isinstance(unit_type, AircraftType): self.tasks_box = QLabel( f"<b>In-Game Tasks:</b> {self.generateAircraftTasks()}") self.tasks_box.setProperty("style", "info-element") self.gridLayout.addWidget(self.tasks_box, 2, 0) # Finally, add the description box. self.details_text = QTextBrowser() self.details_text.setProperty("style", "info-desc") self.details_text.setText(unit_type.description) self.details_text.setOpenExternalLinks( True ) # in aircrafttype.py and groundunittype.py, for the descriptions, if No Data. including a google search link self.gridLayout.addWidget(self.details_text, 3, 0) self.layout.addLayout(self.gridLayout, 1, 0) self.setLayout(self.layout) def generateAircraftTasks(self) -> str: aircraft_tasks = "" unit_type = self.unit_type.dcs_unit_type if unit_type in gen.flights.ai_flight_planner_db.CAP_CAPABLE: aircraft_tasks = ( aircraft_tasks + f"{FlightType.BARCAP}, {FlightType.ESCORT}, {FlightType.INTERCEPTION}, {FlightType.SWEEP}, {FlightType.TARCAP}, " ) if unit_type in gen.flights.ai_flight_planner_db.CAS_CAPABLE: aircraft_tasks = ( aircraft_tasks + f"{FlightType.CAS}, {FlightType.BAI}, {FlightType.OCA_AIRCRAFT}, " ) if unit_type in gen.flights.ai_flight_planner_db.SEAD_CAPABLE: aircraft_tasks = aircraft_tasks + f"{FlightType.SEAD}, " if unit_type in gen.flights.ai_flight_planner_db.DEAD_CAPABLE: aircraft_tasks = aircraft_tasks + f"{FlightType.DEAD}, " if unit_type in gen.flights.ai_flight_planner_db.ANTISHIP_CAPABLE: aircraft_tasks = aircraft_tasks + f"{FlightType.ANTISHIP}, " if unit_type in gen.flights.ai_flight_planner_db.RUNWAY_ATTACK_CAPABLE: aircraft_tasks = aircraft_tasks + f"{FlightType.OCA_RUNWAY}, " if unit_type in gen.flights.ai_flight_planner_db.STRIKE_CAPABLE: aircraft_tasks = aircraft_tasks + f"{FlightType.STRIKE}, " if unit_type in gen.flights.ai_flight_planner_db.REFUELING_CAPABALE: aircraft_tasks = aircraft_tasks + f"{FlightType.REFUELING}, " return aircraft_tasks[:-2]
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)