dabo Commit
Revision 4526
Date: 2008-09-25 09:23:44 -0700 (Thu, 25 Sep 2008)
Author: Nate
Trac: http://svn.dabodev.com/trac/dabo/changeset/4526

Changed:
U   trunk/dabo/ui/uiwx/dEditor.py

Log:
Made some fairly hefty changes to the way that bookmarks are shown.  Before, 
they used to appear in the margin used for line numbers.  However, if you had a 
document that went into the 1000's of lines, setting a bookmark on line 1000+ 
would hide the line numbers.  Also, if you set UseBookmarks to False, you 
couldn't hide the bookmark icons.  Furthermore, you would hide the bookmark 
icons if you set ShowLineNumbers to False.

I have created a new margin for the bookmarks to be shown in.  This margin will 
be visible/not visible based on what UseBookmarks is.  I also capture left 
clicks in the margin.  If the line number margin is click, it behaves as 
before.  If the bookmark margin is clicked, it fires a stub called 
processBookmarkClick and passes the line number and the existing bookmark name 
(if no bookmark, it is passed None).  The user can decide what to do in the 
subclass.

I also added 3 new properties to the editor.  The first is BookmarkIcon.  You 
can set the symbol used as the icon.  BookmarkBackColor and BookmarkForeColor 
are what you expect them to be and take a valid string or rgb tuple input.  The 
properties can be set in the constructor or anytime afterward.  Defaults are 
still the ugly cyan circle with the grey border.

Diff:
Modified: trunk/dabo/ui/uiwx/dEditor.py
===================================================================
--- trunk/dabo/ui/uiwx/dEditor.py       2008-09-25 15:48:56 UTC (rev 4525)
+++ trunk/dabo/ui/uiwx/dEditor.py       2008-09-25 16:23:44 UTC (rev 4526)
@@ -86,7 +86,14 @@
                ".rfxml": "xml",
                ".xml": "xml"}
 
+bmkIconDic = {
+               "circle": stc.STC_MARK_CIRCLE,
+               "down arrow": stc.STC_MARK_ARROWDOWN,
+               "arrow": stc.STC_MARK_SHORTARROW,
+               "arrows": stc.STC_MARK_ARROWS,
+               "rectangle": stc.STC_MARK_SMALLRECT}
 
+
 ## testing load performance:
 delay = False
 
@@ -238,6 +245,9 @@
                self._autoCompleteList = False
                self._autoIndent = True
                self._commentString = "#- "
+               self._bookmarkBackColor = (0, 255, 255)
+               self._bookmarkForeColor = (128, 128, 128)
+               self._bookmarkIcon = "circle"
                self._bufferedDrawing = True
                self._hiliteCharsBeyondLimit = False
                self._hiliteLimitColumn = 79
@@ -318,8 +328,7 @@
                
                # Set the marker used for bookmarks
                self._bmkPos = 5
-               self.MarkerDefine(self._bmkPos, 
-                               stc.STC_MARK_CIRCLE, "gray", "cyan")
+               self._setBookmarkMarker()
                justFname = os.path.split(self._fileName)[1]
                svd = app.getUserSetting("bookmarks.%s" % justFname, "{}")
                if svd:
@@ -472,10 +481,16 @@
                """Returns the name of the bookmark for the current
                line, or None if this line is not bookmarked.
                """
+               return self.getBookmarkFromLine(self.LineNumber)
+       
+       
+       def getBookmarkFromLine(self, line):
+               """Returns the name of the bookmark for the passed
+               line, or None if the line is not bookmarked.
+               """
                ret = None
-               curr = self.LineNumber
                for nm, hnd in self._bookmarks.items():
-                       if self.MarkerLineFromHandle(hnd) == curr:
+                       if self.MarkerLineFromHandle(hnd) == line:
                                ret = nm
                                break
                return ret
@@ -703,13 +718,25 @@
                """Sets the visibility of the line number margin."""
                if self.ShowLineNumbers:
                        self.SetMarginType(1, stc.STC_MARGIN_NUMBER)
+                       self.SetMarginMask(1, 0)
                        self.SetMarginSensitive(1, True)
                        self.SetMarginWidth(1, 36)
                else:
                        self.SetMarginSensitive(1, False)
                        self.SetMarginWidth(1, 0)
-                       
-               
+       
+       def _setBookmarkMarginVisibility(self):
+               """Sets the visibility of the bookmark margin."""
+               if self.UseBookmarks:
+                       self.SetMarginType(0, wx.stc.STC_MARGIN_SYMBOL)
+                       self.SetMarginMask(0, ~stc.STC_MASK_FOLDERS)
+                       self.SetMarginSensitive(0, True)
+                       self.SetMarginWidth(0, 16)
+               else:
+                       self.SetMarginSensitive(0, False)
+                       self.SetMarginWidth(0, 0)
+
+       
        def _setCodeFoldingMarginVisibility(self):
                """Sets the visibility of the code folding margin."""
                if not self.ShowCodeFolding:
@@ -1101,7 +1128,6 @@
                        if evt.GetShift() and evt.GetControl():
                                self.FoldAll()
                        else:
-
                                if self.GetFoldLevel(lineClicked) & 
stc.STC_FOLDLEVELHEADERFLAG:
                                        if evt.GetShift():
                                                
self.SetFoldExpanded(lineClicked, True)
@@ -1119,8 +1145,16 @@
                        # Line number margin; hilite the line
                        ln = self.LineFromPosition(evt.GetPosition())
                        self.hiliteLine(ln, evt.GetShift())
+               if mg == 0:
+                       #Bookmark margin.  Call stubs so dev can decide how to 
handle it.
+                       self.processBookmarkClick(lineClicked, 
self.getBookmarkFromLine(lineClicked))
 
 
+       def processBookmarkClick(self, lineNumber, bookmarkName):
+               "Stub function to process a left click on the bookmark margin 
area."
+               pass
+
+
        def hiliteLine(self, lineNum, extend=False):
                """Selects the specified line. If the line number does not 
exist, 
                a ValueError is raised.
@@ -1846,6 +1880,16 @@
                                pass
 
 
+       def _setBookmarkMarker(self):
+               try:
+                       self.MarkerDefine(self._bmkPos, 
bmkIconDic[self.BookmarkIcon], 
+                               self.BookmarkForeColor, self.BookmarkBackColor)
+               except AttributeError:
+                       #_bmkPos not created yet. Happens if set in 
initProperties or sooner
+                       #solution is to store the value and it gets set further 
down in init
+                       pass
+
+
        ### Property definitions start here
        def _getAutoAutoComplete(self):
                try:
@@ -1891,6 +1935,44 @@
                        self._properties["AutoIndent"] = val
 
 
+       def _getBookmarkBackColor(self):
+               return self._bookmarkBackColor
+
+       def _setBookmarkBackColor(self, val):
+               if isinstance(val, basestring):
+                       val = dabo.dColors.colorTupleFromName(val)
+               if isinstance(val, tuple):
+                       self._bookmarkBackColor = val
+                       self._setBookmarkMarker()
+               else:
+                       raise ValueError, "BookmarkBackColor must be a valid 
color string or tuple"
+
+
+       def _getBookmarkForeColor(self):
+               return self._bookmarkForeColor
+
+       def _setBookmarkForeColor(self, val):
+               if isinstance(val, basestring):
+                       val = dabo.dColors.colorTupleFromName(val)
+               if isinstance(val, tuple):
+                       self._bookmarkForeColor = val
+                       self._setBookmarkMarker()
+               else:
+                       raise ValueError, "BookmarkForeColor must be a valid 
color string or tuple"
+
+
+
+       def _getBookmarkIcon(self):
+               return self._bookmarkIcon
+
+       def _setBookmarkIcon(self, val):
+               if val in bmkIconDic.keys():
+                       self._bookmarkIcon = val
+                       self._setBookmarkMarker()
+               else:
+                       raise ValueError, "Value of BookmarkIcon must be in %s" 
% (bmkIconDic.keys(),)
+
+
        def _getBufferedDrawing(self):
                return self._bufferedDrawing
 
@@ -2275,6 +2357,7 @@
        def _setUseBookmarks(self, val):
                if self._constructed():
                        self._useBookmarks = val
+                       self._setBookmarkMarginVisibility()
                else:
                        self._properties["UseBookmarks"] = val
 
@@ -2361,6 +2444,21 @@
        AutoIndent = property(_getAutoIndent, _setAutoIndent, None,
                        _("Controls if a newline adds the previous line's 
indentation  (bool)"))
        
+       BookmarkBackColor = property(_getBookmarkBackColor, 
_setBookmarkBackColor, None,
+                       _("The color of the icon background Default=(0,255,255) 
(Tuple or String)"))
+       
+       BookmarkForeColor = property(_getBookmarkForeColor, 
_setBookmarkForeColor, None,
+                       _("The color of the icon foreground 
Default=(128,128,128) (Tuple or String)"))
+       
+       BookmarkIcon = property(_getBookmarkIcon, _setBookmarkIcon, None,
+                       _("""The icon of bookmark that is show in the margin 
(default="circle") (string)
+                       Available Values:
+                               - "circle"
+                               - "down arrow"
+                               - "arrow"
+                               - "arrows"
+                               - "rectangle\""""))
+       
        BufferedDrawing = property(_getBufferedDrawing, _setBufferedDrawing, 
None,
                        _("Setting to True (default) reduces display flicker  
(bool)"))
        




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]

Reply via email to