#-*-coding:utf-8-*- import sys, os, Ice, IceGrid import wx #get current work directory cwd = os.getcwd() #get resource file directory resdir = os.path.join(os.path.split(cwd)[0], "resource") slicepath = os.path.join(resdir, "Hello.ice") Ice.loadSlice(slicepath) import Demo class IceGridFrame(wx.Frame): def __init__(self, parent, id): super(IceGridFrame, self).__init__(parent, id, pos=wx.DefaultPosition, size= wx.DefaultSize) panel = IceGridPanel(self) class IceGridPanel(wx.Panel): def __init__(self, parent): super(IceGridPanel, self).__init__(parent) self.szr = wx.BoxSizer(wx.VERTICAL) self._InitIcePrx() self._InitLayout() self._BindEvents() def _InitIcePrx(self): self.helloPrx = None communicator = Ice.initialize() try: self.helloPrx = Demo.HelloPrx.checkedCast(communicator.\ stringToProxy("hello")) except Ice.NotRegisteredException: query = IceGrid.QueryPrx.checkedCast(communicator.\ stringToProxy("DemoIceGrid/Query")) self.helloPrx = Demo.HelloPrx.checkedCast(query.\ findObjectByType("::Demo::Hello")) if not self.helloPrx: wx.MessageBox(u"初始化IceGrid代理失败!") def _InitLayout(self): self.sendBtn = wx.Button(self, -1, label=u"发送") self.shtdwnsvrBtn = wx.Button(self, -1, label=u"关闭服务") self.exitBtn = wx.Button(self, -1, label=u"退出") self.szr.AddMany([(5,5), (self.sendBtn, 0, wx.EXPAND), (5,5), (self.shtdwnsvrBtn, 0, wx.EXPAND), (5,5), (self.exitBtn, 0, wx.EXPAND), (5,5)]) self.SetSizer(self.szr) def _BindEvents(self): self.sendBtn.Bind(wx.EVT_BUTTON, self.OnSend) self.shtdwnsvrBtn.Bind(wx.EVT_BUTTON, self.OnShtdwnSvr) self.exitBtn.Bind(wx.EVT_BUTTON, self.OnExit) def OnSend(self, evt): self.helloPrx.sayHello() pass def OnShtdwnSvr(self, evt): pass def OnExit(self, evt): pass class Main(wx.App): def OnInit(self): frm = IceGridFrame(None, -1) frm.Show() return True if __name__ == "__main__": main = Main() main.MainLoop()