00001 import wx
00002 from types import *
00003
00004
00005 class ModulePanel(wx.Panel):
00006 def __init__(self, parent, conn):
00007 wx.Panel.__init__(self, parent, -1)
00008
00009 self.connconn = conn
00010 self.modulesmodules = []
00011
00012 self.InitLayoutInitLayout()
00013
00014
00015 def InitLayout(self):
00016 mainsizer = wx.BoxSizer(wx.HORIZONTAL)
00017
00018 box = wx.StaticBox(self, -1, 'Modules')
00019 s = wx.StaticBoxSizer(box, wx.VERTICAL)
00020 self.mlistmlist = wx.ListBox(self, -1, wx.DefaultPosition, wx.DefaultSize,
00021 [], wx.LB_SINGLE)
00022 self.Bind(wx.EVT_LISTBOX, self.OnModuleSelectOnModuleSelect, self.mlistmlist)
00023 s.Add(self.mlistmlist, 1, wx.EXPAND|wx.ALL, 5)
00024
00025 s2 = wx.BoxSizer(wx.HORIZONTAL)
00026 btn = wx.Button(self, -1, 'Refresh')
00027 self.Bind(wx.EVT_BUTTON, self.OnRefreshOnRefresh, btn)
00028 s2.Add(btn, 0, wx.RIGHT, 5)
00029 btn = wx.Button(self, -1, 'Load')
00030 self.Bind(wx.EVT_BUTTON, self.OnLoadOnLoad, btn)
00031 s2.Add(btn, 0)
00032 s.Add(s2, 0, wx.EXPAND|wx.ALL, 5)
00033 mainsizer.Add(s, 1, wx.EXPAND|wx.ALL, 5)
00034
00035 box = wx.StaticBox(self, -1, 'Service Tree')
00036 s = wx.StaticBoxSizer(box, wx.VERTICAL)
00037 self.treetree = DefinitionTree(self, -1, wx.DefaultPosition, wx.DefaultSize,
00038 wx.TR_HAS_BUTTONS|wx.TR_EDIT_LABELS)
00039 s.Add(self.treetree, 1, wx.EXPAND|wx.ALL, 5)
00040 mainsizer.Add(s, 1, wx.EXPAND|wx.ALL, 5)
00041
00042 box = wx.StaticBox(self, -1, 'Description')
00043 s = wx.StaticBoxSizer(box, wx.VERTICAL)
00044 self.description_paneldescription_panel = DescriptionPanel(self)
00045 s.Add(self.description_paneldescription_panel, 1, wx.EXPAND|wx.ALL, 5)
00046 mainsizer.Add(s, 1, wx.EXPAND|wx.ALL, 5)
00047
00048 self.SetSizer(mainsizer)
00049
00050 def OnModuleSelect(self, event):
00051 if self.modulesmodules and event.IsSelection():
00052 mname = event.GetString()
00053 for m in self.modulesmodules:
00054 if m[0] == mname:
00055 self.description_paneldescription_panel.SetDescription(m)
00056 break
00057
00058 def OnRefresh(self, event):
00059 pass
00060
00061 def RemoveEmpty(self, string):
00062 for s in string:
00063 if not s or s == '':
00064 string.remove(s)
00065 return string
00066
00067 def OnLoad(self, event):
00068 self.modulesmodules = []
00069 if self.connconn:
00070 input = bs_message_instance('VoidMessage')
00071 request = bs_service_request('BiosphereCoreServices',
00072 'ModuleService',
00073 'ListModules',
00074 input)
00075 response = self.connconn.RequestService(request)
00076 if response and len(response.output.parts):
00077 names = self.RemoveEmptyRemoveEmpty(response.output.parts[0].data.split('#'))
00078 full_names = self.RemoveEmptyRemoveEmpty(response.output.parts[1].data.split('#'))
00079 versions = self.RemoveEmptyRemoveEmpty(response.output.parts[2].data.split('#'))
00080 descriptions = self.RemoveEmptyRemoveEmpty(response.output.parts[3].data.split('#'))
00081 for i in range(0, len(names)):
00082 self.modulesmodules.append((names[i],
00083 full_names[i],
00084 versions[i],
00085 descriptions[i]))
00086 self.mlistmlist.Set(names)
00087
00088
00089 class DefinitionTree(wx.TreeCtrl):
00090 """Class to represent WSDL definitions in a tree-like manner."""
00091 def __init__(self, parent, id, pos, size, style):
00092 wx.TreeCtrl.__init__(self, parent, id, pos, size, style)
00093
00094
00095 class DescriptionPanel(wx.Panel):
00096 def __init__(self, parent):
00097 wx.Panel.__init__(self, parent, -1)
00098 self.sizersizer = wx.BoxSizer(wx.VERTICAL)
00099
00100 txt = wx.StaticText(self, -1, 'A description of the module will be printed here.')
00101 self.sizersizer.Add(txt, 0, wx.ALL, 5)
00102
00103 self.SetSizer(self.sizersizer)
00104
00105 def SetDescription(self, module=None):
00106 self.sizersizer.Clear(True)
00107 if module:
00108 self.sizersizer.Add(wx.StaticText(self, -1, 'Full name: %s' % module[1]),
00109 0, wx.ALL, 5)
00110 self.sizersizer.Add(wx.StaticText(self, -1, 'Version: %s' % module[2]),
00111 0, wx.ALL, 5)
00112 self.sizersizer.Add(wx.StaticText(self, -1, 'Description:'),
00113 0, wx.ALL, 5)
00114 text = wx.StaticText(self, -1, module[3])
00115 text.Wrap(self.GetSizeTuple()[0] - 10)
00116 self.sizersizer.Add(text, 1, wx.ALL, 5)
00117 self.sizersizer.Layout()