本文整理汇总了Python中PyQt5.QtCore.QBasicTimer.isActive方法的典型用法代码示例。如果您正苦于以下问题:Python QBasicTimer.isActive方法的具体用法?Python QBasicTimer.isActive怎么用?Python QBasicTimer.isActive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QBasicTimer
的用法示例。
在下文中一共展示了QBasicTimer.isActive方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Example
# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import isActive [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: AutoSaver
# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import isActive [as 别名]
class AutoSaver(QObject):
"""
Class implementing the auto saver.
"""
AUTOSAVE_IN = 1000 * 3
MAXWAIT = 1000 * 15
def __init__(self, parent, save):
"""
Constructor
@param parent reference to the parent object (QObject)
@param save slot to be called to perform the save operation
@exception RuntimeError raised, if no parent is given
"""
super(AutoSaver, self).__init__(parent)
if parent is None:
raise RuntimeError("AutoSaver: parent must not be None.")
self.__save = save
self.__timer = QBasicTimer()
self.__firstChange = QTime()
def changeOccurred(self):
"""
Public slot handling a change.
"""
if self.__firstChange.isNull():
self.__firstChange.start()
if self.__firstChange.elapsed() > self.MAXWAIT:
self.saveIfNeccessary()
else:
self.__timer.start(self.AUTOSAVE_IN, self)
def timerEvent(self, evt):
"""
Protected method handling timer events.
@param evt reference to the timer event (QTimerEvent)
"""
if evt.timerId() == self.__timer.timerId():
self.saveIfNeccessary()
else:
super(AutoSaver, self).timerEvent(evt)
def saveIfNeccessary(self):
"""
Public method to activate the save operation.
"""
if not self.__timer.isActive():
return
self.__timer.stop()
self.__firstChange = QTime()
self.__save()
示例3: Example
# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import isActive [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')
示例4: MyQt
# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import isActive [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)
示例5: Example
# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import isActive [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:
#.........这里部分代码省略.........
示例6: ScrollArea
# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import isActive [as 别名]
#.........这里部分代码省略.........
viewport = self.viewport().rect()
dx = pos.x() - viewport.left() - 12
if dx >= 0:
dx = max(0, pos.x() - viewport.right() + 12)
dy = pos.y() - viewport.top() - 12
if dy >= 0:
dy = max(0, pos.y() - viewport.bottom() + 12)
self.steadyScroll(QPoint(dx*10, dy*10))
def scrollTo(self, pos):
"""Scroll the View to get pos (QPoint) in the top left corner (if possible).
Returns the actual distance moved.
"""
return self.scrollBy(pos - self.scrollOffset())
def scrollBy(self, diff):
"""Scroll the View diff pixels (QPoint) in x and y direction.
Returns the actual distance moved.
"""
hbar = self.horizontalScrollBar()
vbar = self.verticalScrollBar()
x = hbar.value()
hbar.setValue(hbar.value() + diff.x())
x = hbar.value() - x
y = vbar.value()
vbar.setValue(vbar.value() + diff.y())
y = vbar.value() - y
return QPoint(x, y)
def kineticScrollTo(self, pos):
"""Scroll the View to get pos (QPoint) in the top left corner (if possible).
Returns the actual distance the scroll area will move.
"""
return self.kineticScrollBy(pos - self.scrollOffset())
def kineticScrollBy(self, diff):
"""Scroll the View diff pixels (QPoint) in x and y direction.
Returns the actual distance the scroll area will move.
"""
ret = self.canScrollBy(diff)
if diff:
scroller = KineticScroller()
scroller.scrollBy(diff)
self.startScrolling(scroller)
return ret
def kineticAddDelta(self, diff):
"""Add diff (QPoint) to an existing kinetic scroll.
If no scroll is active, a new one is started (like kineticScrollBy).
"""
if isinstance(self._scroller, KineticScroller):
self._scroller.scrollBy(self._scroller.remainingDistance() + diff)
else:
self.kineticScrollBy(diff)
def steadyScroll(self, diff):
"""Start steadily scrolling diff (QPoint) pixels per second.
Stops automatically when the end is reached.
"""
if diff:
self.startScrolling(SteadyScroller(diff, self.scrollupdatespersec))
else:
self.stopScrolling()
def startScrolling(self, scroller):
"""Begin a scrolling operation using the specified scroller."""
self._scroller = scroller
if not self._scrollTimer.isActive():
self._scrollTimer.start(1000 / self.scrollupdatespersec, self)
def stopScrolling(self):
"""Stop scrolling."""
if self._scroller:
self._scrollTimer.stop()
self._scroller = None
def isScrolling(self):
"""Return True if a scrolling movement is active."""
return bool(self._scroller)
def timerEvent(self, ev):
"""Called by the _scrollTimer."""
diff = self._scroller.step()
# when scrolling slowly, it might be that no redraw is needed
if diff:
# change the scrollbars, but check how far they really moved.
if not self.scrollBy(diff) or self._scroller.finished():
self.stopScrolling()
示例7: Example
# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import isActive [as 别名]
#.........这里部分代码省略.........
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'))
def timerEvent(self, *args, **kwargs):
if self.step >= 100:
self.timer.stop()
self.btn.setText('Finished')
return
self.step += 1
self.pbar.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')
def showDate(self, date):
self.lbl.setText(date.toString())
示例8: YaP
# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import isActive [as 别名]
#.........这里部分代码省略.........
print('query_list is: ')
for l in self.query_list:
print(l.encode('utf-8').decode('cp1251'))
self.file_taken = True
fname_chars = []
for char in self.fname:
if (char == '/'):
fname_chars.append('\\')
else:
fname_chars.append(char)
win_path = ''.join(fname_chars)
self.label_fp.setText(win_path)
self.label_fp.adjustSize()
self.start_search(self.event)
def keyPressEvent(self, event):
if type(event) == QKeyEvent:
if event.key() == Qt.Key_Escape:
self.close()
elif event.key() == Qt.Key_Return:
self.set_query(self)
self.start_search(self)
def set_query(self, event):
self.query = self.field.text()
self.rank = 0
self.file_queries = []
def push_query(self, query):
self.label.setText(query)
self.label.adjustSize()
def start_search(self, event):
if self.timer.isActive():
self.timer.stop()
else:
self.timer.start(100, self)
self.label_done.setText(
'Запросы обработаны, результаты занесены в базу данных.\n\
Для сохранения в файл нажмите кнопку \"Сохранить\".')
if self.file_taken:
for j, item in enumerate(self.query_list):
self.query = self.query_list[j]
r = requests.get(self.query_url + self.query)
self.r_count += 1
# функция limit() может быть вызвана только один раз #
# во избежание неправильных показателей счётчика. #
limit_data = limit(self.r_count, self.db_path, self.req_date) #
# ########################################################### #
if (limit_data[0]):
result = r.text
result_list = result.split('<url>')
for i, item in enumerate(result_list):
if self.rate_url in item:
self.rank += i
break
self.res_list.append((
self.query.encode('utf-8').decode('cp1251'),
self.rank,
self.req_date,))
self.file_queries.append(
self.query.encode('utf-8').decode('cp1251'))
limit_resume = str(limit_data[1]) + ' - Winter is close!'
else:
limit_resume = str(limit_data[1]) +\
'Hour limit is here... Wait about ' +\
示例9: OpenGLWidget
# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import isActive [as 别名]
class OpenGLWidget(QOpenGLWidget):
def __init__(self, *args, **kwargs):
'''
Class representing OpenGL widget in the VisualizationWindow.
'''
super(OpenGLWidget, self).__init__(*args, **kwargs)
self._room = self.parent().room # assign room geometry to a variable
self.setGeometry(self.parent()._width * .25, 0, self.parent()._width, self.parent()._height) # window size/pos
self._timer = QBasicTimer() # create a timer
def initializeGL(self):
'''
A method to initialize all OpenGL features.
'''
glClearColor(.22, .22, .22, 1) # set background color to gray
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # make sure to clear everything at the beginning
glClearDepth(1) # set background depth to farthest
glEnable(GL_DEPTH_TEST) # enable depth testing for z-culling
glDepthFunc(GL_LEQUAL) # set the type of depth-test
glShadeModel(GL_SMOOTH) # enable smooth shading
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) # nice perspective corrections
glMatrixMode(GL_PROJECTION) # necessary for a nice perspective view
glLoadIdentity() # necessary for a nice perspective view
gluPerspective(45, (self.width() / self.height()), .1, 50.0) # configure perspective view
glMatrixMode(GL_MODELVIEW) # necessary for a nice model view
glLoadIdentity() # necessary for a nice model view
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) # wireframe rendering method
gluLookAt( # camera position and looking point
-15, 8, -15,
-3, 0, 0,
0, 1, 0
)
def paintGL(self):
'''
A method to paint in OpenGL.
'''
glClearColor(.22, .22, .22, 1) # set background color to gray
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # clear everything before rendering next frame
self._draw_grid() # drawing grid lines
self._draw_room() # drawing room geometry
if self._timer.isActive(): # if animation is initialized
self._draw_particles() # draw sound waves represented by particles
def timerEvent(self, QTimerEvent):
'''
An overridden method of what happens on each self._timer tick.
Warning! This method should only be used by self.initialize_animation()!!
:param QTimerEvent: should be ignored
'''
self.update() # calling self.update() in order to refresh the widget
def initialize_animation(self, source_pos=(0,0,0), source_spl=80, source_freq=1000, fps=60):
'''
A method to animate the ray tracing method in 4D.
:param source_pos: source position tuple
:param source_spl: source sound pressure level
:param source_freq: source sound frequency
'''
self._source_pos = source_pos
self._source_spl = source_spl
self._source_power = 10 ** (self._source_spl * .1)
self._source_freq = source_freq
self._calculate_particles_normals_positions_energies()
self._timer.start(1000 / fps, self)
def _draw_grid(self):
'''
A method to draw grid lines.
'''
glLineWidth(1) # width of a single grid line
glColor3f(.29, .29, .29, 1) # color of a single grid line (gray)
glBegin(GL_LINES) # tell OpenGL to draw lines
grid_lines = 10 # grid lines range (meaning its gird lines number / 4)
for i in range(-grid_lines, grid_lines + 1): # drawing grid lines
glVertex3f(-grid_lines, 0, i) # draw a horizontal line
glVertex3f(grid_lines, 0, i)
glVertex3f(i, 0, -grid_lines) # draw a vertical line
glVertex3f(i, 0, grid_lines)
glColor3f(.52, .07, .07, 1) # change line color to red
glVertex3f(-grid_lines, 0, 0) # draw red grid line
glVertex3f(grid_lines, 0, 0)
glColor3f(.07, .52, .07, 1) # change line color to green
glVertex3f(0, 0, -grid_lines) # draw green grid line
glVertex3f(0, 0, grid_lines)
glEnd() # tell OpenGL to stop drawing
def _draw_room(self):
'''
A method to draw room geometry.
'''
faces = self._room.faces # store room faces in a new variable
points = self._room.points # store room points in a new variable
glColor3f(.59, .59, .62, 1) # color of an edge (light gray)
for id in faces: # iterate through all faces
glBegin(GL_POLYGON) # tell OpenGL to draw a polygon
for point_id in faces[id][:-1]: # iterate through all points in a single face
#.........这里部分代码省略.........