comparison orpg/tools/pluginui.py @ 122:36919b8a3ef9 alpha

Traipse Alpha 'OpenRPG' {091031-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 (Cleaning up for Beta) Added Bookmarks Fix to Remote Admin Commands Minor fix to text based Server Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager default_manifest.xml renamed to default_upmana.xml Cleaner clode for saved repositories New TrueDebug Class in orpg_log Mercurial's hgweb folder is ported to upmana Happy Halloween!
author sirebral
date Sat, 31 Oct 2009 22:07:55 -0500
parents 217fb049bd00
children
comparison
equal deleted inserted replaced
121:496dbf12a6cb 122:36919b8a3ef9
1 from orpg.orpg_wx import * 1 from orpg.orpg_wx import *
2 from orpg.orpgCore import * 2 from orpg.orpgCore import *
3 import orpg.plugindb as plugindb 3 from orpg.plugindb import plugindb
4 from orpg.dirpath import dir_struct 4 from orpg.dirpath import dir_struct
5 5
6 sys.path.append(dir_struct["plugins"]) 6 #sys.path.append(dir_struct["plugins"])
7 7
8 class PluginFrame(wx.Frame): 8 class PluginFrame(wx.Frame):
9 def __init__(self, parent): 9 def __init__(self, parent):
10 wx.Frame.__init__(self, parent, wx.ID_ANY, "Plugin Control Panel") 10 wx.Frame.__init__(self, parent, wx.ID_ANY, "Plugin Control Panel")
11 self.panel = wx.Panel(self, wx.ID_ANY) 11 self.panel = wx.Panel(self, wx.ID_ANY)
12 self.plugindb = plugindb.PluginDB()
13 self.parent = parent 12 self.parent = parent
14 self.startplugs = self.plugindb.GetList("plugincontroller", "startup_plugins", []) 13 self.startplugs = plugindb.GetList("plugincontroller", "startup_plugins", [])
15 self.available_plugins = {} 14 self.available_plugins = {}
16 self.enabled_plugins = {} 15 self.enabled_plugins = {}
17 self.pluginNames = [] 16 self.pluginNames = []
18 self.SetMinSize((380, 480)) 17 self.SetMinSize((380, 480))
19 self._selectedPlugin = None 18 self._selectedPlugin = None
42 def __buildGUI(self): 41 def __buildGUI(self):
43 self.main_sizer = wx.BoxSizer(wx.VERTICAL) 42 self.main_sizer = wx.BoxSizer(wx.VERTICAL)
44 self.btn_sizer = wx.BoxSizer(wx.HORIZONTAL) 43 self.btn_sizer = wx.BoxSizer(wx.HORIZONTAL)
45 self.btn_sizer2 = wx.BoxSizer(wx.HORIZONTAL) 44 self.btn_sizer2 = wx.BoxSizer(wx.HORIZONTAL)
46 self.head_sizer = wx.BoxSizer(wx.HORIZONTAL) 45 self.head_sizer = wx.BoxSizer(wx.HORIZONTAL)
47 #pnl = wx.Panel(self.panel, wx.ID_ANY)
48 self.err_sizer = wx.BoxSizer(wx.VERTICAL) 46 self.err_sizer = wx.BoxSizer(wx.VERTICAL)
49 self.err_sizer.Add(self.head_sizer, 0, wx.EXPAND) 47 self.err_sizer.Add(self.head_sizer, 0, wx.EXPAND)
50 self.errorMessage = wx.StaticText(self.panel, wx.ID_ANY, "") 48 self.errorMessage = wx.StaticText(self.panel, wx.ID_ANY, "")
51 self.err_sizer.Add(self.errorMessage, 0, wx.EXPAND) 49 self.err_sizer.Add(self.errorMessage, 0, wx.EXPAND)
52 self.main_sizer.Add(self.err_sizer, 0, wx.EXPAND) 50 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) 51 self.pluginList = wx.ListCtrl(self.panel, wx.ID_ANY,
54 #self.pluginList.InsertColumn(0, "Autostart") 52 style=wx.LC_SINGLE_SEL|wx.LC_REPORT|wx.LC_HRULES|wx.LC_SORT_ASCENDING)
55 self.pluginList.InsertColumn(0, "Name") 53 self.pluginList.InsertColumn(0, "Name")
56 self.pluginList.InsertColumn(1, "Author") 54 self.pluginList.InsertColumn(1, "Author")
57 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self._selectPlugin, self.pluginList) 55 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self._selectPlugin, self.pluginList)
58 self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self._deselectPlugin, self.pluginList) 56 self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self._deselectPlugin, self.pluginList)
59 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self._togglePlugin, self.pluginList) 57 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self._togglePlugin, self.pluginList)
126 def __clearError(self): 124 def __clearError(self):
127 self.errorMessage.Label = "" 125 self.errorMessage.Label = ""
128 self.__doLayout() 126 self.__doLayout()
129 127
130 def __checkIdx(self, evt): 128 def __checkIdx(self, evt):
131 if isinstance(evt, int): 129 if isinstance(evt, int): return evt
132 return evt 130 elif self._selectedPlugin is not None: return self._selectedPlugin
133 elif self._selectedPlugin is not None:
134 return self._selectedPlugin
135 else: 131 else:
136 dlg = wx.MessageDialog(None, "You need to select a plugin before you can use this!", 'ERROR', wx.OK) 132 dlg = wx.MessageDialog(None,
133 "You need to select a plugin before you can use this!",
134 'ERROR', wx.OK)
137 dlg.ShowModal() 135 dlg.ShowModal()
138 dlg.Destroy() 136 dlg.Destroy()
139 return None 137 return None
140 138
141 def __impPlugin(self, pname): 139 def __impPlugin(self, pname):
142 try: 140 try:
143 if "plugins." + pname in sys.modules: 141 if "plugins." + pname in sys.modules:
144 del sys.modules["plugins." + pname]#to ensure that the newly-imported one will be used correctly. No, reload() is not a better way to do this. 142 del sys.modules["plugins." + pname]
143 #to ensure that the newly-imported one will be used correctly.
144 #No, reload() is not a better way to do this.
145 mod = __import__("plugins." + pname) 145 mod = __import__("plugins." + pname)
146 plugin = getattr(mod, pname) 146 plugin = getattr(mod, pname)
147 pdata = plugin.Plugin(self.plugindb, self.parent) 147 pdata = plugin.Plugin(plugindb, self.parent)
148 self.available_plugins[pdata.name] = [pname, pdata, pdata.author, pdata.help] 148 self.available_plugins[pdata.name] = [pname, pdata, pdata.author, pdata.help]
149 return plugin 149 return plugin
150 150
151 except Exception, e: 151 except Exception, e:
152 self.__error(e) 152 self.__error(e)
175 self.disableBtn.Disable() 175 self.disableBtn.Disable()
176 if pname in self.startplugs: 176 if pname in self.startplugs:
177 self.autostartBtn.Label = "Disable Autostart" 177 self.autostartBtn.Label = "Disable Autostart"
178 178
179 self.__doLayout() 179 self.__doLayout()
180 self.pluginList.SetItemState(self._selectedPlugin, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED) 180 self.pluginList.SetItemState(self._selectedPlugin,
181 wx.LIST_STATE_SELECTED,
182 wx.LIST_STATE_SELECTED)
181 183
182 def _deselectPlugin(self, evt): 184 def _deselectPlugin(self, evt):
183 self.__disablePluginBtns() 185 self.__disablePluginBtns()
184 self._selectedPlugin = None 186 self._selectedPlugin = None
185 187
186 def _togglePlugin(self, evt): 188 def _togglePlugin(self, evt):
187 idx = evt.GetIndex() 189 idx = evt.GetIndex()
188 pname = self.pluginList.GetItem(idx, 1).GetText() 190 pname = self.pluginList.GetItem(idx, 0).GetText()
189 info = self.available_plugins[pname] 191 info = self.available_plugins[pname]
190 if info[0] in self.enabled_plugins: 192 if info[0] in self.enabled_plugins: self._disable(idx)
191 self._disable(idx) 193 else: self._enable(idx)
192 else:
193 self._enable(idx)
194 self.pluginList.SetItemState(self._selectedPlugin, 0, wx.LIST_STATE_SELECTED) 194 self.pluginList.SetItemState(self._selectedPlugin, 0, wx.LIST_STATE_SELECTED)
195 195
196 def _enableAll(self, evt): 196 def _enableAll(self, evt):
197 for pname in self.available_plugins.iterkeys(): 197 for pname in self.available_plugins.iterkeys():
198 info = self.available_plugins[pname] 198 info = self.available_plugins[pname]
223 self.enableBtn.Disable() 223 self.enableBtn.Disable()
224 self.disableBtn.Enable() 224 self.disableBtn.Enable()
225 225
226 def _disableAll(self, evt): 226 def _disableAll(self, evt):
227 for entry in self.enabled_plugins.keys(): 227 for entry in self.enabled_plugins.keys():
228 #print self.pluginList.FindItem(1, self.enabled_plugins[entry])
229 idx = self.pluginList.FindItem(0, self.enabled_plugins[entry].name) 228 idx = self.pluginList.FindItem(0, self.enabled_plugins[entry].name)
230 print self.pluginList 229 self._disable(idx)
231 self._disable(idx) #New Method
232 230
233 def _disable(self, evt): 231 def _disable(self, evt):
234 idx = self.__checkIdx(evt) 232 idx = self.__checkIdx(evt)
235 if idx is None: 233 if idx is None:
236 return 234 return
250 self.disableBtn.Disable() 248 self.disableBtn.Disable()
251 self.enableBtn.Enable() 249 self.enableBtn.Enable()
252 250
253 def _autostart(self, evt): 251 def _autostart(self, evt):
254 idx = self.__checkIdx(evt) 252 idx = self.__checkIdx(evt)
255 if idx is None: 253 if idx is None: return
256 return 254 pname = self.pluginList.GetItem(idx, 0).GetText()
255 info = self.available_plugins[pname]
257 if self.pluginList.GetItem(idx, 0).GetText() in self.startplugs: 256 if self.pluginList.GetItem(idx, 0).GetText() in self.startplugs:
258 self.startplugs.remove(self.pluginList.GetItem(idx, 0).GetText()) 257 self.startplugs.remove(self.pluginList.GetItem(idx, 0).GetText())
259 self.pluginList.SetItemImage(idx, 0, 0) 258 self.pluginList.SetItemImage(idx, 0, 0)
260 self.autostartBtn.Label = "Autostart" 259 self.autostartBtn.Label = "Autostart"
260 if info[0] in self.enabled_plugins:
261 dlg = wx.MessageDialog(None, 'Disable Plugin Now?', 'Plugin Enabled',
262 wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
263 dlg.ShowModal()
264 if dlg.ShowModal() == wx.ID_YES: self._disable(evt)
261 else: 265 else:
262 self.startplugs.append(self.pluginList.GetItem(idx, 0).GetText()) 266 self.startplugs.append(self.pluginList.GetItem(idx, 0).GetText())
263 self.pluginList.SetItemImage(idx, 1, 0) 267 self.pluginList.SetItemImage(idx, 1, 0)
264 self.autostartBtn.Label = "Disable Autostart" 268 self.autostartBtn.Label = "Disable Autostart"
265 269 if info[0] not in self.enabled_plugins:
266 self.plugindb.SetList("plugincontroller", "startup_plugins", self.startplugs) 270 dlg = wx.MessageDialog(None, 'Enable Plugin Now?', 'Plugin Disabled',
271 wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
272 if dlg.ShowModal() == wx.ID_YES: self._enable(evt)
273
274 plugindb.SetList("plugincontroller", "startup_plugins", self.startplugs)
267 self.__doLayout() 275 self.__doLayout()
268 276
269 def _help(self, evt): 277 def _help(self, evt):
270 if isinstance(evt, int): 278 if isinstance(evt, int): idx = evt
271 idx = evt 279 elif self._selectedPlugin is not None: idx = self._selectedPlugin
272 elif self._selectedPlugin is not None:
273 idx = self._selectedPlugin
274 else: 280 else:
275 dlg = wx.MessageDialog(None, "You need to select a plugin before you can use this!", 'ERROR', wx.OK) 281 dlg = wx.MessageDialog(None,
282 "You need to select a plugin before you can use this!",
283 'ERROR', wx.OK)
276 dlg.ShowModal() 284 dlg.ShowModal()
277 dlg.Destroy() 285 dlg.Destroy()
278 return 286 return
279 287
280 pname = self.pluginList.GetItem(idx, 1).GetText() 288 pname = self.pluginList.GetItem(idx, 0).GetText()
281 info = self.available_plugins[pname] 289 info = self.available_plugins[pname]
282
283 msg = "Author(s):\t" + info[2] + "\n\n" + info[3] 290 msg = "Author(s):\t" + info[2] + "\n\n" + info[3]
284
285 dlg = wx.MessageDialog(None, msg, 'Plugin Information: ' + pname, wx.OK) 291 dlg = wx.MessageDialog(None, msg, 'Plugin Information: ' + pname, wx.OK)
286 dlg.ShowModal() 292 dlg.ShowModal()
287 dlg.Destroy() 293 dlg.Destroy()
288 294
289 def _update(self, evt): 295 def _update(self, evt):
302 self.__impPlugin(p[:-4]) 308 self.__impPlugin(p[:-4])
303 309
304 i = 0 310 i = 0
305 for plugname, info in self.available_plugins.iteritems(): 311 for plugname, info in self.available_plugins.iteritems():
306 self.pluginNames.append(plugname) 312 self.pluginNames.append(plugname)
307 #idx = self.pluginList.InsertImageItem(self.pluginList.GetItemCount(), 0)
308 idx = self.pluginList.InsertStringItem(self.pluginList.GetItemCount(), plugname) 313 idx = self.pluginList.InsertStringItem(self.pluginList.GetItemCount(), plugname)
309 self.pluginList.SetStringItem(idx, 1, info[2]) 314 self.pluginList.SetStringItem(idx, 1, info[2])
310 self.pluginList.SetItemImage(idx, 0, 0) 315 self.pluginList.SetItemImage(idx, 0, 0)
311 #self.pluginList.SetStringItem(idx, 1, plugname)
312 if plugname in self.startplugs: 316 if plugname in self.startplugs:
313 self.pluginList.SetItemImage(idx, 1, 0) 317 self.pluginList.SetItemImage(idx, 1, 0)
314 self._enable(idx) 318 self._enable(idx)
315 self.pluginList.SetItemData(idx, i) 319 self.pluginList.SetItemData(idx, i)
316 i += 1 320 i += 1
317 self.pluginList.SetColumnWidth(0, wx.LIST_AUTOSIZE) 321 self.pluginList.SetColumnWidth(0, wx.LIST_AUTOSIZE)
318 self.pluginList.SetColumnWidth(1, wx.LIST_AUTOSIZE) 322 self.pluginList.SetColumnWidth(1, wx.LIST_AUTOSIZE)
319 #self.pluginList.SetColumnWidth(2, wx.LIST_AUTOSIZE)
320 self.__doLayout() 323 self.__doLayout()
321 self.__disablePluginBtns() 324 self.__disablePluginBtns()
322 325
323 def _close(self, evt): 326 def _close(self, evt):
324 self.Hide() 327 self.Hide()