#!/bin/env /usr/bin/python from wxPython.wx import * from wxPython.grid import * from wxPython.lib.mixins.grid import wxGridAutoEditMixin import os F1_ID = 1 F2_ID = 2 F3_ID = 3 START_X = 100 START_Y = 150 SIZE_WIN_X = 200 SIZE_WIN_Y = 200 INC_X = (SIZE_WIN_X*1.5) INC_Y = (SIZE_WIN_Y*1.5) GRID_SIZE = SIZE_WIN_X / 2 #----------------------------------------------------------------- def oneWindClose(evt): selectFrame.Destroy() constructFrame.Destroy() propFrame.Destroy() def showInfo(parent, text, title): d = wxMessageDialog(parent,text, title, wxOK) d.ShowModal() d.Destroy() return class BeanSelector(wxFrame): def __init__(self,parent,id,title,pos, size): wxFrame.__init__(self,parent,id,title,style=wxDEFAULT_FRAME_STYLE, pos=pos, size=size) self.list = wxListCtrl(self, 0, style=wxLC_SINGLE_SEL) self.list.InsertStringItem(0,"button") self.list.InsertStringItem(0,"timedisp") #EVT_LIST_ITEM_SELECTED(self, 0, self.OnEvent) #EVT_LIST_ITEM_SELECTED(self, 1, self.OnEvent) EVT_CLOSE(self, oneWindClose) def OnEvent(self,e): d = wxMessageDialog(self," An event fired"+e.GetText(),"Information", wxOK) d.ShowModal() d.Destroy() #----------------------------------------------------------------- class BeanConstructor(wxFrame): grid_items = [0,0,0,0] selected_module = NULL def __init__(self,parent,id,title, pos, size): wxFrame.__init__(self,parent,id, title, style=wxDEFAULT_FRAME_STYLE, pos=pos, size=size) self.panel = wxPanel(self, 10) EVT_LEFT_UP(self.panel, self.OnLeftClick) EVT_RIGHT_UP(self.panel, self.OnRightClick) EVT_MIDDLE_UP(self.panel, self.OnMiddleClick) self.sourceBean = NULL EVT_CLOSE(self, oneWindClose) def OnLeftClick(self,e): if (e.GetId() == 10): return showInfo(self, "No Bean in that position", "Error") self.selectedBean = self.grid_items[e.GetId()] #showInfo(self, "Bean No. left clicked" + str(e.GetId()), "Info") propFrame.setSelectedBean(self.selectedBean) e.Skip() def OnRightClick(self,e): if (e.GetId() == 10): col = row = 0 if (e.GetX()>=GRID_SIZE): col = 1 if (e.GetY()>=GRID_SIZE): row = 1 pos = col*2+row item = -1 item = selectFrame.list.GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED) if (item == -1): return showInfo(self, "Please select something from the list" \ "in the Bean selector window", "Info") module = __import__(selectFrame.list.GetItemText(item)) self.grid_items[pos] = module.Bean(self.panel,pos, \ "Bean", (col*GRID_SIZE, row*GRID_SIZE), \ (GRID_SIZE, GRID_SIZE)) EVT_LEFT_UP(self.grid_items[pos], self.OnLeftClick) EVT_RIGHT_UP(self.grid_items[pos], self.OnRightClick) EVT_MIDDLE_UP(self.grid_items[pos], self.OnMiddleClick) else: if (self.sourceBean != NULL): #this guy wants this as a target bean bean = self.grid_items[e.GetId()] if (bean.support_recieving_fire() == 0): showInfo(self,"Bean does not support recieving fire", "Error") else: #establish the connection between source and target self.sourceBean.set_onfire(bean.get_onfire()) self.sourceBean = NULL showInfo(self,"Connection Established", "Info") else: showInfo(self,"Bean already exists in that position","Error") #this should be executed for all cases e.Skip() def OnMiddleClick(self,e): if (e.GetId() == 10): showInfo(self, "No Bean in that position", "Error") else: bean = self.grid_items[e.GetId()] if (bean.support_firing() == 0): showInfo(self, "The bean does not support firing", "Error") else: # it supports firing, so we record it self.sourceBean = bean #showInfo(self, "Source Bean Recorded", "Info") e.Skip() #----------------------------------------------------------------- class BeanPropViewer(wxFrame): def __init__(self,parent,id,title, pos, size): wxFrame.__init__(self,parent,id, title, style=wxDEFAULT_FRAME_STYLE, pos=pos, size=size) sizerv = wxBoxSizer(wxVERTICAL) sizerh = wxGridSizer(2, hgap=20, vgap=20) #sizerh = wxBoxSizer(wxHORIZONTAL) self.bean_name = wxStaticText(self, -1, "None") sizerh.Add(wxStaticText(self, -1, "Selected"),0) sizerh.Add(self.bean_name,1) #sizerv.Add(sizerh, 0) #sizerh = wxBoxSizer(wxHORIZONTAL) self.color = wxStaticText(self, -1, "None") sizerh.Add(wxStaticText(self, -1, "Color"),0) sizerh.Add(self.color,1) sizerv.Add(sizerh, 0) self.changeColor = wxButton(self, 10, "Change Color") sizerv.Add(self.changeColor, 0,wxALIGN_CENTER) self.changeColor.Disable() EVT_BUTTON(self, 10, self.onChangeColor) self.SetSizer(sizerv) self.SetAutoLayout(1) self.Layout() #sizerv.Fit(self) #use this to make frame as small as possible self.col_data = wxColourData() EVT_CLOSE(self, oneWindClose) def setSelectedBean(self,bean): self.cur_sel_bean = bean self.bean_name.SetLabel(bean.get_name()) self.bean_name.Refresh(true) col = bean.get_color() colortext = "R: " + str(col.Red()) + " G: " + str(col.Green()) + \ " B: " + str(col.Blue()) self.color.SetLabel(colortext) self.color.Refresh(true) self.changeColor.Enable(true) self.changeColor.Refresh() #return showInfo(self, "Bean selected: "+bean.get_name(), "Info") def onChangeColor(self,evt): #showInfo(self, "Change Colour Button Fired", "Info") self.col_data.SetColour(self.cur_sel_bean.get_color()) colourDialog = wxColourDialog(self, self.col_data) if (colourDialog.ShowModal() == wxID_OK): col_data2 = colourDialog.GetColourData() self.cur_sel_bean.set_color(col_data2.GetColour()) col = self.cur_sel_bean.get_color() colortext = "R: " + str(col.Red()) + " G: " + str(col.Green()) + \ " B: " + str(col.Blue()) self.color.SetLabel(colortext) self.color.Refresh(true) colourDialog.Destroy() #----------------------------------------------------------------- app = wxPySimpleApp() selectFrame = BeanSelector(None, F1_ID, "Bean Selector", pos=(START_X+(0*INC_X),START_Y), size=(SIZE_WIN_X,SIZE_WIN_Y)) selectFrame.Show(1) constructFrame = BeanConstructor(None, F2_ID, "Bean Constructor",pos=(START_X+(1*INC_X),START_Y), size=(SIZE_WIN_X,SIZE_WIN_Y)) constructFrame.Show(1) propFrame = BeanPropViewer(None, F3_ID, "Property Viewer", pos=(START_X+(2*INC_X),START_Y), size=(SIZE_WIN_X,SIZE_WIN_Y)) propFrame.Show(1) app.MainLoop()