本文整理汇总了Python中PyQt5.QtWidgets.QProgressBar.setGeometry方法的典型用法代码示例。如果您正苦于以下问题:Python QProgressBar.setGeometry方法的具体用法?Python QProgressBar.setGeometry怎么用?Python QProgressBar.setGeometry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QProgressBar
的用法示例。
在下文中一共展示了QProgressBar.setGeometry方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Example
# 需要导入模块: from PyQt5.QtWidgets import QProgressBar [as 别名]
# 或者: from PyQt5.QtWidgets.QProgressBar import setGeometry [as 别名]
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.progress_bar = QProgressBar(self)
self.progress_bar.setGeometry(30, 40, 200, 25)
self.btn = QPushButton('Start', self)
self.btn.move(30, 80)
self.btn.clicked.connect(self.doAction)
self.timer = QBasicTimer()
self.step = 0
self.setGeometry(300, 300, 280, 170)
self.setWindowTitle('QProgressBar')
self.show()
def timerEvent(self, QTimerEvent):
if self.step >= 100:
self.timer.stop()
self.btn.setText('Finished')
return
self.step += 1
self.progress_bar.setValue(self.step)
def doAction(self):
if self.timer.isActive():
self.timer.stop()
self.btn.setText('Start')
else:
self.timer.start(100, self)
self.btn.setText('Stop')
示例2: Example
# 需要导入模块: from PyQt5.QtWidgets import QProgressBar [as 别名]
# 或者: from PyQt5.QtWidgets.QProgressBar import setGeometry [as 别名]
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def main_process(self):
th = MyThread(10)
th.start()
for i in range(10):
print("main process")
sleep(2)
def initUI(self):
self.pbar = QProgressBar(self)
self.pbar.setGeometry(30, 40, 200, 25)
self.btn = QPushButton('Start', self)
self.btn.move(40, 80)
self.btn.clicked.connect(self.main_process)
self.timer = QBasicTimer()
self.step = 0
self.setGeometry(300, 300, 280, 170)
self.setWindowTitle('QProgressBar')
self.show()
示例3: MainProcess
# 需要导入模块: from PyQt5.QtWidgets import QProgressBar [as 别名]
# 或者: from PyQt5.QtWidgets.QProgressBar import setGeometry [as 别名]
class MainProcess(QFrame):
def __init__(self, parent):
super(MainProcess, self).__init__()
self.parent = parent
self.initUI()
def initUI(self):
self.pbar = QProgressBar(self)
self.pbar.setGeometry(120, 40, 300, 25)
self.doing = False
self.btn = QPushButton(u'Старт', self)
self.btn.move(20, 40)
self.btn.clicked.connect(self.doAction)
self.setAutoFillBackground(True)
palette = self.palette()
palette.setColor(self.backgroundRole(), QColor('white'))
self.setPalette(palette)
self.setFrameShape(_frameShape)
self.setFrameShadow(_frameShadow)
self.setLineWidth(_lineWidth)
self.setMidLineWidth(_midLineWidth)
def doAction(self):
if not self.doing:
self.btn.setText(u'Стоп')
self.thread = MyThread()
self.pbar.setValue(0)
self.worker = Worker()
self.worker.moveToThread(self.thread)
self.doing = True
#self.thread.started.connect(self.worker.process)#worker.process)
self.worker.finished.connect(self.thread.quit)
#self.worker.finished.connect(self.worker.deleteLater)
#self.worker.finished.connect(self.update_button)
self.thread.finished.connect(self.update_button)
#self.worker.stoping.connect(self.thread.terminate)
#self.btn.clicked.connect(self.worker.stop)
QtCore.QMetaObject.invokeMethod(self.worker, 'process', Qt.QueuedConnection,
QtCore.Q_ARG(object, self.parent),
QtCore.Q_ARG(object, self.pbar))
self.thread.start()
else:
#self.doing = False
#self.btn.setText(u'Старт')
self.thread.terminate()
#self.pbar.setValue(0)
pass
def update_button(self):
self.doing = False
self.btn.setText(u'Старт')
self.pbar.setValue(0)
示例4: Example
# 需要导入模块: from PyQt5.QtWidgets import QProgressBar [as 别名]
# 或者: from PyQt5.QtWidgets.QProgressBar import setGeometry [as 别名]
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.pbar = QProgressBar(self)
self.pbar.setGeometry(30, 40, 200, 25)
self.btn = QPushButton('Start', self)
self.btn.move(40, 80)
self.btn.clicked.connect(self.doAction)
# タイマー
self.timer = QBasicTimer()
self.step = 0
self.setGeometry(300, 300, 280, 170)
self.setWindowTitle('QProgressBar')
self.show()
def timerEvent(self, e):
# カウントが100に達すると終了
if self.step >= 100:
self.timer.stop()
self.btn.setText('Finished')
return
# 呼ばれるたび1ずつ増やす
self.step = self.step + 1
self.pbar.setValue(self.step)
def doAction(self):
"""ボタンが押されると呼ばれる"""
# タイマーが実行中ならタイマーを停止する
if self.timer.isActive():
self.timer.stop()
self.btn.setText('Start')
# タイマーが停止中ならタイマーを実行する
else:
# (timeout[ms], イベントの受取先)
# timeoutで指定した時間間隔でシグナルが飛ぶ模様
self.timer.start(1000, self)
self.btn.setText('Stop')
示例5: MyQt
# 需要导入模块: from PyQt5.QtWidgets import QProgressBar [as 别名]
# 或者: from PyQt5.QtWidgets.QProgressBar import setGeometry [as 别名]
class MyQt(QWidget):
def __init__(self):
super(MyQt, self).__init__()
self.initUI()
def initUI(self):
# 构建一个进度条
self.pbar = QProgressBar(self)
# 从左上角30-50的界面,显示一个200*25的界面
self.pbar.setGeometry(30, 50, 200, 25) # 设置进度条的位置
# 设置开始按钮
self.btn = QPushButton('开始', self)
self.btn.move(50, 90) # 按钮移动的位置
# 点击按钮
# 信号函数不能加括号
self.btn.clicked.connect(self.doAction)
# 构建一个计时器
self.timer = QBasicTimer()
# 计数
self.step = 0
self.setGeometry(300,300,280,170)
self.setWindowTitle('我是进度条')
self.setWindowIcon(QIcon('1.jpg'))
self.show()
def doAction(self):
# 判断是否处于激活状态
if self.timer.isActive():
self.timer.stop()
self.btn.setText('开始')
else:
self.timer.start(100,self)
self.btn.setText('停止')
def timerEvent(self, *args, **kwargs):
if self.step>=100:
# 停止进度条
self.timer.stop()
self.btn.setText('完成')
return
self.step+=1
# 把进度条每次充值的值赋给进图条
self.pbar.setValue(self.step)
示例6: CpSplashScreen
# 需要导入模块: from PyQt5.QtWidgets import QProgressBar [as 别名]
# 或者: from PyQt5.QtWidgets.QProgressBar import setGeometry [as 别名]
class CpSplashScreen(QSplashScreen):
def __init__(self, parent = None, pixmap = None, maxSteps = 1):
super().__init__(parent, pixmap)
self.maxSteps = maxSteps
self.progress = QProgressBar(self)
#self.progress.setGeometry(15, 15, 100, 10)
self.progress.setTextVisible(False)
self.progress.setMinimum(0)
self.progress.setMaximum(self.maxSteps)
self.progress.setValue(0)
self.progress.hide()
def show(self):
super().show()
geo = self.geometry()
self.progress.setGeometry(5, geo.height() - 20, 100, 10)
self.progress.show()
def showMessage(self, msg, step = None, color = None):
if step is not None:
self.progress.setValue(step)
self.progress.update()
super().showMessage(msg, color=color)
示例7: SplashScreen
# 需要导入模块: from PyQt5.QtWidgets import QProgressBar [as 别名]
# 或者: from PyQt5.QtWidgets.QProgressBar import setGeometry [as 别名]
class SplashScreen(QWidget):
"""
A splash screen window with an image, a textbox for current status, and a progress bar.
"""
def __init__(self):
super().__init__()
self.setWindowFlags(Qt.FramelessWindowHint)
self.setWindowTitle(_('Recharify loading...'))
QLabel(_('Loading splash screen image...'), self).move(15, 10)
self.progress = QProgressBar(self)
self.progress.setRange(0, 100)
self.progress.setGeometry(0, 0, 250, 20)
self.setGeometry(300, 300, 250, 150)
self.movetocenter()
def movetocenter(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def progress_change(self, p):
self.progress.setValue(p)
示例8: Example
# 需要导入模块: from PyQt5.QtWidgets import QProgressBar [as 别名]
# 或者: from PyQt5.QtWidgets.QProgressBar import setGeometry [as 别名]
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
# checkbox
cb = QCheckBox('show title', self)
cb.move(20, 20)
cb.toggle()
cb.stateChanged.connect(self.changeTitle)
# toggle button
self.col = QColor(0, 0, 0)
redb = QPushButton('red', self)
redb.setCheckable(True)
redb.move(20, 40)
redb.clicked[bool].connect(self.setColor)
greenb = QPushButton('green', self)
greenb.setCheckable(True)
greenb.move(20, 60)
greenb.clicked[bool].connect(self.setColor)
blueb = QPushButton('blue', self)
blueb.setCheckable(True)
blueb.move(20, 80)
blueb.clicked[bool].connect(self.setColor)
self.square = QFrame(self)
self.square.setGeometry(150, 20, 100, 100)
self.square.setStyleSheet('QWidget {background-color: %s}' %
self.col.name())
# slider
sld = QSlider(Qt.Horizontal, self)
sld.setFocusPolicy(Qt.NoFocus)
sld.setGeometry(20, 160, 100, 20)
sld.valueChanged[int].connect(self.changeValue)
self.label = QLabel('0', self)
self.label.setGeometry(140, 155, 80, 30)
# progressbar
self.pbar = QProgressBar(self)
self.pbar.setGeometry(20, 200, 200, 25)
self.btn = QPushButton('start', self)
self.btn.move(20, 230)
self.btn.clicked.connect(self.doAction)
self.timer = QBasicTimer()
self.step = 0
# calendar
cal = QCalendarWidget(self)
cal.setGridVisible(True)
cal.move(20, 300)
cal.clicked[QDate].connect(self.showDate)
self.lbl = QLabel(self)
date = cal.selectedDate()
self.lbl.setText(date.toString())
self.lbl.move(20, 280)
self.setGeometry(300, 300, 400, 550)
self.setWindowTitle('widgets')
self.show()
def showDate(self, date):
self.lbl.setText(date.toString())
def timerEvent(self, e):
if self.step >= 100:
self.timer.stop()
self.btn.setText('finished')
return
self.step = self.step + 1
self.pbar.setValue(self.step)
def doAction(self):
if self.timer.isActive():
self.timer.stop()
else:
self.timer.start(100, self)
self.btn.setText('stop')
def changeValue(self, value):
self.label.setText(str(value))
def setColor(self, pressed):
source = self.sender()
if pressed:
#.........这里部分代码省略.........
示例9: Ui_Form
# 需要导入模块: from PyQt5.QtWidgets import QProgressBar [as 别名]
# 或者: from PyQt5.QtWidgets.QProgressBar import setGeometry [as 别名]
class Ui_Form(object):
def setupUi(self,Form):
Form.setObjectName("Form")
Form.resize(730, 491)
self.layoutWidget = QtWidgets.QWidget(Form)
self.layoutWidget.setGeometry(QtCore.QRect(10, 160, 331, 221))
self.layoutWidget.setObjectName("layoutWidget")
self.gridLayout_2 = QtWidgets.QGridLayout(self.layoutWidget)
self.gridLayout_2.setContentsMargins(0, 0, 0, 0)
self.gridLayout_2.setObjectName("gridLayout_2")
self.ROI = QtWidgets.QLineEdit(self.layoutWidget)
self.ROI.setAutoFillBackground(True)
ROIListCompleter = ['leftba1-3','leftba4','leftba5','leftba6','leftba7','leftba8','leftba9','leftba10','leftba11','leftba17','leftba18','leftba19','leftba20'
,'leftba21','leftba22','leftba28','leftba36','leftba37','leftba38','leftba39','leftba40','leftba42','leftba44-45','leftba46'
'leftba47','leftcerebellartonsil','rightba1-3','rightba4','rightba5','rightba6','rightba7','rightba8','rightba9','rightba10','rightba11'
,'rightba17','rightba18','rightba19','rightba20','rightba21','rightba22','rightba28','rightba36','rightba37','rightba38','rightba39'
'rightba40','rightba42','rightba44-45','rightba46','rightba47','rightcerebellartonsil']
self.completerRoi = QCompleter(ROIListCompleter,self.ROI)
self.ROI.setCompleter(self.completerRoi)
self.ROI.setObjectName("ROI")
self.gridLayout_2.addWidget(self.ROI, 5, 1, 1, 1)
self.ROILabel = QtWidgets.QLabel(self.layoutWidget)
self.ROILabel.setObjectName("ROILabel")
self.gridLayout_2.addWidget(self.ROILabel, 5, 0, 1, 1)
self.MinimumTempLabel = QtWidgets.QLabel(self.layoutWidget)
self.MinimumTempLabel.setObjectName("MinimumTempLabel")
self.gridLayout_2.addWidget(self.MinimumTempLabel, 4, 0, 1, 1)
self.tailComboBox = QtWidgets.QComboBox(self.layoutWidget)
self.tailComboBox.setObjectName("tailComboBox")
self.tailComboBox.addItem("")
self.tailComboBox.addItem("")
self.tailComboBox.addItem("")
self.tailComboBox.addItem("")
self.gridLayout_2.addWidget(self.tailComboBox, 6, 1, 1, 1)
self.MinTempCluster = QtWidgets.QLineEdit(self.layoutWidget)
self.MinTempCluster.setObjectName("MinTempCluster")
self.gridLayout_2.addWidget(self.MinTempCluster, 4, 1, 1, 1)
self.Condition1 = QtWidgets.QLineEdit(self.layoutWidget)
self.Condition1.setAutoFillBackground(True)
self.Condition1.setObjectName("Condition1")
self.gridLayout_2.addWidget(self.Condition1, 0, 1, 1, 1)
self.TailLabel = QtWidgets.QLabel(self.layoutWidget)
self.TailLabel.setObjectName("TailLabel")
self.gridLayout_2.addWidget(self.TailLabel, 6, 0, 1, 1)
self.Condition1Label = QtWidgets.QLabel(self.layoutWidget)
self.Condition1Label.setObjectName("Condition1Label")
self.gridLayout_2.addWidget(self.Condition1Label, 0, 0, 1, 1)
#self.Prestimulus = QtWidgets.QLineEdit(self.layoutWidget)
#self.Prestimulus.setObjectName("Prestimulus")
#self.gridLayout_2.addWidget(self.Prestimulus, 3, 1, 1, 1)
#self.PrestimLabel = QtWidgets.QLabel(self.layoutWidget)
#self.PrestimLabel.setObjectName("PrestimLabel")
self.Prestimulus = 0
#self.gridLayout_2.addWidget(self.PrestimLabel, 3, 0, 1, 1)
self.StartTime = QtWidgets.QLineEdit(self.layoutWidget)
self.StartTime.setMaxLength(1000)
self.StartTime.setObjectName("StartTime")
self.gridLayout_2.addWidget(self.StartTime, 2, 1, 1, 1)
self.FindROI = QtWidgets.QPushButton(self.layoutWidget)
self.FindROI.setObjectName("FindROI")
self.gridLayout_2.addWidget(self.FindROI, 5, 2, 1, 1)
self.StartTimelabel = QtWidgets.QLabel(self.layoutWidget)
self.StartTimelabel.setObjectName("StartTimelabel")
self.gridLayout_2.addWidget(self.StartTimelabel, 2, 0, 1, 1)
self.BadSubjects = QtWidgets.QLineEdit(self.layoutWidget)
self.BadSubjects.setAutoFillBackground(False)
self.BadSubjects.setObjectName("BadSubjects")
self.gridLayout_2.addWidget(self.BadSubjects, 1, 1, 1, 1)
self.BadSubjectsLabel = QtWidgets.QLabel(self.layoutWidget)
self.BadSubjectsLabel.setObjectName("BadSubjectsLabel")
self.gridLayout_2.addWidget(self.BadSubjectsLabel, 1, 0, 1, 1)
self.layoutWidget1 = QtWidgets.QWidget(Form)
self.layoutWidget1.setGeometry(QtCore.QRect(340, 160, 292, 151))
self.layoutWidget1.setObjectName("layoutWidget1")
self.gridLayout_3 = QtWidgets.QGridLayout(self.layoutWidget1)
self.gridLayout_3.setContentsMargins(0, 0, 0, 0)
self.gridLayout_3.setObjectName("gridLayout_3")
self.PthreshVal = QtWidgets.QLineEdit(self.layoutWidget1)
self.PthreshVal.setObjectName("PthreshVal")
self.gridLayout_3.addWidget(self.PthreshVal, 2, 1, 1, 1)
self.EndTimeLabel = QtWidgets.QLabel(self.layoutWidget1)
self.EndTimeLabel.setObjectName("EndTimeLabel")
self.gridLayout_3.addWidget(self.EndTimeLabel, 1, 0, 1, 1)
self.Condition2 = QtWidgets.QLineEdit(self.layoutWidget1)
self.Condition2.setObjectName("Condition2")
self.gridLayout_3.addWidget(self.Condition2, 0, 1, 1, 1)
self.Condition2Label = QtWidgets.QLabel(self.layoutWidget1)
self.Condition2Label.setObjectName("Condition2Label")
self.gridLayout_3.addWidget(self.Condition2Label, 0, 0, 1, 1)
#self.MAXFDR = QtWidgets.QLineEdit(self.layoutWidget1)
#self.MAXFDR.setObjectName("MAXFDR")
#self.gridLayout_3.addWidget(self.MAXFDR, 3, 1, 1, 1)
self.MAXFDR = 0
self.PtreshLabel = QtWidgets.QLabel(self.layoutWidget1)
self.PtreshLabel.setObjectName("PtreshLabel")
self.gridLayout_3.addWidget(self.PtreshLabel, 2, 0, 1, 1)
#.........这里部分代码省略.........
示例10: Example
# 需要导入模块: from PyQt5.QtWidgets import QProgressBar [as 别名]
# 或者: from PyQt5.QtWidgets.QProgressBar import setGeometry [as 别名]
class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
# checkBox
cb = QCheckBox('show title', self)
cb.move(10, 10)
cb.toggle()
cb.stateChanged.connect(self.changeTitle)
# 颜色混合
self.col = QColor(0, 0, 0)
redb = QPushButton('Red', self)
redb.setCheckable(True)
redb.move(10, 30)
redb.clicked[bool].connect(self.setColor)
grnb = QPushButton('Green', self)
grnb.setCheckable(True)
grnb.move(10, 60)
grnb.clicked[bool].connect(self.setColor)
blueb = QPushButton('Blue', self)
blueb.setCheckable(True)
blueb.move(10, 90)
blueb.clicked[bool].connect(self.setColor)
self.square = QFrame(self)
self.square.setGeometry(150, 20, 50, 50)
self.square.setStyleSheet("QWidget { background-color: %s}" %
self.col.name())
# slider 滚动条
sld = QSlider(Qt.Horizontal, self)
sld.setFocusPolicy(Qt.NoFocus)
sld.setGeometry(10, 120, 100, 10)
sld.valueChanged[int].connect(self.changeValue)
self.label = QLabel(self)
self.label.setPixmap(QPixmap('1.png'))
self.label.setGeometry(150, 90, 80, 80)
# 进度条ProgressBar
self.pbar = QProgressBar(self)
self.pbar.setGeometry(10, 170, 200, 20)
self.btn = QPushButton('Start', self)
self.btn.move(10, 200)
self.btn.clicked.connect(self.doAction)
self.timer = QBasicTimer()
self.step = 0
# Calendar 日历
cal = QCalendarWidget(self)
cal.setGridVisible(True)
cal.move(10, 230)
cal.clicked[QDate].connect(self.showDate)
self.lbl = QLabel(self)
date = cal.selectedDate()
self.lbl.setText(date.toString())
self.lbl.move(80, 440)
self.setGeometry(300, 200, 300, 500)
self.setWindowTitle('Toggle')
self.show()
def changeTitle(self, state):
if state == Qt.Checked:
self.setWindowTitle('Toogle')
else:
self.setWindowTitle(' ')
def setColor(self, pressed):
source = self.sender()
if pressed:
val = 255
else:
val = 0
if source.text() == "Red":
self.col.setRed(val)
elif source.text() == "Green":
self.col.setGreen(val)
else:
self.col.setBlue(val)
self.square.setStyleSheet("QFrame {background-color: %s}" % self.col.name())
def changeValue(self, value):
if value == 0:
self.label.setPixmap(QPixmap('1.png'))
elif 0 < value <= 30:
self.label.setPixmap(QPixmap('2.png'))
elif 30 < value < 80:
self.label.setPixmap(QPixmap('3.png'))
else:
self.label.setPixmap(QPixmap('4.png'))
#.........这里部分代码省略.........
示例11: Example
# 需要导入模块: from PyQt5.QtWidgets import QProgressBar [as 别名]
# 或者: from PyQt5.QtWidgets.QProgressBar import setGeometry [as 别名]
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
if not os.path.exists(eboots_path):
debug("Something gone wrong")
self.showDialog()
else:
self.local_eboots = ([ f for f in os.listdir(eboots_path) if f.endswith('.bin') and os.path.isfile(os.path.join(eboots_path,f)) ])
r = requests.get(url + '/list.php')
self.remote_eboots = r.json()
self.download_list = list(set(self.remote_eboots) - set(self.local_eboots))
self.upload_list = list(set(self.local_eboots) - set(self.remote_eboots))
#debug("{0}".format(len(self.download_list),self.download_list))
openDir = QAction(QIcon('/usr/share/icons/hicolor/24x24/apps/openx24.png'), 'Open SWAP directory', self)
openDir.setShortcut('Ctrl+O')
openDir.setStatusTip('Open SWAP directory')
openDir.triggered.connect(self.showDialog)
exitAction = QAction(QIcon('/usr/share/icons/hicolor/24x24/apps/exitx24.png'), 'Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit')
exitAction.triggered.connect(qApp.quit)
self.toolbar = self.addToolBar('Open')
self.toolbar.addAction(openDir)
self.toolbar = self.addToolBar('Exit')
self.toolbar.addAction(exitAction)
self.pbar = QProgressBar(self)
self.pbar.setGeometry(30, 40, 300, 25)
if len(self.download_list) > 0:
self.btn1 = QPushButton('Download: {0:6} files'.format(len(self.download_list)), self)
else:
self.btn1 = QPushButton('Nothing to download', self)
self.pbar.setValue(100)
self.btn1.move(100, 80)
self.btn1.resize(150, 30)
self.btn1.clicked.connect(self.doActionDownload)
self.step1 = 0
self.ubar = QProgressBar(self)
self.ubar.setGeometry(30, 120, 300, 25)
if len(self.upload_list) > 0:
self.btn2 = QPushButton('Upload: {0:6} files'.format(len(self.upload_list)), self)
else:
self.btn2 = QPushButton('Nothing to upload', self)
self.ubar.setValue(100)
self.step2 = 0
self.btn2.move(100, 160)
self.btn2.resize(150, 30)
self.btn2.clicked.connect(self.doActionUpload)
self.lbl1 = QLabel('SWAP directory:', self)
self.lbl1.move(10, 190)
self.lbl1.resize(400, 15)
if eboots_path:
self.lbl2 = QLabel(eboots_path, self)
self.lbl2.resize(400, 15)
#debug(eboots_path)
self.lbl2.move(10, 210)
else:
self.lbl1 = QLabel('Please, add SWAP directory', self)
self.lbl1.move(10, 190)
self.lbl1.resize(400, 15)
self.setGeometry(300, 300, 350, 240)
self.setWindowTitle('SwapSyncer')
self.show()
def showDialog(self):
self.eboots_path = QFileDialog.getExistingDirectory(self, 'Open SWAP directory', '/home')
if self.eboots_path:
with open(conf_path, 'w') as fp:
fp.write(str(self.eboots_path))
#debug(self.eboots_path)
sys.exit(app.exec_())
def doActionDownload(self):
if self.download_list is not None and len(self.download_list) > 0:
self.i = 1;
self.palka = 0;
#.........这里部分代码省略.........
示例12: CheckCreds
# 需要导入模块: from PyQt5.QtWidgets import QProgressBar [as 别名]
# 或者: from PyQt5.QtWidgets.QProgressBar import setGeometry [as 别名]
class CheckCreds(QDialog):
"""
This class manages the authentication process for oVirt. If credentials are saved, they're
tried automatically. If they are wrong, the username/password dialog is shown.
"""
def __init__(self, parent, username, password, remember):
QDialog.__init__(self, parent)
self.uname = username
self.pw = password
self.remember = False if conf.CONFIG['allow_remember'] == '0' else remember
self.setModal(True)
self.initUI()
def initUI(self):
"""
Description: A progress bar, a status message will be shown and a timer() method will
be invoked as part of the authentication process.
Arguments: None
Returns: Nothing
"""
self.pbar = QProgressBar(self)
self.pbar.setGeometry(30, 40, 200, 25)
self.status = QLabel(self)
self.status.setGeometry(30, 75, 200, 20)
self.timer = QBasicTimer()
self.step = 0
self.setGeometry(300, 300, 255, 100)
self.center()
self.setWindowTitle(_('loading'))
self.show()
self.timer.start(100, self)
def timerEvent(self, e):
"""
Description: Called periodically as part of the QBasicTimer() object.
Authentication will be handled within this method.
Arguments: The event. Won't be used, though.
Returns: Nothing, just exits when progress bar reaches 100%
"""
global conf
err = QMessageBox()
self.status.setText(_('authenticating'))
if not conf.USERNAME:
try:
kvm = API(url=conf.CONFIG['ovirturl'], username=self.uname + '@' + conf.CONFIG['ovirtdomain'], password=self.pw, insecure=True, timeout=int(conf.CONFIG['conntimeout']), filter=True)
conf.OVIRTCONN = kvm
conf.USERNAME = self.uname
conf.PASSWORD = self.pw
self.status.setText(_('authenticated_and_storing'))
self.step = 49
except ConnectionError as e:
err.critical(self, _('apptitle') + ': ' + _('error'), _('ovirt_connection_error') + ': ' + sub('<[^<]+?>', '', str(e)))
self.status.setText(_('error_while_authenticating'))
self.step = 100
except RequestError as e:
err.critical(self, _('apptitle') + ': ' + _('error'), _('ovirt_request_error') + ': ' + sub('<[^<]+?>', '', str(e)))
self.status.setText(_('error_while_authenticating'))
self.step = 100
if self.step >= 100:
# Authenticacion process has concluded
self.timer.stop()
self.close()
return
elif self.step == 50:
# Credentials were ok, we check whether we should store them for further uses
if self.remember:
self.status.setText(_('storing_credentials'))
with os.fdopen(os.open(conf.USERCREDSFILE, os.O_WRONLY | os.O_CREAT, 0600), 'w') as handle:
handle.write('[credentials]\nusername=%s\npassword=%s' % (self.uname, encode(self.pw, 'rot_13')))
handle.close()
self.step = 99
else:
self.status.setText(_('successfully_authenticated'))
self.step = 99
self.step = self.step + 1
self.pbar.setValue(self.step)
示例13: Splash
# 需要导入模块: from PyQt5.QtWidgets import QProgressBar [as 别名]
# 或者: from PyQt5.QtWidgets.QProgressBar import setGeometry [as 别名]
class Splash(QObject, LogMixin, EventMixin):
"""Splash screen class"""
def __init__(self, parent, msg = ""):
"""
Constructor of Splash screen
:param parent: ui parent
:param msg: initial message text
"""
super().__init__()
self._parent = parent
self.isHidden = True
self._progress = 0
self._progressBar = None
self.msg = msg
pixmap = QtGui.QPixmap(380, 100)
pixmap.fill(QtGui.QColor("darkgreen"))
self._splash = QSplashScreen(pixmap)
self._splash.setParent(self._parent)
self.add_progressbar()
def add_progressbar(self):
"""Add separate progress bar to splash screen"""
self._progressBar = QProgressBar(self._splash)
self._progressBar.setGeometry(self._splash.width() / 10, 8 * self._splash.height() / 10,
8 * self._splash.width() / 10, self._splash.height() / 10)
self._progressBar.hide()
def setProgress(self, val):
"""
Set progress bar to ``val``
If splash has no progressbar, it will be added dynamically.
Remove progressbar with ``val`` as None.
:param val: absolut percent value
:return:
"""
if val is not None:
self._progressBar.show()
self._progressBar.setTextVisible(True)
self.progress = val
try:
self._progressBar.setValue(self.progress)
except:
pass
else:
self._progressBar.setTextVisible(False)
self._progressBar.hide()
self._progressBar.reset()
if self.isHidden is True:
self.isHidden = False
self.show_()
def incProgress(self, val):
"""
Increase progressbar value by ``val``
If splash has no progressbar, it will be added dynamically.
Remove progressbar with ``val`` as None.
:param val: value to increase by
:return:
"""
if val is not None:
self._progressBar.show()
self._progressBar.setTextVisible(True)
self.progress = self.progress + val
try:
self._progressBar.setValue(self.progress)
qApp.processEvents()
except:
pass
else:
self._progressBar.setTextVisible(False)
self._progressBar.hide()
self._progressBar.reset()
if self.isHidden is True:
self.isHidden = False
self.show_()
def setParent(self, parent):
"""Set splash's parent"""
self._parent = parent
self._splash.setParent(parent)
@pyqtSlot()
@pyqtSlot(bool)
def close(self, dummy = True):
self.logger.debug("Hide splash")
self.isHidden = True
#.........这里部分代码省略.........
示例14: Window
# 需要导入模块: from PyQt5.QtWidgets import QProgressBar [as 别名]
# 或者: from PyQt5.QtWidgets.QProgressBar import setGeometry [as 别名]
class Window(QMainWindow):
def __init__(self):
# noinspection PyArgumentList
super(Window, self).__init__()
self.init_ui()
def init_ui(self):
self.statusBar().showMessage('Ready')
action = QAction("Close Window", self)
action.setShortcut("Ctrl+Q")
action.setStatusTip("quit application")
action.triggered.connect(self.close_application)
main_menu = self.menuBar()
file_menu = main_menu.addMenu('&File')
file_menu.addAction(action)
self.setWindowTitle("bind9 DNS")
self.setGeometry(200, 200, 800, 600)
self.setWindowIcon(QIcon('../pics/pythonlogo.png'))
self.home()
def home(self):
btn = QPushButton('quit', self)
btn.clicked.connect(self.close_application)
btn.resize(btn.minimumSizeHint())
btn.move(0, 60)
action = QAction(QIcon('../pics/pythonlogo.png'),
'Flee the Scene', self)
action.triggered.connect(self.close_application)
self.toolBar = self.addToolBar('Extraction')
self.toolBar.addAction(action)
checkBox = QCheckBox('Enlarge window', self)
checkBox.move(50, 25)
# checkBox.toggle()
checkBox.stateChanged.connect(self.enlargeWindow)
self.progress = QProgressBar(self)
self.progress.setGeometry(100, 62, 250, 20)
self.btn = QPushButton("Download", self)
self.btn.clicked.connect(self.download)
self.btn.resize(btn.minimumSizeHint())
self.btn.move(100, 100)
print(self.style().objectName())
self.styleChoice = QLabel('Windows Vista', self)
self.styleChoice.move(50, 200)
comboBox = QComboBox(self)
comboBox.addItem('motif')
comboBox.addItem('Windows')
comboBox.addItem('cde')
comboBox.addItem('Plastique')
comboBox.addItem('Cleanlooks')
comboBox.addItem('windowsvista')
comboBox.move(50, 250)
comboBox.activated[str].connect(self.style_choice)
self.show()
def style_choice(self, text):
self.styleChoice.setText(text)
QApplication.setStyle(QStyleFactory.create(text))
def download(self):
self.completed = 0
while self.completed < 100:
self.completed += 0.0001
self.progress.setValue(self.completed)
def enlargeWindow(self, state):
if state == Qt.Checked:
self.setGeometry(100, 100, 1000, 800)
else:
self.setGeometry(200, 200, 800, 600)
def close_application(self):
choice = QMessageBox.question(self, 'Message',
"Are you sure to quit?", QMessageBox.Yes |
QMessageBox.No, QMessageBox.No)
if choice == QMessageBox.Yes:
print('quit application')
sys.exit()
else:
pass