Module widgets
[hide private]
[frames] | no frames]

Source Code for Module widgets

  1  #!/usr/bin/env python 
  2   
  3  ### BITPIM 
  4  ### 
  5  ### Copyright (C) 2006-2006 Simon Capper <skyjnky@sbcglobal.net> 
  6  ### 
  7  ### This program is free software; you can redistribute it and/or modify 
  8  ### it under the terms of the BitPim license as detailed in the LICENSE file. 
  9  ### 
 10  ### $Id: widgets.py 3890 2007-01-11 03:28:43Z djpham $ 
 11   
 12  ### base class for all widgets 
 13   
 14  import wx 
 15  import re 
 16   
 17  import helpids 
 18  import bphtml 
 19   
20 -class BitPimWidget:
21 MENU_NORMAL=wx.ITEM_NORMAL 22 MENU_SPACER=wx.ITEM_SEPARATOR 23 MENU_CHECK=wx.ITEM_CHECK 24
25 - def __init__(self):
26 pass
27
28 - def InitialiseWidget(self, tree, id, root, config, help_id=None):
29 self.id=id 30 self._tree=tree 31 self.root=root 32 self.config=config 33 self.OnInit() 34 if help_id==None: 35 try: 36 id_name=re.sub("[^A-Za-z]", "",self.GetWidgetName().upper()) 37 self.help_id=getattr(helpids, "ID_TAB_"+id_name) 38 except: 39 self.help_id=helpids.ID_WELCOME 40 else: 41 self.help_id=help_id
42
43 - def OnInit(self):
44 pass
45
46 - def AddSubPage(self, page, name, image=None, after=None):
47 return self._tree.AddPage(self.id, page, name, image, after)
48
49 - def AddNode(self, name, image=None):
50 return self._tree.AddNode(self, name, image)
51
52 - def OnSelected(self, node):
53 """Default does nothing, override to provide specific functionality. 54 node equals value returned from AddNode. 55 """ 56 pass
57
58 - def OnPopupMenu(self, parent, node, pt):
59 menu=self.GetRightClickMenuItems(node) 60 if len(menu): 61 popup_menu=wx.Menu() 62 for menu_item in menu: 63 type, id, name, tooltip=menu_item 64 if type==self.MENU_SPACER: 65 # using append with a type of separator does not work for some reason? 66 popup_menu.AppendSeparator() 67 else: 68 popup_menu.Append(id, name, tooltip, type) 69 parent.PopupMenu(popup_menu, pt) 70 self.OnRightClickMenuExit()
71
72 - def GetWidgetName(self):
73 return self._tree.GetItemText(self.id)
74
75 - def GetHelpID(self):
76 return self.help_id
77
78 - def ActivateSelf(self, id=None):
79 if id==None: 80 id=self.id 81 self._tree.SelectItem(id)
82 83 # override these functions to access menu/toolbar items 84 # each command has a "Can" function, this controls greying 85 # out options that are not supported by the widget 86
87 - def GetRightClickMenuItems(self, node):
88 """Default does nothing, override to provide specific functionality. 89 node equals value returned from AddNode. 90 Return array of (type, ID, name, tootltip) tuples to be used in the popup menu 91 Valid types are "menu", 92 """ 93 result=[] 94 return result
95
96 - def OnRightClickMenuExit(self):
97 pass
98
99 - def OnKeyDown(self, evt):
100 pass
101
102 - def OnKeyUp(self, evt):
103 pass
104
105 - def CanCopy(self):
106 return False
107
108 - def OnCopy(self, evt):
109 pass
110
111 - def CanPaste(self):
112 return False
113
114 - def OnPaste(self, evt):
115 pass
116
117 - def CanRename(self):
118 return False
119
120 - def OnRename(self, evt):
121 pass
122
123 - def CanDelete(self):
124 return False
125
126 - def GetDeleteInfo(self):
127 return wx.ART_DEL_BOOKMARK, "Delete"
128
129 - def OnDelete(self, evt):
130 pass
131
132 - def CanAdd(self):
133 return False
134
135 - def GetAddInfo(self):
136 return wx.ART_ADD_BOOKMARK, "Add"
137
138 - def OnAdd(self, evt):
139 pass
140
141 - def CanPrint(self):
142 return False
143
144 - def OnPrintDialog(self, mainwindow, config):
145 pass
146
147 - def CanSelectAll(self):
148 return False
149
150 - def OnSelectAll(self, evt):
151 pass
152
153 - def HasHistoricalData(self):
154 return False
155
156 - def OnHistoricalData(self):
157 pass
158
159 - def HasPreviewPane(self):
160 return False
161
162 - def IsPreviewPaneEnabled(self):
163 return False
164
165 - def OnViewPreview(self, on):
166 pass
167
168 - def HasColumnSelector(self):
169 return False
170
171 - def OnViewColumnSelector(self):
172 pass
173
174 - def OnPreActivate(self):
175 pass
176 - def OnPostActivate(self):
177 pass
178
179 -class RootWidget(bphtml.HTMLWindow, BitPimWidget):
180 # This page is copied out of the welcome.htm page of the BitPim help 181 # Obviously, it needs to be in sync with the BitPim help. 182 welcome_text=""" 183 <html> 184 <head><title>Welcome</title> 185 </head> 186 <body> 187 <h1>Welcome</h1> 188 189 <p>Welcome to BitPim. 190 191 <p>If you are new to BitPim, please take the <a href="tour-master.htm">tour</a>. 192 <p>BitPim's homepage is <a href="http://www.bitpim.org" target="bitpimhelpexternallink">www.bitpim.org</a>. 193 The project page is <a href="http://www.sourceforge.net/projects/bitpim" target="bitpimhelpexternallink">www.sourceforge.net/projects/bitpim</a>. 194 195 <p>You may be interested in <a href="upgrading.htm">upgrade information</a> or the 196 <a href="versionhistory.htm">version history</a>. 197 198 <p>If you have any problems or questions please read the <a href="support.htm">information about support</a>. 199 200 <p>Praise and <a href="contributing.htm">contributions</a> are always welcome! 201 202 <hr> 203 </body></html> 204 """ 205
206 - def __init__(self, parent, id):
207 wx.html.HtmlWindow.__init__(self, parent, id) 208 self.SetPage(self.welcome_text)
209 - def OnLinkClicked(self, link):
210 _ref=link.GetHref() 211 if _ref.startswith('http'): 212 # web link 213 super(RootWidget, self).OnLinkClicked(link) 214 else: 215 # Help topic 216 wx.GetApp().displayhelpid(str(_ref))
217