Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def init():
'''Return True if the plugin has loaded successfully.'''
ok = not g.unitTesting
# Not for unit testing: overrides core methods.
if ok:
if 0:
# Override the LeoFrame class.
class myLeoFrame(leoFrame.LeoFrame):
def __init__(self, title=None):
g.pr("myLeoFrame ctor", title)
super().__init__(title)
leoFrame.LeoFrame = myLeoFrame
if 0:
# Override methods of the LeoApp class.
oldAppCloseLeoWindow = g.app.closeLeoWindow
def caption(self, s, pane): # To do: center option.
'''Pop up a QPlainTextEdit in the indicated pane.'''
m = self
parent = m.pane_widget(pane)
if not parent:
g.trace('bad pane: %s' % (pane))
return None
s = s.rstrip()
if s and s[-1].isalpha():
s = s + '.'
w = QtWidgets.QPlainTextEdit(s, parent)
w.setObjectName('screencastcaption')
m.widgets.append(w)
w2 = m.pane_widget(pane)
geom = w2.geometry()
w.resize(geom.width(), min(150, geom.height() / 2))
off = QtCore.Qt.ScrollBarAlwaysOff
w.setHorizontalScrollBarPolicy(off)
w.setVerticalScrollBarPolicy(off)
w.show()
return w
def delete_all_labels(self,event=None):
"""
Delete all labels in the outline.
Ask for confirmation before doing so!
"""
title = 'Do you really want to delete ALL labels?'
message_text = 'Do you really want to delete ALL labels?'
root = self.c.frame.outerFrame
dialog = Pmw_MessageDialog(root, title = title, message_text = message_text)
result = dialog.doit()
if result == 'Cancel':
return
if result == 'OK':
g.es("Deleting ALL labels", color='red')
for p in self.c.all_positions():
labels_dict = self.get_labels_dict(p)
if labels_dict:
self.set_labels_dict(p,None)
#@+node:ekr.20050301095332.42: *4* delete_label
k = self.c.k
try:
p = subprocess.Popen(
shlex.split(command),
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL if trace else subprocess.PIPE,
shell=sys.platform.startswith('win'),
)
out, err = p.communicate()
for line in g.splitLines(out):
g.es_print(g.toUnicode(line.rstrip()))
except Exception:
g.es_exception()
k.keyboardQuit()
# Inits vim mode too.
g.es(f"Done: {command}")
#@+node:ekr.20150514063305.92: *3* print plugins info...
return val, False
# Perform all scripting substitutions.
self.save_ins = None
self.save_sel = None
while c.abbrev_subst_start in val:
prefix, rest = val.split(c.abbrev_subst_start, 1)
content = rest.split(c.abbrev_subst_end, 1)
if len(content) != 2:
break
content, rest = content
try:
self.expanding = True
c.abbrev_subst_env['x'] = ''
exec(content, c.abbrev_subst_env, c.abbrev_subst_env)
except Exception:
g.es_print('exception evaluating', content)
g.es_exception()
finally:
self.expanding = False
x = c.abbrev_subst_env.get('x')
if x is None: x = ''
val = f"{prefix}{x}{rest}"
# Save the selection range.
w = c.frame.body.wrapper
self.save_ins = w.getInsertPoint()
self.save_sel = w.getSelectionRange()
if val == "__NEXT_PLACEHOLDER":
# user explicitly called for next placeholder in an abbrev.
# inserted previously
val = ''
do_placeholder = True
else:
def init():
'''Return True if the plugin has loaded successfully.'''
g.registerHandler('after-create-leo-frame',onCreate)
g.plugin_signon(__name__)
return True
def init():
'''Return True if the plugin has loaded successfully.'''
g.registerHandler("after-create-leo-frame", on_create)
g.plugin_signon(__name__)
return True # OK for unit testing.
#@+node:gfunch.20041207100416.5: ** class DateNodes
def destroySelf(self):
QtCore.pyqtRemoveInputHook()
if 'shutdown' in g.app.debug:
g.pr('LeoQtGui.destroySelf: calling qtApp.Quit')
self.qtApp.quit()
#@+node:ekr.20110605121601.18485: *3* qt_gui.Clipboard
def getArgs(self, p):
'''Return the list of @args field of p.h.'''
args = []
if not p:
return args
h, tag = p.h, '@args'
i = h.find(tag)
if i > -1:
j = g.skip_ws(h, i + len(tag))
# 2011/10/16: Make '=' sign optional.
if g.match(h, j, '='): j += 1
if 0:
s = h[j + 1:].strip()
else: # new logic 1/3/2014 Jake Peck
k = h.find('@', j + 1)
if k == -1: k = len(h)
s = h[j: k].strip()
args = s.split(',')
args = [z.strip() for z in args]
# if args: g.trace(args)
return args
#@+node:ekr.20060328125248.15: *4* sc.getButtonText
def rp_wrap_all_lines(c, indents, leading_ws, lines, pageWidth):
"""Compute the result of wrapping all lines."""
trailingNL = lines and lines[-1].endswith('\n')
lines = [z[:-1] if z.endswith('\n') else z for z in lines]
if lines: # Bug fix: 2013/12/22.
s = lines[0]
if startsParagraph(s):
# Adjust indents[1]
# Similar to code in startsParagraph(s)
i = 0
if s[0].isdigit():
while i < len(s) and s[i].isdigit():
i += 1
if g.match(s, i, ')') or g.match(s, i, '.'):
i += 1
elif s[0].isalpha():
if g.match(s, 1, ')') or g.match(s, 1, '.'):
i = 2
elif s[0] == '-':
i = 1
# Never decrease indentation.
i = g.skip_ws(s, i + 1)
if i > indents[1]:
indents[1] = i
leading_ws[1] = ' ' * i
# Wrap the lines, decreasing the page width by indent.
result = g.wrap_lines(lines,
pageWidth - indents[1],
pageWidth - indents[0])
# prefix with the leading whitespace, if any