class MainWindow(Frame):
    buttons = []

    def __init__(self, parent, serverIP):
        Frame.__init__(self, parent, bg="black")
        self.parent = parent
        self.controller = HomeControllerClient(serverIP)
        self.initUI()

    def listSwitches(self):
        count = -1
        while (count == -1):
            try:
                switches = self.controller.getSwitches()
                count = len(switches)
            except:
                count = -1

        for b in self.buttons:
            b.destroy()

        for k in switches.keys():

            bgColor = "red"
            if (switches[k] == 1):
                bgColor = "green"

            btn = Button(self,
                         text=k,
                         bg=bgColor,
                         command=self.generateCallback(k))
            self.buttons.append(btn)
            btn.pack(fill=X, padx=5, pady=5)

    def generateCallback(self, name):
        def callback():
            self.toggle(name)

        return callback

    def toggle(self, name):
        self.controller.toggleSwitch(name)
        self.listSwitches()

    def initUI(self):
        self.parent.title("Main Window")
        self.pack(fill=BOTH, expand=1)
        lbl = Label(self, text="Home Controller", fg="white", bg="black")
        lbl.pack(fill=X, padx=5, pady=5)
        self.listSwitches()
Exemple #2
0
class MainWindow(Frame):
	buttons = []

	def __init__(self, parent, serverIP):
		Frame.__init__(self, parent, bg="black")
		self.parent = parent
		self.controller = HomeControllerClient(serverIP)
		self.initUI()

	def listSwitches(self):
		count = -1
		while (count == -1):
			try:
				switches = self.controller.getSwitches()
				count = len(switches)
			except:
				count = -1

		for b in self.buttons:
			b.destroy()

		for k in switches.keys():

			bgColor = "red"
			if(switches[k] == 1):
				bgColor = "green"

			btn = Button(self, text=k, bg=bgColor, command=self.generateCallback(k))
			self.buttons.append(btn)
			btn.pack(fill=X, padx=5, pady=5)

	def generateCallback(self, name):
		def callback():
			self.toggle(name)
		return callback
		
	def toggle(self, name):
		self.controller.toggleSwitch(name)
		self.listSwitches()

	def initUI(self):
		self.parent.title("Main Window")
		self.pack(fill=BOTH, expand=1)
		lbl = Label(self, text="Home Controller", fg="white", bg="black")
		lbl.pack(fill=X, padx=5, pady=5)
		self.listSwitches()
 def __init__(self, parent, serverIP):
     Frame.__init__(self, parent, bg="black")
     self.parent = parent
     self.controller = HomeControllerClient(serverIP)
     self.initUI()
Exemple #4
0
	def __init__(self, parent, serverIP):
		Frame.__init__(self, parent, bg="black")
		self.parent = parent
		self.controller = HomeControllerClient(serverIP)
		self.initUI()