EditAttributes.py :  » Development » Leo » Leo-4.7.1-final » leo » plugins » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » Leo 
Leo » Leo 4.7.1 final » leo » plugins » EditAttributes.py
#@+leo-ver=4-thin
#@+node:mork.20041018162155.1:@thin EditAttributes.py
#@<< docstring >>
#@+node:ekr.20050226091502:<< docstring >>
'''A plugin that lets the user to associate text with a specific node.

Summon it by pressing button-2 or button-3 on an icon Box in the outline. This
will create an attribute editor where the user can add, remove and edit
attributes. Since attributes use the underlying tnode, clones will share the
attributes of one another.'''
#@nonl
#@-node:ekr.20050226091502:<< docstring >>
#@nl

#@@language python
#@@tabwidth -4

#@<< imports >>
#@+node:mork.20041018162155.2:<< imports >>
# import leo.core.leoPlugins as leoPlugins

import leo.core.leoGlobals as g

import leo.plugins.tkGui as tkGui
leoTkinterFrame = tkGui.leoTkinterFrame   

Pmw = g.importExtension('Pmw',pluginName=__name__,verbose=True,required=True)
#@nonl
#@-node:mork.20041018162155.2:<< imports >>
#@nl

__version__ = ".5"
#@<< version history >>
#@+node:ekr.20050226091502.1:<< version history >>
#@@killcolor

#@+at
# 
# 0.3 EKR:  Base on version 0.2 from Leo User.
#     - Minor changes:  new/different section names.
#     - Use g.importExtension to import PMW.
#     - Added init function.
# 
# 0.4 EKR:
#     - Corrected dispatch logic in newCreateCanvas.
#     - Corrected AttrEditor.__init__ so the Pmw.Dialog is a child of 
# c.frame.top.
#       (Without this the dialog hangs).
#@-at
#@nonl
#@-node:ekr.20050226091502.1:<< version history >>
#@nl

#@+others
#@+node:ekr.20050226091648:init
def init ():

    # At present there is a problem with the interaction of this plugin and the chapters2 plugin.
    ok = Pmw is not None # and 'chapters2' not in leoPlugins.loadedModules
    if not ok: return

    if g.app.gui is None:
        g.app.createTkGui(__file__)

    ok = g.app.gui.guiName() == "tkinter"

    if ok:
        g.plugin_signon( __name__ )

    return ok



#@-node:ekr.20050226091648:init
#@+node:mork.20041018162155.3:class AttrEditor
class AttrEditor:
    #@  @+others
    #@+node:mork.20041018162155.4:__init__
    def __init__ (self,c,p):

        self.c = c
        v = p.v
        self.uAs = v.unknownAttributes = getattr(v,'unknownAttributes',{})
        self.dialog = Pmw.Dialog(c.frame.top, ## Required.
            buttons = ('Add Attribute','Remove Attribute','Close'),
                        title = v.h,
                        command = self.buttonCommands)
        group = Pmw.Group(self.dialog.interior(),tag_text=p.h)
        group.pack(side='top')
        self._mkGui(group.interior())
        self.dialog.activate()
    #@nonl
    #@-node:mork.20041018162155.4:__init__
    #@+node:mork.20041018162155.5:buttonCommands
    def buttonCommands( self, name ):
        if name == 'Add Attribute': return self.add() 
        elif name == 'Remove Attribute': return self.rmv()
        else:
            self.dialog.deactivate()
            self.dialog.destroy()
    #@-node:mork.20041018162155.5:buttonCommands
    #@+node:mork.20041018162155.6:_mkGui
    def _mkGui( self, frame ):

        c = self.c

        group = Pmw.Group( frame , tag_text = "Attributes")
        group.pack( side = 'left' )
        lb = self.lb = Pmw.ScrolledListBox( group.interior() ,
                                           listbox_background = 'white', listbox_foreground = 'blue', 
                                           listbox_selectbackground = '#FFE7C6', 
                                           listbox_selectforeground = 'blue',
                                           selectioncommand = self.selcommand )
        bk = self.uAs.keys()
        bk.sort()
        lb.setlist( bk )
        lb.pack()
        e = self.attEnt = Pmw.EntryField( group.interior(), entry_background = 'white', 
                                          entry_foreground = 'blue' ,
                                          labelpos = 'n', label_text= 'New Attribute:' )
        e.pack()
        self.tx = Pmw.ScrolledText( frame, text_background = 'white', text_foreground = 'blue',
                                    labelpos = 'n', label_text = 'Current Attribute Value' )
        self.tx.pack( side = 'right' )
        w = self.tx.component( 'text' )
        c.bind(w,'<Key>', self.setText )
        if bk:
            lb.setvalue( bk[ 0 ] )
            self.selcommand()
    #@-node:mork.20041018162155.6:_mkGui
    #@+node:mork.20041018162155.7:setText
    def setText( self, event):
        if event.char == '': return
        cs = self.lb.getcurselection() 
        if len( cs ) == 0: return
        cs = cs[ 0 ]
        txt = self.tx.get( '1.0', 'end -1c' ) 
        self.uAs[ cs ] = txt + event.char
    #@-node:mork.20041018162155.7:setText
    #@+node:mork.20041018162155.8:selcommand
    def selcommand( self ):
        cs = self.lb.getcurselection()
        if len( cs ) != 0: cs = cs[ 0 ]
        else: return
        txt = self.uAs[ cs ]
        self.tx.delete( '1.0', 'end' ) 
        self.tx.insert( '1.0' ,txt) 
    #@-node:mork.20041018162155.8:selcommand
    #@+node:mork.20041018162155.9:add
    def add( self ):
        txt = self.attEnt.getvalue()
        if txt.strip() == '': return
        self.attEnt.delete( 0, 'end' )
        self.uAs[ txt ] = ''
        bk = self.uAs.keys() 
        bk.sort()
        self.lb.setlist( bk )
        self.lb.setvalue( txt ) 
        self.tx.delete( '1.0', 'end' )
    #@-node:mork.20041018162155.9:add
    #@+node:mork.20041018162155.10:rmv
    def rmv( self ):
        cs = self.lb.curselection() 
        if len( cs ) != 0 : cs = cs[ 0 ]
        else: return
        del self.uAs[ self.lb.get( cs ) ]
        bk = self.uAs.keys()
        bk.sort()
        self.lb.setlist( bk )
        self.tx.delete( '1.0', 'end' )  
    #@-node:mork.20041018162155.10:rmv
    #@-others
#@-node:mork.20041018162155.3:class AttrEditor
#@+node:mork.20041018193158:newCreateCanvas
olCreateCanvas = leoTkinterFrame.createCanvas

def newCreateCanvas (self,parentFrame,pageName=None):

    # g.trace('editAttributes plugin',pageName)

    c = self.c

    if pageName:
        # Support the chapters2 plugin.
        can = olCreateCanvas(self,parentFrame,pageName=pageName)
    else:
        can = olCreateCanvas(self,parentFrame)

    def hit (event,self=self):

        c = self.c
        tree = c.frame.tree
        iddict = tree.iconIds
        # g.printDict(iddict)
        can = event.widget
        x = can.canvasx(event.x)
        y = can.canvasy(event.y)
        olap = can.find_overlapping(x,y,x,y)
        # g.trace(olap)
        id = olap [1]
        if olap:
            data = iddict.get(id)
            if data:
                p, junk = data
                return AttrEditor(c,p)

    c.bind2(can,'<Button-2>',hit,'+')
    c.bind2(can,'<Button-3>',hit,'+')

    return can

tkGui.leoTkinterFrame.createCanvas = newCreateCanvas

#@-node:mork.20041018193158:newCreateCanvas
#@-others
#@-node:mork.20041018162155.1:@thin EditAttributes.py
#@-leo
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.