Menu

[r238]: / drplugins / PositionMarker.py  Maximize  Restore  History

Download this file

129 lines (103 with data), 6.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Programmer: Franz Steinhaeusler
# E-mail: francescoa@users.sourceforge.net
# Note: Initial Release 18/7/2004
#
# Copyright 2004-2005 Franz Steinhaeusler
#
# Distributed under the terms of the GPL (GNU Public License)
#
# DrPython is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#Version: 0.0.1:
# - no global variables, new DrFrame member variables in form of DrFrame.<PluginNme>_var
#Version: 0.0.2:
# - Added Popup function
#Version: 0.0.3, 08.04.2007.
#Plugin
#PositionMarker
#This plugin allows to to set, clear, goto next, goto previous and clear all position markers.
import wx
import drScrolledMessageDialog
def OnAbout(DrFrame):
Version = "0.0.3"
NameAndVersion = "PositionMarker:\n\nVersion: " + Version + "\n"
AboutString = NameAndVersion + "By Franz Steinhaeusler\n\nReleased under the GPL."
drScrolledMessageDialog.ShowMessage(DrFrame, AboutString, "About")
def OnHelp(DrFrame):
drScrolledMessageDialog.ShowMessage(DrFrame, "Set and get postions in text.", "Help")
def Plugin(DrFrame):
DrFrame.PositionMarker_BOOKMARKMASK = 4
#DrFrame.PositionMarker_BOOKMARKMASK = 4 must be four; else it doesn't work; curious
DrFrame.PositionMarker_BOOKMARKNUMBER = 2
def OnTogglePositionMarker (event):
DrFrame.txtDocument.MarkerDefine(DrFrame.PositionMarker_BOOKMARKNUMBER, wx.stc.STC_MARK_ARROW, 'blue', 'blue')
#reason: each file has its DrFrame.txtDocument object
#therefore it should be initalised
lineNo = DrFrame.txtDocument.GetCurrentLine()
if DrFrame.txtDocument.MarkerGet(lineNo) & DrFrame.PositionMarker_BOOKMARKMASK:
DrFrame.txtDocument.MarkerDelete(lineNo, DrFrame.PositionMarker_BOOKMARKNUMBER)
DrFrame.SetStatusText("Position marker cleared at line %s"% str(lineNo+1), 2)
else:
DrFrame.txtDocument.MarkerAdd(lineNo, DrFrame.PositionMarker_BOOKMARKNUMBER)
DrFrame.SetStatusText("Position marker added at line %s"% str(lineNo+1), 2)
def OnGotoNextPositionMarker (event):
lineNo = DrFrame.txtDocument.GetCurrentLine()
newLineNo = DrFrame.txtDocument.MarkerNext(lineNo + 1, DrFrame.PositionMarker_BOOKMARKMASK)
if newLineNo != -1:
DrFrame.txtDocument.GotoLine(newLineNo)
else:
lineNo = DrFrame.txtDocument.GetLineCount()
newLineNo = DrFrame.txtDocument.MarkerNext(0, DrFrame.PositionMarker_BOOKMARKMASK)
if newLineNo != -1:
DrFrame.txtDocument.GotoLine(newLineNo)
DrFrame.txtDocument.EnsureVisible(DrFrame.txtDocument.GetCurrentLine())
DrFrame.txtDocument.EnsureCaretVisible()
def OnGotoPreviousPositionMarker (event):
lineNo = DrFrame.txtDocument.GetCurrentLine()
newLineNo = DrFrame.txtDocument.MarkerPrevious(lineNo - 1, DrFrame.PositionMarker_BOOKMARKMASK)
if newLineNo != -1:
DrFrame.txtDocument.GotoLine(newLineNo)
else:
lineNo = DrFrame.txtDocument.GetLineCount()
newLineNo = DrFrame.txtDocument.MarkerPrevious(lineNo, DrFrame.PositionMarker_BOOKMARKMASK)
if newLineNo != -1:
DrFrame.txtDocument.GotoLine(newLineNo)
DrFrame.txtDocument.EnsureVisible(DrFrame.txtDocument.GetCurrentLine())
DrFrame.txtDocument.EnsureCaretVisible()
def OnClearAllPositionMarkers (event):
DrFrame.txtDocument.MarkerDeleteAll(DrFrame.PositionMarker_BOOKMARKNUMBER)
ID_SETPOSITIONMARKER = DrFrame.GetNewId()
ID_GOTONEXTPOSITIONMARKER = DrFrame.GetNewId()
ID_GOTOPREVIOUSPOSITIONMARKER = DrFrame.GetNewId()
ID_CLEARALLPOSITIONMARKER = DrFrame.GetNewId()
DrFrame.Bind(wx.EVT_MENU, OnTogglePositionMarker, id=ID_SETPOSITIONMARKER)
DrFrame.Bind(wx.EVT_MENU, OnGotoNextPositionMarker, id=ID_GOTONEXTPOSITIONMARKER)
DrFrame.Bind(wx.EVT_MENU, OnGotoPreviousPositionMarker, id=ID_GOTOPREVIOUSPOSITIONMARKER)
DrFrame.Bind(wx.EVT_MENU, OnClearAllPositionMarkers, id=ID_CLEARALLPOSITIONMARKER)
DrFrame.AddPluginShortcutFunction("PositionMarker", "Toggle Position Marker", OnTogglePositionMarker)
DrFrame.AddPluginShortcutFunction("PositionMarker", "Goto Next Position Marker", OnGotoNextPositionMarker)
DrFrame.AddPluginShortcutFunction("PositionMarker", "Goto Previous Position Marker", OnGotoPreviousPositionMarker)
DrFrame.AddPluginShortcutFunction("PositionMarker", "Clear All Position Markers", OnClearAllPositionMarkers)
DrFrame.AddPluginPopUpMenuFunction("PositionMarker", "Toggle Position Marker", OnTogglePositionMarker)
DrFrame.AddPluginPopUpMenuFunction("PositionMarker", "Goto Next Position Marker", OnGotoNextPositionMarker)
DrFrame.AddPluginPopUpMenuFunction("PositionMarker", "Goto Previous Position Marker", OnGotoPreviousPositionMarker)
DrFrame.AddPluginPopUpMenuFunction("PositionMarker", "Clear All Position Markers", OnClearAllPositionMarkers)
DrFrame.LoadPluginShortcuts('PositionMarker')
positionmarkermenu = wx.Menu()
positionmarkermenu.Append(ID_SETPOSITIONMARKER, DrFrame.GetPluginMenuLabel('PositionMarker', 'Toggle Position Marker', 'Toggle Position Marker'))
positionmarkermenu.Append(ID_GOTONEXTPOSITIONMARKER, DrFrame.GetPluginMenuLabel('PositionMarker', 'Goto Next Position Marker', 'Goto Next Position Marker'))
positionmarkermenu.Append(ID_GOTOPREVIOUSPOSITIONMARKER, DrFrame.GetPluginMenuLabel('PositionMarker', 'Goto Previous Position Marker', 'Goto Previous Position Marker'))
positionmarkermenu.Append(ID_CLEARALLPOSITIONMARKER, DrFrame.GetPluginMenuLabel('PositionMarker', 'Clear All Position Markers', 'Clear All Position Markers'))
DrFrame.viewmenu.AppendSeparator()
DrFrame.viewmenu.AppendMenu(DrFrame.GetNewId(), "Position Marker", positionmarkermenu)