def __init__(self, config):
        self.config = config
        self.client = mqtt.Client(self.config.name)

        # Próba połączenia
        try:
            self.client.connect(self.config.address)
        except:
            show_error('Nie można nawiązać połączenia z serwerem MQTT.')

        self.client.loop_start()

        # Ewentualna subskrypcja tematu temperatury
        if self.config.is_temp_set():
            self.client.subscribe(f"{self.config.sub}/temp")

        # Subskrypcja tematów urządzeń
        for room, devices in self.config.rooms.items():
            for device in devices.keys():
                if self.config.device(room, device)['typ'] == 'przełącznik':
                    self.client.subscribe(
                        f"{self.config.sub}/{self.config.device(room, device)['temat']}/button"
                    )
                elif self.config.device(room, device)['typ'] == 'suwak':
                    self.client.subscribe(
                        f"{self.config.sub}/{self.config.device(room, device)['temat']}/button"
                    )
                    self.client.subscribe(
                        f"{self.config.sub}/{self.config.device(room, device)['temat']}/slider"
                    )
                elif self.config.device(room, device)['typ'] == 'tv':
                    self.client.subscribe(
                        f"{self.config.sub}/{self.config.device(room, device)['temat']}/button"
                    )
                    self.client.subscribe(
                        f"{self.config.sub}/{self.config.device(room, device)['temat']}/channel"
                    )
                    self.client.subscribe(
                        f"{self.config.sub}/{self.config.device(room, device)['temat']}/volume"
                    )
                elif self.config.device(room, device)['typ'] == 'roleta':
                    self.client.subscribe(
                        f"{self.config.sub}/{self.config.device(room, device)['temat']}/blind"
                    )

        # Obsłużenie zatrzymanych wiadomości (retained)
        self.client.on_message = self._on_message_start

        # Uruchomienie okna i zmiana obsługi wiadomości na tryb związany z gui
        self.main_frame = MainFrame(self.config, self.client)
        self.client.on_message = self._on_message_normal
        self.main_frame.start_loop()

        # Zakończenie działania po wyłączeniu okna
        self.client.loop_stop()
        self.client.disconnect()
Пример #2
0
class COPISApp(wx.App):
    mainframe = None

    def __init__(self, *args, **kwargs):
        super(COPISApp, self).__init__(*args, **kwargs)

        self.appconfig = None
        self.appconfig_exists = False
        self.init_appconfig()

        self.SetAppName('COPIS')
        self.locale = wx.Locale(wx.Locale.GetSystemLanguage())
        self.mainframe = MainFrame(
            None,
            style=wx.DEFAULT_FRAME_STYLE | wx.FULL_REPAINT_ON_RESIZE,
            title='COPIS',
            size=(self.appconfig.config.getint('General', 'windowwidth'),
                  self.appconfig.config.getint('General', 'windowheight')))
        self.mainframe.Show()

    def init_appconfig(self):
        if self.appconfig is None:
            self.appconfig = AppConfig()

        self.appconfig_exists = self.appconfig.exists()
        if self.appconfig_exists:
            self.appconfig.load()

    def dark_mode(self):
        wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWFRAME)
Пример #3
0
    def __init__(self, *args, **kwargs):
        super(COPISApp, self).__init__(*args, **kwargs)

        self.appconfig = None
        self.appconfig_exists = False
        self.init_appconfig()

        self.SetAppName('COPIS')
        self.locale = wx.Locale(wx.Locale.GetSystemLanguage())
        self.mainframe = MainFrame(
            None,
            style=wx.DEFAULT_FRAME_STYLE | wx.FULL_REPAINT_ON_RESIZE,
            title='COPIS',
            size=(self.appconfig.config.getint('General', 'windowwidth'),
                  self.appconfig.config.getint('General', 'windowheight')))
        self.mainframe.Show()
Пример #4
0
 def post_login(self):
     """Closes this window and opens the main frame."""
     try:
         from gui.main_frame import MainFrame
         application.main_frame = MainFrame()
         application.main_frame.Show(True)
     except wx.PyDeadObjectError:
         pass  # The user closed it already.
     finally:
         self.Close(True)
class Client:
    def __init__(self, config):
        self.config = config
        self.client = mqtt.Client(self.config.name)

        # Próba połączenia
        try:
            self.client.connect(self.config.address)
        except:
            show_error('Nie można nawiązać połączenia z serwerem MQTT.')

        self.client.loop_start()

        # Ewentualna subskrypcja tematu temperatury
        if self.config.is_temp_set():
            self.client.subscribe(f"{self.config.sub}/temp")

        # Subskrypcja tematów urządzeń
        for room, devices in self.config.rooms.items():
            for device in devices.keys():
                if self.config.device(room, device)['typ'] == 'przełącznik':
                    self.client.subscribe(
                        f"{self.config.sub}/{self.config.device(room, device)['temat']}/button"
                    )
                elif self.config.device(room, device)['typ'] == 'suwak':
                    self.client.subscribe(
                        f"{self.config.sub}/{self.config.device(room, device)['temat']}/button"
                    )
                    self.client.subscribe(
                        f"{self.config.sub}/{self.config.device(room, device)['temat']}/slider"
                    )
                elif self.config.device(room, device)['typ'] == 'tv':
                    self.client.subscribe(
                        f"{self.config.sub}/{self.config.device(room, device)['temat']}/button"
                    )
                    self.client.subscribe(
                        f"{self.config.sub}/{self.config.device(room, device)['temat']}/channel"
                    )
                    self.client.subscribe(
                        f"{self.config.sub}/{self.config.device(room, device)['temat']}/volume"
                    )
                elif self.config.device(room, device)['typ'] == 'roleta':
                    self.client.subscribe(
                        f"{self.config.sub}/{self.config.device(room, device)['temat']}/blind"
                    )

        # Obsłużenie zatrzymanych wiadomości (retained)
        self.client.on_message = self._on_message_start

        # Uruchomienie okna i zmiana obsługi wiadomości na tryb związany z gui
        self.main_frame = MainFrame(self.config, self.client)
        self.client.on_message = self._on_message_normal
        self.main_frame.start_loop()

        # Zakończenie działania po wyłączeniu okna
        self.client.loop_stop()
        self.client.disconnect()

    def _on_message_start(self, client, userdata, message):
        '''
        Callout wykonujący się po otrzymaniu wiadomości z serwera.
        Służy do odebrania wiadomości zatrzymanych na serwerze w celu odtworzenia aktulanego stanu.
        '''
        topic = message.topic.split('/')

        # Temperatura
        if len(topic) == 2:
            state = message.payload.decode("utf-8")
            self.config.add_temp_state(int(state))
        # Urządzenie
        else:
            _, room, device, mode = topic
            state = message.payload.decode("utf-8")
            room, device = self.config.get_room_device(room, device)
            self.config.add_device_state(room, device, mode, state)

    def _on_message_normal(self, client, userdata, message):
        '''
        Callout wykonujący się po otrzymaniu wiadomości z serwera.
        Reakcja na zmiany w trakcie działania programu.
        '''
        topic = message.topic.split('/')

        # Temperatura
        if len(topic) == 2:
            self.main_frame.change_temp_state(
                str(message.payload.decode("utf-8")))
        # Urządzenie
        else:
            _, room, device, mode = topic
            if mode == 'button':
                self.main_frame.change_button_state(
                    room, device, str(message.payload.decode("utf-8")))
            elif mode == 'slider':
                self.main_frame.change_slider_state(
                    room, device, str(message.payload.decode("utf-8")))
            elif mode == 'channel':
                self.main_frame.change_channel_state(
                    room, device, str(message.payload.decode("utf-8")))
            elif mode == 'volume':
                self.main_frame.change_volume_state(
                    room, device, str(message.payload.decode("utf-8")))
            elif mode == 'blind':
                self.main_frame.change_blind_state(
                    room, device, str(message.payload.decode("utf-8")))
Пример #6
0
# MALEX
# Import built-in modules
import wx

# Import project modules
from gui.main_frame import MainFrame

if __name__ == '__main__':
    app = wx.App()
    frame = MainFrame()
    app.MainLoop()
Пример #7
0
import wx

from gui.app import App
from gui.main_frame import MainFrame

if __name__ == '__main__':
    app = App()
    frame = MainFrame(None, wx.ID_ANY, "Hello World!")
    app.SetTopWindow(frame)
    frame.Show()
    app.MainLoop()
Пример #8
0
 import config
 from humanize import naturalsize
 dir = config.config.storage['media_dir']
 if os.path.isdir(dir):
     application.library_size = sum([
         os.path.getsize(os.path.join(dir, x)) for x in os.listdir(dir)
         if os.path.isfile(os.path.join(dir, x))
     ])
 else:
     application.library_size = 0
 logging.info('Library size is %s.',
              naturalsize(application.library_size))
 logging.info('Working out of directory: %s.', config.config_dir)
 db.Base.metadata.create_all()
 from gui.main_frame import MainFrame
 application.frame = MainFrame(None)
 application.frame.Show(True)
 application.frame.Maximize(True)
 from threading import Thread
 from server.base import app
 app.port = args.server_port
 from twisted.web.server import Site
 from twisted.internet import reactor, endpoints
 endpoint_description = "tcp:port={0}:interface={1}".format(
     args.server_port, args.server_host)
 endpoint = endpoints.serverFromString(reactor, endpoint_description)
 endpoint.listen(Site(
     app.resource())).addCallback(lambda result: logging.info(
         'Web server running on port %d.', result.port))
 Thread(target=reactor.run, args=[False]).start()
 application.app.MainLoop()
Пример #9
0
import wx

from gui.main_frame import MainFrame

if __name__ == "__main__":
    supp = wx.App(False)
    MainFrame()
    supp.MainLoop()