def createCommonCommand(self, p, script): ''' Handle a single @command node. Important: Common @button and @command scripts now *do* update dynamically provided that myLeoSettings.leo is open. Otherwise the callback executes the static script. See https://github.com/leo-editor/leo-editor/issues/171 ''' c = self.c args = self.getArgs(p) commonCommandCallback = AtButtonCallback( b=None, buttonText=None, c=c, controller=self, docstring=g.getDocString(p.b).strip(), gnx=p.v.gnx, # Used to search myLeoSettings.leo if it is open. script=script, # Fallback when myLeoSettings.leo is not open. ) self.registerAllCommands( args=args, func=commonCommandCallback, h=p.h, pane= 'button', # Fix bug 416: use 'button', NOT 'command', and NOT 'all' source_c=p.v.context, tag='global @command', )
def handleAtButtonNode (self,p): '''Create a button in the icon area for an @button node. An optional @key=shortcut defines a shortcut that is bound to the button's script. The @key=shortcut does not appear in the button's name, but it *does* appear in the statutus line shown when the mouse moves over the button. An optional @color=colorname defines a color for the button's background. It does not appear in the status line nor the button name.''' trace = False and not g.app.unitTesting and not g.app.batchMode c = self.c ; h = p.h shortcut = self.getShortcut(h) docstring = g.getDocString(p.b) statusLine = docstring if docstring else 'Local script button' if shortcut: statusLine = '%s = %s' % (statusLine,shortcut) g.app.config.atLocalButtonsList.append(p.copy()) # g.trace(c.config,p.h) # This helper is also called by the script-button callback. if trace: g.trace('local @command',h) b = self.createAtButtonHelper(p,h,statusLine,verbose=False)
def handleAtButtonNode(self, p): '''Create a button in the icon area for an @button node. An optional @key=shortcut defines a shortcut that is bound to the button's script. The @key=shortcut does not appear in the button's name, but it *does* appear in the statutus line shown when the mouse moves over the button. An optional @color=colorname defines a color for the button's background. It does not appear in the status line nor the button name.''' trace = False and not g.app.unitTesting and not g.app.batchMode c = self.c h = p.h shortcut = self.getShortcut(h) docstring = g.getDocString(p.b) statusLine = docstring if docstring else 'Local script button' if shortcut: statusLine = '%s = %s' % (statusLine, shortcut) g.app.config.atLocalButtonsList.append(p.copy()) # g.trace(c.config,p.h) # This helper is also called by the script-button callback. if trace: g.trace('local @command', h) b = self.createAtButtonHelper(p, h, statusLine, verbose=False)
def createCommonButton(self, p, script, rclicks=None): ''' Create a button in the icon area for a common @button node in an @setting tree. Binds button presses to a callback that executes the script. ''' c = self.c # g.trace('global @button', c.shortFileName(), p.gnx, p.h) gnx = p.gnx args = self.getArgs(p) # Fix bug #74: problems with @button if defined in myLeoSettings.leo docstring = g.getDocString(p.b).strip() statusLine = docstring or 'Global script button' shortcut = self.getShortcut(p.h) # Get the shortcut from the @key field in the headline. if shortcut: statusLine = '%s = %s' % (statusLine.rstrip(), shortcut) # We must define the callback *after* defining b, # so set both command and shortcut to None here. b = self.createIconButton( args=args, text=p.h, command=None, statusLine=statusLine, kind='at-button', ) if not b: return # Now that b is defined we can define the callback. # Yes, the callback *does* use b (to delete b if requested by the script). buttonText = self.cleanButtonText(p.h) cb = AtButtonCallback( controller=self, b=b, c=c, buttonText=buttonText, docstring=docstring, gnx=gnx, # tag:#367: the gnx is needed for the Goto Script command. script=script, ) # Now patch the button. self.iconBar.setCommandForButton( button=b, command=cb, # This encapsulates the script. command_p=p and p.copy(), # tag:#567 controller=self, gnx=gnx, # For the find-button function. script=script, ) if rclicks: self.iconBar.add_rclick_menu(b.button, rclicks, self, from_settings=True) # At last we can define the command. self.registerAllCommands(args=args, func=cb, h=p.h, pane='button', source_c=p.v.context, tag='@button')
def createCommonButton(self, p, script, rclicks=None): ''' Create a button in the icon area for a common @button node in an @setting tree. Binds button presses to a callback that executes the script. ''' c = self.c # g.trace('global @button',c.shortFileName(),p.h) gnx = p.gnx args = self.getArgs(p) # Fix bug #74: problems with @button if defined in myLeoSettings.leo docstring = g.getDocString(p.b) statusLine = docstring or 'Global script button' shortcut = self.getShortcut(p.h) # Get the shortcut from the @key field in the headline. if shortcut: statusLine = '%s = %s' % (statusLine.rstrip(), shortcut) # We must define the callback *after* defining b, # so set both command and shortcut to None here. b = self.createIconButton( args=args, text=p.h, command=None, statusLine=statusLine, kind='at-button', ) if not b: return # Now that b is defined we can define the callback. # Yes, the callback *does* use b (to delete b if requested by the script). buttonText = self.cleanButtonText(p.h) cb = AtButtonCallback( controller=self, b=b, c=c, buttonText=buttonText, docstring=docstring, gnx=None, # Common buttons have static scripts. script=script, ) # Now patch the button. self.iconBar.setCommandForButton( button=b, command=cb, # This encapsulates the script. command_p=None, controller=self, gnx=gnx, # For the find-button function. script=script, ) if rclicks: self.iconBar.add_rclick_menu(b.button, rclicks, self, from_settings=True) # At last we can define the command. self.registerAllCommands( args=args, func=cb, h=p.h, pane='button', source_c=p.v.context, tag='@button')
def createLocalAtButtonHelper( self, p, h, statusLine, kind='at-button', verbose=True, ): '''Create a button for a local @button node.''' c = self.c buttonText = self.cleanButtonText(h, minimal=True) args = self.getArgs(p) # We must define the callback *after* defining b, # so set both command and shortcut to None here. bg = self.getColor(h) b = self.createIconButton( args=args, text=h, command=None, statusLine=statusLine, kind=kind, bg=bg, ) if not b: return None # Now that b is defined we can define the callback. # Yes, executeScriptFromButton *does* use b (to delete b if requested by the script). docstring = g.getDocString(p.b).strip() cb = AtButtonCallback( controller=self, b=b, c=c, buttonText=buttonText, docstring=docstring, gnx=p.v.gnx, script=None, ) self.iconBar.setCommandForButton( button=b, command=cb, # This encapsulates the script. command_p=p and p.copy(), # This does exist. controller=self, gnx=p and p.gnx, script=None, ) # At last we can define the command and use the shortcut. # registerAllCommands recomputes the shortcut. self.registerAllCommands(args=self.getArgs(p), func=cb, h=h, pane='button', source_c=p.v.context, tag='local @button') return b
def createLocalAtButtonHelper (self,p,h,statusLine,kind='at-button',verbose=True): '''Create a button for a local @button node.''' c = self.c buttonText = self.cleanButtonText(h,minimal=True) args = self.getArgs(p) # We must define the callback *after* defining b, # so set both command and shortcut to None here. bg = self.getColor(h) b = self.createIconButton( args=args, text=h, command=None, statusLine=statusLine, kind=kind, bg=bg, ) if not b: return None # Now that b is defined we can define the callback. # Yes, executeScriptFromButton *does* use b (to delete b if requested by the script). docstring = g.getDocString(p.b) cb = AtButtonCallback( controller=self, b=b, c=c, buttonText=buttonText, docstring=docstring, gnx=p.v.gnx, script=None, ) self.iconBar.setCommandForButton( button=b, command=cb, # This encapsulates the script. command_p=p and p.copy(), # This does exist. controller=self, gnx=p and p.gnx, script=None, ) # At last we can define the command and use the shortcut. # registerAllCommands recomputes the shortcut. self.registerAllCommands( args=self.getArgs(p), func=cb, h=h, pane='button', source_c=p.v.context, tag='local @button') return b
def handleAtCommandNode(self, p): """Handle @command name [@key[=]shortcut].""" c = self.c if not p.h.strip(): return args = self.getArgs(p) def atCommandCallback(event=None, args=args, c=c, p=p.copy()): c.executeScript(args=args, p=p, silent=True) # Fix bug 1251252: https://bugs.launchpad.net/leo-editor/+bug/1251252 # Minibuffer commands created by mod_scripting.py have no docstrings atCommandCallback.__doc__ = g.getDocString(p.b) self.registerAllCommands(p.h, func=atCommandCallback, pane="all", tag="local @command") g.app.config.atLocalCommandsList.append(p.copy())
def createCommonCommand(self, p, script): '''Handle a single @command node.''' c = self.c args = self.getArgs(p) def commonCommandCallback(event=None, script=script): c.executeScript(args=args, script=script, silent=True) commonCommandCallback.__doc__ = g.getDocString(script) # Bug fix: 2015/03/28. self.registerAllCommands(args=args, func=commonCommandCallback, h=p.h, pane='all', source_c=p.v.context, tag='global @command')
def createCommonCommand(self, p, script): '''Handle a single @command node.''' c = self.c args = self.getArgs(p) def commonCommandCallback(event=None, script=script): c.executeScript(args=args, script=script, silent=True) commonCommandCallback.__doc__ = g.getDocString(script) # Bug fix: 2015/03/28. self.registerAllCommands( args=args, func=commonCommandCallback, h=p.h, pane='all', source_c=p.v.context, tag='global @command')
def handleAtCommandNode(self, p): '''Handle @command name [@key[=]shortcut].''' c = self.c if not p.h.strip(): return args = self.getArgs(p) def atCommandCallback(event=None, args=args, c=c, p=p.copy()): c.executeScript(args=args, p=p, silent=True) # Fix bug 1251252: https://bugs.launchpad.net/leo-editor/+bug/1251252 # Minibuffer commands created by mod_scripting.py have no docstrings atCommandCallback.__doc__ = g.getDocString(p.b) self.registerAllCommands( args=args, func=atCommandCallback, h=p.h, pane='all', source_c=p.v.context, tag='local @command') g.app.config.atLocalCommandsList.append(p.copy())
def handleAtCommandNode(self, p): '''Handle @command name [@key[=]shortcut].''' c = self.c if not p.h.strip(): return args = self.getArgs(p) def atCommandCallback(event=None, args=args, c=c, p=p.copy()): # pylint: disable=dangerous-default-value c.executeScript(args=args, p=p, silent=True) # Fix bug 1251252: https://bugs.launchpad.net/leo-editor/+bug/1251252 # Minibuffer commands created by mod_scripting.py have no docstrings atCommandCallback.__doc__ = g.getDocString(p.b) self.registerAllCommands( args=args, func=atCommandCallback, h=p.h, pane='all', source_c=p.v.context, tag='local @command') g.app.config.atLocalCommandsList.append(p.copy())
def docstring(self): p = self.controller.find_gnx(self.gnx) return g.getDocString(p.b) if p else ''
def createCommonButton(self, p, script, rclicks=None): ''' Create a button in the icon area for a common @button node in an @setting tree. Binds button presses to a callback that executes the script. Important: Common @button and @command scripts now *do* update dynamically provided that myLeoSettings.leo is open. Otherwise the callback executes the static script. See https://github.com/leo-editor/leo-editor/issues/171 ''' trace = False and not g.unitTesting c = self.c if trace: g.trace('global @button IN', c.shortFileName()) g.trace('FROM:', p.gnx, p.v.context.shortFileName(), p.h) gnx = p.gnx args = self.getArgs(p) # Fix bug #74: problems with @button if defined in myLeoSettings.leo docstring = g.getDocString(p.b).strip() statusLine = docstring or 'Global script button' shortcut = self.getShortcut(p.h) # Get the shortcut from the @key field in the headline. if shortcut: statusLine = '%s = %s' % (statusLine.rstrip(), shortcut) # We must define the callback *after* defining b, # so set both command and shortcut to None here. b = self.createIconButton( args=args, text=p.h, command=None, statusLine=statusLine, kind='at-button', ) if not b: return # Now that b is defined we can define the callback. # Yes, the callback *does* use b (to delete b if requested by the script). buttonText = self.cleanButtonText(p.h) cb = AtButtonCallback( b=b, buttonText=buttonText, c=c, controller=self, docstring=docstring, gnx=gnx, # tag:#367: the gnx is needed for the Goto Script command. # 2018/03/13: Use gnx to search myLeoSettings.leo if it is open. script=script, ) # Now patch the button. self.iconBar.setCommandForButton( button=b, command=cb, # This encapsulates the script. command_p=p and p.copy(), # tag:#567 controller=self, gnx=gnx, # For the find-button function. script=script, ) self.handleRclicks(rclicks) # At last we can define the command. self.registerAllCommands(args=args, func=cb, h=p.h, pane='button', source_c=p.v.context, tag='@button')
def docstring(self): """Add support for docstrings.""" c, p, script = self.controller.find_gnx(self.gnx) return g.getDocString(p.b) if p else ""
def docstring(self): return g.getDocString(self.p.b)