예제 #1
0
파일: iBrewMac.py 프로젝트: Tristan79/iBrew
   def __init__(self, apiServer):
       super(MacGui, self).__init__("iBrew", icon= AppFolders.iconsPath("logo.png"), quit_button=None)
       self.apiServer = apiServer
       self.menu = [
           'Interface',
 #          None,
 #          'Tea',
           None
       ]         
예제 #2
0
파일: iBrewMac.py 프로젝트: yvorobyov/iBrew
 def __init__(self, apiServer):
     super(MacGui, self).__init__("iBrew",
                                  icon=AppFolders.iconsPath("logo.png"),
                                  quit_button=None)
     self.apiServer = apiServer
     self.menu = [
         'Interface',
         #          None,
         #          'Tea',
         None
     ]
예제 #3
0
 def __init__(self, apiServer):
     
     self.apiServer = apiServer
     
     self.icon = AppFolders.iconsPath("logo.ico")
     print self.icon
     self.hover_text = "iBrew"
         
     menu_options = (
                     ('Interface', None, self.show),
                    )
     
     menu_options = menu_options + (('Quit', None, self.QUIT),)
     self._next_action_id = self.FIRST_ID
     self.menu_actions_by_id = set()
     self.menu_options = self._add_ids_to_menu_options(list(menu_options))
     self.menu_actions_by_id = dict(self.menu_actions_by_id)
     del self._next_action_id
     
     
     self.default_menu_index = 1
     self.window_class_name = "ComicStreamerTrayIcon"
     
     message_map = {win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart,
                    win32con.WM_DESTROY: self.destroy,
                    win32con.WM_COMMAND: self.command,
                    win32con.WM_USER+20 : self.notify,}
     # Register the Window class.
     window_class = win32gui.WNDCLASS()
     hinst = window_class.hInstance = win32gui.GetModuleHandle(None)
     window_class.lpszClassName = self.window_class_name
     window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW;
     window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
     window_class.hbrBackground = win32con.COLOR_WINDOW
     window_class.lpfnWndProc = message_map # could also specify a wndproc.
     classAtom = win32gui.RegisterClass(window_class)
     # Create the Window.
     style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
     self.hwnd = win32gui.CreateWindow(classAtom,
                                       self.window_class_name,
                                       style,
                                       0,
                                       0,
                                       win32con.CW_USEDEFAULT,
                                       win32con.CW_USEDEFAULT,
                                       0,
                                       0,
                                       hinst,
                                       None)
     win32gui.UpdateWindow(self.hwnd)
     self.notify_id = None
     self.refresh_icon()
예제 #4
0
파일: iBrewWin.py 프로젝트: Tristan79/iBrew
 def __init__(self, apiServer):
     
     self.apiServer = apiServer
     
     self.icon = AppFolders.iconsPath("logo.ico")
     print self.icon
     self.hover_text = "iBrew"
         
     menu_options = (
                     ('Interface', None, self.show),
                    )
     
     menu_options = menu_options + (('Quit', None, self.QUIT),)
     self._next_action_id = self.FIRST_ID
     self.menu_actions_by_id = set()
     self.menu_options = self._add_ids_to_menu_options(list(menu_options))
     self.menu_actions_by_id = dict(self.menu_actions_by_id)
     del self._next_action_id
     
     
     self.default_menu_index = 1
     self.window_class_name = "ComicStreamerTrayIcon"
     
     message_map = {win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart,
                    win32con.WM_DESTROY: self.destroy,
                    win32con.WM_COMMAND: self.command,
                    win32con.WM_USER+20 : self.notify,}
     # Register the Window class.
     window_class = win32gui.WNDCLASS()
     hinst = window_class.hInstance = win32gui.GetModuleHandle(None)
     window_class.lpszClassName = self.window_class_name
     window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW;
     window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
     window_class.hbrBackground = win32con.COLOR_WINDOW
     window_class.lpfnWndProc = message_map # could also specify a wndproc.
     classAtom = win32gui.RegisterClass(window_class)
     # Create the Window.
     style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
     self.hwnd = win32gui.CreateWindow(classAtom,
                                       self.window_class_name,
                                       style,
                                       0,
                                       0,
                                       win32con.CW_USEDEFAULT,
                                       win32con.CW_USEDEFAULT,
                                       0,
                                       0,
                                       hinst,
                                       None)
     win32gui.UpdateWindow(self.hwnd)
     self.notify_id = None
     self.refresh_icon()
예제 #5
0
    def run(self,port,dump=False,host=""):
        self.port = port
        self.isRunning = False
        self.dump = dump
        self.host = host
        
        try:
            self.listen(self.port, no_keep_alive = True)
        except Exception:
            logging.error("Web Server: Couldn't open socket on port " + str(self.port))
            raise SmarterError(WebServerListen,"Web Server: Couldn't open socket on port " + str(self.port))
            return
    
    
        
        self.autoconnect()
        

        try:
            settings = {
                "debug"         : True,
                "template_path" : os.path.join(AppFolders.appBase(), 'web'),
                "static_path"   : os.path.join(AppFolders.appBase(), 'resources'),
                "static_url_prefix" : self.webroot + "/resources/", }

            handlers = [
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/status/?",DeviceHandler),
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/calibrate/?",CalibrateHandler),
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/calibrate/base/?",CalibrateBaseHandler),
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/calibrate/base/([0-9]+)/?",CalibrateStoreBaseHandler),

                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/beans/?",BeansHandler),
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/filter/?",FilterHandler),
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/carafe/on/?",CarafeOnHandler),
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/carafe/off?",CarafeOffHandler),
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/mode/cup/?",CupModeHandler),
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/mode/carafe/?",CarafeModeHandler),
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/hotplate/on/([0-9]+)/?",HotPlateOnHandler),
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/hotplate/off/?",HotPlateOffHandler),
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/cups/([0-9]+)/?",CupsHandler),
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/(weak|normal|strong)/?",StrengthHandler),
                
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/scan/?",WifiScanHandler),
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/join/(.+)/(.*)/?",WifiJoinHandler),
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/direct/?",WifiDirectHandler),
                
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/start/?",StartHandler),
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/stop/?",StopHandler),
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/joke/?",JokeHandler),
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/statistics/?",StatsHandler),
                
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/settings/?",SettingsHandler),
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/default/?",SettingsDefaultHandler),
                (self.webroot + r"/api/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/settings/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/?",StoreSettingsHandler),
                
                (self.webroot + r"/api/version/?",VersionHandler),
                (self.webroot + r"/api/devices/?",DevicesHandler),
                (self.webroot + r"/api/joke/?",JokeHandler),
                (self.webroot + r"/api/messages/?",MessagesHandler),
                (self.webroot + r"/api/?.*",UnknownHandler),
                
                # WEB PAGES
                (r"/",MainPageHandler),
                (r"/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/wireless/?", WirelessPageHandler),
                (r"/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/statistics/?", StatsPageHandler),
                (r"/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/settings/?", SettingsPageHandler),
                (r"/statistics/?",ServerPageHandler),
                (r"/info/api/?",APIPageHandler),
                (r"/info/license/?",LicensePageHandler),
                (r"/info/protocol/?",ProtocolPageHandler),
                (r"/info/messages/?",MessagesPageHandler),
                (r"/info/arguments/?",ArgumentsPageHandler),
                (r"/info/groups/?",GroupsPageHandler),
                (r"/info/message/([0-9,A-F,a-f][0-9,A-F,a-f])/?",MessagePageHandler),
                (r"/",MainPageHandler),
                (r"/info/?",InfoPageHandler),
                (r"/(.*)",GenericPageHandler),

                
            ]
            tornado.web.Application.__init__(self, handlers, **settings)
        except Exception:
            print(traceback.format_exc())
            self.kill()
            raise SmarterError(WebServerStartFailed,"Web Server: Couldn't start on port " + str(self.port))

        bonjour = iBrewBonjourThread(self.port)
        bonjour.start()

        try:
            self.thread = threading.Thread(target=self.start)
            self.thread.start()
        except Exception:
            self.kill()
            raise SmarterError(WebServerStartFailed,"Web Server: Couldn't start on port " + str(self.port))


        self.isRunning = True
예제 #6
0
    def autoconnect(self):
        
        #if not self.isRunning:
        #    return
        devices = SmarterClient().find_devices()
        SmarterClient().print_devices_found(devices)
        
        reconnect = 7
        
        for ip in self.clients.keys():
            client = self.clients[ip]
            #print "Checking " + ip
            if not client.connected:
                if self.reconnect_count[ip] < 7:
                    #print "Trying " + ip
                    self.reconnect_count[ip] += 1
                    try:
                        if self.dump:
                            logging.info("[" + ip + "] Auto-connect attempt " + str(self.reconnect_count[ip]))
                        client.connect()
                        try:
                            threading.Thread(target=client.device_all_settings)
                        except Exception, e:
                            logging.info(e)
                    except Exception:
                        client.disconnect()
                else:
                    client.disconnect()
                    if self.dump:
                        logging.warning("[" + ip + "] Auto-connect tried " + str(reconnect) + " attempts, removing")
                    del self.clients[ip]
                    del self.reconnect_count[ip]
            else:
                self.reconnect_count[ip] = 0


        for device in devices:
            if device[0] not in self.clients:
                try:
                    if self.dump:
                        logging.info("[" + device[0] + "] Adding Web Device")
                    client = SmarterClient()
                    client.deviceId = device[1]
                    client.device = Smarter.device_to_string(device[1])
                    client.version = device[2]
                    client.dump = self.dump
                    client.dump_status = self.dump
                    client.host = device[0]
                    client.settingsPath = AppFolders.settings() + "/"
                    client.connect()
                    self.clients[device[0]] = client
                    threading.Thread(target=client.device_all_settings)
                    self.reconnect_count[device[0]] = 0
                    logging.info("iBrew Web Server: " + client.string_connect_status())
                except Exception:
                    client.disconnect()
                    pass #raise SmarterError(WebServerListen,"Web Server: Couldn't open socket on port" + str(self.port))
            else:
                client = self.clients[device[0]]
                if not client.connected:
                    self.reconnect_count[device[0]] += 1
                    client.connect()


        
        if self.host != "":
            ip = socket.gethostbyname(self.host)
            if ip not in self.clients:
                try:
                    if self.dump:
                        logging.info("[" + ip + "] Adding Web Device")
                    client = SmarterClient()
                    client.host = self.host
                    client.dump = self.dump
                    client.dump_status = self.dump
                    client.settingsPath = AppFolders.settings() + "/"
                    client.connect()
                    self.clients[ip] = client
                    client.device_all_settings()
                    self.reconnect_count[ip] = 0
                    logging.info("iBrew Web Server: " + client.string_connect_status())
                except Exception:
                    client.disconnect()
                    pass # raise SmarterError(WebServerListen,"Web Server: Couldn't open socket on port" + str(self.port))


        self.threadAutoConnect = threading.Timer(15, self.autoconnect)
        self.threadAutoConnect.start()