rowcol.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 » rowcol.py
#@+leo-ver=4-thin
#@+node:ekr.20040108095351:@thin rowcol.py
"""Add row/column indicators to the toolbar."""

#@@language python
#@@tabwidth -4

__plugin_name__ = "Row/Column indicators"
__version__ = "0.4"

#@<< imports >>
#@+node:ekr.20040908094021.2:<< imports >>
import leo.core.leoGlobals as g
import leo.core.leoPlugins as leoPlugins

Tk = g.importExtension('Tkinter',pluginName=__name__,verbose=True)
#@nonl
#@-node:ekr.20040908094021.2:<< imports >>
#@nl
#@<< version history >>
#@+node:ekr.20041120114651:<< version history >>
#@@killcolor
#@+at
# 
# 0.1 Initial version.
# 
# 0.2 EKR: Make sure this works properly with multiple windows.
# 0.3 EKR: Removed call to g.top.  We now test whether c is valid using 
# hasattr(c,'frame')
# 0.4 EKR: set __plugin_name__ rather than __name__
#@-at
#@nonl
#@-node:ekr.20041120114651:<< version history >>
#@nl

#@+others
#@+node:ekr.20041120114651.1:onCreate
def onCreate (tag,keywords):

    c = keywords.get("c")
    if c:
        rowCol = rowColClass(c)
        rowCol.addWidgets()
        leoPlugins.registerHandler("idle",rowCol.update)
#@nonl
#@-node:ekr.20041120114651.1:onCreate
#@+node:ekr.20040108095351.1:class rowColClass
class rowColClass:

    """Class that puts row/column indicators in the status bar."""

    #@    @+others
    #@+node:ekr.20040108100040:__init__
    def __init__ (self,c):

        self.c = c
        self.lastRow,self.lastCol = -1,-1
    #@nonl
    #@-node:ekr.20040108100040:__init__
    #@+node:ekr.20040108095351.2:addWidgets
    def addWidgets (self):

        c = self.c
        iconBar = c.frame.iconBar
        iconBarFrame = iconBar.getFrame()

        # Main container 
        self.frame = Tk.Frame(iconBarFrame) 
        self.frame.pack(side="left")

        text = "line 0, col 0"
        width = len(text) # Setting the width here prevents jitters.
        self.label = Tk.Label(self.frame,text=text,width=width,anchor="w")
        self.label.pack(side="left")

        # Update the row/column indicators immediately to reserve a place.
        self.update()
    #@nonl
    #@-node:ekr.20040108095351.2:addWidgets
    #@+node:ekr.20040108095351.4:update
    def update (self,*args,**keys):

        c = self.c

        # This is called at idle-time, and there can be problems when closing the window.
        if g.app.killed or not c or not hasattr(c,'frame'):
            return

        w = c.frame.body.bodyCtrl 
        tab_width = c.frame.tab_width

        s = w.getAllText()
        index = w.getInsertPoint()
        row,col = g.convertPythonIndexToRowCol(s,index)

        if col > 0:
            s2 = s[index-col:index]
            s2 = g.toUnicode(s2)
            col = g.computeWidth (s2,c.tab_width)

        if row != self.lastRow or col != self.lastCol:
            s = "line %d, col %d " % (row,col)
            self.label.configure(text=s)
            self.lastRow,self.lastCol = row,col

        if 0: # Done in idle handler.
            self.label.after(500,self.update)
    #@nonl
    #@-node:ekr.20040108095351.4:update
    #@-others
#@nonl
#@-node:ekr.20040108095351.1:class rowColClass
#@-others

if Tk: # OK for unit testing.

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

    if g.app.gui.guiName() == "tkinter":
        leoPlugins.registerHandler("after-create-leo-frame",onCreate)
        g.plugin_signon("rowcol")
#@nonl
#@-node:ekr.20040108095351:@thin rowcol.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.