This repository was archived by the owner on Sep 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.py
More file actions
152 lines (118 loc) · 5.07 KB
/
ViewController.py
File metadata and controls
152 lines (118 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#***************************************
# Filename: ViewController.py
#
# Description:
# This module is the controller for the GUI.
# All of the other modules route messages
# to and from the GUI through this module.
#
#***************************************
#Import Constants
from Constants import *
#Lib imports:
from threading import Thread
import wx, Queue
#My Module Imports
import View
class ViewController(Thread):
def __init__(self, DataStoragePlug, PacketManagerPlug, MessageProcessorPlug, OGMProcessorPlug):
Thread.__init__(self)
self.DataStoragePlug = DataStoragePlug
self.PacketManagerPlug = PacketManagerPlug
self.MessageProcessorPlug = MessageProcessorPlug
self.OGMProcessorPlug = OGMProcessorPlug
self.guiApp = View.YOBATMANGUI(0)
self.GUIStarter = GUIStarter(self.guiApp)
self.ViewEventQueue = Queue.Queue(QueueSize)
self.BlackListEditQueue = Queue.Queue(1)
self.NewMessageQueue = Queue.Queue(1)
def exit(self, event):
self.ViewEventQueue.put(ViewExit)
def nodeOn(self, event):
self.ViewEventQueue.put(NodeOn)
def nodeOff(self, event):
self.ViewEventQueue.put(NodeOff)
def editBlackList(self, event):
self.ViewEventQueue.put(EditBlackList)
def newMessage(self, event):
if verbose: print "newmess button"
self.ViewEventQueue.put(NewMessageEditor)
def run(self):
if verbose: print "ViewController Start"
#Add bindings for GUI elements
self.guiApp.mainFrame.Bind(wx.EVT_MENU, self.exit, id=9)
self.guiApp.mainFrame.Bind(wx.EVT_MENU, self.nodeOn, id=1)
self.guiApp.mainFrame.Bind(wx.EVT_MENU, self.nodeOff, id=2)
self.guiApp.mainFrame.Bind(wx.EVT_MENU, self.editBlackList, id=3)
self.guiApp.mainFrame.Bind(wx.EVT_BUTTON, self.newMessage, id=10)
self.guiApp.mainFrame.Bind(wx.EVT_CLOSE, self.exit)
#Start the GUI
self.GUIStarter.start()
Exit = False
while(not Exit):
#check the data plug for messages
if not self.DataStoragePlug.isEmpty(__name__):
dataStorageMessage = self.DataStoragePlug.get(__name__)
if dataStorageMessage != None:
if isUpdatedRoutingTable(dataStorageMessage):
wx.CallAfter(self.guiApp.mainFrame.UpdateList, dataStorageMessage[1], dataStorageMessage[2])
elif isConnectedNodes(dataStorageMessage):
connectedNodeList = dataStorageMessage[1]
wx.CallAfter(self.guiApp.mainFrame.StartUpMessageEditor, connectedNodeList, self.NewMessageQueue)
#check the packetmanager plug for messages
if not self.PacketManagerPlug.isEmpty(__name__):
packetManagerMessage = self.PacketManagerPlug.get(__name__)
if packetManagerMessage != None:
if packetManagerMessage == NodeOn:
wx.CallAfter(self.guiApp.mainFrame.NodeStatusUpdate, True)
elif packetManagerMessage == NodeOff:
wx.CallAfter(self.guiApp.mainFrame.NodeStatusUpdate, False)
elif isProcessedPacket(packetManagerMessage):
wx.CallAfter(self.guiApp.mainFrame.UpdateList, 0, packetManagerMessage[1:])
elif isReturnEditBlackList(packetManagerMessage):
blacklist = packetManagerMessage[1]
wx.CallAfter(self.guiApp.mainFrame.StartUpBlackListEditor, blacklist, self.BlackListEditQueue)
elif isAddressMessage(packetManagerMessage):
myAddress = packetManagerMessage[1]
wx.CallAfter(self.guiApp.mainFrame.UpdateTitle, myAddress)
#check the message processor plug for messages
if not self.MessageProcessorPlug.isEmpty(__name__):
messProcessorPlugMessage = self.MessageProcessorPlug.get(__name__)
if messProcessorPlugMessage != None:
if isReturnNewMessage(messProcessorPlugMessage):
wx.CallAfter(self.guiApp.mainFrame.UpdateList, 3, messProcessorPlugMessage[1])
#check the ogm processor plug for messages
#Check the ViewEvent Queue
if self.ViewEventQueue.qsize() != 0:
viewCommand = self.ViewEventQueue.get(QueueWait)
if viewCommand == ViewExit:
Exit = True
self.DataStoragePlug.put(ViewExit, __name__)
self.PacketManagerPlug.put(ViewExit, __name__)
self.MessageProcessorPlug.put(ViewExit, __name__)
self.OGMProcessorPlug.put(ViewExit, __name__)
self.guiApp.mainFrame.Destroy()
self.GUIStarter.join()
elif viewCommand == NodeOn:
self.PacketManagerPlug.put(NodeOn, __name__)
elif viewCommand == NodeOff:
self.PacketManagerPlug.put(NodeOff, __name__)
elif viewCommand == EditBlackList:
self.PacketManagerPlug.put(EditBlackList, __name__)
elif viewCommand == NewMessageEditor:
self.DataStoragePlug.put(NewMessageEditor, __name__)
#Check the edit blacklist queue
if not self.BlackListEditQueue.empty():
newBlackList = self.BlackListEditQueue.get(QueueWait)
self.PacketManagerPlug.put((NewBlackList, newBlackList), __name__)
#Check the new message queue
if not self.NewMessageQueue.empty():
newMessage = self.NewMessageQueue.get(QueueWait)
self.MessageProcessorPlug.put((ReturnNewMessage, newMessage), __name__)
if verbose: print "ViewController Exit"
class GUIStarter(Thread):
def __init__(self, GuiApp):
Thread.__init__(self)
self.GuiApp = GuiApp
def run(self):
self.GuiApp.MainLoop()