本文整理汇总了Python中pyqode.core.api.utils.TextBlockHelper.set_collapsed方法的典型用法代码示例。如果您正苦于以下问题:Python TextBlockHelper.set_collapsed方法的具体用法?Python TextBlockHelper.set_collapsed怎么用?Python TextBlockHelper.set_collapsed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyqode.core.api.utils.TextBlockHelper
的用法示例。
在下文中一共展示了TextBlockHelper.set_collapsed方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fold
# 需要导入模块: from pyqode.core.api.utils import TextBlockHelper [as 别名]
# 或者: from pyqode.core.api.utils.TextBlockHelper import set_collapsed [as 别名]
def fold(self):
"""
Folds the region.
"""
start, end = self.get_range()
TextBlockHelper.set_collapsed(self._trigger, True)
block = self._trigger.next()
while block.blockNumber() <= end and block.isValid():
block.setVisible(False)
block = block.next()
示例2: unfold
# 需要导入模块: from pyqode.core.api.utils import TextBlockHelper [as 别名]
# 或者: from pyqode.core.api.utils.TextBlockHelper import set_collapsed [as 别名]
def unfold(self):
"""
Unfolds the region.
"""
# set all direct child blocks which are not triggers to be visible
self._trigger.setVisible(True)
TextBlockHelper.set_collapsed(self._trigger, False)
for block in self.blocks(ignore_blank_lines=False):
block.setVisible(True)
if TextBlockHelper.is_fold_trigger(block):
TextBlockHelper.set_collapsed(block, False)
示例3: process_block
# 需要导入模块: from pyqode.core.api.utils import TextBlockHelper [as 别名]
# 或者: from pyqode.core.api.utils.TextBlockHelper import set_collapsed [as 别名]
def process_block(self, current_block, previous_block, text):
"""
Processes a block and setup its folding info.
This method call ``detect_fold_level`` and handles most of the tricky
corner cases so that all you have to do is focus on getting the proper
fold level foreach meaningful block, skipping the blank ones.
:param current_block: current block to process
:param previous_block: previous block
:param text: current block text
"""
prev_fold_level = TextBlockHelper.get_fold_lvl(previous_block)
if text.strip() == '':
# blank line always have the same level as the previous line
fold_level = prev_fold_level
else:
fold_level = self.detect_fold_level(
previous_block, current_block)
if fold_level > self.limit:
fold_level = self.limit
prev_fold_level = TextBlockHelper.get_fold_lvl(previous_block)
if fold_level > prev_fold_level:
# apply on previous blank lines
block = current_block.previous()
while block.isValid() and block.text().strip() == '':
TextBlockHelper.set_fold_lvl(block, fold_level)
block = block.previous()
TextBlockHelper.set_fold_trigger(
block, True)
# update block fold level
if text.strip():
TextBlockHelper.set_fold_trigger(
previous_block, fold_level > prev_fold_level)
TextBlockHelper.set_fold_lvl(current_block, fold_level)
# user pressed enter at the beginning of a fold trigger line
# the previous blank line will keep the trigger state and the new line
# (which actually contains the trigger) must use the prev state (
# and prev state must then be reset).
prev = current_block.previous() # real prev block (may be blank)
if (prev and prev.isValid() and prev.text().strip() == '' and
TextBlockHelper.is_fold_trigger(prev)):
# prev line has the correct trigger fold state
TextBlockHelper.set_collapsed(
current_block, TextBlockHelper.is_collapsed(
prev))
# make empty line not a trigger
TextBlockHelper.set_fold_trigger(prev, False)
TextBlockHelper.set_collapsed(prev, False)
示例4: unfold
# 需要导入模块: from pyqode.core.api.utils import TextBlockHelper [as 别名]
# 或者: from pyqode.core.api.utils.TextBlockHelper import set_collapsed [as 别名]
def unfold(self):
"""
Unfolds the region.
"""
# set all direct child blocks which are not triggers to be visible
self._trigger.setVisible(True)
TextBlockHelper.set_collapsed(self._trigger, False)
for block in self.blocks(ignore_blank_lines=False):
block.setVisible(True)
for region in self.child_regions():
if not region.collapsed:
region.unfold()
else:
# leave it closed but open the last blank lines and the
# trigger line
start, bstart = region.get_range(ignore_blank_lines=True)
_, bend = region.get_range(ignore_blank_lines=False)
block = self._trigger.document().findBlockByNumber(start)
block.setVisible(True)
block = self._trigger.document().findBlockByNumber(bend)
while block.blockNumber() > bstart:
block.setVisible(True)
block = block.previous()