def setup_datetime_box(self): """Setup the datetime edit widget and a label.""" self.datetime_edit = datetime_edit = QDateTimeEdit() datetime_edit.setCalendarPopup(True) datetime_edit.setDisplayFormat("yyyy-MM-dd hh:mm") datetime_edit.setKeyboardTracking(False) datetime_edit.dateTimeChanged.connect(self.validate_datetime) datetime_edit.setAlignment(Qt.AlignLeft) ft = datetime_edit.font() ft.setPointSize(ft.pointSize() + 4) datetime_edit.setFont(ft) label = QLabel('Start time :') label.setFont(ft) # Setup the layout datetime_box = ColoredFrame() datetime_box.set_background_color('window') layout = QHBoxLayout(datetime_box) layout.setContentsMargins(5, 10, 5, 10) layout.setSpacing(15) layout.addWidget(label) layout.addWidget(datetime_edit) layout.setStretch(1, 100) return datetime_box
def init_ui(self): """Initializes the window.""" self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.plot_canvas = PlotCanvas(self, width=5, height=4) self.plot_canvas.move(0, 0) # sp_left = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) # sp_left.setHorizontalStretch(3) list_widget = QListWidget() list_widget.addItems(self.weights1.tensors.keys()) list_widget.itemClicked.connect(self.item_clicked) # list_widget.setSizeAdjustPolicy(QSizePolicy.Maximum, QSizePolicy.Preferred) list_widget.setMaximumWidth(300) # sp_right = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) # sp_right.setHorizontalStretch(0.2) # list_widget.setSizeAdjustPolicy(sp_right) window_layout = QHBoxLayout(self) window_layout.setStretch(0, 7) window_layout.setStretch(0, 3) window_layout.addWidget(self.plot_canvas) window_layout.addWidget(list_widget) self.setLayout(window_layout) self.show()
def initUI(self, windowType): self.setStyleSheet(""" #cmdLine, #bar, #bar > * { border: 0px; background: #070707; font-family: "Pro Font"; font-size: 10px; color: white; min-height: 17px } """) self.setWindowTitle('shower') self.setAttribute(Qt.WA_DeleteOnClose) vbox = QVBoxLayout() self.setLayout(vbox) vbox.setContentsMargins(0, 0, 0, 0) vbox.setSpacing(0) bar = QWidget() bar.setObjectName('bar') hbox = QHBoxLayout() hbox.setContentsMargins(2, 0, 0, 0) hbox.setSpacing(0) bar.setLayout(hbox) vbox.addWidget(bar) self.urlLabel = QLabel() self.urlLabel.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Preferred) self.urlLabel.setTextFormat(Qt.RichText) hbox.addWidget(self.urlLabel) hbox.setStretch(0, 1) self.progressLabel = QLabel() self.progressLabel.setTextFormat(Qt.RichText) hbox.addWidget(self.progressLabel) self.cmdLine = QLineEdit() self.cmdLine.setObjectName('cmdLine') vbox.addWidget(self.cmdLine) self.webView = QWebEngineView() self.webView.setPage(BrowserPage(self)) vbox.addWidget(self.webView) self.cmdLine.returnPressed.connect(self.handleCommand) self.webView.page().linkHovered.connect(self.onLinkHovered) self.webView.page().urlChanged.connect(self.urlChanged) self.webView.page().titleChanged.connect(self.onTitleChanged) self.webView.page().loadProgress.connect(self.onLoadProgress) self.webView.page().loadStarted.connect(self.onLoadStarted) self.webView.page().loadFinished.connect(self.onLoadFinished) self.urlChanged.connect(self.onUrlChanged) self.addShortcut("Alt+Left", lambda: self.webView.page().triggerAction(QWebEnginePage.Back)) self.addShortcut("Alt+Right", lambda: self.webView.page().triggerAction(QWebEnginePage.Forward)) self.addShortcut("Ctrl+R", lambda: self.webView.page().triggerAction(QWebEnginePage.Reload)) self.addShortcut("Ctrl+Shift+R", lambda: self.webView.page().triggerAction(QWebEnginePage.ReloadAndBypassCache)) self.stopShortcut = self.addShortcut("Esc", lambda: self.webView.page().triggerAction(QWebEnginePage.Stop)) self.addShortcut("Ctrl+W", lambda: self.close()) self.addShortcut("Ctrl+L", lambda: self.beginEnteringCommand(None)) self.addShortcut("Ctrl+K", lambda: self.beginEnteringCommand('? ')) self.addShortcut("Ctrl+/", lambda: self.beginEnteringCommand('/ ')) self.addShortcut("Ctrl+U", lambda: self.toggleSource())
def init_topic_tracklist(self): self.topic_tracklist = QListView() self.topic_tracklist_label = QLabel("Topic Track List") self.topic_tracklist_model = QStandardItemModel() self.topic_tracklist.setModel(self.topic_tracklist_model) topic_tracklist_buttons = QWidget() topic_tracklist_buttons_layout = QHBoxLayout() topic_tracklist_buttons_layout.setSpacing(0) topic_tracklist_buttons_layout.setContentsMargins(0, 0, 0, 0) topic_tracklist_buttons.setLayout(topic_tracklist_buttons_layout) self.topic_tracklist_add_button = QPushButton("+") self.topic_tracklist_del_button = QPushButton("-") self.topic_tracklist_conf_button = QPushButton("confirm") self.topic_analyze_button = QPushButton("analyze") topic_tracklist_buttons_layout.addWidget( self.topic_tracklist_add_button) topic_tracklist_buttons_layout.addWidget( self.topic_tracklist_del_button) topic_tracklist_buttons_layout.addStretch(20) topic_tracklist_buttons_layout.addWidget( self.topic_tracklist_conf_button) topic_tracklist_buttons_layout.addWidget(self.topic_analyze_button) topic_tracklist_buttons_layout.setStretch(0, 6) topic_tracklist_buttons_layout.setStretch(1, 6) topic_tracklist_buttons_layout.setStretch(2, 6) topic_tracklist_buttons_layout.setStretch(3, 6) self.topic_tracklist_widget = QWidget() topic_tracklist_layout = QVBoxLayout() self.topic_tracklist_widget.setLayout(topic_tracklist_layout) topic_tracklist_layout.addWidget(self.topic_tracklist_label) topic_tracklist_layout.addWidget(self.topic_tracklist) topic_tracklist_layout.addWidget(topic_tracklist_buttons)
class DateRangeSelectorView(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent) self._setupUi() def _setupUi(self): self.resize(259, 32) self.horizontalLayout = QHBoxLayout(self) self.horizontalLayout.setContentsMargins(0, 0, 0, 0) self.prevButton = QPushButton(self) icon = QIcon() icon.addPixmap(QPixmap(":/nav_left_9"), QIcon.Normal, QIcon.Off) self.prevButton.setIcon(icon) self.horizontalLayout.addWidget(self.prevButton) self.typeButton = QPushButton("<date range>") sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.typeButton.sizePolicy().hasHeightForWidth()) self.typeButton.setSizePolicy(sizePolicy) self.typeButton.setMinimumSize(QSize(0, 0)) self.typeButton.setMaximumSize(QSize(16777215, 16777215)) self.typeButton.setIconSize(QSize(6, 6)) self.horizontalLayout.addWidget(self.typeButton) self.nextButton = QPushButton(self) icon1 = QIcon() icon1.addPixmap(QPixmap(":/nav_right_9"), QIcon.Normal, QIcon.Off) self.nextButton.setIcon(icon1) self.horizontalLayout.addWidget(self.nextButton) self.horizontalLayout.setStretch(1, 1)
def init_ui(self): centralWidget = QWidget() info_zone = QWidget() central_layout = QHBoxLayout() info_layout = QVBoxLayout() # central layout central_layout.addWidget(info_zone) central_layout.addWidget(self.tab_zone) central_layout.setStretch(0, 1) central_layout.setStretch(1, 6) # info layout info_layout.addWidget(self.button_zone) info_layout.addWidget(self.edit_zone) info_layout.setStretch(0, 1) info_layout.setStretch(1, 15) # end self.setCentralWidget(centralWidget) centralWidget.setLayout(central_layout) info_zone.setLayout(info_layout) self.setStatusBar(QStatusBar()) self.setGeometry(300, 300, 300, 150)
class Minesweeper(QMainWindow): def __init__(self): super(Minesweeper, self).__init__() self.initUI() def initUI(self): self.setWindowTitle('扫雷') self.resize(600, 400) self.level = Level(self) self.setCentralWidget(self.level) self.show() def setUI(self): self.centralWidget = QWidget(self) self.board = Board(self) self.aside = Aside(self) self.hbox = QHBoxLayout(self.centralWidget) # self.hbox = QSplitter(Qt.Horizontal) # self.hbox.addStretch(1) self.hbox.addWidget(self.board) self.hbox.addWidget(self.aside) # self.hbox.addStretch(1) self.hbox.setStretch(0, 6) self.hbox.setStretch(1, 4) self.setCentralWidget(self.centralWidget) self.board.start()
def setupUi(self): self.setObjectName("LogInspector") self.setWindowTitle("LogInspector") self.resize(1280, 900) self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMinMaxButtonsHint) self.setWindowIcon(QIcon("assets/Magnifying_glass_icon.png")) # MainWindow.showMaximized() self.createFileTree() self.createButtonColumn() self.formatButtonColumn() self.createBottomToolbar() self.figureLayout = QVBoxLayout() self.figureLayout.addWidget(self.canvas) self.figureLayout.addLayout(self.toolLayout) self.figureLayout.setStretchFactor(self.canvas, 1) layout = QHBoxLayout() layout.addLayout(self.controlLayout) layout.addLayout(self.figureLayout) layout.setStretch(1, 1) widget = QWidget() widget.setLayout(layout) self.setCentralWidget(widget) # self.resize(1280, 900) self.resize(1450, 1000) self.setAcceptDrops(True)
def __init__(self): QWidget.__init__(self) self.setObjectName('board') self.setStyleSheet(''' #board { background: #fff; color: #333; } ''') layout = QHBoxLayout() todostore = TodoStore() columns = [ TodoColumn(todostore), InProgressColumn(todostore), DoneColumn(todostore), CancelColumn(todostore) ] for idx, column in enumerate(columns): layout.addWidget(ScrollBar(column)) layout.setStretch(idx, 1) for todo in todostore.get_todos(): if todo.status == 'CANCELLED': columns[3].add(DropZoneLabel(todo)) elif todo.is_completed: columns[2].add(DropZoneLabel(todo)) elif todo.status == 'IN-PROCESS': columns[1].add(DropZoneLabel(todo)) else: columns[0].add(DropZoneLabel(todo)) self.setLayout(layout)
def initUI(self): self.btn_1 = QPushButton('1', self) self.btn_2 = QPushButton('2', self) self.btn_3 = QPushButton('3', self) self.btn_4 = QPushButton('4', self) left_layout = QVBoxLayout() left_layout.addWidget(self.btn_1) left_layout.addWidget(self.btn_2) left_layout.addWidget(self.btn_3) left_layout.addWidget(self.btn_4) left_layout.addStretch(5) left_layout.setSpacing(20) left_widget = QWidget() left_widget.setLayout(left_layout) self.right_widget = QTabWidget() self.right_widget.tabBar().setObjectName("mainTab") main_layout = QHBoxLayout() main_layout.addWidget(left_widget) main_layout.addWidget(self.right_widget) main_layout.setStretch(0, 40) main_layout.setStretch(1, 200) main_widget = QWidget() main_widget.setLayout(main_layout) self.setCentralWidget(main_widget) self.btn_1.clicked.connect(lambda: HUAWEI.Test(self))
def fileSelectShowKfpkg(self, index, name): if index==0 and self.fileSelectWidget_Type(0) == "kfpkg": #only one kgpkg before self.fileSelectWidget_Path(index).setText(name) else:# have bin file before, remove all and add one for kfpkg for i in range(len(self.fileSelectWidgets)): if self.fileSelectWidget_Type(i)=="button": self.fileSelectWidgets[i][3].clicked.disconnect() self.fileSelectWidgets[i][4].clicked.disconnect() else: self.fileSelectWidget_Button(i).clicked.disconnect() # self.fileSelectLayout.removeWidget(self.fileSelectWidget_Widget(i)) self.fileSelectWidget_Widget(i).setParent(None) self.fileSelectWidgets.clear() oneFilePathWidget = QWidget() oneFilePathWidgetLayout = QHBoxLayout() oneFilePathWidget.setLayout(oneFilePathWidgetLayout) filePathWidget = QLineEdit() openFileButton = QPushButton(tr("OpenFile")) oneFilePathWidgetLayout.addWidget(filePathWidget) oneFilePathWidgetLayout.addWidget(openFileButton) oneFilePathWidgetLayout.setStretch(0, 3) oneFilePathWidgetLayout.setStretch(1, 1) self.fileSelectLayout.addWidget(oneFilePathWidget) self.fileSelectWidgets.append(["kfpkg", oneFilePathWidget, oneFilePathWidgetLayout, filePathWidget, None, openFileButton]) openFileButton.clicked.connect(lambda:self.selectFile(filePathWidget)) filePathWidget.setText(name)
def data_local(self): fileName, fileType = QFileDialog.getOpenFileName( self, '选择文件', '', '*.csv') if fileName != None and fileName != "": global_var.filePath = fileName self.dialog = QDialog() self.dialog.resize(400, 40) hbox_u = QHBoxLayout() hbox_d = QHBoxLayout() vbox = QVBoxLayout() label = QLabel("数据集命名:") self.lineText = QLineEdit() self.btn_ok = QPushButton("确定") self.btn_cancel = QPushButton("取消") self.btn_ok.clicked.connect(self.on_ok_click) self.btn_cancel.clicked.connect(self.on_cancel_click) hbox_u.addWidget(label) hbox_u.addWidget(self.lineText) hbox_u.setStretch(0, 1) hbox_u.setStretch(1, 2) hbox_d.addStretch(2) hbox_d.addWidget(self.btn_ok) hbox_d.addWidget(self.btn_cancel) vbox.addLayout(hbox_u) vbox.addLayout(hbox_d) self.dialog.setLayout(vbox) self.dialog.setWindowModality(Qt.ApplicationModal) self.dialog.exec_()
def addAddFileWidget(self): if len(self.fileSelectWidgets) == 2: removeButton0 = QPushButton() removeButton0.setProperty("class", "remove_file_selection") self.fileSelectWidgets[0][2].addWidget(removeButton0) self.fileSelectWidgets[0].append(removeButton0) removeButton0.clicked.connect(lambda:self.removeFileSelection(removeButton0)) oneFilePathWidget = QWidget() oneFilePathWidgetLayout = QHBoxLayout() oneFilePathWidget.setLayout(oneFilePathWidgetLayout) filePathWidget = QLineEdit() fileBurnAddrWidget = QLineEdit("0x00000") fileBurnEncCheckbox = QCheckBox(tr("Prefix")) openFileButton = QPushButton(tr("OpenFile")) removeButton = QPushButton() removeButton.setProperty("class", "remove_file_selection") oneFilePathWidgetLayout.addWidget(filePathWidget) oneFilePathWidgetLayout.addWidget(fileBurnAddrWidget) oneFilePathWidgetLayout.addWidget(fileBurnEncCheckbox) oneFilePathWidgetLayout.addWidget(openFileButton) oneFilePathWidgetLayout.addWidget(removeButton) oneFilePathWidgetLayout.setStretch(0, 4) oneFilePathWidgetLayout.setStretch(1, 2) oneFilePathWidgetLayout.setStretch(2, 1) oneFilePathWidgetLayout.setStretch(3, 2) # oneFilePathWidgetLayout.setStretch(4, 1) index = len(self.fileSelectWidgets)-1 self.fileSelectWidgets.insert(index, ["bin", oneFilePathWidget, oneFilePathWidgetLayout, filePathWidget, fileBurnAddrWidget, openFileButton, fileBurnEncCheckbox, removeButton]) self.fileSelectLayout.insertWidget(index, oneFilePathWidget) openFileButton.clicked.connect(lambda:self.selectFile(filePathWidget)) removeButton.clicked.connect(lambda:self.removeFileSelection(removeButton))
def __init__(self, parent=None): super(FilteringWidget, self).__init__(parent) self._filter = {} self.label = QLabel(self) self.label.setWordWrap(True) self.label.setText(self.filterToText(self._filter)) self.changeFilter = QPushButton(self) self.changeFilter.setText("Upravit filtr") self.changeFilter.clicked.connect(self.on_changeFilter_clicked) self.removeFilter = QPushButton(self) self.removeFilter.setText("Smazat filtr") self.removeFilter.clicked.connect(self.on_removeFilter_clicked) layout = QHBoxLayout() layout.addWidget(QLabel("Aktivní filtr: ")) layout.addWidget(self.label) layout.setStretch(1, 1) layout.addWidget(self.changeFilter) layout.addWidget(self.removeFilter) layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) self.setMinimumHeight(60)
def on_btn_local_click(self): """ 从本地文件导入数据集 :return: """ fileName, fileType = QFileDialog.getOpenFileName( self, '选择文件', '', '*.csv') if fileName is not None and fileName != "": global_var.currentData.type = global_var.DataSetType.IN global_var.filePath = fileName self.dialog = QDialog() self.dialog.resize(400, 40) hbox_u = QHBoxLayout() hbox_d = QHBoxLayout() vbox = QVBoxLayout() label = QLabel("数据集命名:") self.lineText = QLineEdit() self.btn_ok = QPushButton("确定") self.btn_cancel = QPushButton("取消") self.btn_ok.clicked.connect(self.on_ok_click) self.btn_cancel.clicked.connect(self.on_cancel_click) hbox_u.addWidget(label) hbox_u.addWidget(self.lineText) hbox_u.setStretch(0, 1) hbox_u.setStretch(1, 2) hbox_d.addStretch(2) hbox_d.addWidget(self.btn_ok) hbox_d.addWidget(self.btn_cancel) vbox.addLayout(hbox_u) vbox.addLayout(hbox_d) self.dialog.setLayout(vbox) self.dialog.exec_()
def __init__(self, pluginsHelp: dict, parent=None, icon=None): QWidget.__init__(self, parent) CustomTitleBarWindowMixin.__init__(self, init=True, title=_("Help")) self.resize(800, 700) layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.contentWidget.setLayout(layout) # self.setLayout(layout) itemList = QListWidget() itemList.setProperty("class", "helpList") tabs = QStackedWidget() layout.addWidget(itemList) layout.addWidget(tabs) layout.setStretch(0, 1) layout.setStretch(1, 4) for name, help in pluginsHelp.items(): tab = QWidget() tab.setProperty("class", "helpTab") tabLayout = QVBoxLayout() tab.setLayout(tabLayout) if type(help) == str: tabLabel = ScrollLabel(help) else: tabLabel = help tabLayout.addWidget(tabLabel) tabs.addWidget(tab) itemList.addItem(name) itemList.setCurrentRow(0) itemList.currentRowChanged.connect( lambda idx: tabs.setCurrentIndex(idx)) self.show()
class Tetris(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): self.tboard = Board(self) self.slide = Slide(self) self.centralWidget = QWidget(self) self.hbox = QHBoxLayout(self.centralWidget) self.hbox.setContentsMargins(6, 6, 6, 6) self.hbox.addWidget(self.tboard) self.hbox.addWidget(self.slide) self.hbox.setStretch(0, 2) self.hbox.setStretch(1, 1) self.setCentralWidget(self.centralWidget) self.setWindowTitle('俄罗斯方块') self.setWindowIcon(QIcon('web.png')) self.setFixedSize(380, 500) self.center() self.show() self.tboard.start() def center(self): screen = QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
class DateRangeSelectorView(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent) self._setupUi() def _setupUi(self): self.resize(259, 32) self.horizontalLayout = QHBoxLayout(self) self.horizontalLayout.setContentsMargins(0, 0, 0, 0) self.prevButton = QPushButton(self) icon = QIcon() icon.addPixmap(QPixmap(":/nav_left_9"), QIcon.Normal, QIcon.Off) self.prevButton.setIcon(icon) self.horizontalLayout.addWidget(self.prevButton) self.typeButton = QPushButton("<date range>") sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.typeButton.sizePolicy().hasHeightForWidth()) self.typeButton.setSizePolicy(sizePolicy) self.typeButton.setMinimumSize(QSize(0, 0)) self.typeButton.setMaximumSize(QSize(16777215, 16777215)) self.typeButton.setIconSize(QSize(6, 6)) self.horizontalLayout.addWidget(self.typeButton) self.nextButton = QPushButton(self) icon1 = QIcon() icon1.addPixmap(QPixmap(":/nav_right_9"), QIcon.Normal, QIcon.Off) self.nextButton.setIcon(icon1) self.horizontalLayout.addWidget(self.nextButton) self.horizontalLayout.setStretch(1, 1)
def _build_layout(self): layoutTop = QVBoxLayout() words = QWidget() wordsLayout = QHBoxLayout() wordsLayout.addWidget(self.labelActiveWord) wordsLayout.addWidget(self.labelOtherWords) wordsLayout.setStretch(0, 0) wordsLayout.setStretch(1, 1) words.setLayout(wordsLayout) buttons = QWidget() btnLayout = QHBoxLayout() btnLayout.addWidget(self.quitButton) btnLayout.addWidget(self.restartButton) buttons.setLayout(btnLayout) self.tableResults.setRowCount(2) self.tableResults.setColumnCount(2) layoutTop.addWidget(words) layoutTop.addWidget(self.wordBox) layoutTop.addWidget(self.tableResults) layoutTop.addWidget(buttons) self.tableResults.hide() return layoutTop
def init(self, compare_result): if compare_result == None: return #数据 different_dirs_cnt = compare_result["different_dirs_cnt"] different_files_cnt = compare_result["different_files_cnt"] treedata1 = compare_result["only_dir1_tree"] treedata2 = compare_result["only_dir2_tree"] treedata3 = compare_result["modified_tree"] #显示结果数据 self.different_dir_label = QLabel("不同的文件夹个数:" + str(different_dirs_cnt)) self.different_file_label = QLabel("不同的文件个数:" + str(different_files_cnt)) ext_info = { "path_dir1": compare_result["path_dir1"], "path_dir2": compare_result["path_dir2"], } self.tree1 = ResultTreeWidget(treedata1, ext_info) self.tree2 = ResultTreeWidget(treedata2, ext_info) self.tree3 = ResultTreeWidget(treedata3, ext_info) self.tree1.setFixedWidth(450) self.tree2.setFixedWidth(450) self.tree3.setFixedWidth(450) backButton = QPushButton('返回') backButton.clicked.connect(self.onBackButtonClick) exportButton = QPushButton("导出编辑结果") exportButton.setStyleSheet("background-color: #00FF7F") exportButton.clicked.connect(self.onExportButtonClick) buttonBox = QWidget() buttonBox_layout = QHBoxLayout() buttonBox.setLayout(buttonBox_layout) buttonBox_layout.addWidget(backButton) buttonBox_layout.addWidget(exportButton) buttonBox_layout.setStretch(0, 1) buttonBox_layout.setStretch(1, 2) #编辑结果数据 from editWidget import EditWidget self.editWidget = EditWidget(ext_info) #主layout main_layout = QHBoxLayout() result_show_widget = QWidget() main_layout.addWidget(result_show_widget) main_layout.addWidget(self.editWidget) #左侧layout left_layout = QVBoxLayout() left_layout.addWidget(self.different_dir_label) left_layout.addWidget(self.different_file_label) left_layout.addWidget(self.tree1) left_layout.addWidget(self.tree2) left_layout.addWidget(self.tree3) left_layout.addWidget(buttonBox) result_show_widget.setLayout(left_layout) self.setLayout(main_layout)
def init_ui(self) -> None: main_layout = QHBoxLayout(self) main_layout.setContentsMargins(0, 0, 0, 0) right_layout = QVBoxLayout() self.right_text_box.document().setMaximumBlockCount(100) self.right_text_box.setFont(QFont('Consolas')) self.right_text_box.setFontPointSize(10) self.right_text_box.setReadOnly(True) bottom_right_layout = QHBoxLayout() bottom_right_layout.addWidget(self.summary) bottom_right_buttons_layout = QVBoxLayout() self.button_table.clicked.connect(self.on_button_table_clicked) bottom_right_buttons_layout.addWidget(self.button_table) for i in range(5, 9): t = f'Set Expedition Fleet #{i}' b = self.add_button(t, self.select_expedition_fleet, str(i)) bottom_right_buttons_layout.addWidget(b) bottom_right_layout.addLayout(bottom_right_buttons_layout) bottom_right_layout.setStretch(0, 0) bottom_right_layout.setStretch(1, 1) right_layout.addWidget(self.right_text_box) right_layout.addLayout(bottom_right_layout) right_layout.setStretch(0, 1) right_layout.setStretch(1, 0) main_layout.addWidget(self.fleet_table) main_layout.addLayout(right_layout) main_layout.setStretch(0, 0) main_layout.setStretch(1, 1) self.setLayout(main_layout)
def fileSelectShowBin(self, index, name, addr=None, prefix=None, prefixAuto=False, closeButton=False ): if index==0 and self.fileSelectWidget_Type(0) == "kfpkg": #only one kgpkg before self.fileSelectWidget_Button(index).clicked.disconnect() # self.fileSelectLayout.removeWidget(self.fileSelectWidget_Widget(index)) self.fileSelectWidget_Widget(index).setParent(None) self.fileSelectWidgets.clear() oneFilePathWidget = QWidget() oneFilePathWidgetLayout = QHBoxLayout() oneFilePathWidget.setLayout(oneFilePathWidgetLayout) filePathWidget = QLineEdit() fileBurnAddrWidget = QLineEdit("0x00000") fileBurnEncCheckbox = QCheckBox(tr("Prefix")) openFileButton = QPushButton(tr("OpenFile")) if closeButton: removeButton = QPushButton() removeButton.setProperty("class", "remove_file_selection") oneFilePathWidgetLayout.addWidget(filePathWidget) oneFilePathWidgetLayout.addWidget(fileBurnAddrWidget) oneFilePathWidgetLayout.addWidget(fileBurnEncCheckbox) oneFilePathWidgetLayout.addWidget(openFileButton) if closeButton: oneFilePathWidgetLayout.addWidget(removeButton) oneFilePathWidgetLayout.setStretch(0, 4) oneFilePathWidgetLayout.setStretch(1, 2) oneFilePathWidgetLayout.setStretch(2, 1) oneFilePathWidgetLayout.setStretch(3, 2) # oneFilePathWidgetLayout.setStretch(4, 1) self.fileSelectLayout.addWidget(oneFilePathWidget) openFileButton.clicked.connect(lambda:self.selectFile(filePathWidget)) if closeButton: self.fileSelectWidgets.append(["bin", oneFilePathWidget, oneFilePathWidgetLayout, filePathWidget, fileBurnAddrWidget, openFileButton, fileBurnEncCheckbox, removeButton]) removeButton.clicked.connect(lambda:self.removeFileSelection(removeButton)) print(removeButton) else: self.fileSelectWidgets.append(["bin", oneFilePathWidget, oneFilePathWidgetLayout, filePathWidget, fileBurnAddrWidget, openFileButton, fileBurnEncCheckbox]) # add ADD button addoneWidget = QWidget() addoneWidgetLayout = QHBoxLayout() addoneWidget.setLayout(addoneWidgetLayout) addFileButton = QPushButton(tr("Add File")) packFileButton = QPushButton(tr("Pack to kfpkg")) addoneWidgetLayout.addWidget(addFileButton) addoneWidgetLayout.addWidget(packFileButton) self.fileSelectLayout.addWidget(addoneWidget) self.fileSelectWidgets.append(["button", addoneWidget, addoneWidgetLayout, addFileButton, packFileButton]) addFileButton.clicked.connect(self.addAddFileWidget) packFileButton.clicked.connect(self.packFile) self.fileSelectWidget_Path(index).setText(name) if prefixAuto: if name.endswith(".bin"): self.fileSelectWidget_Prefix(index).setChecked(True) else: self.fileSelectWidget_Prefix(index).setChecked(False) elif prefix: self.fileSelectWidget_Prefix(index).setChecked(True) if addr: self.fileSelectWidget_Addr(index).setText("0x%06x" %(addr))
class Ui_FindCollateralTxDlg(object): def setupUi(self, FindCollateralTxDlg): self.dlg = FindCollateralTxDlg FindCollateralTxDlg.resize(658, 257) FindCollateralTxDlg.setModal(True) self.vBox = QVBoxLayout(FindCollateralTxDlg) self.vBox.setContentsMargins(8, 8, 8, 8) self.vBox.setSpacing(8) self.hBox = QHBoxLayout() self.hBox.setContentsMargins(-1, 8, -1, 6) self.addrLabel = QLabel(FindCollateralTxDlg) self.hBox.addWidget(self.addrLabel) self.edtAddress = QLineEdit(FindCollateralTxDlg) self.edtAddress.setReadOnly(True) self.hBox.addWidget(self.edtAddress) spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.hBox.addItem(spacerItem) self.hBox.setStretch(1, 1) self.vBox.addLayout(self.hBox) self.lblMessage = QLabel(FindCollateralTxDlg) self.lblMessage.setText("") self.lblMessage.setWordWrap(True) self.vBox.addWidget(self.lblMessage) self.tableW = QTableWidget(FindCollateralTxDlg) self.tableW.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents) self.tableW.setSelectionMode(QAbstractItemView.SingleSelection) self.tableW.setSelectionBehavior(QAbstractItemView.SelectRows) self.tableW.setShowGrid(True) self.tableW.setColumnCount(4) self.tableW.setRowCount(0) self.tableW.horizontalHeader().setSectionResizeMode( 2, QHeaderView.Stretch) self.tableW.verticalHeader().hide() item = QTableWidgetItem() item.setText("PIVs") item.setTextAlignment(Qt.AlignCenter) self.tableW.setHorizontalHeaderItem(0, item) item = QTableWidgetItem() item.setText("Confirmations") item.setTextAlignment(Qt.AlignCenter) self.tableW.setHorizontalHeaderItem(1, item) item = QTableWidgetItem() item.setText("TX Hash") item.setTextAlignment(Qt.AlignCenter) self.tableW.setHorizontalHeaderItem(2, item) item = QTableWidgetItem() item.setText("TX Output N") item.setTextAlignment(Qt.AlignCenter) self.tableW.setHorizontalHeaderItem(3, item) self.vBox.addWidget(self.tableW) self.buttonBox = QDialogButtonBox(FindCollateralTxDlg) self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) self.vBox.addWidget(self.buttonBox) btnCancel = self.buttonBox.button(QDialogButtonBox.Cancel) btnCancel.clicked.connect(self.reject) btnOk = self.buttonBox.button(QDialogButtonBox.Ok) btnOk.clicked.connect(self.accept)
class SpeedSettings(SettingsSection): NAME = 'Speed' ELEMENT = Speed def __init__(self, size, Id, parent=None): super().__init__(size, parent) self.id = Id self.groupBox = QGroupBox(self) self.groupBox.setGeometry(0, 0, self.width(), 80) self.layout = QHBoxLayout(self.groupBox) self.speedSlider = QSlider(self.groupBox) self.speedSlider.setMinimum(1) self.speedSlider.setMaximum(1000) self.speedSlider.setPageStep(1) self.speedSlider.setValue(100) self.speedSlider.setOrientation(QtCore.Qt.Horizontal) self.speedSlider.setTickPosition(QSlider.TicksAbove) self.speedSlider.setTickInterval(10) self.layout.addWidget(self.speedSlider) self.speedLabel = QLabel(self.groupBox) self.speedLabel.setAlignment(QtCore.Qt.AlignCenter) self.layout.addWidget(self.speedLabel) self.layout.setStretch(0, 3) self.layout.setStretch(1, 1) self.speedSlider.valueChanged.connect(self.speedChanged) self.retranslateUi() def retranslateUi(self): self.groupBox.setTitle("Speed") self.speedLabel.setText("1.0") def enable_check(self, enable): self.groupBox.setCheckable(enable) self.groupBox.setChecked(False) def get_configuration(self): conf = {} if not (self.groupBox.isCheckable() and not self.groupBox.isChecked()): conf[self.id] = {'speed': self.speedSlider.value() / 100} return conf def set_configuration(self, conf): if conf is not None and self.id in conf: self.speedSlider.setValue(conf[self.id]['speed'] * 100) def speedChanged(self, value): self.speedLabel.setText(str(value / 100.0))
def initContentWidget(self): content_layout = QHBoxLayout() content_layout.addWidget(self.content_list_view) content_layout.addWidget(self.initDetailWidget()) content_layout.setStretch(0, 1) content_layout.setStretch(1, 2) content_widget = QWidget() content_widget.setLayout(content_layout) return content_widget
def initSearchWidget(self): search_layout = QHBoxLayout() search_layout.addWidget(self.search_box) search_layout.addWidget(self.clean_btn) search_layout.setStretch(0, 9) search_layout.setStretch(1, 1) search_widget = QWidget() search_widget.setLayout(search_layout) return search_widget
def initUi(self): self.setWindowTitle("手写数字识别DEMO") self.lastPoint = QPoint() # 起始点 self.endPoint = QPoint() # 终点 # 窗口大小设置为600*500 self.resize(600, 410) # 画布大小为400*400,背景为白色 self.pix = QPixmap(400, 400) self.pix.fill(Qt.white) self.pix_lab = QLabel() self.pix_lab.setPixmap(self.pix) self.bin_pix = QPixmap(100, 100) self.bin_pix.fill(Qt.white) self.bin_pix_lab = QLabel() self.bin_pix_lab.setPixmap(self.bin_pix) self.train_button = QPushButton(self) self.test_button = QPushButton(self) self.clear_button = QPushButton(self) self.save_button = QPushButton(self) self.train_button.setText('训练') self.train_button.clicked.connect(self.train) self.test_button.setText('测试') self.test_button.clicked.connect(self.test) self.clear_button.setText('清除') self.clear_button.clicked.connect(self.clear) self.save_button.setText('保存') self.save_button.clicked.connect(self.save) self.select_model_box = QComboBox() for model_name in self.model_names: self.select_model_box.addItem(model_name) self.select_model_box.currentIndexChanged.connect(self.selectionchange) self.pred_box = QLabel() ft = QFont() ft.setPointSize(24) self.pred_box.setFont(ft) left_widget = self.create_left_widget() right_widget = self.create_right_widget() main_layout = QHBoxLayout() main_layout.addWidget(left_widget) main_layout.addWidget(right_widget) main_layout.setStretch(0, 1) main_layout.setStretch(1, 4) main_widget = QWidget() main_widget.setLayout(main_layout) self.statusbar = QStatusBar(self) self.setStatusBar(self.statusbar) self.statusbar.setSizeGripEnabled(False) self.setCentralWidget(main_widget)
def initUI(self): self.resize(800,800) self.setWindowTitle('反馈建议') icon = QIcon() icon.addPixmap(QPixmap('./image/反馈.png'), QIcon.Normal, QIcon.Off) self.setWindowIcon(icon) self.label1 = QLabel('邮件主题:') self.line_edit1 = QLineEdit() self.line_edit1.setPlaceholderText('反馈 or 建议') self.line_edit2 = QLineEdit() self.label2 = QLabel('联系方式:') self.line_edit2.setPlaceholderText('QQ:xxx or Tel:xxx') self.label3 = QLabel('邮件内容:') self.text_edit = QTextEdit() self.text_edit.setPlaceholderText('邮件内容') # self.button_cancel = QPushButton('取消') self.button_send = QPushButton('发送') self.button_clear = QPushButton('清空') hlayout = QHBoxLayout() hlayout.addStretch() hlayout.addWidget(self.button_clear) # hlayout.addWidget(self.button_cancel) hlayout.addWidget(self.button_send) hlayout.setStretch(0,1) hlayout.setStretch(1,1) hlayout.setStretch(2,1) hlayout.setStretch(3,1) hlayout.setSpacing(10) formlayout = QFormLayout() formlayout.addRow(self.label1, self.line_edit1) formlayout.addRow(self.label2, self.line_edit2) formlayout.setSpacing(10) vlayout1 = QVBoxLayout() vlayout1.addWidget(self.text_edit) vlayout1.addItem(hlayout) vlayout1.setStretch(0,8) vlayout1.setStretch(1,1) vlayout1.setSpacing(10) vlayout2 = QVBoxLayout() vlayout2.addItem(formlayout) vlayout2.addItem(vlayout1) self.setLayout(vlayout2) self.button_send.clicked.connect(self.onClickSend) self.button_clear.clicked.connect(self.text_edit.clear)
def _add_dropdown(self, label: str, combobox: QComboBox, x: int, y: int, y_span: int) -> None: w = QWidget() wl = QHBoxLayout() w.setLayout(wl) l = QLabel(label) wl.addWidget(l) wl.addWidget(combobox) wl.setStretch(0, 2) wl.setStretch(1, 8) self.layout.addWidget(w, x, y, 1, y_span)
def Image_tab(window): image_tab = QWidget() Layout_Data_Vis = QVBoxLayout() Bottom_roi = QHBoxLayout() grid_layout = QGridLayout() cor_periodic = QLabel() cor_periodic.setStyleSheet("background-color: rgb(255, 51, 51)") cor_periodic.setFixedSize(20, 20) cor_channel = QLabel() cor_channel.setStyleSheet("background-color: rgb(153,153,255)") cor_channel.setFixedSize(20, 20) sc_image = pg.GraphicsWindow() window.p2 = sc_image.addViewBox(enableMouse=False) sc_image.nextRow() window.p3 = sc_image.addPlot(title="XRF Intensity", movable=True) window.p3.setLogMode(False, True) window.lr_image = pg.LinearRegionItem(movable=False, pen='r') Rgb_button = QPushButton('RGB') image_button = QPushButton('Image Preview') delete_table = QPushButton('Delete Row') grid_layout.addWidget(cor_periodic, 0, 0) grid_layout.addWidget(QLabel('Periodic Table'), 0, 1) grid_layout.addWidget(cor_channel, 1, 0) grid_layout.addWidget(QLabel('Selection by Channel'), 1, 1) grid_layout.addWidget(Rgb_button, 2, 1) grid_layout.addWidget(image_button, 3, 1) grid_layout.addWidget(delete_table, 4, 1) grid_layout.setAlignment(QtCore.Qt.AlignTop) Bottom_roi.addWidget(sc_image) Bottom_roi.addWidget(window.table) Bottom_roi.addLayout(grid_layout) Bottom_roi.setStretch(0, 6) Bottom_roi.setStretch(1, 2) Bottom_roi.setStretch(2, 1) Layout_Data_Vis.addLayout(Bottom_roi) image_tab.setLayout(Layout_Data_Vis) window.tabs.addTab(image_tab, 'Data visualization') window.table.cellClicked.connect(window.show_img) Rgb_button.clicked.connect(window.rgb_show) image_button.clicked.connect(window.img_show_window) delete_table.clicked.connect(window.delete_table_function)
def __init__(self, parent=None): super(FileChooserWidget, self).__init__(parent) self.label = QLabel() self.button = QPushButton('Vybrat soubor...') self.button.clicked.connect(self.on_button_clicked) layout = QHBoxLayout() layout.addWidget(self.label) layout.setStretch(0, 1) layout.addWidget(self.button) layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout)
def set_ticket_display(self) -> None: w = QWidget() layout = QHBoxLayout(w) layout.setContentsMargins(0, 0, 0, 0) self.button_purchase.clicked.connect(self.on_purchase_clicked) layout.addWidget(QLabel("Remaining Sortie Tickets")) layout.addWidget(self.ticket_label) layout.addWidget(QLabel("Purchasable Tickets")) layout.addWidget(self.button_purchase) w.setLayout(layout) for i in range(4): layout.setStretch(i, 0) self.left_layout.addWidget(w, 0, 0, 1, 4)
def __init__(self, master, address, min_val, max_val, name, cb_read, docstring="", cb_write=None): super().__init__(master) # Callbacks self.cb_read = cb_read self.cb_write = cb_write # Widgets l_addr = QLabel(hex(address), self) l_addr.setEnabled(False) l_name = QLabel(name, self) l_name.setAlignment(Qt.AlignRight | Qt.AlignVCenter) self.field = InputField(self, min_val, max_val) self.field.setFixedWidth(77) self.field.set_callback_value_changed(self._update_gui_value) self.b_read = QPushButton("Read", self) self.b_read.setFixedSize(55, 28) self.b_read.clicked.connect(self.read) self.b_write = QPushButton("Write", self) self.b_write.setFixedSize(55, 28) self.b_write.setEnabled(False) if self.cb_write is not None: self.b_write.clicked.connect(self.write) self.field.set_callback_value_valid(self.b_write.setEnabled) self.field.set_callback_return_pressed(self.write) else: self.field.set_read_only(True) # Layout grid = QHBoxLayout() grid.addWidget(l_addr) grid.addWidget(l_name) grid.addSpacing(5) grid.addWidget(self.field) grid.addWidget(self.b_read) grid.addWidget(self.b_write) grid.setStretch(1, 1) grid.setContentsMargins(0, 0, 0, 0) self.setLayout(grid) # Members self.address = address self.device_value = None self.gui_value = self.field.get_value() self._std_style = "QPushButton {}" self._bold_style = "QPushButton { font: bold; }" # Init self._update_boldness() if len(docstring) > 0: l_name.setToolTip(docstring)
def __init__(self, app): QMainWindow.__init__(self, None) self.resize(800, 600) self.centralWidget = QWidget() self.left = ControlWidget(self.centralWidget) self.right = CompassWidget(self.centralWidget) self.left.directionSlider.valueChanged.connect(self.right.setDirection) layout = QHBoxLayout() self.centralWidget.setLayout(layout) layout.addWidget(self.left) layout.addWidget(self.right) layout.setStretch(0, 1); layout.setStretch(1, 1); self.setCentralWidget(self.centralWidget)
def initWindow(self): QToolTip.setFont(QFont('SansSerif', 10)) # main layout frameWidget = QWidget() mainWidget = QSplitter(Qt.Horizontal) frameLayout = QVBoxLayout() self.settingWidget = QWidget() self.settingWidget.setProperty("class","settingWidget") self.receiveSendWidget = QSplitter(Qt.Vertical) self.functionalWiget = QWidget() settingLayout = QVBoxLayout() sendReceiveLayout = QVBoxLayout() sendFunctionalLayout = QVBoxLayout() mainLayout = QHBoxLayout() self.settingWidget.setLayout(settingLayout) self.receiveSendWidget.setLayout(sendReceiveLayout) self.functionalWiget.setLayout(sendFunctionalLayout) mainLayout.addWidget(self.settingWidget) mainLayout.addWidget(self.receiveSendWidget) mainLayout.addWidget(self.functionalWiget) mainLayout.setStretch(0,2) mainLayout.setStretch(1, 6) mainLayout.setStretch(2, 2) menuLayout = QHBoxLayout() mainWidget.setLayout(mainLayout) frameLayout.addLayout(menuLayout) frameLayout.addWidget(mainWidget) frameWidget.setLayout(frameLayout) self.setCentralWidget(frameWidget) # option layout self.settingsButton = QPushButton() self.skinButton = QPushButton("") self.waveButton = QPushButton("") self.aboutButton = QPushButton() self.functionalButton = QPushButton() self.encodingCombobox = ComboBox() self.encodingCombobox.addItem("ASCII") self.encodingCombobox.addItem("UTF-8") self.encodingCombobox.addItem("UTF-16") self.encodingCombobox.addItem("GBK") self.encodingCombobox.addItem("GB2312") self.encodingCombobox.addItem("GB18030") self.settingsButton.setProperty("class", "menuItem1") self.skinButton.setProperty("class", "menuItem2") self.aboutButton.setProperty("class", "menuItem3") self.functionalButton.setProperty("class", "menuItem4") self.waveButton.setProperty("class", "menuItem5") self.settingsButton.setObjectName("menuItem") self.skinButton.setObjectName("menuItem") self.aboutButton.setObjectName("menuItem") self.functionalButton.setObjectName("menuItem") self.waveButton.setObjectName("menuItem") menuLayout.addWidget(self.settingsButton) menuLayout.addWidget(self.skinButton) menuLayout.addWidget(self.waveButton) menuLayout.addWidget(self.aboutButton) menuLayout.addStretch(0) menuLayout.addWidget(self.encodingCombobox) menuLayout.addWidget(self.functionalButton) # widgets receive and send area self.receiveArea = QTextEdit() self.sendArea = QTextEdit() self.clearReceiveButtion = QPushButton(parameters.strClearReceive) self.sendButtion = QPushButton(parameters.strSend) self.sendHistory = ComboBox() sendWidget = QWidget() sendAreaWidgetsLayout = QHBoxLayout() sendWidget.setLayout(sendAreaWidgetsLayout) buttonLayout = QVBoxLayout() buttonLayout.addWidget(self.clearReceiveButtion) buttonLayout.addStretch(1) buttonLayout.addWidget(self.sendButtion) sendAreaWidgetsLayout.addWidget(self.sendArea) sendAreaWidgetsLayout.addLayout(buttonLayout) sendReceiveLayout.addWidget(self.receiveArea) sendReceiveLayout.addWidget(sendWidget) sendReceiveLayout.addWidget(self.sendHistory) sendReceiveLayout.setStretch(0, 7) sendReceiveLayout.setStretch(1, 2) sendReceiveLayout.setStretch(2, 1) # widgets serial settings serialSettingsGroupBox = QGroupBox(parameters.strSerialSettings) serialSettingsLayout = QGridLayout() serialReceiveSettingsLayout = QGridLayout() serialSendSettingsLayout = QGridLayout() serialPortLabek = QLabel(parameters.strSerialPort) serailBaudrateLabel = QLabel(parameters.strSerialBaudrate) serailBytesLabel = QLabel(parameters.strSerialBytes) serailParityLabel = QLabel(parameters.strSerialParity) serailStopbitsLabel = QLabel(parameters.strSerialStopbits) self.serialPortCombobox = ComboBox() self.serailBaudrateCombobox = ComboBox() self.serailBaudrateCombobox.addItem("9600") self.serailBaudrateCombobox.addItem("19200") self.serailBaudrateCombobox.addItem("38400") self.serailBaudrateCombobox.addItem("57600") self.serailBaudrateCombobox.addItem("115200") self.serailBaudrateCombobox.setCurrentIndex(4) self.serailBaudrateCombobox.setEditable(True) self.serailBytesCombobox = ComboBox() self.serailBytesCombobox.addItem("5") self.serailBytesCombobox.addItem("6") self.serailBytesCombobox.addItem("7") self.serailBytesCombobox.addItem("8") self.serailBytesCombobox.setCurrentIndex(3) self.serailParityCombobox = ComboBox() self.serailParityCombobox.addItem("None") self.serailParityCombobox.addItem("Odd") self.serailParityCombobox.addItem("Even") self.serailParityCombobox.addItem("Mark") self.serailParityCombobox.addItem("Space") self.serailParityCombobox.setCurrentIndex(0) self.serailStopbitsCombobox = ComboBox() self.serailStopbitsCombobox.addItem("1") self.serailStopbitsCombobox.addItem("1.5") self.serailStopbitsCombobox.addItem("2") self.serailStopbitsCombobox.setCurrentIndex(0) self.checkBoxRts = QCheckBox("rts") self.checkBoxDtr = QCheckBox("dtr") self.serialOpenCloseButton = QPushButton(parameters.strOpen) serialSettingsLayout.addWidget(serialPortLabek,0,0) serialSettingsLayout.addWidget(serailBaudrateLabel, 1, 0) serialSettingsLayout.addWidget(serailBytesLabel, 2, 0) serialSettingsLayout.addWidget(serailParityLabel, 3, 0) serialSettingsLayout.addWidget(serailStopbitsLabel, 4, 0) serialSettingsLayout.addWidget(self.serialPortCombobox, 0, 1) serialSettingsLayout.addWidget(self.serailBaudrateCombobox, 1, 1) serialSettingsLayout.addWidget(self.serailBytesCombobox, 2, 1) serialSettingsLayout.addWidget(self.serailParityCombobox, 3, 1) serialSettingsLayout.addWidget(self.serailStopbitsCombobox, 4, 1) serialSettingsLayout.addWidget(self.checkBoxRts, 5, 0,1,1) serialSettingsLayout.addWidget(self.checkBoxDtr, 5, 1,1,1) serialSettingsLayout.addWidget(self.serialOpenCloseButton, 6, 0,1,2) serialSettingsGroupBox.setLayout(serialSettingsLayout) settingLayout.addWidget(serialSettingsGroupBox) # serial receive settings serialReceiveSettingsGroupBox = QGroupBox(parameters.strSerialReceiveSettings) self.receiveSettingsAscii = QRadioButton(parameters.strAscii) self.receiveSettingsHex = QRadioButton(parameters.strHex) self.receiveSettingsAscii.setChecked(True) self.receiveSettingsAutoLinefeed = QCheckBox(parameters.strAutoLinefeed) self.receiveSettingsAutoLinefeedTime = QLineEdit(parameters.strAutoLinefeedTime) self.receiveSettingsAutoLinefeed.setMaximumWidth(75) self.receiveSettingsAutoLinefeedTime.setMaximumWidth(75) serialReceiveSettingsLayout.addWidget(self.receiveSettingsAscii,1,0,1,1) serialReceiveSettingsLayout.addWidget(self.receiveSettingsHex,1,1,1,1) serialReceiveSettingsLayout.addWidget(self.receiveSettingsAutoLinefeed, 2, 0, 1, 1) serialReceiveSettingsLayout.addWidget(self.receiveSettingsAutoLinefeedTime, 2, 1, 1, 1) serialReceiveSettingsGroupBox.setLayout(serialReceiveSettingsLayout) settingLayout.addWidget(serialReceiveSettingsGroupBox) # serial send settings serialSendSettingsGroupBox = QGroupBox(parameters.strSerialSendSettings) self.sendSettingsAscii = QRadioButton(parameters.strAscii) self.sendSettingsHex = QRadioButton(parameters.strHex) self.sendSettingsAscii.setChecked(True) self.sendSettingsScheduledCheckBox = QCheckBox(parameters.strScheduled) self.sendSettingsScheduled = QLineEdit(parameters.strScheduledTime) self.sendSettingsScheduledCheckBox.setMaximumWidth(75) self.sendSettingsScheduled.setMaximumWidth(75) self.sendSettingsCFLF = QCheckBox(parameters.strCRLF) self.sendSettingsCFLF.setChecked(False) serialSendSettingsLayout.addWidget(self.sendSettingsAscii,1,0,1,1) serialSendSettingsLayout.addWidget(self.sendSettingsHex,1,1,1,1) serialSendSettingsLayout.addWidget(self.sendSettingsScheduledCheckBox, 2, 0, 1, 1) serialSendSettingsLayout.addWidget(self.sendSettingsScheduled, 2, 1, 1, 1) serialSendSettingsLayout.addWidget(self.sendSettingsCFLF, 3, 0, 1, 2) serialSendSettingsGroupBox.setLayout(serialSendSettingsLayout) settingLayout.addWidget(serialSendSettingsGroupBox) settingLayout.setStretch(0, 5) settingLayout.setStretch(1, 2.5) settingLayout.setStretch(2, 2.5) # right functional layout self.addButton = QPushButton(parameters.strAdd) functionalGroupBox = QGroupBox(parameters.strFunctionalSend) functionalGridLayout = QGridLayout() functionalGridLayout.addWidget(self.addButton,0,1) functionalGroupBox.setLayout(functionalGridLayout) sendFunctionalLayout.addWidget(functionalGroupBox) self.isHideFunctinal = True self.hideFunctional() # main window self.statusBarStauts = QLabel() self.statusBarStauts.setMinimumWidth(80) self.statusBarStauts.setText("<font color=%s>%s</font>" %("#008200", parameters.strReady)) self.statusBarSendCount = QLabel(parameters.strSend+"(bytes): "+"0") self.statusBarReceiveCount = QLabel(parameters.strReceive+"(bytes): "+"0") self.statusBar().addWidget(self.statusBarStauts) self.statusBar().addWidget(self.statusBarSendCount,2) self.statusBar().addWidget(self.statusBarReceiveCount,3) # self.statusBar() self.resize(800, 500) self.MoveToCenter() self.setWindowTitle(parameters.appName+" V"+str(helpAbout.versionMajor)+"."+str(helpAbout.versionMinor)) icon = QIcon() print("icon path:"+self.DataPath+"/"+parameters.appIcon) icon.addPixmap(QPixmap(self.DataPath+"/"+parameters.appIcon), QIcon.Normal, QIcon.Off) self.setWindowIcon(icon) if sys.platform == "win32": ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("comtool") self.show() return
def __init__(self, parent = None): QWidget.__init__(self, parent, Qt.Window) self.board = TetrixBoard() self.indictor = TetrixIndictor() nextPieceLabel = QLabel(self) nextPieceLabel.setFrameStyle(QFrame.Box | QFrame.Raised) nextPieceLabel.setAlignment(Qt.AlignCenter) self.board.setNextPieceLabel(nextPieceLabel) scoreLcd = QLCDNumber(6) scoreLcd.setSegmentStyle(QLCDNumber.Filled) levelLcd = QLCDNumber(2) levelLcd.setSegmentStyle(QLCDNumber.Filled) linesLcd = QLCDNumber(6) linesLcd.setSegmentStyle(QLCDNumber.Filled) startButton = QPushButton(self.tr("&Start")) startButton.setFocusPolicy(Qt.NoFocus) quitButton = QPushButton(self.tr("E&xit")) quitButton.setFocusPolicy(Qt.NoFocus) pauseButton = QPushButton(self.tr("&Pause")) pauseButton.setFocusPolicy(Qt.NoFocus) startButton.clicked.connect(self.board.start) pauseButton.clicked.connect(self.board.pause) quitButton.clicked.connect(self.close) self.board.scoreChanged.connect(scoreLcd.display) self.board.levelChanged.connect(levelLcd.display) self.board.linesRemovedChanged.connect(linesLcd.display) self.board.act.connect(self.indictor.showIndictor) layout1 = QHBoxLayout() layout3 = QVBoxLayout() layout3.addWidget(self.board) layout3.addWidget(self.indictor) layout3.setSpacing(0) layout1.addLayout(layout3) layout2 = QVBoxLayout() layout2.addWidget(self.createLabel(self.tr("Next Block"))) layout2.addWidget(nextPieceLabel) layout2.addWidget(self.createLabel(self.tr("Level"))) layout2.addWidget(levelLcd) layout2.addWidget(self.createLabel(self.tr("Score")),) layout2.addWidget(scoreLcd) layout2.addWidget(self.createLabel(self.tr("Total Lines"))) layout2.addWidget(linesLcd) layout2.addWidget(startButton) layout2.addWidget(quitButton) layout2.addWidget(pauseButton) layout1.addLayout(layout2) layout1.setStretch(0, 75) layout1.setStretch(1, 25) self.setLayout(layout1) self.setWindowTitle(self.tr("Tetrix")) self.resize(self.logicalDpiX() / 96 * 275, self.logicalDpiY() / 96 * 380) r = self.geometry() r.moveCenter(QApplication.instance().desktop().screenGeometry().center()) self.setGeometry(r)
class LayoutSelect(QDialog): def __init__(self, parent=None): super().__init__(parent) self.filepath = '' self.layouts = {} self.setWindowModality(Qt.ApplicationModal) self.setWindowTitle('Layout selection') self.setMaximumSize(675, 300) self.setMinimumSize(675, 300) self.resize(675, 300) self.vLayout = QVBoxLayout(self) self.vLayout.setContentsMargins(5, 5, 5, 5) self.hLayout = QHBoxLayout(self) self.vLayout.addLayout(self.hLayout) self.layoutBox = QComboBox(self) self.hLayout.addWidget(self.layoutBox) self.layButton = QPushButton(self) self.layButton.setText('Select layout') self.hLayout.addWidget(self.layButton) self.fileButton = QPushButton(self) self.fileButton.setText('Open file') self.hLayout.addWidget(self.fileButton) self.hLayout.setStretch(0, 3) self.hLayout.setStretch(1, 2) self.hLayout.setStretch(2, 1) line = QFrame(self) line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) self.vLayout.addWidget(line) self.description = QTextBrowser(self) self.vLayout.addWidget(self.description) for layout_class in layouts.get_layouts(): self.layoutBox.addItem(layout_class.NAME) self.layouts[layout_class.NAME] = (layout_class, layout_class.DESCRIPTION) if self.layoutBox.count() == 0: raise Exception('No layout installed!') self.show_description(self.layoutBox.currentText()) self.layoutBox.currentTextChanged.connect(self.show_description) self.layButton.clicked.connect(self.accept) self.fileButton.clicked.connect(self.open_file) def slected(self): return self.layouts[self.layoutBox.currentText()][0] def show_description(self, layout_name): self.description.setHtml('<center><h2>' + layout_name + '</h2></center><br>' + self.layouts[layout_name][1]) def open_file(self): path, _ = QFileDialog.getOpenFileName(self, filter='*.lsp', directory=os.getenv('HOME')) self.filepath = path self.accept() def closeEvent(self, e): e.ignore()
class WinsWidget(QWidget): """主窗口。""" def __init__(self, parent=None): logger.debug("_init__:begin") super(WinsWidget, self).__init__(parent) self.setObjectName('winsWidget') self.setWindowFlags(Qt.FramelessWindowHint) self.setWindowTitle('wins的小工具') self.setWindowIcon(QIcon('icons/titleIcon.png')) self.resize(1000, 650) # 按钮start. self.btn_exit = QPushButton(self) self.btn_min = QPushButton(self) self.btn_max = QPushButton(self) self.btn_login = QPushButton("Unlogin", self) self.btn_search = QPushButton(self) self.btn_qry_stock = QPushButton(self) self.btn_add_stock = QPushButton(self) self.btn_del_stock = QPushButton(self) # 按钮end. # 标签start. self.lbe_pic = QLabel(self) self.header_hr = QLabel(self) self.header_icon = QLabel(self) self.header_text = QLabel(self) self.spacing = QLabel(self) self.spacing2 = QLabel(self) self.spacing3 = QFrame() self.spacing4 = QFrame() # ------- # 输入框start. self.search_line = QLineEdit(self) # 输入框end. # ------- # 列表框start. self.stockTableView = QtWidgets.QTableView(self) self.stockTableModel=QSqlTableModel(self) # ------- # 布局与属性设置。 self.mainLayout = QGridLayout() self.topLayout = QHBoxLayout() self.leftLayout = QVBoxLayout() self.centerLayout = QHBoxLayout() self.rightLayout = QVBoxLayout() self.rightLayout1 = QHBoxLayout() self.rightLayout2 = QVBoxLayout() self.rightLayout21 = QHBoxLayout() self.bottomLayout = QHBoxLayout() self.bottomLayout1 = QVBoxLayout() self.playLayout = QHBoxLayout() self.set_buttons() self.set_labels() self.set_lines() self.load_stock_tableview() # ------- # 其他功能。 self.load_login() self.setLayout(self.set_layouts()) logger.debug("_init__:end") # 设置布局。 def set_layouts(self): """ 布局。 """ # 头布局start. logger.debug("set_layouts:begin") self.topLayout.setObjectName('Headerhbox') self.topLayout.addWidget(self.header_icon) self.topLayout.addWidget(self.header_text) self.topLayout.addWidget(self.spacing2) self.topLayout.addWidget(self.search_line) self.topLayout.addWidget(self.btn_search) self.topLayout.addStretch(1) self.topLayout.addWidget(self.lbe_pic) self.topLayout.addWidget(self.btn_login) self.topLayout.addWidget(self.spacing) self.topLayout.addWidget(self.btn_min) self.topLayout.addWidget(self.btn_max) self.topLayout.addWidget(self.btn_exit) self.topLayout.setSpacing(7) # ------- self.mainLayout.addLayout(self.topLayout, 0, 0, Qt.AlignTop) self.mainLayout.addWidget(self.header_hr, 1, 0, Qt.AlignTop) # 头布局end. # -------- # 中心布局start. # 左部分start. self.leftLayout.addWidget(self.btn_qry_stock) self.leftLayout.addWidget(self.btn_add_stock) self.leftLayout.addWidget(self.btn_del_stock) self.leftLayout.setSpacing(10) # 左部分end。 # ------- # 右部分end. # ------- self.centerLayout.addLayout(self.leftLayout) self.centerLayout.addWidget(self.spacing3) self.centerLayout.addWidget(self.stockTableView) self.centerLayout.addLayout(self.rightLayout) self.centerLayout.setStretch(0, 180) self.centerLayout.setStretch(1, 1) self.centerLayout.setStretch(2, 0) self.centerLayout.setStretch(3, 830) self.centerLayout.setStretch(4, 0) self.mainLayout.addLayout(self.centerLayout, 2, 0, Qt.AlignTop | Qt.AlignLeft) # 中心布局end. # ------- # 下部分start. self.mainLayout.addWidget(self.spacing4, 3, 0, Qt.AlignTop) self.mainLayout.addLayout(self.bottomLayout, 3, 0, Qt.AlignBottom) # self.mainLayout.addWidget(self.current_list, 2, 0, Qt.AlignBottom | Qt.AlignRight) # 下部分end. self.mainLayout.setRowStretch(1, 1) self.mainLayout.setRowStretch(2, 20) self.mainLayout.setRowStretch(3, 3) logger.debug("set_layouts:end") return self.mainLayout def set_labels(self): """ 全部的标签组件。 """ p = QPixmap() p.load('icons/unlogin.png') p2 = QPixmap() p2.load('icons/titleIcon.png') # 头部装饰start。 self.lbe_pic.setObjectName("headpic") self.lbe_pic.setPixmap(p.scaled(40, 40)) self.header_hr.setObjectName('Headerhr') self.header_hr.setText("推荐") self.header_icon.setObjectName('HIcon') self.header_icon.setPixmap(p2.scaled(50, 50)) self.header_text.setObjectName('HText') self.header_text.setText(" Music") def load_login(self): """ 登录 """ logger.debug("load_login:"******""" 退出 """ logger.debug("quit_login:"******""" 加载表格 """ logger.debug("load_stock_tableview:begin") self.stockTableModel.setTable("t1") self.stockTableModel.select() self.stockTableModel.setEditStrategy(QSqlTableModel.OnManualSubmit) # 数据更新的策略,详细可以查看Qt文档 self.stockTableView.setModel(self.stockTableModel) self.stockTableView.setSelectionBehavior(QAbstractItemView.SelectRows) self.stockTableView.setSelectionMode(QAbstractItemView.ExtendedSelection) #self.stockTableView.setGeometry(QtCore.QRect(290, 110, 471, 221)) self.stockTableView.setObjectName("stockTableView") logger.debug("load_stock_tableview:end") def set_buttons(self): """ 全部的按钮组件。 """ # 退出。 logger.debug("set_buttons:begin") self.btn_exit.setObjectName('exit') self.btn_exit.setText('×') self.btn_exit.clicked.connect(self.close) self.btn_exit.setToolTip('退出') # 最小化。 self.btn_min.setObjectName('mini') self.btn_min.setText('-') self.btn_min.clicked.connect(self.showMinimized) self.btn_min.setToolTip('最小化') # 最大化。 self.btn_max.setObjectName('maxi') self.btn_max.setText('□') self.btn_max.setToolTip('^_^此功能已上火星') # 登陆。 self.btn_login.setObjectName('login') self.btn_login.setToolTip('登陆') # 搜索。 self.btn_search.setObjectName('searchBtn') self.btn_search.resize(48, 48) # 查询。 self.btn_qry_stock.setObjectName('btnQryStock') self.btn_qry_stock.setIcon(QIcon('icons/qryBtn.png')) self.btn_qry_stock.setText("查询") self.btn_qry_stock.clicked.connect(self.qryStockFunc) # 增加。 self.btn_add_stock.setObjectName('btnAddStock') self.btn_add_stock.setIcon(QIcon('icons/addBtn.png')) self.btn_add_stock.setText("增加") self.btn_add_stock.clicked.connect(self.addStockFunc) # 删除。 self.btn_del_stock.setObjectName('btnDelStock') self.btn_del_stock.setIcon(QIcon('icons/delBtn.png')) self.btn_del_stock.setText("删除") self.btn_del_stock.clicked.connect(self.delStockFunc) logger.debug("set_buttons:end") def set_lines(self): """ 输入框。 """ logger.debug("set_lines:begin") self.search_line.setObjectName('SearchLine') self.search_line.setPlaceholderText('搜索') logger.debug("set_lines:end") def set_sliders(self): """ 滚动组件。 """ logger.debug("set_sliders:begin") self.slider.setObjectName("slider") self.slider.setOrientation(Qt.Horizontal) logger.debug("set_sliders:end") def hide_index(self): """ 隐藏主页, 显示歌单详细信息。 """ logger.debug("hide_index") def show_index(self): """ 显示主页。 """ logger.debug("show_index") # 切换页面end. """重写鼠标事件,实现窗口拖动。""" def mousePressEvent(self, event): logger.debug("mousePressEvent:") if event.buttons() == Qt.LeftButton: self.m_drag = True self.m_DragPosition = event.globalPos()-self.pos() event.accept() def mouseMoveEvent(self, event): logger.debug("mouseMoveEvent:") try: if event.buttons() and Qt.LeftButton: self.move(event.globalPos()-self.m_DragPosition) event.accept() except AttributeError: pass def mouseReleaseEvent(self, event): logger.debug("mouseReleaseEvent:") self.m_drag = False """按键绑定。。""" def keyPressEvent(self, event): logger.debug("keyPressEvent:") if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Enter-1: self.song_search() """退出窗口时做的一些事。""" def closeEvent(self, event): # 退出时保存歌曲列表缓存。 logger.debug("showEvent:") """界面开始前的一些事。""" def showEvent(self, event): logger.debug("showEvent:") #查询按钮关联的槽函数 def qryStockFunc(self): #self.db.execSQL("select * from t1") logger.debug("qryStockFunc:") #插入按钮关联的槽函数 def addStockFunc(self): logger.debug("addStockFunc:begin") f1=random.randint(1, 99) self.myTableModel.insertRows(0, 1) self.myTableModel.setData(self.myTableModel.index(0, 0), f1) self.myTableModel.setData(self.myTableModel.index(0, 1), "test") self.myTableModel.submitAll() logger.debug("addStockFunc:end") def delStockFunc(self): logger.debug("delStockFunc:begin") rs=list(map(lambda x:x.row(),self.myTableView.selectedIndexes())) if len(rs)==0: QMessageBox.information(self,'提醒','请先选中至少一行,再点击此按钮!') return for i in reversed(rs): self.myTableModel.removeRows(i,1) self.myTableModel.submitAll() logger.debug("delStockFunc:end")
class PitchSettings(SettingsSection): NAME = 'Pitch' ELEMENT = Pitch def __init__(self, size, Id, parent=None): super().__init__(size, parent) self.id = Id self.groupBox = QGroupBox(self) self.groupBox.setGeometry(0, 0, self.width(), 80) self.layout = QHBoxLayout(self.groupBox) self.pitchSlider = QSlider(self.groupBox) self.pitchSlider.setMinimum(-12) self.pitchSlider.setMaximum(12) self.pitchSlider.setPageStep(1) self.pitchSlider.setValue(0) self.pitchSlider.setOrientation(QtCore.Qt.Horizontal) self.pitchSlider.setTickPosition(QSlider.TicksAbove) self.pitchSlider.setTickInterval(1) self.layout.addWidget(self.pitchSlider) self.pitchLabel = QLabel(self.groupBox) self.pitchLabel.setAlignment(QtCore.Qt.AlignCenter) self.layout.addWidget(self.pitchLabel) self.layout.setStretch(0, 3) self.layout.setStretch(1, 1) self.pitchSlider.valueChanged.connect(self.pitch_changed) self.retranslateUi() def retranslateUi(self): self.groupBox.setTitle("Pitch") self.pitchLabel.setText("+0 semitones") def enable_check(self, enable): self.groupBox.setCheckable(enable) self.groupBox.setChecked(False) def get_configuration(self): conf = {} if not (self.groupBox.isCheckable() and not self.groupBox.isChecked()): pitch = math.pow(2, self.pitchSlider.value() / 12) conf[self.id] = {'pitch': pitch} return conf def set_configuration(self, conf): if conf is not None and self.id in conf: self.pitchSlider.setValue( round(12 * math.log(conf[self.id]['pitch'], 2))) def pitch_changed(self, value): if value < 0: self.pitchLabel.setText(str(value) + ' semitones') else: self.pitchLabel.setText('+' + str(value) + ' semitones')
def __init__(self, app): QMainWindow.__init__(self, None) self.l.debug('Initializing MainWindow ...') self.theSun = SunSimulator() self.timeZones = [] for x in QTimeZone.availableTimeZoneIds(): tz = QTimeZone(x) self.timeZones.append(tz) #print(" {} {} {}".format(str(tz.id()), tz.comment(), tz.hasDaylightTime())) #self.revLookup = {} #idx = 0 #for d in self.timeZones: # self.revLookup[d[1]] = idx # idx += 1 self.setWindowTitle('Shadow') # app.setWindowIcon(QIcon(':/icons/mynpad.png')) # # if os.name == 'nt': # # On Windows, make sure to use a unique Application User Model Id, otherwise # # Windows shows the default python icon in the taskbar # # see http://stackoverflow.com/questions/1551605/how-to-set-applications-taskbar-icon-in-windows-7 # myappid = 'afester.mynpad' # import ctypes; ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid) self.theApplication = app app.aboutToQuit.connect(self.saveState) # read the local configuration file iniPath = 'shadow.ini' if not os.path.exists(iniPath): iniPath = os.path.join(expanduser("~"), iniPath) self.settings = Settings(iniPath) self.settings.load() # Set up the menu bar menuBar = QMenuBar(self) exitAction = QAction("Exit", self, triggered=self.theApplication.exit) fileMenu = menuBar.addMenu("&File") fileMenu.addAction(exitAction) aboutAction = QAction("About ...", self, triggered = self.handleAbout) helpMenu = menuBar.addMenu("&Help") helpMenu.addAction(aboutAction) self.setMenuBar(menuBar) self.centralWidget = QWidget() self.left = DataWidget(self.centralWidget) self.right = ShadowWidget(self.centralWidget) # Create time zone selector self.left.ui.timeZoneComboBox.clear() for tz in self.timeZones: # TODO: Hack (?) displayId = tz.id().data().decode(encoding="UTF-8") if not displayId.startswith('UTC'): utcOffset = tz.displayName(QTimeZone.GenericTime, QTimeZone.OffsetName) #self.left.ui.timeZoneComboBox.addItem("({}) {} - {}".format(utcOffset, displayId, tz.comment())) self.left.ui.timeZoneComboBox.addItem("({}) {}".format(utcOffset, displayId)) self.left.ui.timeZoneComboBox.setCurrentIndex(self.settings.getTzIndex()) self.left.ui.timeZoneComboBox.currentIndexChanged.connect(self.setTimeZone) self.left.ui.dateEdit.dateChanged.connect(self.updateDate) self.left.ui.timeEdit.timeChanged.connect(self.updateTime) self.left.ui.timeSlider.valueChanged.connect(self.slideTime) layout = QHBoxLayout() self.centralWidget.setLayout(layout) layout.addWidget(self.left) layout.addWidget(self.right) layout.setStretch(0, 0); layout.setStretch(1, 1); self.setCentralWidget(self.centralWidget) # Reset main window size and position pos = self.settings.getMainWindowPos() self.move(pos.x(), pos.y()) size = self.settings.getMainWindowSize() self.resize(size) # sample values self.left.ui.treeHeightLineEdit.setValue(10) self.left.ui.latitudeLineEdit.setValue(48.1) self.left.ui.LongitudeLineEdit.setValue(11.6) self.left.ui.dateEdit.setDate(QDate(2015, 9, 11)) self.left.ui.timeEdit.setTime(QTime(8, 0))