0001 #!/usr/bin/env python 0002 0003 ### BITPIM 0004 ### 0005 ### Copyright (C) 2006-2006 Simon Capper <skyjnky@sbcglobal.net> 0006 ### 0007 ### This program is free software; you can redistribute it and/or modify 0008 ### it under the terms of the BitPim license as detailed in the LICENSE file. 0009 ### 0010 ### $Id: widgets.py 3890 2007-01-11 03:28:43Z djpham $ 0011 0012 ### base class for all widgets 0013 0014 import wx 0015 import re 0016 0017 import helpids 0018 import bphtml 0019 0020 class BitPimWidget: 0021 MENU_NORMAL=wx.ITEM_NORMAL 0022 MENU_SPACER=wx.ITEM_SEPARATOR 0023 MENU_CHECK=wx.ITEM_CHECK 0024 0025 def __init__(self): 0026 pass 0027 0028 def InitialiseWidget(self, tree, id, root, config, help_id=None): 0029 self.id=id 0030 self._tree=tree 0031 self.root=root 0032 self.config=config 0033 self.OnInit() 0034 if help_id==None: 0035 try: 0036 id_name=re.sub("[^A-Za-z]", "",self.GetWidgetName().upper()) 0037 self.help_id=getattr(helpids, "ID_TAB_"+id_name) 0038 except: 0039 self.help_id=helpids.ID_WELCOME 0040 else: 0041 self.help_id=help_id 0042 0043 def OnInit(self): 0044 pass 0045 0046 def AddSubPage(self, page, name, image=None, after=None): 0047 return self._tree.AddPage(self.id, page, name, image, after) 0048 0049 def AddNode(self, name, image=None): 0050 return self._tree.AddNode(self, name, image) 0051 0052 def OnSelected(self, node): 0053 """Default does nothing, override to provide specific functionality. 0054 node equals value returned from AddNode. 0055 """ 0056 pass 0057 0058 def OnPopupMenu(self, parent, node, pt): 0059 menu=self.GetRightClickMenuItems(node) 0060 if len(menu): 0061 popup_menu=wx.Menu() 0062 for menu_item in menu: 0063 type, id, name, tooltip=menu_item 0064 if type==self.MENU_SPACER: 0065 # using append with a type of separator does not work for some reason? 0066 popup_menu.AppendSeparator() 0067 else: 0068 popup_menu.Append(id, name, tooltip, type) 0069 parent.PopupMenu(popup_menu, pt) 0070 self.OnRightClickMenuExit() 0071 0072 def GetWidgetName(self): 0073 return self._tree.GetItemText(self.id) 0074 0075 def GetHelpID(self): 0076 return self.help_id 0077 0078 def ActivateSelf(self, id=None): 0079 if id==None: 0080 id=self.id 0081 self._tree.SelectItem(id) 0082 0083 # override these functions to access menu/toolbar items 0084 # each command has a "Can" function, this controls greying 0085 # out options that are not supported by the widget 0086 0087 def GetRightClickMenuItems(self, node): 0088 """Default does nothing, override to provide specific functionality. 0089 node equals value returned from AddNode. 0090 Return array of (type, ID, name, tootltip) tuples to be used in the popup menu 0091 Valid types are "menu", 0092 """ 0093 result=[] 0094 return result 0095 0096 def OnRightClickMenuExit(self): 0097 pass 0098 0099 def OnKeyDown(self, evt): 0100 pass 0101 0102 def OnKeyUp(self, evt): 0103 pass 0104 0105 def CanCopy(self): 0106 return False 0107 0108 def OnCopy(self, evt): 0109 pass 0110 0111 def CanPaste(self): 0112 return False 0113 0114 def OnPaste(self, evt): 0115 pass 0116 0117 def CanRename(self): 0118 return False 0119 0120 def OnRename(self, evt): 0121 pass 0122 0123 def CanDelete(self): 0124 return False 0125 0126 def GetDeleteInfo(self): 0127 return wx.ART_DEL_BOOKMARK, "Delete" 0128 0129 def OnDelete(self, evt): 0130 pass 0131 0132 def CanAdd(self): 0133 return False 0134 0135 def GetAddInfo(self): 0136 return wx.ART_ADD_BOOKMARK, "Add" 0137 0138 def OnAdd(self, evt): 0139 pass 0140 0141 def CanPrint(self): 0142 return False 0143 0144 def OnPrintDialog(self, mainwindow, config): 0145 pass 0146 0147 def CanSelectAll(self): 0148 return False 0149 0150 def OnSelectAll(self, evt): 0151 pass 0152 0153 def HasHistoricalData(self): 0154 return False 0155 0156 def OnHistoricalData(self): 0157 pass 0158 0159 def HasPreviewPane(self): 0160 return False 0161 0162 def IsPreviewPaneEnabled(self): 0163 return False 0164 0165 def OnViewPreview(self, on): 0166 pass 0167 0168 def HasColumnSelector(self): 0169 return False 0170 0171 def OnViewColumnSelector(self): 0172 pass 0173 0174 def OnPreActivate(self): 0175 pass 0176 def OnPostActivate(self): 0177 pass 0178 0179 class RootWidget(bphtml.HTMLWindow, BitPimWidget): 0180 # This page is copied out of the welcome.htm page of the BitPim help 0181 # Obviously, it needs to be in sync with the BitPim help. 0182 welcome_text=""" 0183 <html> 0184 <head><title>Welcome</title> 0185 </head> 0186 <body> 0187 <h1>Welcome</h1> 0188 0189 <p>Welcome to BitPim. 0190 0191 <p>If you are new to BitPim, please take the <a href="tour-master.htm">tour</a>. 0192 <p>BitPim's homepage is <a href="http://www.bitpim.org" target="bitpimhelpexternallink">www.bitpim.org</a>. 0193 The project page is <a href="http://www.sourceforge.net/projects/bitpim" target="bitpimhelpexternallink">www.sourceforge.net/projects/bitpim</a>. 0194 0195 <p>You may be interested in <a href="upgrading.htm">upgrade information</a> or the 0196 <a href="versionhistory.htm">version history</a>. 0197 0198 <p>If you have any problems or questions please read the <a href="support.htm">information about support</a>. 0199 0200 <p>Praise and <a href="contributing.htm">contributions</a> are always welcome! 0201 0202 <hr> 0203 </body></html> 0204 """ 0205 0206 def __init__(self, parent, id): 0207 wx.html.HtmlWindow.__init__(self, parent, id) 0208 self.SetPage(self.welcome_text) 0209 def OnLinkClicked(self, link): 0210 _ref=link.GetHref() 0211 if _ref.startswith('http'): 0212 # web link 0213 super(RootWidget, self).OnLinkClicked(link) 0214 else: 0215 # Help topic 0216 wx.GetApp().displayhelpid(str(_ref)) 0217
Generated by PyXR 0.9.4