本文整理匯總了Python中pyqode.core.api.utils.TextBlockHelper.get_fold_trigger_state方法的典型用法代碼示例。如果您正苦於以下問題:Python TextBlockHelper.get_fold_trigger_state方法的具體用法?Python TextBlockHelper.get_fold_trigger_state怎麽用?Python TextBlockHelper.get_fold_trigger_state使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyqode.core.api.utils.TextBlockHelper
的用法示例。
在下文中一共展示了TextBlockHelper.get_fold_trigger_state方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: process_block
# 需要導入模塊: from pyqode.core.api.utils import TextBlockHelper [as 別名]
# 或者: from pyqode.core.api.utils.TextBlockHelper import get_fold_trigger_state [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
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)
delta_abs = abs(fold_level - prev_fold_level)
if delta_abs > 1:
if fold_level > prev_fold_level:
# try to fix inconsistent fold level
_logger().debug(
'(l%d) inconsistent fold level, difference between '
'consecutive blocks cannot be greater than 1 (%d).',
current_block.blockNumber() + 1, delta_abs)
fold_level = prev_fold_level + 1
# 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_fold_trigger_state(
current_block, TextBlockHelper.get_fold_trigger_state(
prev))
# make empty line not a trigger
TextBlockHelper.set_fold_trigger(prev, False)
TextBlockHelper.set_fold_trigger_state(prev, False)
示例2: collapsed
# 需要導入模塊: from pyqode.core.api.utils import TextBlockHelper [as 別名]
# 或者: from pyqode.core.api.utils.TextBlockHelper import get_fold_trigger_state [as 別名]
def collapsed(self):
"""
Returns True if the block is collasped, False if it is expanded.
"""
return TextBlockHelper.get_fold_trigger_state(self._trigger)