Menu

[r173]: / drplugins / DocumentationBookmarksMenu.py  Maximize  Restore  History

Download this file

166 lines (136 with data), 5.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Programmer: Daniel Pozmanter
# E-mail: drpython@bluebottle.com
# Note: You must reply to the verification e-mail to get through.
#
# Copyright 2003-2004 Daniel Pozmanter
#
# 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
#Documentation Bookmarks Menu
#Plugin
'''
1.1.0:
Updating for DrPython 3.10.6
For Version 1.0.2:
Changes:
version update. Bugreport (Thanks Jens, Franz).
Updated dialogs.
For Version 1.0.1:
Changes:
Updated for DrPython 3.4.0
'''
import os.path
import wx
from drProperty import *
import wx.lib.dialogs
def OnAbout(DrFrame):
AboutString = '''Documentation Bookmarks Menu:
Version: 1.1.0
By Daniel Pozmanter
Released under the GPL.
Credits:
Bug-Report, Thanks Jens, Franz.
'''
DrFrame.ShowMessage(AboutString, "About")
class drDocsBookmarksMenu(wx.Menu):
def __init__(self, parent):
wx.Menu.__init__(self)
self.ID_EDIT_BOOKMARKS = 3010
self.ID_BOOKMARK_BASE = 15000
self.ID_BOOKMARK_MENU = 1199
self.bookmarks = []
self.wildcard = parent.prefs.wildcard
self.parent = parent
self.pluginsdatdirectory = parent.pluginsdatdirectory
self.setupMenu()
self.loadBookmarks()
def loadBookmarks(self):
bookfile = self.pluginsdatdirectory + "/documentation.bookmarks.dat"
if os.path.exists(bookfile):
try:
#Read from the file
f = open(bookfile, 'r')
folders = [self]
folderindex = 0
menuTitles = []
menuTitleindex = -1
lastCount = 1
bookmarkcount = 0
#Skip the First Line
line = f.readline()
#Initialize
line = f.readline()
while line:
c = line.count('\t')
line = line[c:].rstrip()
while lastCount > c:
folders[(folderindex - 1)].AppendMenu(self.ID_BOOKMARK_MENU, menuTitles.pop(), folders.pop())
folderindex = folderindex - 1
menuTitleindex = menuTitleindex - 1
lastCount = lastCount - 1
if line[0] == '>':
folders.append(wx.Menu())
menuTitles.append(line[1:])
folderindex = folderindex + 1
menuTitleindex = menuTitleindex + 1
else:
self.bookmarks.append(line)
self.parent.Bind(wx.EVT_MENU, self.OnBookmark, id=(self.ID_BOOKMARK_BASE + bookmarkcount))
folders[folderindex].Append((self.ID_BOOKMARK_BASE + bookmarkcount), line, line)
bookmarkcount = bookmarkcount + 1
lastCount = c
line = f.readline()
f.close()
#Add any menus not yet added:
c = 1
while lastCount > c:
folders[(folderindex - 1)].AppendMenu(self.ID_BOOKMARK_MENU, menuTitles.pop(), folders.pop())
folderindex = folderindex - 1
menuTitleindex = menuTitleindex - 1
lastCount = lastCount - 1
except:
d = wx.lib.dialogs.ScrolledMessageDialog(self.parent, ("Your bookmarks file is a tad messed up.\n"), "Error")
d.ShowModal()
d.Destroy()
def OnBookmark(self, event):
bookmarkindex = event.GetId() - self.ID_BOOKMARK_BASE
self.parent.ViewURLInBrowser(self.bookmarks[bookmarkindex])
def OnEditBookmarks(self, event):
from drBookmarksDialog import drBookmarksDialog
d = drBookmarksDialog(self.parent, self.pluginsdatdirectory + "/documentation.bookmarks.dat")
d.ShowModal()
d.Destroy()
self.reloadBookmarks()
def setupMenu(self):
self.Append(self.ID_EDIT_BOOKMARKS, "&Edit Bookmarks...", " Edit Bookmarks")
self.AppendSeparator()
self.parent.Bind(wx.EVT_MENU, self.OnEditBookmarks, id=self.ID_EDIT_BOOKMARKS)
def reloadBookmarks(self):
mnuitems = self.GetMenuItems()
num = len(mnuitems)
x = 0
while x < num:
self.Remove(mnuitems[x].GetId())
mnuitems[x].Destroy()
x = x + 1
self.bookmarks = []
self.setupMenu()
self.loadBookmarks()
def Plugin(DrFrame):
DrFrame.LoadPluginShortcuts('DocumentationBookmarksMenu')
DrFrame.docbookmarksmenu = drDocsBookmarksMenu(DrFrame)
DrFrame.helpmenu.AppendSeparator()
DrFrame.helpmenu.AppendMenu(wx.NewId(), "Documentation Bookmarks", DrFrame.docbookmarksmenu)