Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
content = "<pre>%s</pre>" % p.b if not self.was_rich else ''
data = data.replace('[CONTENT]', content)
# replace textarea with CKEditor, with or without config.
if self.config:
data = data.replace('[CONFIG]', ', '+self.config)
else:
data = data.replace('[CONFIG]', '')
# try and make the path for URL evaluation relative to the node's path
aList = g.get_directives_dict_list(p)
path = c.scanAtPathDirectives(aList)
if p.h.startswith('@'): # see if it's a @ node of some sort
nodepath = p.h.split(None, 1)[-1]
nodepath = g.os_path_join(path, nodepath)
if not g.os_path_isdir(nodepath): # remove filename
nodepath = g.os_path_dirname(nodepath)
if g.os_path_isdir(nodepath): # append if it's a directory
path = nodepath
self.webview.setHtml(data, QtCore.QUrl.fromLocalFile(path+"/"))
#@+node:tbrown.20130813134319.7228: *3* unselect_node
def onCreate (tag, keywords):
"""
Showing how to define a global hook that affects all commanders.
"""
import leo.plugins.tkGui as tkGui
leoTkinterFrame = tkGui.leoTkinterFrame
log = tkGui.leoTkinterLog
# Ensure that the templates folder is there
folder = g.os_path_join(g.app.loadDir,"..","plugins", "templates")
try:
os.mkdir(folder)
except OSError as err:
pass # Ok if it is there already
global helpers
c = keywords.get("c")
helpers[c] = helper = UIHelperClass(c,folder)
helper.addWidgets()
#@+node:pap.20051011221702: *3* Commands exposed as menus
def init_mode (self,name):
'''Name may be a language name or a delegate name.'''
if not name: return False
language,rulesetName = self.nameToRulesetName(name)
bunch = self.modes.get(rulesetName)
if bunch:
# g.trace('found',language,rulesetName)
self.initModeFromBunch(bunch)
return True
else:
# g.trace('****',language,rulesetName)
path = g.os_path_join(g.app.loadDir,'..','modes')
# Bug fix: 2008/2/10: Don't try to import a non-existent language.
fileName = g.os_path_join(path,'%s.py' % (language))
if g.os_path_exists(fileName):
mode = g.importFromPath (language,path)
else: mode = None
if mode:
# A hack to give modes/forth.py access to c.
if hasattr(mode,'pre_init_mode'):
mode.pre_init_mode(self.c)
else:
# Create a dummy bunch to limit recursion.
self.modes [rulesetName] = self.modeBunch = g.Bunch(
attributesDict = {},
defaultColor = None,
keywordsDict = {},
def isValidLanguage(self, language):
"""True if language exists in leo/modes."""
fn = g.os_path_join(g.app.loadDir, '..', 'modes', f"{language}.py")
return g.os_path_exists(fn)
#@+node:ekr.20170127142001.7: *4* bjc.useSyntaxColoring & helper
if g.os_path_exists(fileName):
return None
ok = g.app.gui.runAskYesNoDialog(c,
title='Create myLeoSettings.leo?',
message=f"Create myLeoSettings.leo in {homeLeoDir}?",
)
if ok == 'no':
return None
# get '@enabled-plugins' from g.app.globalConfigDir
fileName = g.os_path_join(configDir, "leoSettings.leo")
leosettings = g.openWithFileName(fileName, old_c=c)
enabledplugins = g.findNodeAnywhere(leosettings, '@enabled-plugins')
enabledplugins = enabledplugins.b
leosettings.close()
# now create "~/.leo/myLeoSettings.leo"
fileName = g.os_path_join(homeLeoDir, name)
c2 = g.openWithFileName(fileName, old_c=c)
# add content to outline
nd = c2.rootPosition()
nd.h = "Settings README"
nd.b = (
"myLeoSettings.leo personal settings file created {time}\n\n"
"Only nodes that are descendants of the @settings node are read.\n\n"
"Only settings you need to modify should be in this file, do\n"
"not copy large parts of leoSettings.py here.\n\n"
"For more information see http://leoeditor.com/customizing.html"
"".format(time=time.asctime())
)
nd = nd.insertAfter()
nd.h = '@settings'
nd = nd.insertAsNthChild(0)
nd.h = '@enabled-plugins'
def setDefaultIcon(self):
"""Set the icon to be used in all Leo windows.
This code does nothing for Tk versions before 8.4.3."""
gui = self
try:
version = gui.root.getvar("tk_patchLevel")
# g.trace(repr(version),g.CheckVersion(version,"8.4.3"))
if g.CheckVersion(version,"8.4.3") and sys.platform == "win32":
# tk 8.4.3 or greater: load a 16 by 16 icon.
path = g.os_path_join(g.app.loadDir,"..","Icons")
if g.os_path_exists(path):
theFile = g.os_path_join(path,"LeoApp16.ico")
if g.os_path_exists(path):
self.bitmap = Tk.BitmapImage(theFile)
else:
g.es('','LeoApp16.ico','not in','Icons','directory',color="red")
else:
g.es('','Icons','directory not found:',path, color="red")
except:
g.pr("exception setting bitmap")
import traceback ; traceback.print_exc()
#@-node:ekr.20031218072017.1856:setDefaultIcon
# Bug fix: 2/6/05: put result in g.app.leoID.
g.app.leoID = leoid
# Careful: periods in the id field of a gnx will corrupt the .leo file!
g.app.leoID = g.app.leoID.replace('.','-')
# g.trace(g.app.leoID)
g.blue('leoID=',repr(g.app.leoID),spaces=False)
#@-<< put up a dialog requiring a valid id >>
#@+<< attempt to create leoID.txt >>
#@+node:ekr.20031218072017.1982: *4* << attempt to create leoID.txt >> (changed)
for theDir in (homeLeoDir,globalConfigDir,loadDir):
# N.B. We would use the _working_ directory if theDir is None!
if theDir:
try:
fn = g.os_path_join(theDir,tag)
f = open(fn,'w')
s = g.app.leoID
if not g.isPython3: # 2010/08/27
s = g.toEncodedString(s,encoding='utf-8',reportErrors=True)
f.write(s)
f.close()
if g.os_path_exists(fn):
g.error('',tag,'created in',theDir)
return
except IOError:
pass
g.error('can not create',tag,'in',theDir)
#@-<< attempt to create leoID.txt >>
self.view = view = QtDeclarative.QDeclarativeView()
ctx = view.rootContext()
@g.command("nb-all")
def nb_all_f(event):
self.add_all_nodes()
self.view.show()
@g.command("nb-subtree")
def nb_subtree_f(event):
p = self.c.p
self.add_subtree(p)
self.view.show()
ctx.setContextProperty("nodesModel", self.mw.model)
path = g.os_path_join(g.computeLeoDir(), 'plugins', 'qmlnb', 'qml', 'leonbmain.qml')
view.setSource(QtCore.QUrl(path))
if isQt5:
mode = view.SizeRootObjectToView
else:
mode = QtDeclarative.QDeclarativeView.SizeRootObjectToView
view.setResizeMode(mode)
# Display the user interface and allow the user to interact with it.
view.hide()
view.setGeometry(100, 100, 800, 600)
#view.show()
c.dummy = view
#@+node:ville.20120604212857.4239: *3* add_all_nodes
# SilverCity seems not to be supported, so this warning is strange.
if False and ext in ('.html', '.htm') and not SilverCity:
if not self.silverCityWarningGiven:
self.silverCityWarningGiven = True
if not g.unitTesting:
g.es('SilverCity not present so no syntax highlighting')
# Make the stylesheet path relative to the directory containing the output file.
rel_stylesheet_path = self.getOption(p, 'stylesheet_path') or ''
# New in Leo 4.5: The rel_stylesheet_path is relative to the open directory.
stylesheet_path = g.os_path_finalize_join(
openDirectory, rel_stylesheet_path)
stylesheet_name = self.getOption(p, 'stylesheet_name')
assert stylesheet_name
path = g.os_path_finalize_join(stylesheet_path, stylesheet_name)
if self.getOption(p, 'stylesheet_embed') is False:
rel_path = g.os_path_join(
rel_stylesheet_path, self.getOption(p, 'stylesheet_name'))
rel_path = rel_path.replace('\\', '/') # 2010/01/28
overrides['stylesheet'] = rel_path
overrides['stylesheet_path'] = None
overrides['embed_stylesheet'] = None
elif g.os_path_exists(path):
if ext != '.pdf':
overrides['stylesheet'] = path
overrides['stylesheet_path'] = None
elif styleSheetArgsDict:
g.es_print('using publish_argv_for_missing_stylesheets',
styleSheetArgsDict)
overrides.update(styleSheetArgsDict)
# MWC add args to settings
elif rel_stylesheet_path == stylesheet_path:
g.error(f"stylesheet not found: {path}")
try: ypad = int(ypad)
except: ypad = 0
#@-node:ekr.20040803072955.48:<< set offsets and pads >>
#@nl
theType = theDict.get("type")
if theType == "icon":
### not ready yet.
# s = theDict.get("icon")
pass
elif theType == "file":
theFile = theDict.get("file")
relPath = theDict.get('relPath')
#@ << draw the icon at file >>
#@+node:ekr.20040803072955.50:<< draw the icon at file >>
if relPath:
fullname = g.os_path_join(g.app.loadDir,"..","Icons",relPath)
else:
fullname = g.os_path_join(g.app.loadDir,"..","Icons",theFile)
fullname = g.os_path_normpath(fullname)
# Bug fix: the key must include distinguish nodes.
key = (fullname,p.v.t)
image = self.iconimages.get(key)
if not image:
try:
from PIL import Image, ImageTk
image1 = Image.open(fullname)
image = ImageTk.PhotoImage(image1)
self.iconimages[key] = image
except Exception:
#g.es_exception()