12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import FSM
- import utils as u
- import menus as m
- import os
- import socket
- #====================================
-
- State = type("State", (object,), {})
- #====================================
- class State(object):
- def __init__(self, FSM):
- self.FSM = FSM
- def Enter(self):
- pass
- def Execute(self):
- pass
- def Exit(self):
- pass
-
-
-
- class Wifi(State):
- def __init__(self,FSM):
- super(Wifi, self).__init__(FSM)
-
- def Enter(self):
- o = self.FSM.owner
-
- o.header_text = "Wifi"
- o.pub.register("beat", self)
-
- self.ipad = self.extract_ip()
- self.ssid = os.popen("sudo iwgetid -r").read()
- o.center_block(self.ipad, o.h2, [0, 0, o.width,o.height], o.light_grey)
-
- u.draw_header(o)
- self.draw_main(o)
- o.update_display(0)
- super(Wifi, self).Enter()
-
- def Execute(self):
- o = self.FSM.owner
- m.menu1_actions(self, o)
- if o.keyState[16] == 1:
- m.draw_menu1(o)
- o.update_display(0)
- elif o.keyState[16] == 4:
- u.draw_header(o)
- #self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
-
- if o.keyState[0] == 1 or o.keyState[0] == 3 or o.keyState[1] == 1 or o.keyState[1] == 3 or o.keyState[2] == 1 or o.keyState[2] == 3 or o.keyState[3] == 1 or o.keyState[3] == 3:
- u.draw_header(o)
- #self.draw_footer(o)
- self.draw_main(o)
- o.update_display(0)
-
-
- def draw_main(self, o):
- o.center_block(self.ipad, o.h2, [0, 0, o.width, o.height], o.light_grey)
- o.center_block(self.ssid, o.h2, [0, 40, o.width, o.height+40], o.light_grey)
-
-
- def extract_ip(self):
- st = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- try:
- #st.connect(('10.255.255.255', 1))
- st.connect(("8.8.8.8", 80))
- IP = st.getsockname()[0]
- except Exception:
- IP = '127.0.0.1'
- finally:
- st.close()
- return IP
- #print(extract_ip())
-
- def ReceiveMessage(self, message):
- o = self.FSM.owner
- u.play_seq(o, message)
-
- def Exit(self):
- self.FSM.owner.pub.unregister("beat", self)
-
- #====================================
|