本文整理汇总了Python中PyQt4.QtCore.QMutex.unlock方法的典型用法代码示例。如果您正苦于以下问题:Python QMutex.unlock方法的具体用法?Python QMutex.unlock怎么用?Python QMutex.unlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QMutex
的用法示例。
在下文中一共展示了QMutex.unlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QtStreamHandler
# 需要导入模块: from PyQt4.QtCore import QMutex [as 别名]
# 或者: from PyQt4.QtCore.QMutex import unlock [as 别名]
class QtStreamHandler(logging.Handler):
def __init__(self, parent, main):
logging.Handler.__init__(self)
self.parent = parent
self.main = main
self.textWidget = parent
self.formater = logging.Formatter("%(asctime)s - %(levelname)s -> %(message)s")
self.logString = ""
def getLoggingCompleteText(self):
return self.logString
def createLock(self):
self.mutex = QMutex()
def acquire(self):
self.mutex.lock()
def release(self):
self.mutex.unlock()
def emit(self, record):
# self.textWidget.appendPlainText(self.formater.format(record))
formattedText = self.formater.format(record)
#separate text from date
index = formattedText.find('->')
self.textWidget.setTextColor(QColor("green"))
self.textWidget.insertPlainText(formattedText[:index])
self.textWidget.setTextColor(QColor("blue"))
self.textWidget.insertPlainText(formattedText[index:] + "\n")
self.textWidget.moveCursor(QTextCursor.EndOfLine)
self.textWidget.ensureCursorVisible()
self.logString += formattedText + "\n";
示例2: Feed
# 需要导入模块: from PyQt4.QtCore import QMutex [as 别名]
# 或者: from PyQt4.QtCore.QMutex import unlock [as 别名]
class Feed(QRunnable):
def __init__(self, label, parent=None):
QRunnable.__init__(self)
self.label = label
self.parent = parent
self.data = None
self.mutex = QMutex()
self.setAutoDelete(True)
def run(self):
self.check()
def check(self):
try:
self.fetch()
except (urllib2.URLError, urllib2.HTTPError) as err:
self.parent.error.emit(str(err))
else:
self.read()
if self.data:
self.parse()
def fetch(self):
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(REALM, HOST,
self.parent.user, self.parent.passwd)
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
url = "%s/%s" % (URL_ATOM, self.label) if self.label else URL_ATOM
self.conn = urllib2.urlopen(url)
def read(self):
code = self.conn.getcode()
if code != 200:
self.conn.close()
self.parent.error.emit("HTTP Error %d: %s" % (
code, BaseHTTPRequestHandler.responses[code]))
else:
self.data = self.conn.read()
self.conn.close()
def parse(self):
tree = et.fromstring(self.data)
for e in tree.findall("%sentry" % XMLNS):
entry = Entry()
entry.title = e.find("%stitle" % XMLNS).text
entry.summary = e.find("%ssummary" % XMLNS).text
entry.link = e.find("%slink" % XMLNS).attrib["href"]
entry.modified = e.find("%smodified" % XMLNS).text
entry.issued = e.find("%sissued" % XMLNS).text
entry.id = e.find("%sid" % XMLNS).text
for a in e.findall("%sauthor" % XMLNS):
entry.author_name = a.find("%sname" % XMLNS).text
entry.author_email = a.find("%semail" % XMLNS).text
self.mutex.lock()
self.parent.entries.append((self.label, entry))
self.mutex.unlock()
示例3: QCallbacksManager
# 需要导入模块: from PyQt4.QtCore import QMutex [as 别名]
# 或者: from PyQt4.QtCore.QMutex import unlock [as 别名]
class QCallbacksManager(QObject):
class Request(object):
def __init__(self):
self.event = Event()
self.answer = None
def __call__(self):
raise NotImplementedError()
class LoginRequest(Request):
def __init__(self, backend_name, value):
QCallbacksManager.Request.__init__(self)
self.backend_name = backend_name
self.value = value
def __call__(self):
password, ok = QInputDialog.getText(None,
'%s request' % self.value.label,
'Please enter %s for %s' % (self.value.label,
self.backend_name),
QLineEdit.Password)
return password
new_request = Signal()
def __init__(self, weboob, parent=None):
QObject.__init__(self, parent)
self.weboob = weboob
self.weboob.callbacks['login'] = self.callback(self.LoginRequest)
self.mutex = QMutex()
self.requests = []
self.new_request.connect(self.do_request)
def callback(self, klass):
def cb(*args, **kwargs):
return self.add_request(klass(*args, **kwargs))
return cb
@Slot()
def do_request(self):
self.mutex.lock()
request = self.requests.pop()
request.answer = request()
request.event.set()
self.mutex.unlock()
def add_request(self, request):
self.mutex.lock()
self.requests.append(request)
self.mutex.unlock()
self.new_request.emit()
request.event.wait()
return request.answer
示例4: MyStreamHandler
# 需要导入模块: from PyQt4.QtCore import QMutex [as 别名]
# 或者: from PyQt4.QtCore.QMutex import unlock [as 别名]
class MyStreamHandler(StreamHandler):
def __init__(self):
StreamHandler.__init__(self)
def createLock(self):
# must be Recursive (= reentrant)
self._mutex = QMutex(QMutex.Recursive)
def acquire(self):
self._mutex.lock()
def release(self):
self._mutex.unlock()
示例5: ImporterThread
# 需要导入模块: from PyQt4.QtCore import QMutex [as 别名]
# 或者: from PyQt4.QtCore.QMutex import unlock [as 别名]
class ImporterThread(QThread):
def __init__(self, framework, parent = None):
QThread.__init__(self, parent)
self.framework = framework
self.qlock = QMutex()
self.cursor = None
QObject.connect(self, SIGNAL('quit()'), self.quitHandler)
QObject.connect(self, SIGNAL('started()'), self.startedHandler)
def run(self):
QObject.connect(self, SIGNAL('do_runImport()'), self.handle_runImport, Qt.DirectConnection)
self.exec_()
def quitHandler(self):
if self.cursor:
self.cursor.close()
self.exit(0)
def startedHandler(self):
pass
def runImport(self, importers, proxy_file, source, callback):
self.importers = importers
self.proxy_filelist = [proxy_file]
self.source = source
self.callbackObj = callback
QTimer.singleShot(50, self, SIGNAL('do_runImport()'))
def runImportList(self, importers, proxy_filelist, source, callback):
self.importers = importers
self.proxy_filelist = proxy_filelist
self.source = source
self.callbackObj = callback
QTimer.singleShot(50, self, SIGNAL('do_runImport()'))
def handle_runImport(self):
if self.qlock.tryLock():
try:
for proxy_file in self.proxy_filelist:
try:
self.framework.debug_log('attempting import of %s' % (str(proxy_file)))
self.importers.process_import(str(proxy_file), self.framework, self.source)
except Exception as ex:
self.framework.report_exception(ex)
finally:
self.qlock.unlock()
self.callbackObj.emit(SIGNAL('runImportFinished()'))
示例6: Lock
# 需要导入模块: from PyQt4.QtCore import QMutex [as 别名]
# 或者: from PyQt4.QtCore.QMutex import unlock [as 别名]
class Lock(object):
def __init__(self):
self._mutex = QMutex()
def __enter__(self):
self._mutex.lock()
def __exit__(self, type, value, tb):
self._mutex.unlock()
def acquire(self):
self._mutex.lock()
def release(self):
self._mutex.unlock()
示例7: Evaluate
# 需要导入模块: from PyQt4.QtCore import QMutex [as 别名]
# 或者: from PyQt4.QtCore.QMutex import unlock [as 别名]
class Evaluate(QThread):
"""Thread used to insolate calculation process in entities (stream, project
and equipment, so gui can response while calculation is in process"""
def __init__(self, parent=None):
super(Evaluate, self).__init__(parent)
self.mutex = QMutex()
def start(self, entity, kwargs):
self.entity = entity
self.kwargs = kwargs
QThread.start(self)
def run(self):
self.mutex.lock()
self.entity(**self.kwargs)
self.mutex.unlock()
示例8: UdpClient
# 需要导入模块: from PyQt4.QtCore import QMutex [as 别名]
# 或者: from PyQt4.QtCore.QMutex import unlock [as 别名]
class UdpClient(QThread):
def __init__(self, parent):
QThread.__init__(self, parent)
self.prnt = parent
self.udp = QUdpSocket()
addr = QHostAddress(QHostAddress.Any)
print 'bind to:', addr.toString()
self.udp.bind(addr, 34001)
self.udp.error.connect(self.errorAnalyser)
self.udp.readyRead.connect(self.readUdp)
print "Binding..."
self.STOP = False
self.locker = QMutex()
def run(self):
self.prnt.initAvahiService()
while True :
if self.udp is not None and self.udp.state() == QAbstractSocket.ConnectedState :
self.udp.waitForReadyRead()
else : self.msleep(100)
if self.STOP and self.udp is not None: self.udp.close(); break
print 'UDPClient closed...'
self.prnt.changeConnectState.emit()
def stop(self):
self.locker.lock()
self.STOP = True
self.locker.unlock()
def readUdp(self):
while ( self.udp.hasPendingDatagrams() ):
data = QByteArray()
addr = QHostAddress()
port = 0
try :
datagramSize = self.udp.pendingDatagramSize()
if datagramSize > 0 :
(data, addr, port) = self.udp.readDatagram(datagramSize)
#print "Datagram: [%s] from %s:%i" % (QString().fromUtf8(data), addr.toString(), port)
self.prnt.contactMessage.emit(QString().fromUtf8(data), addr.toString())
except socket.error, err :
print '[in readUdp() UdpClient] SocketError1 : ', err
except socket.timeout, err :
print '[in readUdp() UdpClient] SocketError2 : ', err
except :
示例9: SQLRenderThread
# 需要导入模块: from PyQt4.QtCore import QMutex [as 别名]
# 或者: from PyQt4.QtCore.QMutex import unlock [as 别名]
class SQLRenderThread(CachedRenderThread):
"""
RenderThread extending the UniqueMethodRenderThread by supplying a cancel
method for classes with database access. The database object needs to be
given either on the object as .db subobject or explicitly by
setObjectDBObject().
The database object needs to have a 'connection' attribute which supports an
interrupt() method.
"""
def __init__(self, parent=0):
self.dbObjectLock = QMutex(QMutex.Recursive)
self.dbObject = {}
CachedRenderThread.__init__(self, parent)
def setObject(self, classObject, *args, **param):
self.dbObjectLock.lock()
if classObject in self.dbObject:
del self.dbObject[classObject]
self.dbObjectLock.unlock()
CachedRenderThread.setObject(self, classObject, *args, **param)
def setObjectDBObject(self, classObject, db):
self.dbObjectLock.lock()
self.dbObject[classObject] = db
self.dbObjectLock.unlock()
def cancelCurrentJob(self):
QMutexLocker(self.renderingLock)
if self.currentlyRenderingJob:
_, classObject, _, _, _ = self.currentlyRenderingJob
try:
QMutexLocker(self.dbObjectLock)
if classObject in self.dbObject:
db = self.dbObject[classObject]
else:
classObjectInst = self.getObjectInstance(classObject)
if hasattr(classObjectInst, 'db'):
db = classObjectInst.db
else:
return False
self.clearCurrentJob()
db.connection.interrupt()
return True
except KeyError:
return False
示例10: ComputationThread
# 需要导入模块: from PyQt4.QtCore import QMutex [as 别名]
# 或者: from PyQt4.QtCore.QMutex import unlock [as 别名]
class ComputationThread(QThread):
def __init__(self, animation_thread):
QThread.__init__(self)
self.is_running = True
self.mutex = QMutex()
self.other_thread = animation_thread
def stop(self):
self.is_running = False
def run(self):
while self.is_running:
self.mutex.lock() # locking may not be necessary
raw_input("")
#self.other_thread.stop( )
self.mutex.unlock()
print " run method ends "
示例11: ImageTile
# 需要导入模块: from PyQt4.QtCore import QMutex [as 别名]
# 或者: from PyQt4.QtCore.QMutex import unlock [as 别名]
class ImageTile(object):
def __init__(self, rect):
self._mutex = QMutex()
self.image = QImage(rect.width(), rect.height(),
QImage.Format_ARGB32_Premultiplied)
self.image.fill(0)
self._topLeft = rect.topLeft()
#Whenever the underlying data changes, the data version is incremented.
#By comparing the data version to the image and request version, it can
#be determined if the content of this tile is recent or needs to be
#re-computed.
#version of the data
self.dataVer = 0
#version of self.image
#
#If self.imgVer < self.dataVer, the image needs to be re-computed
#from the new data.
self.imgVer = -1
#version of the request that has been generated to update the contents
#of self.image
#
#If self.reqVer == self.dataVer, a request is currently running that will
#eventually replace self.image with the new data.
self.reqVer = -2
def clear(self):
self.image.fill(0)
def paint(self, painter):
self.lock()
painter.drawImage(self._topLeft, self.image)
self.unlock()
def lock(self):
self._mutex.lock()
def unlock(self):
self._mutex.unlock()
示例12: AnimationThread
# 需要导入模块: from PyQt4.QtCore import QMutex [as 别名]
# 或者: from PyQt4.QtCore.QMutex import unlock [as 别名]
class AnimationThread(QThread):
def __init__(self):
QThread.__init__(self)
self.is_running = True
self.mutex = QMutex()
def stop(self):
self.is_running = False
def get_state(self):
return self.is_running
def change_state(self):
self.is_running = not self.is_running
def run(self):
while self.is_running:
self.mutex.lock( ) # locking may not be necessary
self.emit(SIGNAL("window_update_request" ))
self.mutex.unlock()
sleep( 0.005 )
示例13: _LoggingMutexQt
# 需要导入模块: from PyQt4.QtCore import QMutex [as 别名]
# 或者: from PyQt4.QtCore.QMutex import unlock [as 别名]
class _LoggingMutexQt(_LoggingMutex):
def __init__(self, name):
super(_LoggingMutexQt, self).__init__(name)
from PyQt4.QtCore import QMutex
self.mutex = QMutex()
def currentThreadID(self):
from PyQt4.QtCore import QThread
return QThread.currentThreadId()
def _acquire(self):
self.mutex.lock()
def _release(self):
self.mutex.unlock()
def enterMutex(self):
self.mutex.lock()
def exitMutex(self, *_args, **_kwargs):
self.mutex.unlock()
示例14: SignalThread
# 需要导入模块: from PyQt4.QtCore import QMutex [as 别名]
# 或者: from PyQt4.QtCore.QMutex import unlock [as 别名]
class SignalThread(QThread):
def __init__(self, parent = None):
QThread.__init__(self, parent)
self.waitcond = QWaitCondition()
self.mutex = QMutex()
self.isstopped = False
def trigger(self):
"""lock first to make sure the QThread is actually waiting for a signal"""
self.mutex.lock()
self.waitcond.wakeOne()
self.mutex.unlock()
def stopThread(self):
self.mutex.lock()
self.isstopped = True
self.waitcond.wakeOne()
self.mutex.unlock()
def run(self):
self.mutex.lock()
while not self.isstopped:
# just wait, and trigger every time we receive a signal
self.waitcond.wait(self.mutex)
if not self.isstopped:
self.emit(SIGNAL("triggerSignal()"))
self.mutex.unlock()
示例15: DatabaseThread
# 需要导入模块: from PyQt4.QtCore import QMutex [as 别名]
# 或者: from PyQt4.QtCore.QMutex import unlock [as 别名]
class DatabaseThread(QThread):
def __init__(self, framework, Data, parent = None):
QThread.__init__(self, parent)
self.framework = framework
self.Data = Data
self.qlock = QMutex()
QObject.connect(self, SIGNAL('quit()'), self.quitHandler)
QObject.connect(self, SIGNAL('started()'), self.startedHandler)
def run(self):
QObject.connect(self, SIGNAL('doConnectDb()'), self.connectDbHandler, Qt.DirectConnection)
self.exec_()
def close(self):
self.qlock.lock()
try:
self.Data.close()
finally:
self.qlock.unlock()
def quitHandler(self):
self.Data.close()
self.exit(0)
def startedHandler(self):
pass
def connectDb(self, filename, callback):
self.filename = filename
self.callbackObj = callback
QTimer.singleShot(50, self, SIGNAL('doConnectDb()'))
def connectDbHandler(self):
self.qlock.lock()
try:
self.Data.connect(self.filename)
finally:
self.qlock.unlock()
self.callbackObj.emit(SIGNAL('connectDbFinished()'))