comparison orpg/tools/pluginui.py @ 106:8e2b7da4f509 alpha

Traipse Alpha 'OpenRPG' {091007-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary: {091006} 00: Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images! 03: Changes made to the map for increased portability. SnowDog has changes planned in Core, though. Added an initial push to the BCG. Not much to see, just shows off how it is re-writing Main code. {091007} 00: New images added to Plugin Control Panel for Auto Start.
author sirebral
date Wed, 07 Oct 2009 14:52:12 -0500
parents c54768cffbd4
children 61fc775862f7
comparison
equal deleted inserted replaced
105:2f2bebe9c77f 106:8e2b7da4f509
49 self.err_sizer.Add(self.head_sizer, 0, wx.EXPAND) 49 self.err_sizer.Add(self.head_sizer, 0, wx.EXPAND)
50 self.errorMessage = wx.StaticText(self.panel, wx.ID_ANY, "") 50 self.errorMessage = wx.StaticText(self.panel, wx.ID_ANY, "")
51 self.err_sizer.Add(self.errorMessage, 0, wx.EXPAND) 51 self.err_sizer.Add(self.errorMessage, 0, wx.EXPAND)
52 self.main_sizer.Add(self.err_sizer, 0, wx.EXPAND) 52 self.main_sizer.Add(self.err_sizer, 0, wx.EXPAND)
53 self.pluginList = wx.ListCtrl(self.panel, wx.ID_ANY, style=wx.LC_SINGLE_SEL|wx.LC_REPORT|wx.LC_HRULES|wx.LC_SORT_ASCENDING) 53 self.pluginList = wx.ListCtrl(self.panel, wx.ID_ANY, style=wx.LC_SINGLE_SEL|wx.LC_REPORT|wx.LC_HRULES|wx.LC_SORT_ASCENDING)
54 self.pluginList.InsertColumn(0, "Autostart")
54 self.pluginList.InsertColumn(1, "Name") 55 self.pluginList.InsertColumn(1, "Name")
55 self.pluginList.InsertColumn(2, "Autostart") 56 self.pluginList.InsertColumn(2, "Author")
56 self.pluginList.InsertColumn(3, "Author")
57 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self._selectPlugin, self.pluginList) 57 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self._selectPlugin, self.pluginList)
58 self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self._deselectPlugin, self.pluginList) 58 self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self._deselectPlugin, self.pluginList)
59 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self._togglePlugin, self.pluginList) 59 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self._togglePlugin, self.pluginList)
60 self.Bind(wx.EVT_LIST_COL_CLICK, self._sort, self.pluginList) 60 self.Bind(wx.EVT_LIST_COL_CLICK, self._sort, self.pluginList)
61 self.main_sizer.Add(self.pluginList, 1, wx.EXPAND) 61 self.main_sizer.Add(self.pluginList, 1, wx.EXPAND)
87 87
88 self.__disablePluginBtns() 88 self.__disablePluginBtns()
89 89
90 self.main_sizer.Add(self.btn_sizer, 0, wx.EXPAND) 90 self.main_sizer.Add(self.btn_sizer, 0, wx.EXPAND)
91 self.main_sizer.Add(self.btn_sizer2, 0, wx.EXPAND) 91 self.main_sizer.Add(self.btn_sizer2, 0, wx.EXPAND)
92
93 # Create Book Mark Image List
94 self.pluginList.Bind(wx.EVT_LEFT_DOWN, self.on_hit)
95 self._imageList = wx.ImageList( 16, 16, False )
96 img = wx.Image(dir_struct["icon"]+"add_button.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
97 self._imageList.Add( img )
98 img = wx.Image(dir_struct["icon"]+"check_button.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
99 self._imageList.Add( img )
100 self.pluginList.SetImageList( self._imageList, wx.IMAGE_LIST_SMALL )
101
102 def on_hit(self, evt):
103 pos = wx.Point( evt.GetX(), evt.GetY() )
104 (item, flag, sub) = self.pluginList.HitTestSubItem( pos )
105 ## Item == list[server], flag == (32 = 0 colum, 128 = else) ##
106 if flag == 32: self._autostart(item)
107 evt.Skip()
92 108
93 def __disablePluginBtns(self): 109 def __disablePluginBtns(self):
94 self.enableBtn.Disable() 110 self.enableBtn.Disable()
95 self.disableBtn.Disable() 111 self.disableBtn.Disable()
96 self.autostartBtn.Disable() 112 self.autostartBtn.Disable()
148 164
149 #Events 165 #Events
150 def _selectPlugin(self, evt): 166 def _selectPlugin(self, evt):
151 self._selectedPlugin = evt.GetIndex() 167 self._selectedPlugin = evt.GetIndex()
152 self.__enablePluginBtns() 168 self.__enablePluginBtns()
153 pname = self.pluginList.GetItem(self._selectedPlugin, 0).GetText() 169 pname = self.pluginList.GetItem(self._selectedPlugin, 1).GetText()
154 info = self.available_plugins[pname] 170 info = self.available_plugins[pname]
155 171
156 if info[0] in self.enabled_plugins: 172 if info[0] in self.enabled_plugins:
157 self.enableBtn.Disable() 173 self.enableBtn.Disable()
158 else: 174 else:
159 self.disableBtn.Disable() 175 self.disableBtn.Disable()
160 if self.pluginList.GetItem(self._selectedPlugin, 1).GetText() == "X": 176 if self.pluginList.GetItem(self._selectedPlugin, 0).GetText() == "X":
161 self.autostartBtn.Label = "Disable Autostart" 177 self.autostartBtn.Label = "Disable Autostart"
162 178
163 self.__doLayout() 179 self.__doLayout()
164 self.pluginList.SetItemState(self._selectedPlugin, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED) 180 self.pluginList.SetItemState(self._selectedPlugin, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)
165 181
188 204
189 def _enable(self, evt): 205 def _enable(self, evt):
190 idx = self.__checkIdx(evt) 206 idx = self.__checkIdx(evt)
191 if idx is None: 207 if idx is None:
192 return 208 return
193 pname = self.pluginList.GetItem(idx, 0).GetText() 209 pname = self.pluginList.GetItem(idx, 1).GetText()
194 info = self.available_plugins[pname] 210 info = self.available_plugins[pname]
195 info[1].menu_start() 211 info[1].menu_start()
196 212
197 try: 213 try:
198 info[1].plugin_enabled() 214 info[1].plugin_enabled()
209 self.enableBtn.Disable() 225 self.enableBtn.Disable()
210 self.disableBtn.Enable() 226 self.disableBtn.Enable()
211 227
212 def _disableAll(self, evt): 228 def _disableAll(self, evt):
213 for entry in self.enabled_plugins.keys(): 229 for entry in self.enabled_plugins.keys():
214 idx = self.pluginList.FindItem(0, self.enabled_plugins[entry].name) 230 #idx = self.pluginList.FindItem(1, self.enabled_plugins[entry].name) #Old Method
215 self._disable(idx) 231 self._disable(self.enabled_plugins[entry]) #New Method
216 232
217 def _disable(self, evt): 233 def _disable(self, evt):
218 idx = self.__checkIdx(evt) 234 idx = self.__checkIdx(evt)
219 if idx is None: 235 if idx is None:
220 return 236 return
221 pname = self.pluginList.GetItem(idx, 0).GetText() 237 pname = self.pluginList.GetItem(idx, 1).GetText()
222 info = self.available_plugins[pname] 238 info = self.available_plugins[pname]
223 info[1].menu_cleanup() 239 info[1].menu_cleanup()
224 try: 240 try:
225 info[1].plugin_disabled() 241 info[1].plugin_disabled()
226 del self.enabled_plugins[info[0]] 242 del self.enabled_plugins[info[0]]
236 252
237 def _autostart(self, evt): 253 def _autostart(self, evt):
238 idx = self.__checkIdx(evt) 254 idx = self.__checkIdx(evt)
239 if idx is None: 255 if idx is None:
240 return 256 return
241 if self.pluginList.GetItem(idx, 1).GetText() == "X": 257 if self.pluginList.GetItem(idx, 1).GetText() in self.startplugs:
242 self.startplugs.remove(self.pluginList.GetItem(idx, 0).GetText()) 258 self.startplugs.remove(self.pluginList.GetItem(idx, 1).GetText())
243 self.pluginList.SetStringItem(idx, 1, "") 259 self.pluginList.SetItemImage(idx, 0, 0)
244 self.autostartBtn.Label = "Autostart" 260 self.autostartBtn.Label = "Autostart"
245 else: 261 else:
246 self.startplugs.append(self.pluginList.GetItem(idx, 0).GetText()) 262 self.startplugs.append(self.pluginList.GetItem(idx, 1).GetText())
247 self.pluginList.SetStringItem(idx, 1, "X") 263 self.pluginList.SetItemImage(idx, 1, 0)
248 self.autostartBtn.Label = "Disable Autostart" 264 self.autostartBtn.Label = "Disable Autostart"
249 265
250 self.plugindb.SetList("plugincontroller", "startup_plugins", self.startplugs) 266 self.plugindb.SetList("plugincontroller", "startup_plugins", self.startplugs)
251 self.__doLayout() 267 self.__doLayout()
252 268
259 dlg = wx.MessageDialog(None, "You need to select a plugin before you can use this!", 'ERROR', wx.OK) 275 dlg = wx.MessageDialog(None, "You need to select a plugin before you can use this!", 'ERROR', wx.OK)
260 dlg.ShowModal() 276 dlg.ShowModal()
261 dlg.Destroy() 277 dlg.Destroy()
262 return 278 return
263 279
264 pname = self.pluginList.GetItem(idx, 0).GetText() 280 pname = self.pluginList.GetItem(idx, 1).GetText()
265 info = self.available_plugins[pname] 281 info = self.available_plugins[pname]
266 282
267 msg = "Author(s):\t" + info[2] + "\n\n" + info[3] 283 msg = "Author(s):\t" + info[2] + "\n\n" + info[3]
268 284
269 dlg = wx.MessageDialog(None, msg, 'Plugin Information: ' + pname, wx.OK) 285 dlg = wx.MessageDialog(None, msg, 'Plugin Information: ' + pname, wx.OK)
278 self.pluginList.DeleteAllItems() 294 self.pluginList.DeleteAllItems()
279 self.pluginNames = [] 295 self.pluginNames = []
280 296
281 list_of_plugin_dir = os.listdir(dir_struct["plugins"]) 297 list_of_plugin_dir = os.listdir(dir_struct["plugins"])
282 for p in list_of_plugin_dir: 298 for p in list_of_plugin_dir:
283 #print p[:2]; print p[-4:]
284 if p[:2].lower()=="xx" and p[-3:]==".py": 299 if p[:2].lower()=="xx" and p[-3:]==".py":
285 self.__impPlugin(p[:-3]) 300 self.__impPlugin(p[:-3])
286 elif p[:2].lower()=="xx" and p[-4:]==".pyc": 301 elif p[:2].lower()=="xx" and p[-4:]==".pyc":
287 self.__impPlugin(p[:-4]) 302 self.__impPlugin(p[:-4])
288 303
289 i = 0 304 i = 0
290 for plugname, info in self.available_plugins.iteritems(): 305 for plugname, info in self.available_plugins.iteritems():
291 self.pluginNames.append(plugname) 306 self.pluginNames.append(plugname)
292 idx = self.pluginList.InsertStringItem(self.pluginList.GetItemCount(), plugname) 307 idx = self.pluginList.InsertImageItem(self.pluginList.GetItemCount(), 0)
293 self.pluginList.SetStringItem(idx, 2, info[2]) 308 self.pluginList.SetStringItem(idx, 2, info[2])
309 self.pluginList.SetStringItem(idx, 1, plugname)
294 if plugname in self.startplugs: 310 if plugname in self.startplugs:
295 self.pluginList.SetStringItem(idx, 1, "X") 311 self.pluginList.SetItemImage(idx, 1, 0)
296 self._enable(idx) 312 self._enable(idx)
297 self.pluginList.SetItemData(idx, i) 313 self.pluginList.SetItemData(idx, i)
298 i += 1 314 i += 1
299 self.pluginList.SetColumnWidth(0, wx.LIST_AUTOSIZE) 315 self.pluginList.SetColumnWidth(0, 75)
316 self.pluginList.SetColumnWidth(1, wx.LIST_AUTOSIZE)
317 self.pluginList.SetColumnWidth(2, wx.LIST_AUTOSIZE)
300 self.__doLayout() 318 self.__doLayout()
301 self.__disablePluginBtns() 319 self.__disablePluginBtns()
302 320
303 def _close(self, evt): 321 def _close(self, evt):
304 self.Hide() 322 self.Hide()