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():
# Equivalent functionality comes with contextmenu.py on qt ui.
ok = Tk and g.app.gui.guiName() == 'tkinter'
if ok:
g.app.hasOpenWithMenu = True
g.enableIdleTimeHook(idleTimeDelay=1000) # Check every second.
g.registerHandler("idle", on_idle)
g.registerHandler('menu2', create_open_with_menu)
g.plugin_signon(__name__)
return ok
#@+node:EKR.20040517075715.5: ** on_idle
def init():
if g.app.unitTesting: # Not Ok for unit testing!
return False
if not gtk:
return False
if g.app.gui:
return g.app.gui.guiName() == 'gtk'
else:
g.app.gui = leoGtkGui.gtkGui()
# g.app.root = g.app.gui.createRootWindow()
g.app.gui.finishCreate()
g.plugin_signon(__name__)
return True
#@-node:ekr.20080112150934.1:init
Prompt the user to save changes.
Return True if the user vetos the quit or save operation.
'''
c = self.c
# if g.app.gui.guiName() == 'curses':
# g.trace('Saves disabled for curses gui')
# return False
theType = "quitting?" if g.app.quitting else "closing?"
# See if we are in quick edit/save mode.
root = c.rootPosition()
quick_save = not c.mFileName and not root.next() and root.isAtEditNode()
if quick_save:
name = g.shortFileName(root.atEditNodeName())
else:
name = c.mFileName if c.mFileName else self.title
answer = g.app.gui.runAskYesNoCancelDialog(c,
title="Confirm",
message='Save changes to %s before %s' % (
g.splitLongFileName(name), theType))
if answer == "cancel":
return True # Veto.
if answer == "no":
return False # Don't save and don't veto.
if not c.mFileName:
root = c.rootPosition()
if not root.next() and root.isAtEditNode():
# There is only a single @edit node in the outline.
# A hack to allow "quick edit" of non-Leo files.
# See https://bugs.launchpad.net/leo-editor/+bug/381527
# Write the @edit node if needed.
if root.isDirty():
c.atFileCommands.writeOneAtEditNode(root,
theFile = lm.openLeoOrZipFile(fn)
if theFile:
message('reading settings in %s' % (fn))
# Changing g.app.gui here is a major hack. It is necessary.
oldGui = g.app.gui
g.app.gui = g.app.nullGui
c = g.app.newCommander(fn)
frame = c.frame
frame.log.enable(False)
g.app.lockLog()
ok = c.fileCommands.openLeoFile(theFile,fn,
readAtFileNodesFlag=False,silent=True)
# closes theFile.
g.app.unlockLog()
c.openDirectory = frame.openDirectory = g.os_path_dirname(fn)
g.app.gui = oldGui
return ok and c or None
#@+node:ekr.20120213081706.10382: *4* lm.readGlobalSettingsFiles
self.colorTags = [] # list of color names used as tags.
self.enabled = False
self.isVisible = False
self.lastRow = self.lastCol = 0
self.log = c.frame.log
#if 'black' not in self.log.colorTags:
# self.log.colorTags.append("black")
self.parentFrame = parentFrame
self.statusFrame = Tk.Frame(parentFrame,bd=2)
text = "line 0, col 0, fcol 0"
width = len(text) + 4
self.labelWidget = Tk.Label(self.statusFrame,text=text,width=width,anchor="w")
self.labelWidget.pack(side="left",padx=1)
bg = self.statusFrame.cget("background")
self.textWidget = w = g.app.gui.bodyTextWidget(
self.statusFrame,
height=1,state="disabled",bg=bg,relief="groove",name='status-line')
self.textWidget.pack(side="left",expand=1,fill="x")
c.bind(w,"", self.onActivate)
self.show()
c.frame.statusFrame = self.statusFrame
c.frame.statusLabel = self.labelWidget
c.frame.statusText = self.textWidget
#@-node:ekr.20031218072017.3961:ctor
def init ():
ok = Pmw and Tk
if ok:
if g.app.gui is None:
g.app.createTkGui(__file__)
ok = g.app.gui.guiName() == "tkinter"
if ok:
g.registerHandler('before-create-leo-frame',onCreate)
g.plugin_signon(__name__)
return ok
#@+node:ekr.20050301105220: ** onCreate
def replaceClipboardWith (self,s):
# g.app.gui.win32clipboard is always None.
wcb = g.app.gui.win32clipboard
if wcb:
try:
wcb.OpenClipboard(0)
wcb.EmptyClipboard()
wcb.SetClipboardText(s)
wcb.CloseClipboard()
except:
g.es_exception()
else:
self.root.clipboard_clear()
self.root.clipboard_append(s)
#@-node:ekr.20031218072017.845:replaceClipboardWith
def readOpmlCommand(self, event=None):
'''Open a Leo window containing the contents of an .opml file.'''
c = self.c
fileName = g.app.gui.runOpenFileDialog(c,
title="Read OPML",
filetypes=[("OPML files", "*.opml"), ("All files", "*")],
defaultextension=".opml")
c.bringToFront()
if fileName:
self.readFile(fileName)
else:
c.bodyWantsFocus()
#@+node:ekr.20060904103721.1: *3* oc.writeFile
def weave(self, event=None):
"""Simulate a literate-programming weave operation by writing the outline to a text file."""
c = self
filetypes = [("Text files", "*.txt"), ("All files", "*")]
fileName = g.app.gui.runSaveFileDialog(c,
initialfile="weave.txt",
title="Weave",
filetypes=filetypes,
defaultextension=".txt")
c.bringToFront()
if fileName:
g.setGlobalOpenDir(fileName)
g.chdir(fileName)
c.importCommands.weave(fileName)
#@+node:ekr.20031218072017.2838: ** Read/Write
def attachIconCallback(top=self.top):
g.app.gui.attachLeoIcon(top)