def createLabel(self, text):
lbl = QLabel(text)
lbl.setAlignment(Qt.AlignHCenter | Qt.AlignBottom)
return lbl
python类AlignHCenter()的实例源码
def _assemble_plot(self, qpainter):
qpainter.save()
#---
# draw bounding box
qpainter.setPen(self._bbox_pen)
qpainter.setBrush(self._bbox_brush)
qpainter.drawRect(self._bbox_rect)
# x-axis
qpainter.setFont(self._labelFont)
qpainter.setPen(self._axes_tick_pen)
qpainter.setBrush(self._axes_tick_brush)
for tick_line in self._xaxis_ticks:
qpainter.drawLine(tick_line)
for i in range(len(self._xaxis_ticks_text)):
qpainter.drawText(self._xaxis_ticks_text_rect[i], Qt.AlignVCenter | Qt.AlignHCenter, self._xaxis_ticks_text[i])
# y-axis
for tick_line in self._yaxis_ticks:
qpainter.drawLine(tick_line)
for i in range(len(self._yaxis_ticks_text)):
qpainter.drawText(self._yaxis_ticks_text_rect[i], Qt.AlignVCenter | Qt.AlignHCenter, self._yaxis_ticks_text[i])
# x-axis origin
qpainter.setPen(self._axes_origin_pen)
qpainter.setBrush(self._axes_origin_brush)
if self._xaxis_origin_x > self._bbox_x0 and self._xaxis_origin_x < self._bbox_x1:
qpainter.drawLine(self._xaxis_origin_line)
# y-axis origin
if self._yaxis_origin_y > self._bbox_y0 and self._yaxis_origin_y < self._bbox_y1:
qpainter.drawLine(self._yaxis_origin_line)
# draw plots
for plot_key in self._plot_points.keys():
qpainter.setPen(self._plot_pens[plot_key])
qpainter.setBrush(QBrush(Qt.NoBrush))
if self._plot_draw_method[plot_key] == 'line' and len(self._plot_points[plot_key]) > 1:
qpainter.drawPolyline(QPolygonF(self._plot_points[plot_key]))
else:
for plot_point in self._plot_points[plot_key]:
qpainter.drawPoint(plot_point)
#---
qpainter.restore()
# G E T T E R S / S E T T E R S
#===========================================================================
def init_ui(self):
# v.box
box = QVBoxLayout()
box.setSpacing(5)
box2 = QVBoxLayout()
box2.setSpacing(0)
l1 = QLabel('Red Discord Bot', self)
l1.setFont(QtGui.QFont("Times", 14))
box.addWidget(l1, 0, Qt.AlignTop)
box.insertSpacing(1, 10)
b1 = QPushButton("Start Red", self)
b1.setMinimumWidth(100)
box.addWidget(b1, 0, Qt.AlignHCenter)
b2 = QPushButton("Start Red Loop", self)
b2.setMinimumWidth(100)
box.addWidget(b2, 0, Qt.AlignHCenter)
box.insertSpacing(4, 10)
b3 = QPushButton("Update Red", self)
b3.setMinimumWidth(80)
box2.addWidget(b3, 0, Qt.AlignHCenter)
b4 = QPushButton("Install Requirements", self)
b4.setMinimumWidth(120)
box2.addWidget(b4, 0, Qt.AlignHCenter)
b5 = QPushButton("Maintenance", self)
b5.setMinimumWidth(100)
box2.addWidget(b5, 0, Qt.AlignHCenter)
# b2.setEnabled(False)
box.setAlignment(Qt.AlignHCenter)
box2.addStretch(5)
box.addLayout(box2)
self.setLayout(box)
# binds
b1.clicked.connect(lambda: self.startred(autorestart=False))
b2.clicked.connect(lambda: self.startred(autorestart=True))
b3.clicked.connect(lambda: self.switchwindow(window=UpdateWindow()))
b4.clicked.connect(lambda: self.switchwindow(window=RequirementsWindow()))
b5.clicked.connect(lambda: self.switchwindow(window=MaintenanceWindow()))
# window
self.setFixedSize(220, 210)
self.setWindowIcon(QtGui.QIcon('red.ico'))
self.setWindowTitle('Red Bot')
self.show()
def init_ui(self):
# v.box
box = QVBoxLayout()
box.setSpacing(5)
box2 = QHBoxLayout()
l1 = QLabel('Update', self)
l1.setFont(QtGui.QFont("Times", 12))
box.addWidget(l1, 0, Qt.AlignHCenter)
# box.insertSpacing(1, 10)
l2 = QLabel("Red:", self)
box.addWidget(l2, 0, Qt.AlignLeft)
self.r1 = QRadioButton("Update Red + Requirements \n(recommended)")
self.r1.setChecked(True)
box.addWidget(self.r1, 0, Qt.AlignLeft)
self.r2 = QRadioButton("Update Red")
box.addWidget(self.r2, 0, Qt.AlignLeft)
self.r3 = QRadioButton("Update Requirements")
box.addWidget(self.r3, 0, Qt.AlignLeft)
# box.insertSpacing(1, 10)
l3 = QLabel("Others:", self)
box.addWidget(l3, 0, Qt.AlignLeft)
self.r4 = QRadioButton("Update PIP \n(Might require admin privileges)")
box.addWidget(self.r4, 0, Qt.AlignLeft)
# box.insertSpacing(1, 10)
b1 = QPushButton("OK", self)
b1.setMinimumWidth(100)
box2.addWidget(b1, 0, Qt.AlignBottom)
b2 = QPushButton("Cancel", self)
b2.setMinimumWidth(100)
box2.addWidget(b2, 0, Qt.AlignBottom)
box.setAlignment(Qt.AlignHCenter)
box.addLayout(box2)
self.setLayout(box)
# binds
b1.clicked.connect(self.ok_clicked)
b2.clicked.connect(self.switchwindow)
# window
self.setFixedSize(220, 210)
self.setWindowIcon(QtGui.QIcon('red.ico'))
self.setWindowTitle('Red Bot - Update')
self.show()
def init_ui(self):
# v.box
box = QVBoxLayout()
box.setSpacing(5)
box2 = QHBoxLayout()
l1 = QLabel('Red Requirements', self)
l1.setFont(QtGui.QFont("Times", 12))
box.addWidget(l1, 0, Qt.AlignHCenter)
# box.insertSpacing(1, 10)
l2 = QLabel("Main Requirements", self)
box.addWidget(l2, 0, Qt.AlignLeft)
self.r1 = QRadioButton("Install basic + audio requirements \n(recommended)")
self.r1.setChecked(True)
box.addWidget(self.r1, 0, Qt.AlignLeft)
self.r2 = QRadioButton("Install basic requirements")
box.addWidget(self.r2, 0, Qt.AlignLeft)
# box.insertSpacing(1, 10)
l3 = QLabel("FFMPEG (required for audio)", self)
box.addWidget(l3, 0, Qt.AlignLeft)
self.r3 = QRadioButton("Install ffmpeg 32bit")
box.addWidget(self.r3, 0, Qt.AlignLeft)
self.r4 = QRadioButton("Install ffmpeg 64bit")
box.addWidget(self.r4, 0, Qt.AlignLeft)
# box.insertSpacing(1, 10)
b1 = QPushButton("OK", self)
b1.setMinimumWidth(100)
box2.addWidget(b1, 0, Qt.AlignBottom)
b2 = QPushButton("Cancel", self)
b2.setMinimumWidth(100)
box2.addWidget(b2, 0, Qt.AlignBottom)
box.setAlignment(Qt.AlignHCenter)
box.addLayout(box2)
self.setLayout(box)
# binds
b1.clicked.connect(self.ok_clicked)
b2.clicked.connect(self.switchwindow)
# window
self.setFixedSize(220, 210)
self.setWindowIcon(QtGui.QIcon('red.ico'))
self.setWindowTitle('Red Bot - Requirements')
self.show()
def init_ui(self):
# v.box
box = QVBoxLayout()
box.setSpacing(5)
box2 = QHBoxLayout()
l1 = QLabel('Maintenance', self)
l1.setFont(QtGui.QFont("Times", 12))
box.addWidget(l1, 0, Qt.AlignHCenter)
# box.insertSpacing(1, 10)
l2 = QLabel("Repair:", self)
box.addWidget(l2, 0, Qt.AlignLeft)
self.r1 = QRadioButton("Repair Red \n(discards code changes, keeps data intact)")
self.r1.setChecked(True)
box.addWidget(self.r1, 0, Qt.AlignLeft)
self.r2 = QRadioButton("Wipe 'data' folder \n(all settings, cogs' data...)")
box.addWidget(self.r2, 0, Qt.AlignLeft)
self.r3 = QRadioButton("Wipe 'lib' folder \n(all local requirements / local installed python packages)")
box.addWidget(self.r3, 0, Qt.AlignLeft)
self.r4 = QRadioButton("Factory reset")
box.addWidget(self.r4, 0, Qt.AlignLeft)
# box.insertSpacing(1, 10)
b1 = QPushButton("OK", self)
b1.setMaximumWidth(100)
box2.addWidget(b1, 0, Qt.AlignBottom)
b2 = QPushButton("Cancel", self)
b2.setMaximumWidth(100)
box2.addWidget(b2, 0, Qt.AlignBottom)
box.setAlignment(Qt.AlignHCenter)
box.addLayout(box2)
self.setLayout(box)
# binds
b1.clicked.connect(self.ok_clicked)
b2.clicked.connect(self.switchwindow)
# window
self.setFixedSize(320, 210)
self.setWindowIcon(QtGui.QIcon('red.ico'))
self.setWindowTitle('Red Bot - Maintenance')
self.show()
def createTabDesktopTheme(self):
self.tabDesktopTheme = QWidget()
self.tabDesktopTheme.setObjectName("tabDesktopTheme")
self.verticalLayout_4 = QVBoxLayout(self.tabDesktopTheme)
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.listWidgetDesktopTheme = QListWidget(self.tabDesktopTheme)
self.listWidgetDesktopTheme.setObjectName("listWidgetDesktopTheme")
self.listWidgetDesktopTheme.setViewMode(QListView.IconMode)
self.listWidgetDesktopTheme.setIconSize(QSize(240, 145))
self.listWidgetDesktopTheme.setResizeMode(QListView.Adjust)
item = QListWidgetItem(self.listWidgetDesktopTheme)
icon = QIcon(QPixmap(":/data/images/air_panel.png").scaled(QSize(240, 145), Qt.IgnoreAspectRatio, Qt.FastTransformation))
item.setSizeHint(QSize(240, 145))
item.setIcon(icon)
item.panelText = "air"
item = QListWidgetItem(self.listWidgetDesktopTheme)
item.setTextAlignment(Qt.AlignHCenter)
icon = QIcon(QPixmap(":/data/images/breeze_panel.png").scaled(QSize(240, 145), Qt.IgnoreAspectRatio, Qt.FastTransformation))
item.setSizeHint(QSize(240, 145))
item.setIcon(icon)
item.panelText = "default"
item = QListWidgetItem(self.listWidgetDesktopTheme)
item.setTextAlignment(Qt.AlignHCenter)
icon = QIcon(QPixmap(":/data/images/breeze-dark_panel.png").scaled(QSize(240, 145), Qt.IgnoreAspectRatio, Qt.FastTransformation))
item.setSizeHint(QSize(240, 145))
item.setIcon(icon)
item.panelText = "breeze-dark"
item = QListWidgetItem(self.listWidgetDesktopTheme)
item.setTextAlignment(Qt.AlignHCenter)
icon = QIcon(QPixmap(":/data/images/midna_panel.png").scaled(QSize(240, 145), Qt.IgnoreAspectRatio, Qt.FastTransformation))
item.setSizeHint(QSize(240, 145))
item.setIcon(icon)
item.panelText = "midna"
item = QListWidgetItem(self.listWidgetDesktopTheme)
item.setTextAlignment(Qt.AlignHCenter)
icon = QIcon(QPixmap(":/data/images/midna-dark_panel.png").scaled(QSize(240, 145), Qt.IgnoreAspectRatio, Qt.FastTransformation))
item.setSizeHint(QSize(240, 145))
item.setIcon(icon)
item.panelText = "midna_dark"
item = QListWidgetItem(self.listWidgetDesktopTheme)
item.setTextAlignment(Qt.AlignHCenter)
icon = QIcon(QPixmap(":/data/images/oxygen_panel.png").scaled(QSize(240, 145), Qt.IgnoreAspectRatio, Qt.FastTransformation))
item.setSizeHint(QSize(240, 145))
item.setIcon(icon)
item.panelText = "oxygen"
self.verticalLayout_4.addWidget(self.listWidgetDesktopTheme)
self.addTab(self.tabDesktopTheme, self.tr("Desktop Theme"))
def __init__(self, parent, index):
super(TimestampDialog, self).__init__(parent)
self.setAttribute(Qt.WA_DeleteOnClose, True)
self.setWindowFlags(dialogwindowflags)
self.setWindowTitle(_("Timestamp"))
self.index = index
self.timestampdialoglayout = QVBoxLayout()
self.groupboxlayout = QHBoxLayout()
self.layout_h = QHBoxLayout()
self.layout_h.setContentsMargins(1, 1, 1, 1)
self.layout_m = QHBoxLayout()
self.layout_m.setContentsMargins(1, 1, 1, 1)
self.layout_s = QHBoxLayout()
self.layout_s.setContentsMargins(1, 1, 1, 1)
self.groupbox_h = QGroupBox(_("Hours"), self)
self.groupbox_m = QGroupBox(_("Minutes"), self)
self.groupbox_s = QGroupBox(_("Seconds"), self)
self.spinbox_h = QSpinBox(self)
self.spinbox_h.setMinimum(0)
self.spinbox_h.setMaximum(99)
self.spinbox_m = QSpinBox(self)
self.spinbox_m.setMinimum(0)
self.spinbox_m.setMaximum(59)
self.spinbox_s = QSpinBox(self)
self.spinbox_s.setMinimum(0)
self.spinbox_s.setMaximum(59)
self.layout_h.addWidget(self.spinbox_h)
self.layout_m.addWidget(self.spinbox_m)
self.layout_s.addWidget(self.spinbox_s)
self.groupbox_h.setLayout(self.layout_h)
self.groupbox_m.setLayout(self.layout_m)
self.groupbox_s.setLayout(self.layout_s)
self.groupboxlayout.addWidget(self.groupbox_h)
self.groupboxlayout.addWidget(self.groupbox_m)
self.groupboxlayout.addWidget(self.groupbox_s)
self.acceptbutton = QPushButton(_("OK"), self)
self.acceptbutton.clicked.connect(self.clickedAcceptButton)
self.timestampdialoglayout.addLayout(self.groupboxlayout)
self.timestampdialoglayout.addWidget(self.acceptbutton)
self.timestampdialoglayout.setAlignment(self.groupboxlayout, Qt.AlignHCenter)
self.timestampdialoglayout.setAlignment(self.acceptbutton, Qt.AlignHCenter)
self.setLayout(self.timestampdialoglayout)
timestamp = commentmodel.item(commentlistview.selectedIndexes()[0].row(), 0).text()
str_h, str_m, str_s = timestamp.split(":")
self.spinbox_h.setValue(int(str_h))
self.spinbox_m.setValue(int(str_m))
self.spinbox_s.setValue(int(str_s))
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 createTabDesktopTheme(self):
self.tabDesktopTheme = QWidget()
self.tabDesktopTheme.setObjectName("tabDesktopTheme")
self.gridLayout = QGridLayout(self.tabDesktopTheme)
self.gridLayout.setObjectName("gridLayout")
self.listWidgetDesktopTheme = QListWidget(self.tabDesktopTheme)
self.listWidgetDesktopTheme.setViewMode(QListView.IconMode)
self.listWidgetDesktopTheme.setResizeMode(QListView.Adjust)
self.listWidgetDesktopTheme.setIconSize(QSize(212, 129))
self.gridLayout.addWidget(self.listWidgetDesktopTheme, 0, 0, 1, 1)
item = QListWidgetItem(self.listWidgetDesktopTheme)
icon = QIcon(":/data/images/air-panel.png")
item.setIcon(icon)
item.panelText = "air"
item = QListWidgetItem(self.listWidgetDesktopTheme)
item.setTextAlignment(Qt.AlignHCenter)
icon = QIcon(":/data/images/breeze-panel.png")
item.setIcon(icon)
item.panelText = "default"
item = QListWidgetItem(self.listWidgetDesktopTheme)
item.setTextAlignment(Qt.AlignHCenter)
icon = QIcon(":/data/images/breeze-light-panel.png")
item.setIcon(icon)
item.panelText = "breeze-light"
item = QListWidgetItem(self.listWidgetDesktopTheme)
icon = QIcon(":/data/images/breeze-dark-panel.png")
item.setIcon(icon)
item.panelText = "breeze-dark"
item = QListWidgetItem(self.listWidgetDesktopTheme)
item.setTextAlignment(Qt.AlignHCenter)
icon = QIcon(":/data/images/maia-panel.png")
item.setIcon(icon)
item.panelText = "maia"
item = QListWidgetItem(self.listWidgetDesktopTheme)
item.setTextAlignment(Qt.AlignHCenter)
icon = QIcon(":/data/images/oxygen-panel.png")
item.setIcon(icon)
item.panelText = "oxygen"
self.addTab(self.tabDesktopTheme, self.tr("Desktop Theme"))