def shutdown(self, *args):
if self.closing:
return
self.closing = True
global bitmaskd
bitmaskd.join()
if os.path.isfile(pid):
with open(pid) as f:
pidno = int(f.read())
print('[bitmask] terminating bitmaskd...')
os.kill(pidno, signal.SIGTERM)
print('[bitmask] shutting down gui...')
try:
self.stop()
try:
global pixbrowser
pixbrowser.stop()
del pixbrowser
except:
pass
QtCore.QTimer.singleShot(0, qApp.deleteLater)
except Exception as ex:
print('exception catched: %r' % ex)
sys.exit(1)
python类QTimer()的实例源码
def open(self, url, timeout=60):
"""Wait for download to complete and return result"""
loop = QEventLoop()
timer = QTimer()
timer.setSingleShot(True)
timer.timeout.connect(loop.quit)
self.loadFinished.connect(loop.quit)
self.load(QUrl(url))
timer.start(timeout * 1000)
loop.exec_() # delay here until download finished
if timer.isActive():
# downloaded successfully
timer.stop()
return self.html()
else:
# timed out
print 'Request timed out:', url
def __init__(self, obj):
self.mesh_obj = obj
self.form = FreeCADGui.PySideUic.loadUi(CfdTools.getModulePath() + "/TaskPanelCaeMesherGmsh.ui")
self.Timer = QtCore.QTimer()
self.Timer.start(100) # 100 milli seconds
self.gmsh_runs = False
self.console_message_gmsh = ''
QtCore.QObject.connect(self.form.if_max, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.max_changed)
QtCore.QObject.connect(self.form.if_min, QtCore.SIGNAL("valueChanged(Base::Quantity)"), self.min_changed)
QtCore.QObject.connect(self.form.cb_dimension, QtCore.SIGNAL("activated(int)"), self.choose_dimension)
QtCore.QObject.connect(self.Timer, QtCore.SIGNAL("timeout()"), self.update_timer_text)
self.form.cb_dimension.addItems(_CaeMeshGmsh._CaeMeshGmsh.known_element_dimensions)
self.get_mesh_params()
self.get_active_analysis()
self.update()
def open(self, url, timeout=60):
"""Wait for download to complete and return result"""
loop = QEventLoop()
timer = QTimer()
timer.setSingleShot(True)
timer.timeout.connect(loop.quit)
self.loadFinished.connect(loop.quit)
self.load(QUrl(url))
timer.start(timeout * 1000)
loop.exec_() # delay here until download finished
if timer.isActive():
# downloaded successfully
timer.stop()
return self.html()
else:
# timed out
print 'Request timed out:', url
browser_render.py 文件源码
项目:Python-Web-Scraping-Second-Edition
作者: PacktPublishing
项目源码
文件源码
阅读 25
收藏 0
点赞 0
评论 0
def open(self, url, timeout=60):
"""Wait for download to complete and return result"""
loop = QEventLoop()
timer = QTimer()
timer.setSingleShot(True)
timer.timeout.connect(loop.quit)
self.loadFinished.connect(loop.quit)
self.load(QUrl(url))
timer.start(timeout * 1000)
loop.exec_() # delay here until download finished
if timer.isActive():
# downloaded successfully
timer.stop()
return self.html()
else:
# timed out
print 'Request timed out:', url
def __init__(self, config):
super(MainWindow, self).__init__()
self._schedule_id = '0'
self._config = config
self._region_view = []
self._xmds = None
self._xmr = None
self._running = False
self._layout_id = None
self._layout_time = (0, 0)
self.setup_xmr()
self.setup_xmds()
self._central_widget = CentralWidget(self._xmds, self)
self._layout_timer = QTimer()
self._layout_timer.setSingleShot(True)
self._layout_timer.timeout.connect(self.stop)
self.setCentralWidget(self._central_widget)
def __init__(self, media, parent):
super(MediaView, self).__init__(parent)
self._parent = parent
self._id = media['id']
self._type = media['type']
self._duration = media['duration']
self._render = media['render']
self._options = media['options']
self._raws = media['raws']
self._layout_id = media['_layout_id']
self._schedule_id = media['_schedule_id']
self._region_id = media['_region_id']
self._save_dir = media['_save_dir']
self._widget = None
self._play_timer = QTimer(self)
self._started = 0
self._finished = 0
self._errors = None
# self.setObjectName('Media-%s-%s' % (self._type, self._id))
# self._play_timer.setObjectName('%s-timer' % self.objectName())
self._connect_signals()
def __init__(self, media, parent):
super(VideoMediaView, self).__init__(media, parent)
self._widget = QWidget(parent)
self._process = QProcess(self._widget)
self._process.setObjectName('%s-process' % self.objectName())
self._std_out = []
self._errors = []
self._stopping = False
self._mute = False
if 'mute' in self._options:
self._mute = bool(int(self._options['mute']))
self._widget.setGeometry(media['_geometry'])
self.connect(self._process, SIGNAL("error()"), self._process_error)
self.connect(self._process, SIGNAL("finished()"), self.stop)
self.connect(self._process, SIGNAL("readyReadStandardOutput()"), self.__grep_std_out)
self.set_default_widget_prop()
self._stop_timer = QTimer(self)
self._stop_timer.setSingleShot(True)
self._stop_timer.setInterval(1000)
self._stop_timer.timeout.connect(self._force_stop)
def timer():
"""The procedure needed to use QTimer."""
global t
t = QtCore.QTimer()
return t
def _handle_kill(*args, **kw):
win = kw.get('win')
if win:
QtCore.QTimer.singleShot(0, win.close)
global pixbrowser
if pixbrowser:
QtCore.QTimer.singleShot(0, pixbrowser.close)
def launch_gui():
global qApp
global bitmaskd
global browser
if IS_WIN:
freeze_support()
bitmaskd = Process(target=run_bitmaskd)
bitmaskd.start()
qApp = QApplication([])
try:
browser = BrowserWindow(None)
except NoAuthToken as e:
print('ERROR: ' + e.message)
sys.exit(1)
browser.setupSysTray()
qApp.setQuitOnLastWindowClosed(True)
qApp.lastWindowClosed.connect(browser.shutdown)
signal.signal(
signal.SIGINT,
partial(_handle_kill, win=browser))
# Avoid code to get stuck inside c++ loop, returning control
# to python land.
timer = QtCore.QTimer()
timer.timeout.connect(lambda: None)
timer.start(500)
browser.show()
sys.exit(qApp.exec_())
def __init__(self, renderer, glformat, app):
"Creates an OpenGL context and a window, and acquires OpenGL resources"
super(MyGlWidget, self).__init__(glformat)
self.renderer = renderer
self.app = app
# Use a timer to rerender as fast as possible
self.timer = QTimer(self)
self.timer.setSingleShot(True)
self.timer.setInterval(0)
self.timer.timeout.connect(self.render_vr)
# Accept keyboard events
self.setFocusPolicy(Qt.StrongFocus)
def __setup_connection_timer(self, force=False):
"""
Sets up the connection timer that handles monitoring of the live
connection, as well as the triggering of message processing.
:param bool force: Forces the creation of a new connection timer,
even if one already exists. When this occurs,
if a timer already exists, it will be stopped.
"""
if self._CHECK_CONNECTION_TIMER is None or force:
self.log_debug("Creating connection timer...")
if self._CHECK_CONNECTION_TIMER:
self.log_debug(
"Connection timer already exists, so it will be stopped."
)
try:
self._CHECK_CONNECTION_TIMER.stop()
except Exception:
# No reason to be alarmed here. Just let it go and it'll
# garbage collected when appropriate.
pass
from sgtk.platform.qt import QtCore
timer = QtCore.QTimer(
parent=QtCore.QCoreApplication.instance(),
)
timer.timeout.connect(self._check_connection)
# The class variable is in seconds, so multiply to get milliseconds.
timer.start(
self.SHOTGUN_ADOBE_HEARTBEAT_INTERVAL * 1000.0,
)
self._CHECK_CONNECTION_TIMER = timer
self.log_debug("Connection timer created and started.")
def __init__(self):
super().__init__()
remove_from_startup()
self.webserver = launch_webserver_as_process()
self.init_ui()
self.set_bg_image()
self.timer = QtCore.QTimer(self)
self.timer.timeout.connect(self.check_db)
self.timer.start(1000)
self.fully_kill = True
def _show_when_systray_available(self):
if self.trayIcon.isSystemTrayAvailable():
self.trayIcon.show()
else:
QtCore.QTimer.singleShot(1000,self._show_when_systray_available)
def runTimer(self,obj):
self.Object=obj
self.myTimer = QtCore.QTimer() # instantiate a new timer and store a reference to it in 'myTimer'
self.myTimer.setInterval(1000) # set the delay to 1 second
self.myTimer.timeout.connect(self.someOtherFunction) # once the timer runs out, run someOtherFunction
self.myTimer.start()
def runTimer(self,obj):
self.Object=obj
self.myTimer = QtCore.QTimer()
self.myTimer.setInterval(1000)
self.myTimer.timeout.connect(self.someOtherFunction)
self.myTimer.start()
def __init__(self, parent=None):
super(KeySequenceObject, self).__init__(parent=parent)
self._modifiers = QtGui.QApplication.keyboardModifiers()
self._modifierlessAllowed = True # True allows "b" as a shortcut, False requires shift/alt/ctrl/etc
self._recording_sequence = QtGui.QKeySequence()
self._seq = QtGui.QKeySequence()
self._timer = QtCore.QTimer()
self._timer.setSingleShot(True)
self._is_recording = False
self._timer.timeout.connect(self.done_recording)
def __init__(self, parent, colour='#000000'):
QWidget.__init__(self, parent)
self._colour = QColor(colour)
self.setMinimumSize(20, 20)
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self._lit = False
self._timer = QTimer(self)
self._timer.setInterval(200)
self._timer.timeout.connect(self.__flash_off)
def __init__(self, solver_runner_obj):
ui_path = os.path.dirname(__file__) + os.path.sep + "TaskPanelCfdSolverControl.ui"
self.form = FreeCADGui.PySideUic.loadUi(ui_path)
self.fem_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem")
self.analysis_object = FemGui.getActiveAnalysis()
self.solver_runner = solver_runner_obj
self.solver_object = solver_runner_obj.solver
self.SolverProcess = QtCore.QProcess()
self.Timer = QtCore.QTimer()
self.Timer.start(3000) # may not enough for CFD
# update UI
self.fem_console_message = ''
#======================================================================================================
#
# Code associated with running solver from GUI
#
#======================================================================================================
self.solver_run_process = QtCore.QProcess()
QtCore.QObject.connect(self.solver_run_process, QtCore.SIGNAL("started()"), self.solverProcessStarted)
#QtCore.QObject.connect(self.solver_run_process, QtCore.SIGNAL("stateChanged(QProcess::ProcessState)"), self.solverProcessStateChanged)
QtCore.QObject.connect(self.solver_run_process, QtCore.SIGNAL("finished(int)"), self.solverProcessFinished)
QtCore.QObject.connect(self.solver_run_process, QtCore.SIGNAL("error(QProcess::ProcessError)"), self.solverProcessError)
#self.solver_run_process.readyReadStandardOutput.connect(self.stdoutReady)
QtCore.QObject.connect(self.solver_run_process, QtCore.SIGNAL("readyReadStandardOutput()"), self.plotResiduals)
#======================================================================================================
# Connect Signals and Slots
QtCore.QObject.connect(self.form.tb_choose_working_dir, QtCore.SIGNAL("clicked()"), self.chooseWorkingDir)
QtCore.QObject.connect(self.form.pb_write_inp, QtCore.SIGNAL("clicked()"), self.writeSolverInput)
QtCore.QObject.connect(self.form.pb_edit_inp, QtCore.SIGNAL("clicked()"), self.editSolverInput)
QtCore.QObject.connect(self.form.pb_run_solver, QtCore.SIGNAL("clicked()"), self.runSolverProcess)
QtCore.QObject.connect(self.form.pb_terminate_solver, QtCore.SIGNAL("clicked()"), self.killSolverProcess)
QtCore.QObject.connect(self.form.pb_show_result, QtCore.SIGNAL("clicked()"), self.showResult)
QtCore.QObject.connect(self.form.pb_view_externally, QtCore.SIGNAL("clicked()"), self.viewResultExternally)
self.form.pb_terminate_solver.setEnabled(False)
self.form.pb_show_result.setEnabled(False)
self.form.pb_view_externally.setEnabled(True) # can be used to view init field
QtCore.QObject.connect(self.Timer, QtCore.SIGNAL("timeout()"), self.updateText)
self.form.pb_show_result.setEnabled(True) # delete this once finished signal is correctly managed
if self.solver_object.ResultObtained:
self.form.pb_show_result.setEnabled(True)
self.form.pb_view_externally.setEnabled(True)
self.Start = time.time() #debug tobe removed, it is not used in this taskpanel
self.update() # update UI from FemSolverObject, like WorkingDir
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(823, 677)
self.label = QtGui.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(10, 10, 800, 400))
self.label.setFrameShape(QtGui.QFrame.WinPanel)
self.label.setText("")
self.label.setObjectName("label")
self.listWidget = QtGui.QListWidget(Dialog)
self.listWidget.setGeometry(QtCore.QRect(10, 470, 801, 192))
self.listWidget.setObjectName("listWidget")
self.widget = QtGui.QWidget(Dialog)
self.widget.setGeometry(QtCore.QRect(10, 429, 801, 25))
self.widget.setObjectName("widget")
self.horizontalLayout = QtGui.QHBoxLayout(self.widget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.label_2 = QtGui.QLabel(self.widget)
self.label_2.setObjectName("label_2")
self.horizontalLayout.addWidget(self.label_2)
self.lineEdit = QtGui.QLineEdit(self.widget)
self.lineEdit.setObjectName("lineEdit")
self.horizontalLayout.addWidget(self.lineEdit)
self.pushButton = QtGui.QPushButton(self.widget)
self.pushButton.setObjectName("pushButton")
self.horizontalLayout.addWidget(self.pushButton)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
#
self.pushButton.clicked.connect(self.on_buttom_pressed)
self.listWidget.doubleClicked.connect(self.goTweet)
#
self.alText = u''
self.fullText = u''
self.twitter = Twitter(language='tr')
self.prevId = None
self.timer = QtCore.QTimer(Dialog)
self.timer.timeout.connect(self.on_timer)
self.dialog = Dialog
self.twIds = []