def __init__(self, session, tool_name): ToolInstance.__init__(self, session, tool_name) # 'display_name' defaults to class name with spaces inserted # between lower-then-upper-case characters (therefore "Tool UI" # in this case), so only override if different name desired self.display_name = "ChimeraX Python Shell" from chimerax.ui import MainToolWindow self.tool_window = MainToolWindow(self) parent = self.tool_window.ui_area # UI content code from ipykernel.ipkernel import IPythonKernel save_ns = IPythonKernel.user_ns IPythonKernel.user_ns = {'session': session} from qtconsole.inprocess import QtInProcessKernelManager kernel_manager = QtInProcessKernelManager() kernel_manager.start_kernel() kernel_client = kernel_manager.client() kernel_client.start_channels() from qtconsole.rich_jupyter_widget import RichJupyterWidget self.shell = RichJupyterWidget(parent) def_banner = self.shell.banner self.shell.banner = "{}\nCurrent ChimeraX session available as 'session'.\n\n".format( def_banner) self.shell.kernel_manager = kernel_manager self.shell.kernel_client = kernel_client IPythonKernel.user_ns = save_ns from PyQt5.QtWidgets import QHBoxLayout layout = QHBoxLayout() layout.addWidget(self.shell) layout.setStretchFactor(self.shell, 1) parent.setLayout(layout) self.tool_window.manage(placement=None)
def __init__(self, ui, title, recent_message, timestamp_ms, parent=None): super().__init__(parent) self.row = QVBoxLayout() # self.row.maximumSize = ui.conversationsList.maximumSize() title = truncate(title, 15) recent_message = truncate(recent_message, 30) heading_row = QHBoxLayout() heading_row.maximumSize = ui.conversationsList.maximumSize() title_font = QFont("Sans Serif", 10) title_label = QLabel(title) title_label.setFont(title_font) heading_row.addWidget(title_label) heading_row.setStretchFactor(title_label, 1) time_font = QFont("Sans Serif", 10) time_string = timestamp_ms_to_timestring(timestamp_ms) time_label = QLabel(time_string) time_label.setFont(time_font) heading_row.addWidget(time_label) heading_row.setStretchFactor(time_label, 0) self.row.addItem(heading_row) preview_font = QFont("Sans Serif", 9) preview_label = QLabel(recent_message) preview_label.setFont(preview_font) preview_label.setStyleSheet("QLabel {color: #555555;}") self.row.addWidget(preview_label) self.setLayout(self.row)
def setup_ui(self): self.setWindowTitle("EFM8 programmer") self.refresh_ports_button.setIcon(self.style().standardIcon( QStyle.SP_BrowserReload)) self.refresh_ports_button.setToolTip("Refresh ports list") pblayout = QHBoxLayout() pblayout.addWidget(QLabel("Com port:")) pblayout.addWidget(self.ports_combobox) pblayout.addWidget(self.refresh_ports_button) pblayout.setStretchFactor(self.ports_combobox, 3) btnlayout = QHBoxLayout() for b in [ self.flash_arduino_button, self.flash_efm_button, self.read_efm_button, ]: s = b.sizePolicy() s.setHorizontalPolicy(QSizePolicy.Maximum) b.setSizePolicy(s) btnlayout.addWidget(b) main_layout = QVBoxLayout() main_layout.addLayout(pblayout) main_layout.addLayout(btnlayout) main_layout.addWidget(self.stdout_textedit) self.setLayout(main_layout) self.show()
def init_ui(self, address, rssi, battery): infoLayout = QHBoxLayout() infoLayout.setSpacing(5) # Myo armband icon lbl = QLabel(self) orig = QPixmap( join( abspath(__file__).replace("online_test.py", ""), "icons/myo.png")) new = orig.scaled(QSize(30, 30), Qt.KeepAspectRatio) lbl.setPixmap(new) # # Format the Myo hardware (MAC) into a readable form # infoLayout.addWidget(lbl) formatted_address = "" length = len(address.hex()) for i, ch in enumerate(address.hex()): formatted_address += ch if ((i - 1) % 2 == 0) and (i != length - 1): formatted_address += "-" vline = QFrame() vline.setFrameShape(QFrame.VLine) vline.setFrameShadow(QFrame.Sunken) # vline2 = QFrame() # vline2.setFrameShape(QFrame.VLine) # vline2.setFrameShadow(QFrame.Sunken) # # Myo armband address, signal strength # addr_label = QLabel(formatted_address) addr_label.setContentsMargins(5, 0, 0, 0) cur_font = addr_label.font() cur_font.setPointSize(10) addr_label.setFont(cur_font) infoLayout.addWidget(addr_label) infoLayout.addWidget(vline) #rssi_label = QLabel(str(rssi) + " dBm") #infoLayout.addWidget(rssi_label) #infoLayout.addWidget(vline2) #infoLayout.setStretchFactor(rssi_label, 3) infoLayout.setStretchFactor(addr_label, 4) # # Battery Level # self.battery_level = QProgressBar() self.battery_level.setMinimum(0) self.battery_level.setMaximum(100) self.battery_level.setValue(battery) infoLayout.addWidget(self.battery_level) infoLayout.setStretchFactor(self.battery_level, 2) self.setLayout(infoLayout)
class SynchronizationInterface(QWidget): def __init__(self, parent, shared_data): super(SynchronizationInterface, self).__init__(parent) self.__shared_data = shared_data # Create the widgets self.__video_widget = VideoWidget(self, self.__shared_data) self.__data_widget = DataWidget(self, self.__shared_data) self.__sidebar_widget = SideBarWidget(self, self.__shared_data) # Create the layouts self.__left_layout = QVBoxLayout() self.__left_layout.addWidget(self.__video_widget) self.__left_layout.addWidget(self.__data_widget) self.__left_layout.setStretchFactor(self.__video_widget, 2) self.__left_layout.setStretchFactor(self.__data_widget, 1) self.__main_layout = QHBoxLayout() self.__main_layout.addLayout(self.__left_layout) self.__main_layout.addWidget(self.__sidebar_widget) self.__main_layout.setStretchFactor(self.__left_layout, 3) self.__main_layout.setStretchFactor(self.__sidebar_widget, 1) # Set the layout self.setLayout(self.__main_layout)
def tab_nstUI(self): layout = QHBoxLayout() left_widget = QWidget() left_panel = QVBoxLayout(left_widget) self.btn_input.setFixedSize(225, 30) self.btn_output.setFixedSize(225, 30) self.btn_casedate.setFixedSize(300, 30) left_panel.addWidget(QLabel('数据文件夹输入')) left_panel.addWidget(self.btn_input) left_panel.addWidget(self.text_input) left_panel.addStretch(1) left_panel.addWidget(self.btn_output) left_panel.addWidget(self.text_output) left_panel.addStretch(1) left_panel.addWidget(self.btn_casedate) left_panel.addStretch(2) left_panel.addWidget(self.btn_execute) left_panel.addWidget(self.text_info) left_panel.addStretch(1) right_widget = QWidget() right_panel = QVBoxLayout(right_widget) right_panel.addWidget(self.direct_res) right_panel.addWidget(self.indirect_res) # print('xx') right_panel.addWidget(QLabel('直接传播结果')) layout.addWidget(left_widget) right_panel.addWidget(QLabel('间接传播结果')) layout.addWidget(right_widget) layout.setStretchFactor(left_widget, 3) layout.setStretchFactor(right_widget, 7) self.setLayout(layout)
def __init__(self, config: 'SimpleConfig', app: QApplication, plugins: 'Plugins', *, gui_object: 'ElectrumGui'): QDialog.__init__(self, None) BaseWizard.__init__(self, config, plugins) self.setWindowTitle('Firo Electrum - ' + _('Install Wizard')) self.app = app self.config = config self.gui_thread = gui_object.gui_thread self.setMinimumSize(600, 400) self.accept_signal.connect(self.accept) self.title = QLabel() self.main_widget = QWidget() self.save_button = QPushButton(_('Save and exit'), self) self.save_button.hide() self.back_button = QPushButton(_("Back"), self) self.back_button.setText( _('Back') if self.can_go_back() else _('Cancel')) self.next_button = QPushButton(_("Next"), self) self.next_button.setDefault(True) self.logo = QLabel() self.please_wait = QLabel(_("Please wait...")) self.please_wait.setAlignment(Qt.AlignCenter) self.icon_filename = None self.loop = QEventLoop() self.rejected.connect(lambda: self.loop.exit(0)) self.back_button.clicked.connect(lambda: self.loop.exit(1)) self.next_button.clicked.connect(lambda: self.loop.exit(2)) self.save_button.clicked.connect(lambda: self.loop.exit(3)) outer_vbox = QVBoxLayout(self) inner_vbox = QVBoxLayout() inner_vbox.addWidget(self.title) inner_vbox.addWidget(self.main_widget) inner_vbox.addStretch(1) inner_vbox.addWidget(self.please_wait) inner_vbox.addStretch(1) scroll_widget = QWidget() scroll_widget.setLayout(inner_vbox) scroll = QScrollArea() scroll.setWidget(scroll_widget) scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) scroll.setWidgetResizable(True) icon_vbox = QVBoxLayout() icon_vbox.addWidget(self.logo) icon_vbox.addStretch(1) hbox = QHBoxLayout() hbox.addLayout(icon_vbox) hbox.addSpacing(5) hbox.addWidget(scroll) hbox.setStretchFactor(scroll, 1) outer_vbox.addLayout(hbox) btns_hbox = QHBoxLayout() btns_hbox.addWidget(self.save_button) btns_hbox.addStretch(1) btns_hbox.addLayout(Buttons(self.back_button, self.next_button)) outer_vbox.addLayout(btns_hbox) self.set_icon('electrum-dash.png') self.show() self.raise_() self.refresh_gui() # Need for QT on MacOSX. Lame.
def mainUI(self): layout = QHBoxLayout() left_widget = QWidget() left_panel = QVBoxLayout(left_widget) self.dir_input = QPushButton("输入文件夹") self.dir_input.setFixedSize(100, 30) self.qline = QLabel('未选择文件夹,请指定') self.qline.setFixedSize(225, 30) self.execute = QPushButton('执行') self.execute.setFixedSize(225, 30) self.line2 = QLineEdit() self.line2.setValidator(QIntValidator(0, 99)), self.line2.setText('50') self.btn3 = QPushButton("打印结果") self.btn3.setEnabled(False) self.btn3.setFixedSize(225, 30) self.btn4 = QPushButton('导出阳性化合物库信息') self.btn4.setEnabled(False) self.btn4.setFixedSize(225, 30) self.btn5 = QPushButton('显示阳性分子结构') self.btn5.setEnabled(False) self.btn5.setFixedSize(225, 30) self.btn6 = QPushButton('寻找化合类似物') self.btn6.setEnabled(False) self.btn6.setFixedSize(225, 30) left_panel.addWidget(self.dir_input) left_panel.addWidget(self.qline) left_panel.addWidget(QLabel('设置抑菌比例(1-99),默认50%')) left_panel.addWidget(self.line2) left_panel.addStretch(1) left_panel.addWidget(self.execute) left_panel.addStretch(6) left_panel.addWidget(self.btn3) left_panel.addWidget(self.btn4) left_panel.addWidget(self.btn5) left_panel.addWidget(self.btn6) left_panel.addStretch(6) right_widget = QWidget() right_panel = QVBoxLayout(right_widget) res = QLabel('小于指定比例(如50%)酶活(DMSO平均值)的孔: ') self.res1 = QTextEdit() self.res1.setFontFamily('Consolas') self.res1.setFontPointSize(12) error = QLabel('xls文件有误: ') self.error1 = QTextEdit() self.error1.setFontFamily('Consolas') self.error1.setFontPointSize(12) right_panel.addWidget(res) right_panel.addWidget(self.res1) right_panel.addWidget(error) right_panel.addWidget(self.error1) layout.addWidget(left_widget) layout.setStretchFactor(left_widget, 3) layout.addWidget(right_widget) layout.setStretchFactor(right_widget, 7) self.setLayout(layout)
def __init__(self, config, app, manager, parent): BaseWizard.__init__(self, config, None, None) QDialog.__init__(self, None) self.app = app self.gui = parent self.manager = manager self.setMinimumSize(600, 400) self.accept_signal.connect(self.accept) self.setWindowTitle('Electrum-AUDAX - ' + _('Masternode Wizard')) self.mn = MasternodeAnnounce() self.alias_e = None self.address_e = None self.privkey_e = None self.valid_utxo_list = None self.title = QLabel() self.main_widget = QWidget() self.back_button = QPushButton(_("Back"), self) self.back_button.setText( _('Back') if self.can_go_back() else _('Cancel')) self.next_button = QPushButton(_("Next"), self) self.next_button.setDefault(True) self.logo = QLabel() self.icon_filename = None self.loop = QEventLoop() self.rejected.connect(lambda: self.loop.exit(0)) self.back_button.clicked.connect(lambda: self.loop.exit(1)) self.next_button.clicked.connect(lambda: self.loop.exit(2)) outer_vbox = QVBoxLayout(self) inner_vbox = QVBoxLayout() inner_vbox.addWidget(self.title) inner_vbox.addWidget(self.main_widget) inner_vbox.addStretch(1) # inner_vbox.addWidget(self.please_wait) inner_vbox.addStretch(1) scroll_widget = QWidget() scroll_widget.setLayout(inner_vbox) scroll = QScrollArea() scroll.setWidget(scroll_widget) scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) scroll.setWidgetResizable(True) icon_vbox = QVBoxLayout() icon_vbox.addWidget(self.logo) icon_vbox.addStretch(1) hbox = QHBoxLayout() hbox.addLayout(icon_vbox) hbox.addSpacing(5) hbox.addWidget(scroll) hbox.setStretchFactor(scroll, 1) outer_vbox.addLayout(hbox) outer_vbox.addLayout(Buttons(self.back_button, self.next_button)) self.set_icon('electrum.png') self.show() self.raise_() self.refresh_gui() # Need for QT on MacOSX. Lame.
def __init__(self, config, app, plugins): BaseWizard.__init__(self, config, plugins) QDialog.__init__(self, None) self.setWindowTitle('NYCFlash Electrum Wallet - ' + _('Install Wizard')) self.app = app self.config = config # Set for base base class self.language_for_seed = config.get('language') self.setMinimumSize(600, 400) self.accept_signal.connect(self.accept) self.title = QLabel() self.main_widget = QWidget() self.back_button = QPushButton(_("Back"), self) self.back_button.setText( _('Back') if self.can_go_back() else _('Cancel')) self.next_button = QPushButton(_("Next"), self) self.next_button.setDefault(True) self.logo = QLabel() self.please_wait = QLabel(_("Please wait...")) self.please_wait.setAlignment(Qt.AlignCenter) self.icon_filename = None self.loop = QEventLoop() self.rejected.connect(lambda: self.loop.exit(0)) self.back_button.clicked.connect(lambda: self.loop.exit(1)) self.next_button.clicked.connect(lambda: self.loop.exit(2)) outer_vbox = QVBoxLayout(self) inner_vbox = QVBoxLayout() inner_vbox.addWidget(self.title) inner_vbox.addWidget(self.main_widget) inner_vbox.addStretch(1) inner_vbox.addWidget(self.please_wait) inner_vbox.addStretch(1) scroll_widget = QWidget() scroll_widget.setLayout(inner_vbox) scroll = QScrollArea() scroll.setWidget(scroll_widget) scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) scroll.setWidgetResizable(True) icon_vbox = QVBoxLayout() icon_vbox.addWidget(self.logo) icon_vbox.addStretch(1) hbox = QHBoxLayout() hbox.addLayout(icon_vbox) hbox.addSpacing(5) hbox.addWidget(scroll) hbox.setStretchFactor(scroll, 1) outer_vbox.addLayout(hbox) outer_vbox.addLayout(Buttons(self.back_button, self.next_button)) self.set_icon('electrum_nyc.png') self.show() self.raise_() self.refresh_gui() # Need for QT on MacOSX. Lame.
def __init__(self, win_idx: int): super().__init__() self.setFrameStyle(QFrame.StyledPanel) self.setAutoFillBackground(True) self.script = QThread() self.script.start() self.script.quit() self.win_idx = win_idx #COM Label self.com_label = QLabel('COM') #状态Label self.status_label = QLabel('状态') #异常信息 self.error_label = QLabel('') self.error_label.setStyleSheet('.QLabel {color:#A57A80;}') leftLayout = QVBoxLayout() leftLayout.setSpacing(5) leftLayout.addWidget(self.com_label) leftLayout.addWidget(self.status_label) leftLayout.addWidget(self.error_label) leftLayout.addStretch(1) ####显示关键信息 self.productmodel_label = QLabel('') self.softversoin_label = QLabel('') self.chipid_label = QLabel('') #测试按钮 self.start_button = QPushButton('测试', clicked=self.onUnitTest) self.start_button.setSizePolicy( QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)) rightLayout = QVBoxLayout() rightLayout.addWidget(self.productmodel_label) rightLayout.addWidget(self.softversoin_label) rightLayout.addWidget(self.chipid_label) rightLayout.addStretch(1) rightLayout.addWidget(self.start_button) rightLayout.setAlignment(self.start_button, Qt.AlignRight) #总布局 mainlayout = QHBoxLayout() mainlayout.addLayout(leftLayout) mainlayout.addLayout(rightLayout) mainlayout.setStretchFactor(leftLayout, 4) mainlayout.setStretchFactor(rightLayout, 1) self.setLayout(mainlayout) self.devInitState()
def initUI(self): self.total_money = 0 font = QFont() font.setBold(True) font.setPointSize(15) self.setFont(font) self.total_label = QLabel("总金额:{}¥".format(self.total_money)) t_font = QFont() t_font.setBold(True) t_font.setPointSize(20) self.total_label.setFont(t_font) self.money_edit = QLineEdit() self.money_edit.setValidator( QRegExpValidator(QRegExp("^[1-9][0-9]{1,8}$"))) self.add_money = QPushButton("加钱") editLayout = QHBoxLayout() editLayout.addWidget(self.total_label) editLayout.setStretchFactor(self.total_label, 2) editLayout.addWidget(self.money_edit) editLayout.setStretchFactor(self.money_edit, 1) editLayout.addWidget(self.add_money) editLayout.setStretchFactor(self.add_money, 1) self.add_money.clicked.connect(self.add_handle) self.money_edit.returnPressed.connect(self.add_handle) self.new_num = QLineEdit() self.new_num.setValidator( QRegExpValidator(QRegExp("^[1-9][0-9]{1,8}$"))) self.add_new_num = QPushButton("减钱") newLayout = QHBoxLayout() newLayout.addWidget(self.new_num) newLayout.addWidget(self.add_new_num) self.add_new_num.clicked.connect(self.minus_handle) self.new_num.returnPressed.connect(self.minus_handle) self.reset = QPushButton("重置") self.reset.setToolTip("重置按钮将所有号码的金额与总金额数设置为0") self.reset.clicked.connect(self.reset_handle) manageLayout = QHBoxLayout() manageLayout.addLayout(editLayout) manageLayout.addSpacing(100) manageLayout.addLayout(newLayout) manageLayout.addSpacing(100) manageLayout.addWidget(self.reset) #set strech layout factor manageLayout.setStretchFactor(editLayout, 3) manageLayout.setStretchFactor(newLayout, 1) self.setLayout(manageLayout)
def __init__(self, config: 'SimpleConfig', app: QApplication, plugins: 'Plugins'): QDialog.__init__(self, None) BaseWizard.__init__(self, config, plugins) self.app = app self.config = config self.setMinimumSize(600, 400) self.accept_signal.connect(self.accept) self.title = QLabel() self.main_widget = QWidget() self.back_button = QPushButton(self) self.next_button = QPushButton(self) self.next_button.text() self.next_button.setDefault(True) self.logo = QLabel() self.please_wait = QLabel() self.please_wait.setAlignment(Qt.AlignCenter) self.icon_filename = None self.loop = QEventLoop() self.rejected.connect(lambda: self.loop.exit(0)) self.back_button.clicked.connect(lambda: self.loop.exit(1)) self.next_button.clicked.connect(lambda: self.loop.exit(2)) outer_vbox = QVBoxLayout(self) inner_vbox = QVBoxLayout() inner_vbox.addWidget(self.title) inner_vbox.addWidget(self.main_widget) inner_vbox.addStretch(1) inner_vbox.addWidget(self.please_wait) inner_vbox.addStretch(1) scroll_widget = QWidget() scroll_widget.setLayout(inner_vbox) scroll = QScrollArea() scroll.setWidget(scroll_widget) scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) scroll.setWidgetResizable(True) icon_vbox = QVBoxLayout() icon_vbox.addWidget(self.logo) icon_vbox.addStretch(1) hbox = QHBoxLayout() hbox.addLayout(icon_vbox) hbox.addSpacing(5) hbox.addWidget(scroll) hbox.setStretchFactor(scroll, 1) outer_vbox.addLayout(hbox) outer_vbox.addLayout(Buttons(self.back_button, self.next_button)) self._add_advanced_button() self.set_icon('electrum.png') self._set_gui_text() self.show() self.raise_() self.refresh_gui() # Need for QT on MacOSX. Lame. LastChosenState.clear()
def createMainGroup(self): mgroup = QGroupBox() hbox = QHBoxLayout() mgroup.setLayout(hbox) inputform = self.createInputForm() hbox.addWidget(inputform) list = self.createList() hbox.addWidget(list) hbox.setStretchFactor(inputform, 1) hbox.setStretchFactor(list, 2) return mgroup
def __init__(self, config, app, plugins): QDialog.__init__(self, None) BaseWizard.__init__(self, config, plugins) self.setWindowTitle('Vialectrum - ' + _('Install Wizard')) self.app = app self.config = config # Set for base base class self.language_for_seed = config.get('language') self.setMinimumSize(600, 400) self.accept_signal.connect(self.accept) self.title = QLabel() self.main_widget = QWidget() self.back_button = QPushButton(_("Back"), self) self.back_button.setText(_('Back') if self.can_go_back() else _('Cancel')) self.next_button = QPushButton(_("Next"), self) self.next_button.setDefault(True) self.logo = QLabel() self.please_wait = QLabel(_("Please wait...")) self.please_wait.setAlignment(Qt.AlignCenter) self.icon_filename = None self.loop = QEventLoop() self.rejected.connect(lambda: self.loop.exit(0)) self.back_button.clicked.connect(lambda: self.loop.exit(1)) self.next_button.clicked.connect(lambda: self.loop.exit(2)) outer_vbox = QVBoxLayout(self) inner_vbox = QVBoxLayout() inner_vbox.addWidget(self.title) inner_vbox.addWidget(self.main_widget) inner_vbox.addStretch(1) inner_vbox.addWidget(self.please_wait) inner_vbox.addStretch(1) scroll_widget = QWidget() scroll_widget.setLayout(inner_vbox) scroll = QScrollArea() scroll.setWidget(scroll_widget) scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) scroll.setWidgetResizable(True) icon_vbox = QVBoxLayout() icon_vbox.addWidget(self.logo) icon_vbox.addStretch(1) hbox = QHBoxLayout() hbox.addLayout(icon_vbox) hbox.addSpacing(5) hbox.addWidget(scroll) hbox.setStretchFactor(scroll, 1) outer_vbox.addLayout(hbox) outer_vbox.addLayout(Buttons(self.back_button, self.next_button)) self.set_icon('vialectrum.png') self.show() self.raise_() self.refresh_gui() # Need for QT on MacOSX. Lame.
def init_save_file(self): file_box = QHBoxLayout() file_box.addWidget(self.save_dir) self.save_dir.setFocusPolicy(Qt.NoFocus) self.save_dir.setText(os.getcwd()) self.save_dir.clicked.connect(self.show_dir_dialogue) file_box.setStretchFactor(self.save_dir, 4) file_box.addWidget(QLabel('/')) file_box.addWidget(self.dir1) self.dir1.setText('0') file_box.setStretchFactor(self.dir1, 1) file_box.addWidget(QLabel('/')) file_box.addWidget(self.dir2) self.dir2.setText('0') file_box.setStretchFactor(self.dir2, 1) file_box.addWidget(QLabel('/')) file_box.addWidget(self.filename) self.filename.setText('0') file_box.setStretchFactor(self.filename, 1) file_box.addWidget(QLabel('.wav')) return file_box
def __init__(self, mainwin): super(AssetWidget, self).__init__() self.mainwin = mainwin mainLayout = QVBoxLayout() viewBase = View("<BASE>", basedir) viewData = View("<DATA>", datadir) viewSrc = View("<SRC>", srcdir) viewDst = View("<DST>", dstdir) viewBase.addToLayout(mainLayout) viewData.addToLayout(mainLayout) viewSrc.addToLayout(mainLayout) viewDst.addToLayout(mainLayout) sbutton = QPushButton() style = QStyleFactory.create("Macintosh") #icon = style.standardIcon(QStyle.SP_FileIcon) #sbutton.setIcon(icon) #sbutton.setStyleSheet("background-color: rgb(0, 0, 64); border-radius: 2; ") sbutton.pressed.connect(self.selectInput) self.srced = Edit("Source File") slay2 = QHBoxLayout() slay2.addLayout(self.srced.layout) self.srced.edit.setStyleSheet( bgcolor(128, 32, 128) + fgcolor(0, 255, 0)) slay2.addWidget(sbutton) mainLayout.addLayout(slay2) ad_lo = QHBoxLayout() self.assettypeview = View("AssetType", "???") self.assettypeview.addToLayout(ad_lo) self.assettypeview.layout.setStretchFactor(self.assettypeview.labl, 1) self.assettypeview.layout.setStretchFactor(self.assettypeview.edit, 3) self.dsted = View("Dest File", "") self.dsted.addToLayout(ad_lo) self.dsted.layout.setStretchFactor(self.dsted.edit, 8) self.dsted.layout.setStretchFactor(self.dsted.labl, 1) ad_lo.setStretchFactor(self.assettypeview.layout, 1) ad_lo.setStretchFactor(self.dsted.layout, 3) mainLayout.addLayout(ad_lo) gobutton = QPushButton("Go") gobutton.setStyleSheet(bgcolor(32, 32, 128) + fgcolor(255, 255, 128)) mainLayout.addWidget(gobutton) gobutton.pressed.connect(self.goPushed) self.setLayout(mainLayout)
def init_ui(self): self.primary_cmb.addItems([item["primary"] for item in PROGRAM_LIST]) self.primary_cmb.currentTextChanged.connect(self.set_secondary) self.state_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) self.path_btn.clicked.connect(self.select_path) font = QFont() font.setBold(True) self.install_btn.setFont(font) self.install_btn.clicked.connect(self.install) self.upgrade_btn.setFont(font) self.upgrade_btn.clicked.connect(self.upgrade) self.uninstall_btn.setFont(font) self.uninstall_btn.clicked.connect(self.uninstall) self.config_btn.setFont(font) self.config_btn.clicked.connect(self.config) label = (f"Chocolatey (v{self.get_version().strip()})" if which("choco") is not None else "Chocolatey") choco_hlayout1 = QHBoxLayout() choco_hlayout1.addWidget(self.primary_cmb) choco_hlayout1.setStretchFactor(self.primary_cmb, 15) choco_hlayout1.addWidget(self.secondary_cmb) choco_hlayout1.setStretchFactor(self.secondary_cmb, 15) choco_hlayout1.addWidget(self.state_label) choco_hlayout1.setStretchFactor(self.state_label, 10) choco_hlayout2 = QHBoxLayout() choco_hlayout2.addWidget(self.path_le) choco_hlayout2.setStretchFactor(self.path_le, 3) choco_hlayout2.addWidget(self.path_btn) choco_hlayout2.setStretchFactor(self.path_btn, 1) choco_hlayout3 = QHBoxLayout() choco_hlayout3.addWidget(self.install_btn) choco_hlayout3.addWidget(self.upgrade_btn) choco_hlayout3.addWidget(self.uninstall_btn) choco_hlayout3.addWidget(self.config_btn) choco_vlayout1 = QVBoxLayout() choco_vlayout1.addLayout(choco_hlayout1) choco_vlayout1.addLayout(choco_hlayout2) choco_vlayout1.addLayout(choco_hlayout3) choco_group = QGroupBox(label) choco_group.setLayout(choco_vlayout1) choco_layout = QVBoxLayout() choco_layout.addWidget(choco_group) self.setLayout(choco_layout)
def __init__(self,mainwin): super(AssetWidget, self).__init__() self.mainwin = mainwin mainLayout = QVBoxLayout() viewBase = View("<BASE>",basedir) viewData = View("<DATA>",datadir) viewSrc = View("<SRC>",srcdir) viewDst = View("<DST>",dstdir) viewBase.addToLayout(mainLayout) viewData.addToLayout(mainLayout) viewSrc.addToLayout(mainLayout) viewDst.addToLayout(mainLayout) sbutton = QPushButton() style = QStyleFactory.create("Macintosh") icon = style.standardIcon(QStyle.SP_FileIcon) sbutton.setIcon(icon) #sbutton.setStyleSheet("background-color: rgb(0, 0, 64); border-radius: 2; ") sbutton.pressed.connect(self.selectInput) self.srced = Edit("Source File") slay2 = QHBoxLayout() slay2.addLayout(self.srced.layout) self.srced.edit.setStyleSheet(bgcolor(128,32,128)+fgcolor(0,255,0)) slay2.addWidget(sbutton) mainLayout.addLayout(slay2) ad_lo = QHBoxLayout() self.assettypeview = View("AssetType","???") self.assettypeview.addToLayout(ad_lo) self.assettypeview.layout.setStretchFactor(self.assettypeview.labl,1) self.assettypeview.layout.setStretchFactor(self.assettypeview.edit,3) self.dsted = View("Dest File",""); self.dsted.addToLayout(ad_lo) self.dsted.layout.setStretchFactor(self.dsted.edit,8) self.dsted.layout.setStretchFactor(self.dsted.labl,1) ad_lo.setStretchFactor(self.assettypeview.layout,1) ad_lo.setStretchFactor(self.dsted.layout,3) mainLayout.addLayout(ad_lo) gobutton = QPushButton("Go") gobutton.setStyleSheet(bgcolor(32,32,128)+fgcolor(255,255,128)) mainLayout.addWidget(gobutton) gobutton.pressed.connect(self.goPushed) self.setLayout(mainLayout)
def initUI(self, parent): keyGenButton = QPushButton('密钥生成', self) keyGenButton.setIcon(QIcon('./image/keyGen.png')) keyGenButton.setStyleSheet("QPushButton{color:black}" "QPushButton:hover{color:red}") keyGenButton.clicked.connect(lambda: self.onkeyGen(parent)) launchButton = QPushButton('发起投票', self) launchButton.setIcon(QIcon('./image/launch.png')) launchButton.setStyleSheet("QPushButton{color:black}" "QPushButton:hover{color:red}") launchButton.clicked.connect(lambda: self.onLaunch(parent)) voteButton = QPushButton('进行投票', self) voteButton.setIcon(QIcon('./image/vote.jpg')) voteButton.setStyleSheet("QPushButton{color:black}" "QPushButton:hover{color:red}") voteButton.clicked.connect(lambda: self.onVote(parent)) viewButton = QPushButton('查看投票', self) viewButton.setIcon(QIcon('./image/view.png')) viewButton.setStyleSheet("QPushButton{color:black}" "QPushButton:hover{color:red}") viewButton.clicked.connect(lambda: self.onView(parent)) vbox = QVBoxLayout() vbox.addWidget(keyGenButton) vbox.addWidget(launchButton) vbox.addWidget(voteButton) vbox.addWidget(viewButton) midhobx = QHBoxLayout() midhobx.addStretch(1) midhobx.addLayout(vbox) midhobx.addStretch(1) centerFrame = QFrame(self) centerFrame.setFrameShape(QFrame.WinPanel) centerFrame.setLayout(midhobx) hbox = QHBoxLayout() hbox.addStretch(1) hbox.addWidget(centerFrame) hbox.addStretch(1) hbox.setStretchFactor(centerFrame, 6) self.setLayout(hbox)
def initUI(self): b1 = QPushButton("Button") b2 = QPushButton("Button") b3 = QPushButton("Button") hbox = QHBoxLayout() hbox.addWidget(b1) hbox.addWidget(b2) hbox.addWidget(b3) hbox.setStretchFactor(b1, 1) hbox.setStretchFactor(b2, 5) hbox.setStretchFactor(b3, 8) self.setLayout(hbox)
def initUI(self): self.setWindowTitle('界面对数据库操作') self.resize(600,400) widget=QWidget() self.setCentralWidget(widget) layout=QHBoxLayout() widget.setLayout(layout) #左边 box=QGroupBox('数据库按钮') boxlayout=QVBoxLayout() box.setLayout(boxlayout) #添加数据库按钮 self.b1=QPushButton('创建连接数据库') boxlayout.addWidget(self.b1) self.b1.clicked.connect(self.create_db) self.b11=QPushButton('创建表') boxlayout.addWidget(self.b11) self.b11.setEnabled(False) self.b11.clicked.connect(self.create_table) self.b11.clicked.connect(self.create_table) self.b2=QPushButton('浏览数据') boxlayout.addWidget(self.b2) self.b2.setEnabled(False) self.b2.clicked.connect(self.show_db) self.b3=QPushButton('添加一行') boxlayout.addWidget(self.b3) self.b3.setEnabled(False) self.b3.clicked.connect(self.add_db) self.b4=QPushButton('删除一行') boxlayout.addWidget(self.b4) self.b4.setEnabled(False) self.b4.clicked.connect(self.del_db) self.b5=QPushButton('退出') boxlayout.addWidget(self.b5) self.b5.setEnabled(False) self.b5.clicked.connect(self.exit_db) layout.addWidget(box) #右边 self.tableview=QTableView() layout.addWidget(self.tableview) layout.setStretchFactor(box,1) layout.setStretchFactor(self.tableview,3)
def main_ui(self): layout = QHBoxLayout() left_frame = QFrame() left_frame.setFrameShape(QFrame.Box) left_layout = QVBoxLayout(left_frame) w1 = QWidget() w1_layout = QHBoxLayout(w1) self.btn1 = QPushButton('选择文件夹') self.btn2 = QPushButton('选择文件') self.label = QLabel('未选择文件夹,请指定') self.sample_label = QLabel() w1_layout.addWidget(self.btn1) w1_layout.addWidget(self.btn2) left_layout.addWidget(w1) left_layout.addWidget(self.label) left_layout.addWidget(self.sample_label) # 功能选择模块 left_layout.addStretch(1) self.excute_kaptive = QPushButton('荚膜型检测') self.excute_kaptive.setObjectName('kaptive') self.execute_mlst = QPushButton('ST型检测') self.execute_mlst.setObjectName('mlst') self.execute_abricate = QPushButton('耐药/毒力基因检测') self.execute_abricate.setObjectName('abricate') self.labe2 = QLabel('未执行检测') left_layout.addWidget(self.execute_mlst) left_layout.addWidget(self.excute_kaptive) left_layout.addWidget(self.execute_abricate) left_layout.addWidget(self.labe2) # left_layout.addStretch(3) right_frame = QFrame() self.tableview = QTableView(right_frame) self.tableview.resize(650, 500) right_frame.setFrameShape(QFrame.Box) layout.addWidget(left_frame) layout.addWidget(right_frame) layout.setStretchFactor(left_frame, 3) layout.setStretchFactor(right_frame, 7) self.setLayout(layout)
class WxClientsPanel(QFrame): def __init__(self, parent=None, wxclients={}): super().__init__(parent) self.wxclients = wxclients self.browsers = [Browser(self) for _ in range(6)] self.ctrlPanel = WxClientsCtrlPanel(self, wxclients, runAllClients=self.runAllClients) self.dispPanel = WxClientsDisplayPanel(self, self.browsers) self.layout = QHBoxLayout() self.layout.addWidget(self.ctrlPanel) self.layout.addWidget(self.dispPanel) self.layout.setStretchFactor(self.ctrlPanel, 1) self.layout.setStretchFactor(self.dispPanel, 5) self.setLayout(self.layout) def runAllClients(self, urls): for i in range(len(urls)): self.browsers[i].openUrl(urls[i])
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.seriesmap = {} # map items to series # create widgets self.stat_list = QListWidget(self) chart = QChart() self.chart_view = QChartView(chart, self) for i in range(30): series = QLineSeries(self) for j in range(20): series.append(j, i * 3 + j) item = QListWidgetItem() item.setData(Qt.DisplayRole, str(i)) item.setData(Qt.UserRole, i) if i < 10: item.setData(Qt.CheckStateRole, Qt.Checked) else: item.setData(Qt.CheckStateRole, Qt.Unchecked) series.hide() chart.addSeries(series) self.stat_list.addItem(item) self.seriesmap[i] = series # create layout layout = QHBoxLayout(self) layout.addWidget(self.stat_list) layout.addWidget(self.chart_view) layout.setStretchFactor(self.chart_view, 3) # configure widgets chart.legend().hide() chart.createDefaultAxes() chart.setTitle("Daily aggregated stats of your school") self.chart_view.setRenderHint(QPainter.Antialiasing) self.retranslateUi() # connect signals self.stat_list.itemClicked.connect(self.on_stat_clicked)
def main_ui(self): layout = QHBoxLayout() left_frame = QFrame() left_frame.setFrameShape(QFrame.Box) left_layout = QVBoxLayout(left_frame) w1 = QWidget() w1_layout = QHBoxLayout(w1) w1_layout.addWidget(self.btn1) left_layout.addWidget(w1) left_layout.addWidget(self.label) left_layout.addWidget(self.sample_label) # 功能选择模块 left_layout.addStretch(1) self.excute_kaptive.setObjectName('kaptive') self.execute_mlst.setObjectName('mlst') self.execute_abricate.setObjectName('abricate') left_layout.addWidget(self.execute_mlst) left_layout.addWidget(self.excute_kaptive) left_layout.addWidget(self.execute_abricate) left_layout.addWidget(self.labe2) # left_layout.addStretch(3) right_frame = QFrame() right_layout = QHBoxLayout(right_frame) right_widget = QScrollArea() right_layout.addWidget(right_widget) scroll_layout = QHBoxLayout(right_widget) scroll_layout.addWidget(self.tableview) # right_layout.addWidget(right_widget) # right_layout.addWidget(self.tableview) right_frame.setFrameShape(QFrame.Box) layout.addWidget(left_frame) layout.addWidget(right_frame) layout.setStretchFactor(left_frame, 3) layout.setStretchFactor(right_frame, 7) self.setLayout(layout)
def initUI(self): cname = QLabel('课程名: ') self.cnameInput = QLineEdit() ctime = QLabel('上课时间: ') self.ctimeInput = QLineEdit() self.ctimeInput.setPlaceholderText('星期一10-11') self.confirmbtn = QPushButton('确认开课') self.confirmbtn.setIcon(QIcon('./image/confirm.png')) self.confirmbtn.setFont(QFont('宋体')) self.confirmbtn.clicked.connect(self.onConfirm) topvbox1 = QVBoxLayout() topvbox1.addWidget(cname) topvbox1.addWidget(ctime) topvbox2 = QVBoxLayout() topvbox2.addWidget(self.cnameInput) topvbox2.addWidget(self.ctimeInput) tophbox = QHBoxLayout() tophbox.addLayout(topvbox1) tophbox.addLayout(topvbox2) tophbox.setStretchFactor(topvbox1, 1) tophbox.setStretchFactor(topvbox2, 3) downhbox = QHBoxLayout() downhbox.addStretch(1) downhbox.addStretch(1) downhbox.addWidget(self.confirmbtn) downhbox.addStretch(1) downhbox.addStretch(1) totalvbox = QVBoxLayout() totalvbox.addLayout(tophbox) totalvbox.addLayout(downhbox) self.setLayout(totalvbox)
def _layoutUI(self): """Initialize the user interface of this :py:class:`FacePanel`. """ # The big picture: # # +--------------------+----------------------------------------+ # |+------------------+|+---------------+ +---------------+ ... | # ||dataInspector |||QDetectorWidget| |QDetectorWidget| | # ||[view] ||| Result | | Result | | # || ||| | | | | # || ||| | | | | # || ||| | | | | # || ||| Controls | | Controls | | # || ||| | | | | # ||[navigator] ||| | | | | # || ||| | | | | # || ||| Selector | | Selector | | # |+------------------+|+---------------+ +---------------+ ... | # +--------------------+----------------------------------------+ layout = QHBoxLayout() layout2 = QVBoxLayout() layout2.addWidget(self._dataInspector) row = QHBoxLayout() row.addWidget(self._processCounter) row.addWidget(QLabel("/")) row.addWidget(self._inputCounter) row.addStretch() layout2.addLayout(row) layout2.addStretch(1) layout.addLayout(layout2) layout.setStretchFactor(layout2, 1) grid = QGridLayout() for i, view in enumerate(self._detectorViews): grid.addWidget(view, i // 2, i % 2) layout.addLayout(grid) layout.setStretchFactor(grid, 1) self.setLayout(layout)
def init_misc_gui(self) -> None: w = QWidget(self) self.setCentralWidget(w) ly = QVBoxLayout() w.setLayout(ly) ly.setSpacing(10) self.title_label = QLabel("Klotski", w) ft = self.title_label.font() ft.setPointSize(20) self.title_label.setFont(ft) self.title_label.setAlignment(Qt.AlignCenter) self.title_label.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)) ly.addWidget(self.title_label) hb = QHBoxLayout() self.board = KLBoard(w) hb.addWidget(self.board) hb.setStretchFactor(self.board, 100) ly.addLayout(hb) # horizontal bottom hbox [ QLabel | QLcdNumber ] hb = QHBoxLayout() # hb.setSpacing( 5 ) # hb.setMargin( 5 ) ml = QLabel("Moves : ", w) ml.setFont(ft) ml.setAlignment(Qt.AlignRight) hb.addWidget(ml) self.move_lcd_nb = QLCDNumber(4, w) self.move_lcd_nb.adjustSize() self.move_lcd_nb.setFixedSize(self.move_lcd_nb.width(), 30) hb.addWidget(self.move_lcd_nb) # hb.setFixedHeight( hb.height() ) ly.addLayout(hb) self.adjustSize()
def __init__(self, *args, **kwargs): super(TransListWidget, self).__init__(*args, **kwargs) main_layout = QHBoxLayout() self.left_menu_widget = LeftMenuWidget() self.download_widget = TransWidget('DOWN') self.upload_widget = TransWidget('UP') self.finished_widget = FinishedWidget() self.stack_widget = QStackedWidget(self) self.stack_widget.addWidget(self.download_widget) self.stack_widget.addWidget(self.upload_widget) self.stack_widget.addWidget(self.finished_widget) main_layout.addWidget(self.left_menu_widget) main_layout.addWidget(self.stack_widget) self.setLayout(main_layout) main_layout.setStretchFactor(self.left_menu_widget, 1) main_layout.setStretchFactor(self.stack_widget, 5) self.left_menu_widget.setObjectName('select_type') self.left_menu_widget.item_click_signal.connect(self.stack_widget.setCurrentIndex) self.upload_widget.item_count_signal.connect(self.update_left_menu) self.download_widget.item_count_signal.connect(self.update_left_menu)
def mainUI(self): layout = QHBoxLayout() left_panel = QWidget() left_layout = QVBoxLayout(left_panel) left_layout.addWidget(QLabel('选择化合物')) self.combox = QComboBox() self.combox.addItems(self.dff.keys()) self.combox.setCurrentIndex(1) left_layout.addWidget(self.combox) self.btn = QPushButton('执行(默认前20)') self.btn.setFixedSize(225, 30) left_layout.addWidget(self.btn) right_panel = QWidget() right_layout = QHBoxLayout(right_panel) self.res = QTextEdit() right_layout.addWidget(self.res) layout.addWidget(left_panel) layout.setStretchFactor(left_panel, 2) layout.addWidget(right_panel) layout.setStretchFactor(right_panel, 8) self.setLayout(layout)
def initUI(self, onames, fnames): self.viewO = ExamViewWindow(onames) self.viewC = ExamViewWindow(fnames) self.cancelB = QPushButton("&cancel") self.maxNormB = QPushButton("&max/norm") self.cancelB.clicked.connect(self.reject) self.maxNormB.clicked.connect(self.swapMaxNorm) self.originalGB = QGroupBox("Original") self.collideGB = QGroupBox("Collision") self.optionTW = QTabWidget() self.initTabs() ob = QHBoxLayout() ob.addWidget(self.viewO) self.originalGB.setLayout(ob) cb = QHBoxLayout() cb.addWidget(self.viewC) self.collideGB.setLayout(cb) grid = QGridLayout() grid.addWidget(self.maxNormB, 1, 4) grid.addWidget(self.cancelB, 10, 4) grid.addWidget(self.optionTW, 2, 1, 8, 4) self.pane = QWidget() self.pane.setLayout(grid) hb = QHBoxLayout() hb.addWidget(self.originalGB) hb.setStretchFactor(self.originalGB, 1) hb.addWidget(self.collideGB) hb.setStretchFactor(self.collideGB, 1) hb.addWidget(self.pane) self.setLayout(hb) self.show()
def initUI(self): self.resize(400, 200) vbox = QVBoxLayout() # 第一行 hbox = QHBoxLayout() label = QLabel('姓名:', self) hbox.addWidget(label) editBox = QLineEdit(self) hbox.addWidget(editBox) hbox.setStretchFactor(editBox, 2) # 设定三个控件横向拉伸比例为2:1:5 label = QLabel('年龄:', self) hbox.addWidget(label) editBox = QLineEdit(self) hbox.addWidget(editBox) hbox.setStretchFactor(editBox, 1) label = QLabel('家庭住址:', self) hbox.addWidget(label) editBox = QLineEdit(self) hbox.addWidget(editBox) hbox.setStretchFactor(editBox, 5) vbox.addLayout(hbox) # 第二行 hbox = QHBoxLayout() label = QLabel('电话:', self) hbox.addWidget(label) # label按需分配,如果没有指定比例,QLineEdit平均分配 editBox = QLineEdit(self) hbox.addWidget(editBox) label = QLabel('邮箱:', self) hbox.addWidget(label) editBox = QLineEdit(self) hbox.addWidget(editBox) vbox.addLayout(hbox) # 第三行 hbox = QHBoxLayout() label = QLabel('身份证号:', self) hbox.addWidget(label) editBox = QLineEdit(self) hbox.addWidget(editBox) vbox.addLayout(hbox) # 第四行 hbox = QHBoxLayout() hbox.addStretch(2) # 设定两个按钮的横向布局为 2 : 确定 : 取消 : 1 btn = QPushButton('确定') hbox.addWidget(btn) btn = QPushButton('取消') hbox.addWidget(btn) hbox.addStretch(1) vbox.addLayout(hbox) vbox.addStretch(1) self.setLayout(vbox) self.show()
def initUI(self): self.resize(800, 600) vbox = QVBoxLayout() hbox = QHBoxLayout() subvbox = QVBoxLayout() subhbox = QHBoxLayout() label = QLabel('当前状态:', self) subhbox.addWidget(label) self.stateNameEditBox = QLineEdit(self) self.stateNameEditBox.setReadOnly(True) subhbox.addWidget(self.stateNameEditBox) subhbox.setStretchFactor(self.stateNameEditBox, 2) self.qLineImmDict[self.stateNameEditBox] = 'currStateName' subvbox.addLayout(subhbox) subhbox = QHBoxLayout() label = QLabel('光标位置:', self) subhbox.addWidget(label) self.cursorPosEditBox = QLineEdit(self) self.cursorPosEditBox.setReadOnly(True) self.cursorPosEditBox.resize(100, 30) subhbox.addWidget(self.cursorPosEditBox) subvbox.addLayout(subhbox) self.qLineImmDict[self.cursorPosEditBox] = 'cursorPos' subhbox = QHBoxLayout() label = QLabel('上屏串:', self) subhbox.addWidget(label) self.completedEditBox = QLineEdit(self) self.completedEditBox.setReadOnly(True) subhbox.addWidget(self.completedEditBox) subvbox.addLayout(subhbox) # 行--------------------- self.qLineImmDict[self.completedEditBox] = 'Completed' subhbox = QHBoxLayout() label = QLabel('输入串:', self) subhbox.addWidget(label) self.compositionEditBox = QLineEdit(self) self.compositionEditBox.setReadOnly(True) subhbox.addWidget(self.compositionEditBox) self.qLineImmDict[self.compositionEditBox] = 'Composition' subvbox.addLayout(subhbox) subhbox = QHBoxLayout() label = QLabel('输入串显示为:', self) subhbox.addWidget(label) self.compDisplayEditBox = QLineEdit(self) self.compDisplayEditBox.setReadOnly(True) subhbox.addWidget(self.compDisplayEditBox) subvbox.addLayout(subhbox) # 行--------------------- self.qLineImmDict[self.compDisplayEditBox] = 'CompDisplay' hbox.addLayout(subvbox) subvbox = QVBoxLayout() label = QLabel('候选串', self) subvbox.addWidget(label) self.candList = QListWidget(self) subvbox.addWidget(self.candList) hbox.addLayout(subvbox) vbox.addLayout(hbox) hbox = QHBoxLayout() label = QLabel('在此输入:', self) hbox.addWidget(label) self.editorBox = QLineEdit4Ime(self.getIMM(), self) hbox.addWidget(self.editorBox) vbox.addLayout(hbox) # 行--------------------- vbox.addStretch(1) self.setLayout(vbox) self.show()
class NewGameWidget(Tab): def __init__(self, parent=None): super(NewGameWidget, self).__init__(parent) self.parent = parent self.initUI() def initUI(self): # Setup Layouts self.widgetLayout = QHBoxLayout(self) self.leftColumnLayout = QVBoxLayout() self.rightColumnLayout = QVBoxLayout() self.widgetLayout.addLayout(self.leftColumnLayout) self.widgetLayout.addLayout(self.rightColumnLayout) self.gameStatsBox = None # Players GroupBox self.playersGroupBox = QGroupBox(self) self.rightColumnLayout.addWidget(self.playersGroupBox) self.widgetLayout.setStretchFactor(self.rightColumnLayout, 1) self.populatePlayersGroupBox() # Game GroupBox self.gameGroupBox = QGroupBox(self) self.leftColumnLayout.addWidget(self.gameGroupBox) self.widgetLayout.setStretchFactor(self.leftColumnLayout, 3) self.populateGamesGroupBox() # self.retranslateUI() def retranslateUI(self): self.gameGroupBox.setTitle( i18n("NewGameWidget", "Games")) self.updateGameInfo() self.playersGroupBox.setTitle( i18n("NewGameWidget", "Players")) self.availablePlayersGroup.setTitle( i18n("NewGameWidget", "Available Players")) self.newPlayerButton.setText( i18n("NewGameWidget", "New Player")) self.inGameGroup.setTitle(i18n( "NewGameWidget", "Selected Players")) self.startGameButton.setText( i18n("NewGameWidget", "Play!")) self.resumeGroup.retranslateUI() self.gameStatsBox.retranslateUI() def populateGamesGroupBox(self): self.gameGroupBoxLayout = QVBoxLayout(self.gameGroupBox) self.gameComboBox = QComboBox(self.gameGroupBox) self.gameGroupBoxLayout.addWidget(self.gameComboBox) self.gameDescriptionLabel = QLabel(self.gameGroupBox) self.resumeGroup = ResumeBox(self.parent) self.resumeGroup.restartRequested.connect(self.restartGame) # self.gameRulesBrowser = QTextBrowser(self.gameGroupBox) self.gameGroupBoxLayout.addWidget(self.gameDescriptionLabel) self.gameGroupBoxLayout.addWidget(self.resumeGroup) # self.gameGroupBoxLayout.addWidget(self.gameRulesBrowser) # self.gameGroupBoxLayout.addStretch() self.games = db.getAvailableGames() for game in sorted(self.games.keys()): self.gameComboBox.addItem(game) lastgame = db.getLastGame() if lastgame: self.gameComboBox.setCurrentIndex( self.gameComboBox.findText(lastgame)) self.gameStatsBox = None # self.updateGameInfo() self.gameComboBox.currentIndexChanged.connect(self.updateGameInfo) def updateGameInfo(self, foo=0): game = str(self.gameComboBox.currentText()) description = "2 - {} {}\n\n{}".format( self.games[game]['maxPlayers'], i18n("NewGameWidget", 'players'), self.games[game]['description']) self.gameDescriptionLabel.setText(description) # self.gameRulesBrowser.setText("{}".format(self.games[game]['rules'])) # self.gameStatsBox.update(game) if self.gameStatsBox is not None: self.gameGroupBoxLayout.removeWidget(self.gameStatsBox) # print("UGI deleting") self.gameStatsBox.deleteLater() self.gameStatsBox = QSFactory.createQS(game, None, self) self.gameGroupBoxLayout.addWidget(self.gameStatsBox) self.updateStats() self.resumeGroup.changeGame(game) def updateStats(self): if self.gameStatsBox: try: self.gameStatsBox.update(self.gameComboBox.currentText( ), self.playersInGameList.model().retrievePlayers()) except TypeError: # Should not happen, but silently ignore pass def populatePlayersGroupBox(self): self.playersGroupBoxLayout = QVBoxLayout( self.playersGroupBox) # Start button self.startGameButton = QPushButton(self) self.startGameButton.clicked.connect(self.createNewGame) self.playersGroupBoxLayout.addWidget(self.startGameButton) self.inGameGroup = QGroupBox(self) self.playersGroupBoxLayout.addWidget(self.inGameGroup) self.inGameGroupLayout = QVBoxLayout(self.inGameGroup) self.playersInGameList = PlayerList(None, self.inGameGroup) self.inGameGroup.setMaximumHeight(280) self.inGameGroupLayout.addWidget(self.playersInGameList) self.playersButtonsLayout = QHBoxLayout() self.playersGroupBoxLayout.addLayout(self.playersButtonsLayout) self.newPlayerButton = QPushButton(self.playersGroupBox) self.newPlayerButton.clicked.connect(self.createNewPlayer) self.playersButtonsLayout.addWidget(self.newPlayerButton) self.availablePlayersGroup = QGroupBox(self) self.playersGroupBoxLayout.addWidget(self.availablePlayersGroup) self.availablePlayersGroupLayout = QVBoxLayout( self.availablePlayersGroup) self.playersAvailableList = PlayerList(None, self.playersGroupBox) self.availablePlayersGroupLayout.addWidget(self.playersAvailableList) # self.availablePlayersGroupLayout.addStretch() self.playersAvailableList.doubleclickeditem.connect( self.playersInGameList.addItem) self.playersInGameList.doubleclickeditem.connect( self.playersAvailableList.addItem) self.playersInGameList.changed.connect(self.updateStats) for p in db.getPlayers(): if p['favourite']: self.playersInGameList.addItem(p['nick']) else: self.playersAvailableList.addItem(p['nick']) def createNewGame(self): game = str(self.gameComboBox.currentText()) maxPlayers = self.games[game]['maxPlayers'] players = self.playersInGameList.model().retrievePlayers() tit = i18n("NewGameWidget", "New Match") if len(players) < 2: msg = i18n( "NewGameWidget", "At least 2 players are needed to play") QMessageBox.warning(self, tit, msg) elif len(players) > maxPlayers: msg = i18n("NewGameWidget", 'The maximum number of players is') QMessageBox.warning(self, tit, "{} {}".format(msg, maxPlayers)) else: matchTab = GameWidgetFactory.createGameWidget( game, players, self.parent) if matchTab: matchTab.closeRequested.connect(self.parent.removeTab) matchTab.restartRequested.connect(self.restartGame) self.parent.newTab(matchTab, game) else: QMessageBox.warning(self, tit, i18n("NewGameWidget", "Widget not implemented")) return def restartGame(self, gamewidget): players = gamewidget.players game = gamewidget.game self.parent.removeTab(gamewidget) matchTab = GameWidgetFactory.createGameWidget( game, players, self.parent) if matchTab: matchTab.closeRequested.connect(self.parent.removeTab) matchTab.restartRequested.connect(self.restartGame) self.parent.newTab(matchTab, game) else: QMessageBox.warning(self, tit, i18n("NewGameWidget", "Widget not implemented")) return def createNewPlayer(self): npd = NewPlayerDialog(self) npd.addedNewPlayer.connect(self.addPlayer) npd.exec_() def addPlayer(self, player): player = str(player) self.playersAvailableList.model().addPlayer(player) def showEvent(self, event): if (hasattr(self, 'gameStatsBox') and hasattr(self, 'gameComboBox') and self.gameComboBox.currentText()): self.gameStatsBox.update(self.gameComboBox.currentText()) self.resumeGroup.changeGame(self.gameComboBox.currentText()) return QWidget.showEvent(self, event)