本文整理汇总了Python中PyQt5.Qt.QThread.currentThread方法的典型用法代码示例。如果您正苦于以下问题:Python QThread.currentThread方法的具体用法?Python QThread.currentThread怎么用?Python QThread.currentThread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QThread
的用法示例。
在下文中一共展示了QThread.currentThread方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: must_use_qt
# 需要导入模块: from PyQt5.Qt import QThread [as 别名]
# 或者: from PyQt5.Qt.QThread import currentThread [as 别名]
def must_use_qt(headless=True):
''' This function should be called if you want to use Qt for some non-GUI
task like rendering HTML/SVG or using a headless browser. It will raise a
RuntimeError if using Qt is not possible, which will happen if the current
thread is not the main GUI thread. On linux, it uses a special QPA headless
plugin, so that the X server does not need to be running. '''
global gui_thread
ensure_app(headless=headless)
if gui_thread is None:
gui_thread = QThread.currentThread()
if gui_thread is not QThread.currentThread():
raise RuntimeError('Cannot use Qt in non GUI thread')
示例2: must_use_qt
# 需要导入模块: from PyQt5.Qt import QThread [as 别名]
# 或者: from PyQt5.Qt.QThread import currentThread [as 别名]
def must_use_qt():
''' This function should be called if you want to use Qt for some non-GUI
task like rendering HTML/SVG or using a headless browser. It will raise a
RuntimeError if using Qt is not possible, which will happen if the current
thread is not the main GUI thread. On linux, it uses a special QPA headless
plugin, so that the X server does not need to be running. '''
global gui_thread, _store_app
if _store_app is None and QApplication.instance() is None:
args = sys.argv[:1]
if islinux or isbsd:
args += ['-platformpluginpath', sys.extensions_location, '-platform', 'headless']
_store_app = QApplication(args)
if gui_thread is None:
gui_thread = QThread.currentThread()
if gui_thread is not QThread.currentThread():
raise RuntimeError('Cannot use Qt in non GUI thread')
示例3: __init__
# 需要导入模块: from PyQt5.Qt import QThread [as 别名]
# 或者: from PyQt5.Qt.QThread import currentThread [as 别名]
def __init__(self, args, force_calibre_style=False, override_program_name=None, headless=False, color_prefs=gprefs):
self.file_event_hook = None
if override_program_name:
args = [override_program_name] + args[1:]
if headless:
if not args:
args = sys.argv[:1]
args.extend(['-platformpluginpath', sys.extensions_location, '-platform', 'headless'])
qargs = [i.encode('utf-8') if isinstance(i, unicode) else i for i in args]
self.pi = plugins['progress_indicator'][0]
QApplication.__init__(self, qargs)
self.setup_styles(force_calibre_style)
f = QFont(QApplication.font())
if (f.family(), f.pointSize()) == ('Sans Serif', 9): # Hard coded Qt settings, no user preference detected
f.setPointSize(10)
QApplication.setFont(f)
f = QFontInfo(f)
self.original_font = (f.family(), f.pointSize(), f.weight(), f.italic(), 100)
if not self.using_calibre_style and self.style().objectName() == 'fusion':
# Since Qt is using the fusion style anyway, specialize it
self.load_calibre_style()
fi = gprefs['font']
if fi is not None:
font = QFont(*(fi[:4]))
s = gprefs.get('font_stretch', None)
if s is not None:
font.setStretch(s)
QApplication.setFont(font)
dl = QLocale(get_lang())
if unicode(dl.bcp47Name()) != u'C':
QLocale.setDefault(dl)
global gui_thread, qt_app
gui_thread = QThread.currentThread()
self._translator = None
self.load_translations()
qt_app = self
self._file_open_paths = []
self._file_open_lock = RLock()
if not isosx:
# OS X uses a native color dialog that does not support custom
# colors
self.color_prefs = color_prefs
self.read_custom_colors()
self.lastWindowClosed.connect(self.save_custom_colors)
if isxp:
error_dialog(None, _('Windows XP not supported'), '<p>' + _(
'calibre versions newer than 2.0 do not run on Windows XP. This is'
' because the graphics toolkit calibre uses (Qt 5) crashes a lot'
' on Windows XP. We suggest you stay with <a href="%s">calibre 1.48</a>'
' which works well on Windows XP.') % 'http://download.calibre-ebook.com/1.48.0/', show=True)
raise SystemExit(1)
示例4: __init__
# 需要导入模块: from PyQt5.Qt import QThread [as 别名]
# 或者: from PyQt5.Qt.QThread import currentThread [as 别名]
def __init__(self, func, queued=True, parent=None):
global gui_thread
if gui_thread is None:
gui_thread = QThread.currentThread()
if not is_gui_thread():
raise ValueError(
'You can only create a FunctionDispatcher in the GUI thread')
QObject.__init__(self, parent)
self.func = func
typ = Qt.QueuedConnection
if not queued:
typ = Qt.AutoConnection if queued is None else Qt.DirectConnection
self.dispatch_signal.connect(self.dispatch, type=typ)
self.q = Queue.Queue()
self.lock = threading.Lock()
示例5: __init__
# 需要导入模块: from PyQt5.Qt import QThread [as 别名]
# 或者: from PyQt5.Qt.QThread import currentThread [as 别名]
def __init__(self, args, force_calibre_style=False, override_program_name=None, headless=False):
self.file_event_hook = None
if override_program_name:
args = [override_program_name] + args[1:]
if headless:
if not args:
args = sys.argv[:1]
args.extend(['-platformpluginpath', sys.extensions_location, '-platform', 'headless'])
qargs = [i.encode('utf-8') if isinstance(i, unicode) else i for i in args]
self.pi = plugins['progress_indicator'][0]
self.setup_styles(force_calibre_style)
QApplication.__init__(self, qargs)
f = QFont(QApplication.font())
if (f.family(), f.pointSize()) == ('Sans Serif', 9): # Hard coded Qt settings, no user preference detected
f.setPointSize(10)
QApplication.setFont(f)
f = QFontInfo(f)
self.original_font = (f.family(), f.pointSize(), f.weight(), f.italic(), 100)
if not self.using_calibre_style and self.style().objectName() == 'fusion':
# Since Qt is using the fusion style anyway, specialize it
self.load_calibre_style()
fi = gprefs['font']
if fi is not None:
font = QFont(*(fi[:4]))
s = gprefs.get('font_stretch', None)
if s is not None:
font.setStretch(s)
QApplication.setFont(font)
dl = QLocale(get_lang())
if unicode(dl.bcp47Name()) != u'C':
QLocale.setDefault(dl)
global gui_thread, qt_app
gui_thread = QThread.currentThread()
self._translator = None
self.load_translations()
qt_app = self
self._file_open_paths = []
self._file_open_lock = RLock()
示例6: is_gui_thread
# 需要导入模块: from PyQt5.Qt import QThread [as 别名]
# 或者: from PyQt5.Qt.QThread import currentThread [as 别名]
def is_gui_thread():
global gui_thread
return gui_thread is QThread.currentThread()