コード例 #1
0
ファイル: main.py プロジェクト: dz111/mjc-broker
 def __init__(self):
     wx.Frame.__init__(self, parent=None, title=TITLE + " - " + VERSION, size=(250,320))
     # Load config
     self.config = load_json("config.json")
     # Create panel elements
     self.panel = wx.Panel(self)
     wx.StaticText(self.panel, label="Name", pos=(5,5))
     wx.StaticText(self.panel, label="IP Addr", pos=(5,88))
     self.ctrl_name = wx.TextCtrl(self.panel, pos=(5,25), size=(230,-1))
     self.ctrl_ipaddr = wx.TextCtrl(self.panel, pos=(55,85), size=(180,-1), style=wx.TE_READONLY)
     self.ctrl_register = wx.Button(self.panel, pos=(5,55), label="Register")
     self.ctrl_pair = wx.Button(self.panel, pos=(5,245), label="Pair")
     self.ctrl_list = wx.ListBox(self.panel, pos=(5,115), size=(230,120), style=wx.LB_SINGLE)
     self.SetStatusBar(wx.StatusBar(self))
     # Set gui initial state
     self.ctrl_pair.Disable()
     self.SetStatusText("closed")
     # Bind element event handlers
     self.Bind(wx.EVT_BUTTON, lambda _: self.DoRegister(), self.ctrl_register)
     self.Bind(wx.EVT_BUTTON, lambda _: self.DoPair(), self.ctrl_pair)
     # Create client
     self.client = BrokerClient(self.config["server"]["address"], self.config["server"]["port"])
     self.client.subscribe(self.MessageHandler)
     self.client_timer = wx.Timer(self)
     self.Bind(wx.EVT_TIMER, lambda _: asyncore.poll(), self.client_timer)
     self.client_timer.Start(100)
     self.client.Connect()
コード例 #2
0
ファイル: main.py プロジェクト: dz111/mjc-broker
 def __init__(self):
     wx.Frame.__init__(self,
                       parent=None,
                       title=TITLE + " - " + VERSION,
                       size=(250, 320))
     # Load config
     self.config = load_json("config.json")
     # Create panel elements
     self.panel = wx.Panel(self)
     wx.StaticText(self.panel, label="Name", pos=(5, 5))
     wx.StaticText(self.panel, label="IP Addr", pos=(5, 88))
     self.ctrl_name = wx.TextCtrl(self.panel, pos=(5, 25), size=(230, -1))
     self.ctrl_ipaddr = wx.TextCtrl(self.panel,
                                    pos=(55, 85),
                                    size=(180, -1),
                                    style=wx.TE_READONLY)
     self.ctrl_register = wx.Button(self.panel,
                                    pos=(5, 55),
                                    label="Register")
     self.ctrl_pair = wx.Button(self.panel, pos=(5, 245), label="Pair")
     self.ctrl_list = wx.ListBox(self.panel,
                                 pos=(5, 115),
                                 size=(230, 120),
                                 style=wx.LB_SINGLE)
     self.SetStatusBar(wx.StatusBar(self))
     # Set gui initial state
     self.ctrl_pair.Disable()
     self.SetStatusText("closed")
     # Bind element event handlers
     self.Bind(wx.EVT_BUTTON, lambda _: self.DoRegister(),
               self.ctrl_register)
     self.Bind(wx.EVT_BUTTON, lambda _: self.DoPair(), self.ctrl_pair)
     # Create client
     self.client = BrokerClient(self.config["server"]["address"],
                                self.config["server"]["port"])
     self.client.subscribe(self.MessageHandler)
     self.client_timer = wx.Timer(self)
     self.Bind(wx.EVT_TIMER, lambda _: asyncore.poll(), self.client_timer)
     self.client_timer.Start(100)
     self.client.Connect()
コード例 #3
0
ファイル: main.py プロジェクト: dz111/mjc-broker
class AppFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self,
                          parent=None,
                          title=TITLE + " - " + VERSION,
                          size=(250, 320))
        # Load config
        self.config = load_json("config.json")
        # Create panel elements
        self.panel = wx.Panel(self)
        wx.StaticText(self.panel, label="Name", pos=(5, 5))
        wx.StaticText(self.panel, label="IP Addr", pos=(5, 88))
        self.ctrl_name = wx.TextCtrl(self.panel, pos=(5, 25), size=(230, -1))
        self.ctrl_ipaddr = wx.TextCtrl(self.panel,
                                       pos=(55, 85),
                                       size=(180, -1),
                                       style=wx.TE_READONLY)
        self.ctrl_register = wx.Button(self.panel,
                                       pos=(5, 55),
                                       label="Register")
        self.ctrl_pair = wx.Button(self.panel, pos=(5, 245), label="Pair")
        self.ctrl_list = wx.ListBox(self.panel,
                                    pos=(5, 115),
                                    size=(230, 120),
                                    style=wx.LB_SINGLE)
        self.SetStatusBar(wx.StatusBar(self))
        # Set gui initial state
        self.ctrl_pair.Disable()
        self.SetStatusText("closed")
        # Bind element event handlers
        self.Bind(wx.EVT_BUTTON, lambda _: self.DoRegister(),
                  self.ctrl_register)
        self.Bind(wx.EVT_BUTTON, lambda _: self.DoPair(), self.ctrl_pair)
        # Create client
        self.client = BrokerClient(self.config["server"]["address"],
                                   self.config["server"]["port"])
        self.client.subscribe(self.MessageHandler)
        self.client_timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, lambda _: asyncore.poll(), self.client_timer)
        self.client_timer.Start(100)
        self.client.Connect()

    def MessageHandler(self, topic, message):
        if topic == "status":
            self.SetStatusText(message)
            if message == "registered":
                self.OnRegistered()
            else:
                self.OnDeregistered()
        elif topic == "address":
            self.SetIPAddress(message)
        elif topic == "clients":
            self.SetClientList(message)
        elif topic == "error":
            self.ShowError(message, False)
        elif topic == "fatal":
            self.ShowError(message, True)
        elif topic == "pair":
            sim = self.ApplySettings(*message[1:])
            self.ShowPairResult(sim, *message)
            self.Close()

    def OnRegistered(self):
        self.ctrl_name.Disable()
        self.ctrl_register.Disable()
        self.ctrl_pair.Enable()

    def OnDeregistered(self):
        self.ctrl_name.Enable()
        self.ctrl_register.Enable()
        self.ctrl_pair.Disable()

    def SetIPAddress(self, addr):
        self.ctrl_ipaddr.SetValue(addr)

    def SetClientList(self, clients):
        self.ctrl_list.SetItems(clients)
        idx = self.ctrl_list.FindString(self.GetName())
        if idx >= 0:
            self.ctrl_list.Delete(idx)

    def ShowPairResult(self, sim, name, local_port, remote_addr, remote_port):
        message = "Sim: %s\nPairing with '%s'\nLocal port: %d\nRemote: %s:%d" % (
            sim, name, local_port, remote_addr, remote_port)
        wx.MessageDialog(self,
                         message=message,
                         caption="Pairing Request",
                         style=wx.OK | wx.ICON_INFORMATION).ShowModal()

    def ShowWarning(self, message):
        wx.MessageDialog(self,
                         message=message,
                         caption="Warning",
                         style=wx.OK | wx.ICON_WARNING).ShowModal()

    def ShowError(self, message, fatal):
        if fatal:
            caption = "Fatal Error"
        else:
            caption = "Error"
        wx.MessageDialog(self,
                         message=message,
                         caption=caption,
                         style=wx.OK | wx.ICON_ERROR).ShowModal()
        if fatal:
            self.Close()

    def DoRegister(self):
        self.client.DoRegister(self.GetName())

    def DoPair(self):
        try:
            self.client.DoRequestPair(self.GetSelection())
        except IndexError:
            self.ShowWarning("Please select a partner")

    def ApplySettings(self, local_port, remote_addr, remote_port):
        mjcroot = self.config["mjcroot"]
        sim = "Loaded from config.json"
        if not mjcroot:
            sim, mjcroot = configurator.GetMJCPath()[0]
        configurator.SetPairingData(local_port, remote_addr, remote_port,
                                    mjcroot)
        return sim

    def GetName(self):
        return self.ctrl_name.GetValue()

    def GetSelection(self):
        idx = self.ctrl_list.GetSelection()
        if idx < 0:
            raise IndexError("no selection has been made")
        return self.ctrl_list.GetString(idx)
コード例 #4
0
 def __init__(self, *args, **kwargs):
     self.client = BrokerClient(self.host, get_certificate())
コード例 #5
0
 def __init__(self, *args, **kwargs):
     self.client = BrokerClient(self.host, CREDENTIALS)
コード例 #6
0
ファイル: main.py プロジェクト: dz111/mjc-broker
class AppFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, parent=None, title=TITLE + " - " + VERSION, size=(250,320))
        # Load config
        self.config = load_json("config.json")
        # Create panel elements
        self.panel = wx.Panel(self)
        wx.StaticText(self.panel, label="Name", pos=(5,5))
        wx.StaticText(self.panel, label="IP Addr", pos=(5,88))
        self.ctrl_name = wx.TextCtrl(self.panel, pos=(5,25), size=(230,-1))
        self.ctrl_ipaddr = wx.TextCtrl(self.panel, pos=(55,85), size=(180,-1), style=wx.TE_READONLY)
        self.ctrl_register = wx.Button(self.panel, pos=(5,55), label="Register")
        self.ctrl_pair = wx.Button(self.panel, pos=(5,245), label="Pair")
        self.ctrl_list = wx.ListBox(self.panel, pos=(5,115), size=(230,120), style=wx.LB_SINGLE)
        self.SetStatusBar(wx.StatusBar(self))
        # Set gui initial state
        self.ctrl_pair.Disable()
        self.SetStatusText("closed")
        # Bind element event handlers
        self.Bind(wx.EVT_BUTTON, lambda _: self.DoRegister(), self.ctrl_register)
        self.Bind(wx.EVT_BUTTON, lambda _: self.DoPair(), self.ctrl_pair)
        # Create client
        self.client = BrokerClient(self.config["server"]["address"], self.config["server"]["port"])
        self.client.subscribe(self.MessageHandler)
        self.client_timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, lambda _: asyncore.poll(), self.client_timer)
        self.client_timer.Start(100)
        self.client.Connect()

    def MessageHandler(self, topic, message):
        if topic == "status":
            self.SetStatusText(message)
            if message == "registered":
                self.OnRegistered()
            else:
                self.OnDeregistered()
        elif topic == "address":
            self.SetIPAddress(message)
        elif topic == "clients":
            self.SetClientList(message)
        elif topic == "error":
            self.ShowError(message, False)
        elif topic == "fatal":
            self.ShowError(message, True)
        elif topic == "pair":
            sim = self.ApplySettings(*message[1:])
            self.ShowPairResult(sim, *message)
            self.Close()

    def OnRegistered(self):
        self.ctrl_name.Disable()
        self.ctrl_register.Disable()
        self.ctrl_pair.Enable()

    def OnDeregistered(self):
        self.ctrl_name.Enable()
        self.ctrl_register.Enable()
        self.ctrl_pair.Disable()

    def SetIPAddress(self, addr):
        self.ctrl_ipaddr.SetValue(addr)

    def SetClientList(self, clients):
        self.ctrl_list.SetItems(clients)
        idx = self.ctrl_list.FindString(self.GetName())
        if idx >= 0:
            self.ctrl_list.Delete(idx)

    def ShowPairResult(self, sim, name, local_port, remote_addr, remote_port):
        message = "Sim: %s\nPairing with '%s'\nLocal port: %d\nRemote: %s:%d" % (sim, name, local_port, remote_addr, remote_port)
        wx.MessageDialog(self, message=message, caption="Pairing Request", style=wx.OK|wx.ICON_INFORMATION).ShowModal()

    def ShowWarning(self, message):
        wx.MessageDialog(self, message=message, caption="Warning", style=wx.OK|wx.ICON_WARNING).ShowModal()

    def ShowError(self, message, fatal):
        if fatal:
            caption = "Fatal Error"
        else:
            caption = "Error"
        wx.MessageDialog(self, message=message, caption=caption, style=wx.OK|wx.ICON_ERROR).ShowModal()
        if fatal:
            self.Close()

    def DoRegister(self):
        self.client.DoRegister(self.GetName())

    def DoPair(self):
        try:
            self.client.DoRequestPair(self.GetSelection())
        except IndexError:
            self.ShowWarning("Please select a partner")

    def ApplySettings(self, local_port, remote_addr, remote_port):
        mjcroot = self.config["mjcroot"]
        sim = "Loaded from config.json"
        if not mjcroot:
            sim, mjcroot = configurator.GetMJCPath()[0]
        configurator.SetPairingData(local_port, remote_addr, remote_port, mjcroot)
        return sim

    def GetName(self):
        return self.ctrl_name.GetValue()

    def GetSelection(self):
        idx = self.ctrl_list.GetSelection()
        if idx < 0:
            raise IndexError("no selection has been made")
        return self.ctrl_list.GetString(idx)