本文整理汇总了Python中pyqode.core.api.DelayJobRunner类的典型用法代码示例。如果您正苦于以下问题:Python DelayJobRunner类的具体用法?Python DelayJobRunner怎么用?Python DelayJobRunner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DelayJobRunner类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: HtmlPreviewWidget
class HtmlPreviewWidget(QtWebWidgets.QWebView):
hide_requested = QtCore.Signal()
show_requested = QtCore.Signal()
def __init__(self, parent=None):
super(HtmlPreviewWidget, self).__init__(parent)
self._editor = None
self._timer = DelayJobRunner(delay=1000)
try:
# prevent opening internal links when using QtWebKit
self.page().setLinkDelegationPolicy(
QtWebWidgets.QWebPage.DelegateAllLinks)
except (TypeError, AttributeError):
# no needed with QtWebEngine, internal links are properly handled
# by the default implementation
pass
def set_editor(self, editor):
url = QtCore.QUrl('')
if editor is not None:
url = QtCore.QUrl.fromLocalFile(editor.file.path)
try:
self.setHtml(editor.to_html(), url)
except (TypeError, AttributeError):
self.setHtml('<center>No preview available...</center>', url)
self._editor = None
self.hide_requested.emit()
else:
if self._editor is not None and editor != self._editor:
try:
self._editor.textChanged.disconnect(self._on_text_changed)
except TypeError:
pass
editor.textChanged.connect(self._on_text_changed)
self._editor = proxy(editor)
self.show_requested.emit()
def _on_text_changed(self, *_):
self._timer.request_job(self._update_preview)
def _update_preview(self):
url = QtCore.QUrl('')
if self._editor is not None:
url = QtCore.QUrl.fromLocalFile(self._editor.file.path)
try:
try:
pos = self.page().mainFrame().scrollBarValue(QtCore.Qt.Vertical)
self.setHtml(self._editor.to_html(), url)
self.page().mainFrame().setScrollBarValue(QtCore.Qt.Vertical, pos)
except AttributeError:
# Not possible with QtWebEngine???
# self._scroll_pos = self.page().mainFrame().scrollBarValue(
# QtCore.Qt.Vertical)
self.setHtml(self._editor.to_html(), url)
except (TypeError, AttributeError):
self.setHtml('<center>No preview available...</center>', url)
self.hide_requested.emit()
开发者ID:must40,项目名称:pyqode.core,代码行数:57,代码来源:preview.py
示例2: HtmlPreviewWidget
class HtmlPreviewWidget(QtWidgets.QTextEdit):
"""
Display html preview of a document as rich text in a QTextEdit.
"""
hide_requested = QtCore.Signal()
show_requested = QtCore.Signal()
def __init__(self, parent=None):
super(HtmlPreviewWidget, self).__init__(parent)
self._editor = None
self._timer = DelayJobRunner(delay=1000)
def set_editor(self, editor):
try:
self.setHtml(editor.to_html())
except (TypeError, AttributeError):
self.setHtml('<center>No preview available...</center>')
self._editor = None
self.hide_requested.emit()
else:
if self._editor is not None and editor != self._editor:
try:
self._editor.textChanged.disconnect(self._on_text_changed)
except TypeError:
pass
editor.textChanged.connect(self._on_text_changed)
self._editor = proxy(editor)
self.show_requested.emit()
def _on_text_changed(self, *_):
self._timer.request_job(self._update_preview)
def _update_preview(self):
try:
# remember cursor/scrollbar position
p = self.textCursor().position()
v = self.verticalScrollBar().value()
# display new html
self.setHtml(self._editor.to_html())
# restore cursor/scrollbar position
c = self.textCursor()
c.setPosition(p)
self.setTextCursor(c)
self.verticalScrollBar().setValue(v)
except (TypeError, AttributeError):
self.setHtml('<center>No preview available...</center>')
self.hide_requested.emit()
开发者ID:OpenCobolIDE,项目名称:OpenCobolIDE,代码行数:49,代码来源:preview.py
示例3: __init__
def __init__(self, highlight_caret_scope=False):
Panel.__init__(self)
self._native = True
self._custom_indicators = (
':/pyqode-icons/rc/arrow_right_off.png',
':/pyqode-icons/rc/arrow_right_on.png',
':/pyqode-icons/rc/arrow_down_off.png',
':/pyqode-icons/rc/arrow_down_on.png'
)
self._custom_color = QtGui.QColor('gray')
self._block_nbr = -1
self._highlight_caret = False
self.highlight_caret_scope = highlight_caret_scope
self._indic_size = 16
#: the list of deco used to highlight the current fold region (
#: surrounding regions are darker)
self._scope_decos = []
#: the list of folded blocs decorations
self._block_decos = []
self.setMouseTracking(True)
self.scrollable = True
self._mouse_over_line = None
self._current_scope = None
self._prev_cursor = None
self.context_menu = None
self.action_collapse = None
self.action_expand = None
self.action_collapse_all = None
self.action_expand_all = None
self._original_background = None
self._highlight_runner = DelayJobRunner(delay=250)
开发者ID:sopak,项目名称:cadquery-freecad-module,代码行数:31,代码来源:folding.py
示例4: __init__
def __init__(self):
QObject.__init__(self)
Mode.__init__(self)
self._root_node = None
self._vars = []
self._paragraphs = []
self._runner = DelayJobRunner()
开发者ID:dtonal,项目名称:pyqode.cobol,代码行数:7,代码来源:doc_outline.py
示例5: __init__
def __init__(self, delay=1000):
Mode.__init__(self)
QtCore.QObject.__init__(self)
self._jobRunner = DelayJobRunner(delay=delay)
#: The list of results (elements might have children; this is actually
#: a tree).
self.results = []
开发者ID:AlexLee,项目名称:cadquery-freecad-module,代码行数:7,代码来源:document_analyser.py
示例6: __init__
def __init__(self):
QtCore.QObject.__init__(self)
Mode.__init__(self)
self._previous_cursor_start = -1
self._previous_cursor_end = -1
self._deco = None
self._cursor = None
self._timer = DelayJobRunner(delay=200)
开发者ID:OpenCobolIDE,项目名称:OpenCobolIDE,代码行数:8,代码来源:wordclick.py
示例7: __init__
def __init__(self, worker, delay=1000):
Mode.__init__(self)
QtCore.QObject.__init__(self)
self._worker = worker
self._jobRunner = DelayJobRunner(delay=delay)
#: The list of definitions found in the file, each item is a
#: pyqode.core.share.Definition.
self._results = []
开发者ID:abdullahtahiriyo,项目名称:cadquery-freecad-module,代码行数:8,代码来源:outline.py
示例8: __init__
def __init__(self):
super(OccurrencesHighlighterMode, self).__init__()
self._decorations = []
#: Timer used to run the search request with a specific delay
self.timer = DelayJobRunner(delay=1000)
self._sub = None
self._background = QtGui.QColor('#CCFFCC')
self._foreground = None
self._underlined = False
开发者ID:SirmoGames,项目名称:hackedit,代码行数:9,代码来源:occurences.py
示例9: __init__
def __init__(self):
super(GoToAssignmentsMode, self).__init__()
self._definitions = []
self._goto_requested = False
self.action_goto = QtWidgets.QAction("Go to assignments", self)
self.action_goto.setShortcut(self.shortcut)
self.action_goto.triggered.connect(self.request_goto)
self.word_clicked.connect(self._on_word_clicked)
self._runner = DelayJobRunner(delay=1)
开发者ID:AlexLee,项目名称:cadquery-freecad-module,代码行数:9,代码来源:goto_assignements.py
示例10: __init__
def __init__(self, parent=None):
super(HtmlPreviewWidget, self).__init__(parent)
self._editor = None
self._timer = DelayJobRunner(delay=1000)
try:
# prevent opening internal links when using QtWebKit
self.page().setLinkDelegationPolicy(
QtWebWidgets.QWebPage.DelegateAllLinks)
except (TypeError, AttributeError):
# no needed with QtWebEngine, internal links are properly handled
# by the default implementation
pass
开发者ID:must40,项目名称:pyqode.core,代码行数:12,代码来源:preview.py
示例11: __init__
def __init__(self):
super(GoToAssignmentsMode, self).__init__()
self._definitions = []
self._goto_requested = False
self.action_goto = QtWidgets.QAction(_("Go to assignments"), self)
self.action_goto.setShortcut(self.shortcut)
self.action_goto.triggered.connect(self.request_goto)
icon = icons.icon(qta_name='fa.share')
if icon:
self.action_goto.setIcon(icon)
self.word_clicked.connect(self._on_word_clicked)
self._runner = DelayJobRunner(delay=1)
开发者ID:SirmoGames,项目名称:hackedit,代码行数:12,代码来源:goto_assignements.py
示例12: TabBar
class TabBar(QtWidgets.QTabBar):
"""
Tab bar specialized to allow the user to close a tab using mouse middle
click. Also exposes a double clicked signal.
"""
double_clicked = QtCore.Signal()
def __init__(self, parent):
QtWidgets.QTabBar.__init__(self, parent)
self.setTabsClosable(True)
self._timer = DelayJobRunner(delay=1)
def mousePressEvent(self, event):
QtWidgets.QTabBar.mousePressEvent(self, event)
if event.button() == QtCore.Qt.MiddleButton:
tab = self.tabAt(event.pos())
self._timer.request_job(
self.parentWidget().tabCloseRequested.emit, tab)
def mouseDoubleClickEvent(self, event):
if event.button() == QtCore.Qt.LeftButton:
self.double_clicked.emit()
开发者ID:OpenCobolIDE,项目名称:OpenCobolIDE,代码行数:22,代码来源:tab_bar.py
示例13: __init__
def __init__(self):
QObject.__init__(self)
Mode.__init__(self)
self._previous_cursor_start = -1
self._previous_cursor_end = -1
self._definition = None
self._deco = None
self._pending = False
self.action_goto = QAction(_("Go to assignments"), self)
self.action_goto.setShortcut('F7')
self.action_goto.triggered.connect(self.request_goto)
self.word_clicked.connect(self.request_goto)
self._timer = DelayJobRunner(delay=200)
开发者ID:brunoviu,项目名称:OpenCobolIDE,代码行数:13,代码来源:goto.py
示例14: __init__
def __init__(self):
super(CheckerPanel, self).__init__()
self._previous_line = -1
self.scrollable = True
self._job_runner = DelayJobRunner(delay=100)
self.setMouseTracking(True)
#: Info icon
self.info_icon = QtGui.QIcon.fromTheme(
'dialog-info', QtGui.QIcon(':pyqode-icons/rc/dialog-info.png'))
#: Warning icon
self.warning_icon = QtGui.QIcon.fromTheme(
'dialog-warning',
QtGui.QIcon(':pyqode-icons/rc/dialog-warning.png'))
#: Error icon
self.error_icon = QtGui.QIcon.fromTheme(
'dialog-error', QtGui.QIcon(':pyqode-icons/rc/dialog-error.png'))
开发者ID:AlexLee,项目名称:cadquery-freecad-module,代码行数:16,代码来源:checker.py
示例15: __init__
def __init__(self):
super(CheckerPanel, self).__init__()
self._previous_line = -1
self.scrollable = True
self._job_runner = DelayJobRunner(delay=100)
self.setMouseTracking(True)
#: Info icon
self.info_icon = icons.icon(
'dialog-info', ':pyqode-icons/rc/dialog-info.png',
'fa.info-circle', qta_options={'color': '#4040DD'})
self.warning_icon = icons.icon(
'dialog-warning', ':pyqode-icons/rc/dialog-warning.png',
'fa.exclamation-triangle', qta_options={'color': '#DDDD40'})
self.error_icon = icons.icon(
'dialog-error', ':pyqode-icons/rc/dialog-error.png',
'fa.exclamation-circle', qta_options={'color': '#DD4040'})
开发者ID:OpenCobolIDE,项目名称:OpenCobolIDE,代码行数:16,代码来源:checker.py
示例16: GoToAssignmentsMode
class GoToAssignmentsMode(WordClickMode):
"""
Goes to the assignments (using jedi.Script.goto_assignments) when the user
execute the shortcut or click word. If there are more than one assignments,
an input dialog is used to ask the user to choose the desired assignment.
This mode will emit the :attr:`out_of_doc` signal if the definition can
not be reached in the current document. IDE will typically connects a slot
that open a new editor tab and goes to the definition position.
"""
#: Signal emitted when the definition cannot be reached in the current
#: document
out_of_doc = QtCore.Signal(Assignment)
#: Signal emitted when no results could be found.
no_results_found = QtCore.Signal()
shortcut = 'Alt+F2'
def __init__(self):
super(GoToAssignmentsMode, self).__init__()
self._definitions = []
self._goto_requested = False
self.action_goto = QtWidgets.QAction("Go to assignments", self)
self.action_goto.setShortcut(self.shortcut)
self.action_goto.triggered.connect(self.request_goto)
self.word_clicked.connect(self._on_word_clicked)
self._runner = DelayJobRunner(delay=1)
def on_state_changed(self, state):
super(GoToAssignmentsMode, self).on_state_changed(state)
if state:
self.editor.add_action(self.action_goto)
else:
self.editor.remove_action(self.action_goto)
def request_goto(self):
"""
Request a goto action for the word under the text cursor.
"""
self._goto_requested = True
self._check_word_cursor()
def _check_word_cursor(self, tc=None):
"""
Request a go to assignment.
:param tc: Text cursor which contains the text that we must look for
its assignment. Can be None to go to the text that is under
the text cursor.
:type tc: QtGui.QTextCursor
"""
if not tc:
tc = TextHelper(self.editor).word_under_cursor()
request_data = {
'code': self.editor.toPlainText(),
'line': tc.blockNumber(),
'column': tc.columnNumber(),
'path': self.editor.file.path,
'encoding': self.editor.file.encoding
}
try:
self.editor.backend.send_request(
workers.goto_assignments, request_data,
on_receive=self._on_results_available)
except NotRunning:
pass
def _goto(self, definition):
fp = ''
if self.editor.file.path:
fp = os.path.normpath(self.editor.file.path.replace(".pyc", ".py"))
if definition.module_path == fp:
line = definition.line
col = definition.column
_logger().debug("Go to %s" % definition)
self._runner.request_job(
TextHelper(self.editor).goto_line,
line, move=True, column=col)
else:
_logger().debug("Out of doc: %s" % definition)
self.out_of_doc.emit(definition)
def _unique(self, seq):
"""
Not performant but works.
"""
# order preserving
checked = []
for e in seq:
present = False
for c in checked:
if str(c) == str(e):
present = True
break
if not present:
checked.append(e)
return checked
#.........这里部分代码省略.........
开发者ID:AlexLee,项目名称:cadquery-freecad-module,代码行数:101,代码来源:goto_assignements.py
示例17: DocumentOutlineMode
class DocumentOutlineMode(QObject, Mode):
"""
Parses the current cobol document when the text changed and emit the
changed event if any properties of any document node has changed.
This mode can be used to implement a document outline widget.
"""
#: Signal emitted when the document layout changed
changed = Signal(Name, list, list)
@property
def root_node(self):
"""
Returns the document root node.
"""
return self._root_node
@property
def variables(self):
"""
Returns the list of variable document nodes
"""
return self._vars
@property
def paragraphs(self):
"""
Returns the list of paragraphs document nodes
"""
return self._paragraphs
def __init__(self):
QObject.__init__(self)
Mode.__init__(self)
self._root_node = None
self._vars = []
self._paragraphs = []
self._runner = DelayJobRunner()
def on_state_changed(self, state):
"""
Called when the mode is activated/deactivated
"""
if state:
self.editor.new_text_set.connect(self.parse)
self.editor.textChanged.connect(self._parse)
else:
self.editor.new_text_set.disconnect(self.parse)
self.editor.textChanged.disconnect(self._parse)
self._runner.cancel_requests()
def _parse(self):
self._runner.request_job(self.parse)
def parse(self):
""" Parse the document layout.
To get the results, use the following properties:
- root_node
- variables
- paragraphs
"""
# preview in preferences dialog have no file path
if not self.editor.file.path:
return
txt = self.editor.toPlainText()
fmt = self.editor.free_format
try:
root_node, variables, paragraphs = defined_names(txt, fmt)
except AttributeError:
# this should never happen but we must exit gracefully
_logger().exception("Failed to parse document, probably due to "
"a malformed syntax.")
else:
changed = False
if self._root_node is None or cmp_name(root_node, self._root_node):
changed = True
self._root_node = root_node
self._vars = variables
self._paragraphs = paragraphs
if changed:
_logger().debug('changed')
self.changed.emit(
self.root_node, self.variables, self.paragraphs)
开发者ID:dtonal,项目名称:pyqode.cobol,代码行数:85,代码来源:doc_outline.py
示例18: CheckerPanel
class CheckerPanel(Panel):
""" Shows messages collected by one or more checker modes """
def __init__(self):
super(CheckerPanel, self).__init__()
self._previous_line = -1
self.scrollable = True
self._job_runner = DelayJobRunner(delay=100)
self.setMouseTracking(True)
#: Info icon
self.info_icon = icons.icon(
'dialog-info', ':pyqode-icons/rc/dialog-info.png',
'fa.info-circle', qta_options={'color': '#4040DD'})
self.warning_icon = icons.icon(
'dialog-warning', ':pyqode-icons/rc/dialog-warning.png',
'fa.exclamation-triangle', qta_options={'color': '#DDDD40'})
self.error_icon = icons.icon(
'dialog-error', ':pyqode-icons/rc/dialog-error.png',
'fa.exclamation-circle', qta_options={'color': '#DD4040'})
def marker_for_line(self, line):
"""
Returns the marker that is displayed at the specified line number if
any.
:param line: The marker line.
:return: Marker of None
:rtype: pyqode.core.Marker
"""
block = self.editor.document().findBlockByNumber(line)
try:
return block.userData().messages
except AttributeError:
return []
def sizeHint(self):
"""
Returns the panel size hint. (fixed with of 16px)
"""
metrics = QtGui.QFontMetricsF(self.editor.font())
size_hint = QtCore.QSize(metrics.height(), metrics.height())
if size_hint.width() > 16:
size_hint.setWidth(16)
return size_hint
def on_uninstall(self):
self._job_runner.cancel_requests()
super(CheckerPanel, self).on_uninstall()
def paintEvent(self, event):
super(CheckerPanel, self).paintEvent(event)
painter = QtGui.QPainter(self)
for top, block_nbr, block in self.editor.visible_blocks:
user_data = block.userData()
if user_data and user_data.messages:
for msg in user_data.messages:
icon = self._icon_from_message(msg)
if icon:
rect = QtCore.QRect()
rect.setX(0)
rect.setY(top)
rect.setWidth(self.sizeHint().width())
rect.setHeight(self.sizeHint().height())
icon.paint(painter, rect)
def _icon_from_message(self, message):
icons = {
CheckerMessages.INFO: self.info_icon,
CheckerMessages.WARNING: self.warning_icon,
CheckerMessages.ERROR: self.error_icon
}
return icons[message.status]
def mouseMoveEvent(self, event):
# Requests a tooltip if the cursor is currently over a marker.
line = TextHelper(self.editor).line_nbr_from_position(event.pos().y())
if line:
markers = self.marker_for_line(line)
text = '\n'.join([marker.description for marker in markers if
marker.description])
if len(markers):
if self._previous_line != line:
top = TextHelper(self.editor).line_pos_from_number(
markers[0].line)
if top:
self._job_runner.request_job(self._display_tooltip,
text, top)
else:
self._job_runner.cancel_requests()
self._previous_line = line
def leaveEvent(self, *args):
"""
Hide tooltip when leaving the panel region.
"""
QtWidgets.QToolTip.hideText()
self._previous_line = -1
def _display_tooltip(self, tooltip, top):
"""
#.........这里部分代码省略.........
开发者ID:OpenCobolIDE,项目名称:OpenCobolIDE,代码行数:101,代码来源:checker.py
示例19: DocumentAnalyserMode
class DocumentAnalyserMode(Mode, QtCore.QObject):
""" Analyses the document outline as a tree of statements.
This mode analyses the structure of a document (a tree of
:class:`pyqode.python.backend.workers.Definition`.
:attr:`pyqode.python.modes.DocumentAnalyserMode.document_changed`
is emitted whenever the document structure changed.
To keep good performances, the analysis task is run when the application is
idle for more than 1 second (by default).
"""
#: Signal emitted when the document structure changed.
document_changed = QtCore.Signal()
def __init__(self, delay=1000):
Mode.__init__(self)
QtCore.QObject.__init__(self)
self._jobRunner = DelayJobRunner(delay=delay)
#: The list of results (elements might have children; this is actually
#: a tree).
self.results = []
def on_state_changed(self, state):
if state:
self.editor.new_text_set.connect(self._run_analysis)
self.editor.textChanged.connect(self._request_analysis)
else:
self.editor.textChanged.disconnect(self._request_analysis)
self.editor.new_text_set.disconnect(self._run_analysis)
self._jobRunner.cancel_requests()
def _request_analysis(self):
self._jobRunner.request_job(self._run_analysis)
def _run_analysis(self):
if self.enabled and self.editor and self.editor.toPlainText() and \
self.editor.file:
request_data = {
'code': self.editor.toPlainText(),
'path': self.editor.file.path,
'encoding': self.editor.file.encoding
}
try:
self.editor.backend.send_request(
defined_names, request_data,
on_receive=self._on_results_available)
except NotRunning:
QtCore.QTimer.singleShot(100, self._run_analysis)
else:
self.results = []
self.document_changed.emit()
def _on_results_available(self, results):
if results:
results = [Definition().from_dict(ddict) for ddict in results]
self.results = results
if self.results is not None:
_logger().debug("Document structure changed")
self.document_changed.emit()
@property
def flattened_results(self):
"""
Flattens the document structure tree as a simple sequential list.
"""
ret_val = []
for d in self.results:
ret_val.append(d)
for sub_d in d.children:
nd = Definition(sub_d.name, sub_d.icon, sub_d.line,
sub_d.column, sub_d.full_name)
nd.name = " " + nd.name
nd.full_name = " " + nd.full_name
ret_val.append(nd)
return ret_val
def to_tree_widget_items(self, to_collapse=None):
"""
Returns the results as a list of top level QTreeWidgetItem.
This is a convenience function that you can use to update a document
tree widget wheneve the document changed.
"""
def convert(name, editor, to_collapse):
ti = QtWidgets.QTreeWidgetItem()
ti.setText(0, name.name)
ti.setIcon(0, QtGui.QIcon(name.icon))
name.block = editor.document().findBlockByNumber(name.line)
ti.setData(0, QtCore.Qt.UserRole, name)
block_data = name.block.userData()
if block_data is None:
block_data = TextBlockUserData()
name.block.setUserData(block_data)
block_data.tree_item = ti
if to_collapse is not None and \
TextBlockHelper.get_fold_trigger_state(name.block):
to_collapse.append(ti)
#.........这里部分代码省略.........
开发者ID:AlexLee,项目名称:cadquery-freecad-module,代码行数:101,代码来源:document_analyser.py
示例20: __init__
def __init__(self, parent):
QtWidgets.QTabBar.__init__(self, parent)
self.setTabsClosable(True)
self._timer = DelayJobRunner(delay=1)
开发者ID:OpenCobolIDE,项目名称:OpenCobolIDE,代码行数:4,代码来源:tab_bar.py
注:本文中的pyqode.core.api.DelayJobRunner类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论