root/imbot/gui.py

Revision 51, 3.7 kB (checked in by pantley2, 3 years ago)

IMBOT: Broken due to major code cleanup.

The bot files are now located directly in the /imbot/ directory.

Also note the addition of Graph.py and Cleaner.py

Line 
1 import wx
2 import sigartbot
3 from twisted.internet import protocol, reactor
4
5 app = None
6
7 class MyApp(wx.App):
8         def OnInit(self):
9                 # set up a timer to handle bot events when there are no GUI events
10                 reactor.startRunning()
11                 wx.EVT_TIMER(self, 999999, self.OnTimer)
12                 self.timer = wx.Timer(self, 999999)
13                 self.timer.Start(250, False)
14                
15                 # display the 'sign on' window
16                 signon = SignOnWindow(None, -1)
17                 self.SetTopWindow(signon)
18                 signon.Show()
19                
20                 return True
21        
22         def OnTimer(self,event):
23                 # process bot events
24                 reactor.runUntilCurrent()
25                 reactor.doIteration(0)
26
27 class SignOnWindow(wx.Dialog):
28         def __init__(self, *args, **kwds):
29                 kwds["style"] = wx.DEFAULT_DIALOG_STYLE
30                 wx.Dialog.__init__(self, *args, **kwds)
31                 self.bitmap_1 = wx.StaticBitmap(self, -1, wx.Bitmap("logo.jpg", wx.BITMAP_TYPE_ANY))
32                 self.lblScreenName = wx.StaticText(self, -1, "Screen Name:")
33                 self.cbScreenName = wx.ComboBox(self, -1, choices=[], style=wx.CB_DROPDOWN)
34                 self.lblPassword = wx.StaticText(self, -1, "Password:")
35                 self.txtPassword = wx.TextCtrl(self, -1, "", style=wx.TE_PASSWORD)
36                 self.SignOn = wx.Button(self, -1, "&Sign On")
37                
38                 self.__set_properties()
39                 self.__do_layout()
40                
41                 self.Bind(wx.EVT_BUTTON, self.SignOnEvent, self.SignOn)
42                 self.Bind(wx.EVT_CLOSE, self.CloseEvent)
43        
44         def __set_properties(self):
45                 self.SetTitle("SIGART Bot Manager")
46        
47         def __do_layout(self):
48                 sizer = wx.BoxSizer(wx.VERTICAL)
49                 sizer_5 = wx.BoxSizer(wx.VERTICAL)
50                 sizer.Add(self.bitmap_1, 0, 0, 0)
51                 sizer_5.Add(self.lblScreenName, 0, 0, 0)
52                 sizer_5.Add(self.cbScreenName, 0, wx.EXPAND, 0)
53                 sizer_5.Add(self.lblPassword, 0, 0, 0)
54                 sizer_5.Add(self.txtPassword, 0, wx.EXPAND, 0)
55                 sizer_5.Add(self.SignOn, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
56                 sizer.Add(sizer_5, 1, wx.EXPAND, 0)
57                 self.SetSizer(sizer)
58                 sizer.Fit(self)
59                 self.Layout()
60        
61         def SignOnEvent(self, event):
62                 self.screenname = self.cbScreenName.GetValue()
63                 password = self.txtPassword.GetValue()
64                
65                 if self.screenname == "" or len(self.screenname) > 15 or password == "":
66                         wx.MessageBox("You must enter a valid user name and password.", "Error", wx.OK)
67                 else:
68                         protocol.ClientCreator(reactor, sigartbot.OA, self.screenname, password, icq=0).connectTCP(*(sigartbot.hostport))
69                         self.main = MainWindow(None, -1)
70                         self.Hide()
71                         self.main.Show()
72        
73         def CloseEvent(self, event=None):
74                 self.Destroy()
75
76
77 class TabContents(wx.Panel):
78         def __init__(self, *args, **kwds):
79                 kwds["style"] = wx.TAB_TRAVERSAL
80                 wx.Panel.__init__(self, *args, **kwds)
81                 self.output = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE|wx.TE_READONLY)
82                
83                 sizer_tabContents = wx.BoxSizer(wx.HORIZONTAL)
84                 sizer_tabContents.Add(self.output, 1, wx.EXPAND, 0)
85                 self.SetSizer(sizer_tabContents)
86                 sizer_tabContents.Fit(self)
87
88
89 class MainWindow(wx.Frame):
90         def __init__(self, *args, **kwds):
91                 # initialize the window
92                 kwds["style"] = wx.DEFAULT_FRAME_STYLE
93                 wx.Frame.__init__(self, *args, **kwds)
94                 self.SetTitle("SIGART Bot Manager")
95                
96                 # set up the tabs
97                 self.tabs = wx.Notebook(self, -1, style=0)
98                 self.tabpages = {}
99                 self.tabpages['exampleuser'] = TabContents(self.tabs, -1)
100                 self.tabpages['anotherguy'] = TabContents(self.tabs, -1)
101                 self.tabs.AddPage(self.tabpages['exampleuser'], "exampleuser")
102                 self.tabs.AddPage(self.tabpages['anotherguy'], "anotherguy")
103                
104                 # make the tabs take up the entire window
105                 sizer_MainWindow = wx.BoxSizer(wx.VERTICAL)
106                 sizer_MainWindow.Add(self.tabs, 1, wx.EXPAND, 0)
107                 self.SetSizer(sizer_MainWindow)
108                 sizer_MainWindow.Fit(self)
109                 self.Layout()
110                
111                 self.Bind(wx.EVT_CLOSE, self.CloseEvent)
112        
113         def CloseEvent(self, event=None):
114                 exit(0)
115
116
117 if __name__ == "__main__":
118         wx.InitAllImageHandlers()
119         app = MyApp(0)
120         app.MainLoop()
Note: See TracBrowser for help on using the browser.