def init_ui(self):
# v.box
gbox = QtWidgets.QGridLayout()
box = QtWidgets.QVBoxLayout()
self.rbox = QtWidgets.QVBoxLayout()
self.hbox = QtWidgets.QHBoxLayout()
# padding/margins
gbox.setContentsMargins(0, 0, 0, 0)
self.rbox.setContentsMargins(0, 0, 10, 10)
self.hbox.setContentsMargins(0, 0, 10, 10)
box.addStretch()
self.hbox.addStretch()
gbox.setSpacing(10)
box.setSpacing(0)
self.rbox.setSpacing(5)
self.hbox.setSpacing(0)
image = QtGui.QImage()
image.loadFromData(urllib.request.urlopen('http://i.imgur.com/04DUqa3.png').read())
png = QLabel(self)
pixmap = QtGui.QPixmap(image)
png.setPixmap(pixmap)
gbox.addWidget(png, 0, 0, 1, 1, Qt.AlignTop)
box.insertSpacing(1, 10)
self.l1 = QLabel(self)
self.l1.setWordWrap(True)
self.large_font.setBold(True)
self.l1.setFont(self.large_font)
box.addWidget(self.l1, 0, Qt.AlignTop)
hline = QtWidgets.QFrame()
hline.setFrameShape(QtWidgets.QFrame.HLine)
hline.setFrameShadow(QtWidgets.QFrame.Sunken)
gbox.addWidget(hline, 0, 0, 1, 3, Qt.AlignBottom)
# start form
self.req_ui()
self.rbox.setAlignment(Qt.AlignTop)
box.addLayout(self.rbox, 1)
gbox.addLayout(box, 0, 1, 1, 2)
gbox.addLayout(self.hbox, 1, 0, 1, 3)
self.setLayout(gbox)
# window
self.setFixedSize(490, 400)
self.setWindowIcon(QtGui.QIcon('red.ico'))
self.setWindowTitle('Red Discord Bot - Setup')
self.show()
python类AlignTop()的实例源码
def console_ui(self, audio):
self.clear_layout(self.rbox)
self.clear_layout(self.hbox)
self.hbox.addStretch()
self.l1.setText("Installing requirements")
self.process = QProcess()
self.output = QTextEdit()
self.percent = 0
self.rbox.insertSpacing(1, 10)
l2 = QLabel('Press Next when the last line says "Successfully Installed--"')
self.rbox.addWidget(l2, 0, Qt.AlignTop)
# this can be uncommented whenever I actually figure out Progress Bars
# self.pbar = QtWidgets.QProgressBar()
# self.pbar.setGeometry(30, 40, 200, 25)
# self.rbox.addWidget(self.pbar)
b5 = QPushButton("Dialog", self)
b5.setMaximumWidth(75)
self.rbox.addWidget(b5)
self.rbox.addWidget(self.output)
self.process.readyRead.connect(self.console_data)
self.output.hide()
# data flow
remove_reqs_readonly()
interpreter = sys.executable
if interpreter is None:
QMessageBox.warning(self, "404", "Python interpreter not found.")
self.close()
txt = REQS_TXT if audio else REQS_NO_AUDIO_TXT
args = ["-m", "pip", "install", "--upgrade", "--target", REQS_DIR, "-r", txt]
if IS_MAC: # --target is a problem on Homebrew. See PR #552
args.remove("--target")
args.remove(REQS_DIR)
# do call
self.process.start(interpreter, args)
# buttons
self.buttons_panel()
# binds
self.b1.setEnabled(True)
# self.b2.setEnabled(False)
self.b1.clicked.connect(self.req_ui)
self.b1.clicked.connect(self.process.close)
self.b2.clicked.connect(self.token_ui)
self.b3.clicked.connect(self.close_prompt)
b5.clicked.connect(self.console_hide)
def __init__(self, parent=None):
super(AddressBook, self).__init__(parent)
self.contacts = SortedDict()
self.oldName = ''
self.oldAddress = ''
nameLabel = QLabel("Name:")
self.nameLine = QLineEdit()
self.nameLine.setReadOnly(True)
addressLabel = QLabel("Address:")
self.addressText = QTextEdit()
self.addressText.setReadOnly(True)
self.addButton = QPushButton("&Add")
self.addButton.show()
self.submitButton = QPushButton("&Submit")
self.submitButton.hide()
self.cancelButton = QPushButton("&Cancel")
self.cancelButton.hide()
self.nextButton = QPushButton("&Next")
self.nextButton.setEnabled(False)
self.previousButton = QPushButton("&Previous")
self.previousButton.setEnabled(False)
self.addButton.clicked.connect(self.addContact)
self.submitButton.clicked.connect(self.submitContact)
self.cancelButton.clicked.connect(self.cancel)
self.nextButton.clicked.connect(self.next)
self.previousButton.clicked.connect(self.previous)
buttonLayout1 = QVBoxLayout()
buttonLayout1.addWidget(self.addButton, Qt.AlignTop)
buttonLayout1.addWidget(self.submitButton)
buttonLayout1.addWidget(self.cancelButton)
buttonLayout1.addStretch()
buttonLayout2 = QHBoxLayout()
buttonLayout2.addWidget(self.previousButton)
buttonLayout2.addWidget(self.nextButton)
mainLayout = QGridLayout()
mainLayout.addWidget(nameLabel, 0, 0)
mainLayout.addWidget(self.nameLine, 0, 1)
mainLayout.addWidget(addressLabel, 1, 0, Qt.AlignTop)
mainLayout.addWidget(self.addressText, 1, 1)
mainLayout.addLayout(buttonLayout1, 1, 2)
mainLayout.addLayout(buttonLayout2, 3, 1)
self.setLayout(mainLayout)
self.setWindowTitle("Simple Address Book")
def __init__(self, parent=None):
super(AddressBook, self).__init__(parent)
self.contacts = SortedDict()
self.oldName = ''
self.oldAddress = ''
nameLabel = QLabel("Name:")
self.nameLine = QLineEdit()
self.nameLine.setReadOnly(True)
addressLabel = QLabel("Address:")
self.addressText = QTextEdit()
self.addressText.setReadOnly(True)
self.addButton = QPushButton("&Add")
self.addButton.show()
self.submitButton = QPushButton("&Submit")
self.submitButton.hide()
self.cancelButton = QPushButton("&Cancel")
self.cancelButton.hide()
self.nextButton = QPushButton("&Next")
self.nextButton.setEnabled(False)
self.previousButton = QPushButton("&Previous")
self.previousButton.setEnabled(False)
self.addButton.clicked.connect(self.addContact)
self.submitButton.clicked.connect(self.submitContact)
self.cancelButton.clicked.connect(self.cancel)
self.nextButton.clicked.connect(self.next)
self.previousButton.clicked.connect(self.previous)
buttonLayout1 = QVBoxLayout()
buttonLayout1.addWidget(self.addButton, Qt.AlignTop)
buttonLayout1.addWidget(self.submitButton)
buttonLayout1.addWidget(self.cancelButton)
buttonLayout1.addStretch()
buttonLayout2 = QHBoxLayout()
buttonLayout2.addWidget(self.previousButton)
buttonLayout2.addWidget(self.nextButton)
mainLayout = QGridLayout()
mainLayout.addWidget(nameLabel, 0, 0)
mainLayout.addWidget(self.nameLine, 0, 1)
mainLayout.addWidget(addressLabel, 1, 0, Qt.AlignTop)
mainLayout.addWidget(self.addressText, 1, 1)
mainLayout.addLayout(buttonLayout1, 1, 2)
mainLayout.addLayout(buttonLayout2, 3, 1)
self.setLayout(mainLayout)
self.setWindowTitle("Simple Address Book")
def __init__(self, socket, name, testDate, startTime, endTime, banList, allowList, parent=None):
QtWidgets.QDialog.__init__(self, parent)
self.ui = uic.loadUi(config.config.ROOT_PATH +'view/updateCourse.ui', self)
self.sock = socket
self.name = name
self.date = testDate.split('-')
self.startTime = startTime.split(':')
self.endTime = endTime.split(':')
self.banList = banList
self.allowList = allowList
self.students = []
self.ui.label_5.setText(self.name)
self.ui.dateEdit.setDate(QDate(int(self.date[0]), int(self.date[1]), int(self.date[2])))
self.ui.timeEdit.setTime(QTime(int(self.startTime[0]), int(self.startTime[1])))
self.ui.timeEdit_2.setTime(QTime(int(self.endTime[0]), int(self.endTime[1])))
pListWidget = QtWidgets.QWidget()
self.ui.scrollArea.setWidgetResizable(True)
self.ui.scrollArea.setWidget(pListWidget)
pListLayout = QtWidgets.QVBoxLayout()
pListLayout.setAlignment(Qt.AlignTop)
pListWidget.setLayout(pListLayout)
for i in range(1, len(config.config.BAN_PROGRAM)):
checkBox = QtWidgets.QCheckBox(config.config.BAN_PROGRAM[i])
checkBox.clicked.connect(self.set_ban_list)
if i in self.banList:
checkBox.setChecked(True)
pListLayout.addWidget(checkBox)
sListWidget = QtWidgets.QWidget()
self.ui.scrollArea_2.setWidgetResizable(True)
self.ui.scrollArea_2.setWidget(sListWidget)
sListLayout = QtWidgets.QVBoxLayout()
sListLayout.setAlignment(Qt.AlignTop)
sListWidget.setLayout(sListLayout)
for i in range(1, len(config.config.ALLOW_SITE)):
checkBox = QtWidgets.QCheckBox(config.config.ALLOW_SITE[i])
checkBox.clicked.connect(self.set_allow_list)
if i in self.allowList:
checkBox.setChecked(True)
sListLayout.addWidget(checkBox)
self.ui.show()
def initUI(self):
"""
Initialize the Central Widget user interface.
"""
def __get_top_layout(parent):
image = ImageWidget(parent, B3_BANNER)
layout = QHBoxLayout()
layout.addWidget(image)
layout.setAlignment(Qt.AlignTop)
layout.setContentsMargins(0, 0, 0, 0)
return layout
def __get_middle_layout(parent):
parent.main_table = MainTable(parent)
parent.help_label = HelpLabel(parent.main_table)
layout = QVBoxLayout()
layout.addWidget(parent.main_table)
#layout.addWidget(parent.help_label)
layout.setAlignment(Qt.AlignHCenter | Qt.AlignTop)
layout.setContentsMargins(0, 2, 0, 0)
return layout
def __get_bottom_layout(parent):
parent.news = MarqueeLabel(parent)
parent.news.parseFeed()
btn_new = Button(parent=parent, text='Add', shortcut='Ctrl+N')
btn_new.clicked.connect(self.parent().new_process_dialog)
btn_new.setStatusTip('Add a new B3')
btn_new.setVisible(True)
btn_quit = Button(parent=parent, text='Quit', shortcut='Ctrl+Q')
btn_quit.clicked.connect(B3App.Instance().shutdown)
btn_quit.setStatusTip('Shutdown B3')
btn_quit.setVisible(True)
layout = QHBoxLayout()
layout.addWidget(parent.news)
layout.addWidget(btn_new)
layout.addWidget(btn_quit)
layout.setAlignment(Qt.AlignBottom | Qt.AlignRight)
layout.setSpacing(10)
layout.setContentsMargins(0, 0, 11, GEOMETRY[b3.getPlatform()]['CENTRAL_WIDGET_BOTTOM_LAYOUT_MARGIN_BOTTOM'])
return layout
main_layout = QVBoxLayout()
main_layout.addLayout(__get_top_layout(self))
main_layout.addLayout(__get_middle_layout(self))
main_layout.addLayout(__get_bottom_layout(self))
main_layout.setContentsMargins(0, 0, 0, 0)
self.setLayout(main_layout)
self.setFixedSize(614, 512)
self.setStyleSheet("""
QWidget, QDialog, QMessageBox {
background: #F2F2F2;
}
""")
self.setFocus()
def initUI(self):
"""
Initialize the Dialog layout.
"""
self.setWindowTitle(B3_LICENSE)
self.setFixedSize(GEOMETRY[b3.getPlatform()]['LICENSE_DIALOG_WIDTH'],
GEOMETRY[b3.getPlatform()]['LICENSE_DIALOG_HEIGHT'])
self.setStyleSheet("""
QDialog {
background: #F2F2F2;
}
""")
def __get_top_layout(parent):
message = """
%(COPYRIGHT)s<br/>
<br/>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.<br/>
<br/>
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.<br/>
<br/>
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
""" % dict(COPYRIGHT=B3_COPYRIGHT)
label = QLabel(message, parent)
label.setWordWrap(True)
label.setOpenExternalLinks(True)
label.setAlignment(Qt.AlignLeft)
layout = QHBoxLayout()
layout.addWidget(label)
layout.setAlignment(Qt.AlignTop)
layout.setContentsMargins(0, 0, 0, 0)
return layout
def __get_bottom_layout(parent):
btn_close = Button(parent=parent, text='Close')
btn_close.clicked.connect(parent.close)
btn_close.setVisible(True)
layout = QHBoxLayout()
layout.addWidget(btn_close)
layout.setAlignment(Qt.AlignHCenter|Qt.AlignTop)
layout.setContentsMargins(0, 20, 0, 0)
return layout
main_layout = QVBoxLayout()
main_layout.addLayout(__get_top_layout(self))
main_layout.addLayout(__get_bottom_layout(self))
self.setLayout(main_layout)
self.setModal(True)
def initUI(self):
"""
Initialize the Dialog layout.
"""
self.setWindowTitle('B3 database update')
self.setFixedSize(420, 160)
self.setStyleSheet("""
QDialog {
background: #F2F2F2;
}
""")
## INIT CLOSE BUTTON
self.btn_close = Button(parent=self, text='Close')
self.btn_close.clicked.connect(self.close)
self.btn_close.hide()
## INIT UPDATE BUTTON
self.btn_update = Button(parent=self, text='Update')
self.btn_update.clicked.connect(self.do_update)
self.btn_update.show()
## CREATE THE PROGRESS BAR
self.progress = ProgressBar(self)
self.progress.setAlignment(Qt.AlignHCenter)
self.progress.hide()
self.progress.setRange(0, 0)
self.progress.setValue(-1)
## INIT DISPLAY MESSAGE
self.message = QLabel("This tool will update all your B3 databases to version %s.\n"
"The update process should take less than 2 minutes and\n"
"cannot be interrupted." % b3.__version__, self)
def __get_top_layout(parent):
parent.layout1 = QVBoxLayout()
parent.layout1.addWidget(parent.progress)
parent.layout1.addWidget(parent.message)
parent.layout1.setAlignment(Qt.AlignTop|Qt.AlignHCenter)
parent.layout1.setContentsMargins(0, 0, 0, 0)
return parent.layout1
def __get_bottom_layout(parent):
parent.layout2 = QHBoxLayout()
parent.layout2.addWidget(parent.btn_close)
parent.layout2.addWidget(parent.btn_update)
parent.layout2.setAlignment(Qt.AlignHCenter)
parent.layout2.setSpacing(20 if b3.getPlatform() != 'win32' else 10)
parent.layout2.setContentsMargins(0, 10, 0, 0)
return parent.layout2
self.setModal(True)
self.main_layout = QVBoxLayout()
self.main_layout.addLayout(__get_top_layout(self))
self.main_layout.addLayout(__get_bottom_layout(self))
self.main_layout.setAlignment(Qt.AlignCenter)
self.setLayout(self.main_layout)
def __init__(self, parent=None):
super(AddressBook, self).__init__(parent)
self.contacts = SortedDict()
self.oldName = ''
self.oldAddress = ''
nameLabel = QLabel("Name:")
self.nameLine = QLineEdit()
self.nameLine.setReadOnly(True)
addressLabel = QLabel("Address:")
self.addressText = QTextEdit()
self.addressText.setReadOnly(True)
self.addButton = QPushButton("&Add")
self.addButton.show()
self.submitButton = QPushButton("&Submit")
self.submitButton.hide()
self.cancelButton = QPushButton("&Cancel")
self.cancelButton.hide()
self.nextButton = QPushButton("&Next")
self.nextButton.setEnabled(False)
self.previousButton = QPushButton("&Previous")
self.previousButton.setEnabled(False)
self.addButton.clicked.connect(self.addContact)
self.submitButton.clicked.connect(self.submitContact)
self.cancelButton.clicked.connect(self.cancel)
self.nextButton.clicked.connect(self.next)
self.previousButton.clicked.connect(self.previous)
buttonLayout1 = QVBoxLayout()
buttonLayout1.addWidget(self.addButton, Qt.AlignTop)
buttonLayout1.addWidget(self.submitButton)
buttonLayout1.addWidget(self.cancelButton)
buttonLayout1.addStretch()
buttonLayout2 = QHBoxLayout()
buttonLayout2.addWidget(self.previousButton)
buttonLayout2.addWidget(self.nextButton)
mainLayout = QGridLayout()
mainLayout.addWidget(nameLabel, 0, 0)
mainLayout.addWidget(self.nameLine, 0, 1)
mainLayout.addWidget(addressLabel, 1, 0, Qt.AlignTop)
mainLayout.addWidget(self.addressText, 1, 1)
mainLayout.addLayout(buttonLayout1, 1, 2)
mainLayout.addLayout(buttonLayout2, 3, 1)
self.setLayout(mainLayout)
self.setWindowTitle("Simple Address Book")