Ejemplo n.º 1
0
	def __init__( self ):
		wx.Frame.__init__( self, None, wx.ID_ANY, "MWCam", style=wx.DEFAULT_FRAME_STYLE & ~wx.RESIZE_BORDER )
		
		# Socket Cleint
		self.SocketClient = MWScore.SocketClient( SOCKET_CLIENT_HOST, SOCKET_CLIENT_PORT )
		self.SocketClient.StartThread()
		
		# IP Camera
		#self.Camera = Trendnet( CAMERA_IP, CAMERA_USERNAME, CAMERA_PASSWORD )
		self.Camera = DLink( CAMERA_IP, CAMERA_USERNAME, CAMERA_PASSWORD )
		self.Camera.Connect()
		
		# Camera Panel
		self.CameraPanel = CameraPanel( self, self.Camera, self.SocketClient )
		
		# Frame timer
		self.Timer = wx.Timer( self, self.ID_FRAME_REFRESH )
		self.Timer.Start(10)
		wx.EVT_TIMER( self, self.ID_FRAME_REFRESH, self.Refresh )
		
		# Frame Sizer
		self.Sizer = None
		self.Size()
		
		# Show frame
		self.Show( True )
Ejemplo n.º 2
0
 def SocketSetup(self, event):
     dlg = SocketServerDialog(self, -1)
     if dlg.ShowModal() == wx.ID_OK:
         self.ScoreServer.SocketServer.KillThread()
         self.ScoreServer.SocketServer = MWScore.SocketServer(
             self.ScoreServer, dlg.HostChoice.GetValue(),
             int(dlg.PortChoice.GetValue()))
     dlg.Destroy()
Ejemplo n.º 3
0
 def TransponderSetup(self, event):
     dlg = TransponderDialog(self, -1)
     if dlg.ShowModal() == wx.ID_OK:
         self.ScoreServer.TransponderListener.KillThread()
         self.ScoreServer.TransponderListener = MWScore.TransponderListener(
             self.ScoreServer, dlg.PortChoice.GetValue(),
             int(dlg.BaudChoice.GetValue()))
     dlg.Destroy()
Ejemplo n.º 4
0
 def TransponderSetup( self, event ):
         dlg = TransponderDialog( self, -1 )
         if dlg.ShowModal() == wx.ID_OK:
                 self.ScoreServer.TransponderListener.KillThread()
                 self.ScoreServer.TransponderListener = MWScore.TransponderListener( self.ScoreServer, dlg.PortChoice.GetValue(), int(dlg.BaudChoice.GetValue()) )
                 if not self.ScoreServer.TransponderListener.Xbee:
                         wx.MessageBox("Could not open Transponder port " + ScoreServer.TransponderListener.Port, "Error", wx.OK | wx.ICON_ERROR)
                 dlg.Destroy()
Ejemplo n.º 5
0
    def __init__(self):
        wx.Frame.__init__(self,
                          None,
                          wx.ID_ANY,
                          style=wx.DEFAULT_FRAME_STYLE,
                          name="MWScore Server")

        # MWScore ScoreServer.
        self.ScoreServer = MWScore.ScoreServer()

        # Menu Bar
        self.MenuBar = wx.MenuBar()
        self.FileMenu = wx.Menu()
        self.TransponderMenu = wx.Menu()
        self.SocketMenu = wx.Menu()
        self.MatchMenu = wx.Menu()

        self.FileMenu.Append(self.ID_QUIT, "Quit")
        self.Bind(wx.EVT_MENU, self.Quit, id=self.ID_QUIT)

        self.TransponderMenu.Append(self.ID_TRANSPONDERSETUP, "Setup")
        self.Bind(wx.EVT_MENU,
                  self.TransponderSetup,
                  id=self.ID_TRANSPONDERSETUP)

        self.SocketMenu.Append(self.ID_SOCKETSETUP, "Setup")
        self.Bind(wx.EVT_MENU, self.SocketSetup, id=self.ID_SOCKETSETUP)

        self.MatchMenu.Append(self.ID_MATCHSETUP, "Setup")
        self.MatchMenu.Append(self.ID_MATCHSTART, "Start/Resume")
        self.MatchMenu.Append(self.ID_MATCHPAUSE, "Pause")
        self.MatchMenu.Append(self.ID_MATCHRESET, "Reset")
        self.MatchMenu.Append(self.ID_MATCHRESETHP, "Reset HP")
        self.Bind(wx.EVT_MENU, self.MatchSetup, id=self.ID_MATCHSETUP)
        self.Bind(wx.EVT_MENU, self.MatchStart, id=self.ID_MATCHSTART)
        self.Bind(wx.EVT_MENU, self.MatchPause, id=self.ID_MATCHPAUSE)
        self.Bind(wx.EVT_MENU, self.MatchReset, id=self.ID_MATCHRESET)
        self.Bind(wx.EVT_MENU, self.MatchResetHP, id=self.ID_MATCHRESETHP)

        self.MenuBar.Append(self.FileMenu, "&File")
        self.MenuBar.Append(self.MatchMenu, "&Match")
        self.MenuBar.Append(self.TransponderMenu, "&Transponder")
        self.MenuBar.Append(self.SocketMenu, "&Socket")

        self.SetMenuBar(self.MenuBar)

        # Panel
        self.Panel = MatchPanel(self, -1)

        # Frame Update Timer
        self.Timer = wx.Timer(self, self.FRAME_UPDATE_TIMER_ID)
        self.Timer.Start(100)
        wx.EVT_TIMER(self, self.FRAME_UPDATE_TIMER_ID, self.OnTimer)

        self.Show(True)
        self.SetTitle("Mech Warfare Match Score")
Ejemplo n.º 6
0
    def MatchSetup(self, event):
        MatchLength = None
        MatchType = None
        NumTeams = None
        MatchRuleSet = None
        MechList = []
        try:
            f = open("last-match.pkl", "rb")
            data = pickle.load(f)
            f.close()
            MatchLength = data.get("MatchLength", MatchLength)
            MatchType = data.get("MatchType", MatchType)
            NumTeams = data.get("NumTeams", NumTeams)
            MatchRuleSet = data.get("MatchRuleSet", MatchRuleSet)
            MechList = data.get("MechList", MechList)
        except:
            print("Pickle Failed")
            pass
        data = {
            "MatchLength": MatchLength,
            "MatchType": MatchType,
            "NumTeams": NumTeams,
            "MatchRuleSet": MatchRuleSet,
            "MechList": MechList
        }
        dlg = MatchDialog(self, -1, data)

        if dlg.ShowModal() == wx.ID_OK:
            MatchLength = int(dlg.MatchLengthChoice.GetValue()) * 600
            if dlg.MatchTypeChoice.GetValue() == "Team":
                MatchType = MWScore.MATCH_TEAM
            else:
                MatchType = MWScore.MATCH_FFA
            if dlg.MatchRulesChoice.GetValue() == "Default":
                MatchRuleSet = 0
            if dlg.MatchRulesChoice.GetValue() == "Max HP Per Panel":
                MatchRuleSet = 1
            if dlg.MatchRulesChoice.GetValue() == "Healing":
                MatchRuleSet = 2
            if dlg.MatchRulesChoice.GetValue() == "Cooldown Increase":
                MatchRuleSet = 3
            NumTeams = int(dlg.NumTeamsChoice.GetValue())
            dlg.Destroy()
        else:
            dlg.Destroy()
            return

        MechList = []

        # Reset the Mech List
        self.ScoreServer.MechList.ResetMechs()

        if MatchType == MWScore.MATCH_TEAM:
            for t in xrange(NumTeams):
                dlg = TeamDialog(self, -1, "Team #" + str(t + 1) + " Setup")

                if dlg.ShowModal() == wx.ID_OK:
                    for s in dlg.MechChoice.GetSelections():
                        m = self.ScoreServer.MechList.MechByID(
                            int(dlg.MechChoice.GetString(s).split(":")[0]))
                        m.Team = t + 1
                        MechList.append(m)
                    dlg.Destroy()
                else:
                    dlg.Destroy()
                    return

        else:
            dlg = TeamDialog(self, -1, "FFA Mech Selection")
            if dlg.ShowModal() == wx.ID_OK:
                t = 1
                for s in dlg.MechChoice.GetSelections():
                    m = self.ScoreServer.MechList.MechByID(
                        int(dlg.MechChoice.GetString(s).split(":")[0]))
                    m.Team = t
                    MechList.append(m)
                    t += 1
                    dlg.Destroy()
            else:
                dlg.Destroy()
                return

                data = {
                    "MatchLength": MatchLength,
                    "MatchType": MatchType,
                    "NumTeams": NumTeams,
                    "MatchRuleSet": MatchRuleSet,
                    "MechList": MechList
                }
                f = open("last-match.pkl", "wb")
                pickle.dump(data, f)
                f.close()

                # Stop the frame update timer and current match thread.
                self.Timer.Stop()
                self.ScoreServer.Match.KillThread()

                # Create the new match.
                self.ScoreServer.Match = MWScore.Match(self.ScoreServer,
                                                       MatchType, MatchLength,
                                                       MatchRuleSet, MechList)

                # Destroy and recreate a new match panel.
                self.Panel.Destroy()
                self.Panel = MatchPanel(self, -1)

                # Resume the frame update timer.
                self.Timer.Start()

# start or resume a match

        def MatchStart(self, event):
            self.ScoreServer.Match.Start()

# Pause a match

        def MatchPause(self, event):
            self.ScoreServer.Match.Pause()

# Reset the match

        def MatchReset(self, event):
            try:
                self.ScoreServer.Match.Reset()
            except Exception as x:
                traceback.print_exc()
                wx.MessageBox("Exception in Reset:\r\n" + str(x), "Error",
                              wx.OK | wx.ICON_ERROR)

        # Reset the match
        def MatchResetHP(self, event):
            try:
                self.ScoreServer.Match.ResetHP()
            except Exception as x:
                traceback.print_exc()
                wx.MessageBox("Exception in Reset:\r\n" + str(x), "Error",
                              wx.OK | wx.ICON_ERROR)

# Opens dialog to configure to ScoreServer's SocketServer

        def SocketSetup(self, event):
            dlg = SocketServerDialog(self, -1)
            if dlg.ShowModal() == wx.ID_OK:
                self.ScoreServer.SocketServer.KillThread()
                self.ScoreServer.SocketServer = MWScore.SocketServer(
                    self.ScoreServer, dlg.HostChoice.GetValue(),
                    int(dlg.PortChoice.GetValue()))
            dlg.Destroy()

# Opens dialog to configure to ScoreServer's TransponderListener

        def TransponderSetup(self, event):
            dlg = TransponderDialog(self, -1)
            if dlg.ShowModal() == wx.ID_OK:
                self.ScoreServer.TransponderListener.KillThread()
                self.ScoreServer.TransponderListener = MWScore.TransponderListener(
                    self.ScoreServer, dlg.PortChoice.GetValue(),
                    int(dlg.BaudChoice.GetValue()))
                if not self.ScoreServer.TransponderListener.Xbee:
                    wx.MessageBox(
                        "Could not open Transponder port " +
                        ScoreServer.TransponderListener.Port, "Error",
                        wx.OK | wx.ICON_ERROR)
            dlg.Destroy()

        # Opens dialog to configure Transponder variables
        # Only works with 2018 Transponders
        def TransponderVar(self, event):
            dlg = TransponderVarDialog(self, -1)
            if dlg.ShowModal() == wx.ID_OK:
                if dlg.MatchRulesChoice.GetValue() == "Default":
                    MatchRuleSet = 0
                if dlg.MatchRulesChoice.GetValue() == "Max HP Per Panel":
                    MatchRuleSet = 1
                if dlg.MatchRulesChoice.GetValue() == "Healing":
                    MatchRuleSet = 2
                if dlg.MatchRulesChoice.GetValue() == "Cooldown Increase":
                    MatchRuleSet = 3
                self.ScoreServer.TransponderListener.WriteTransponderNewID(
                    int(dlg.CurrentIDChoice.GetValue()),
                    int(dlg.NewIDChoice.GetValue()))
                self.ScoreServer.TransponderListener.WriteTransponder(
                    int(dlg.NewIDChoice.GetValue()),
                    int(dlg.SetHpChoice.GetValue()), MatchRuleSet)
                if not self.ScoreServer.TransponderListener.Xbee:
                    wx.MessageBox(
                        "Could not open Transponder port " +
                        dlg.PortChoice.GetValue(), "Error",
                        wx.OK | wx.ICON_ERROR)
            dlg.Destroy()

        # Reset the match
        def TransponderHpUpdate(self, event):
            try:
                self.ScoreServer.Match.UpdateTransponderHP()
            except Exception as x:
                traceback.print_exc()
                wx.MessageBox("Exception in Transmit HP:\r\n" + str(x),
                              "Error", wx.OK | wx.ICON_ERROR)

# Kills all threads and closes the program

        def Quit(self, event):
            self.ScoreServer.KillAll()
            self.Close()
Ejemplo n.º 7
0
    def MatchSetup(self, event):

        MatchLength = None
        MatchType = None
        NumTeams = None
        MechList = []

        dlg = MatchDialog(self, -1)
        if dlg.ShowModal() == wx.ID_OK:
            MatchLength = int(dlg.MatchLengthChoice.GetValue()) * 600
            if dlg.MatchTypeChoice.GetValue() == "Team":
                MatchType = MWScore.MATCH_TEAM
            else:
                MatchType = MWScore.MATCH_FFA
            NumTeams = int(dlg.NumTeamsChoice.GetValue())
            dlg.Destroy()
        else:
            dlg.Destroy()
            return

        # Reset the Mech List
        self.ScoreServer.MechList.ResetMechs()

        if MatchType == MWScore.MATCH_TEAM:

            for t in xrange(NumTeams):
                dlg = TeamDialog(self, -1, "Team #" + str(t + 1) + " Setup")

                if dlg.ShowModal() == wx.ID_OK:

                    for s in dlg.MechChoice.GetSelections():
                        m = self.ScoreServer.MechList.MechByID(
                            int(dlg.MechChoice.GetString(s).split(":")[0]))
                        m.Team = t + 1
                        MechList.append(m)
                    dlg.Destroy()
                else:
                    dlg.Destroy()
                    return

        else:

            dlg = TeamDialog(self, -1, "FFA Mech Selection")

            if dlg.ShowModal() == wx.ID_OK:

                t = 1

                for s in dlg.MechChoice.GetSelections():
                    m = self.ScoreServer.MechList.MechByID(
                        int(dlg.MechChoice.GetString(s).split(":")[0]))
                    m.Team = t
                    MechList.append(m)
                    t += 1

                dlg.Destroy()

            else:
                dlg.Destroy()
                return

        # Stop the frame update timer and current match thread.
        self.Timer.Stop()
        self.ScoreServer.Match.KillThread()

        # Create the new match.
        self.ScoreServer.Match = MWScore.Match(self.ScoreServer, MatchType,
                                               MatchLength, MechList)

        # Destroy and recreate a new match panel.
        self.Panel.Destroy()
        self.Panel = MatchPanel(self, -1)

        # Resume the fram update timer.
        self.Timer.Start()
Ejemplo n.º 8
0
    def MatchSetup(self, event):

        MatchLength = None
        MatchType = None
        NumTeams = None
        MatchRuleSet = None
        MechList = []

        try:
            f = open("last-match.pkl", "rb")
            data = pickle.load(f)
            f.close()
            MatchLength = data.get("MatchLength", MatchLength)
            MatchType = data.get("MatchType", MatchType)
            NumTeams = data.get("NumTeams", NumTeams)
            MatchRuleSet = data.get("MatchRuleSet", MatchRuleSet)
            MechList = data.get("MechList", MechList)
        except:
            pass
        data = {
            "MatchLength": MatchLength,
            "MatchType": MatchType,
            "NumTeams": NumTeams,
            "MatchRuleSet": MatchRuleSet,
            "MechList": MechList
        }

        dlg = MatchDialog(self, -1, data)
        if dlg.ShowModal() == wx.ID_OK:
            MatchLength = int(dlg.MatchLengthChoice.GetValue()) * 600
            if dlg.MatchTypeChoice.GetValue() == "Team":
                MatchType = MWScore.MATCH_TEAM
            else:
                MatchType = MWScore.MATCH_FFA
            if dlg.MatchRulesChoice.GetValue() == "Default":
                MatchRuleSet = 0
            if dlg.MatchRulesChoice.GetValue() == "Max HP Per Panel":
                MatchRuleSet = 1
            if dlg.MatchRulesChoice.GetValue() == "Healing":
                MatchRuleSet = 2
            NumTeams = int(dlg.NumTeamsChoice.GetValue())
            dlg.Destroy()
        else:
            dlg.Destroy()
            return
        MechList = []

        # Reset the Mech List
        self.ScoreServer.MechList.ResetMechs()

        if MatchType == MWScore.MATCH_TEAM:

            for t in xrange(NumTeams):
                dlg = TeamDialog(self, -1, "Team #" + str(t + 1) + " Setup")

                if dlg.ShowModal() == wx.ID_OK:

                    for s in dlg.MechChoice.GetSelections():
                        m = self.ScoreServer.MechList.MechByID(
                            int(dlg.MechChoice.GetString(s).split(":")[0]))
                        m.Team = t + 1
                        MechList.append(m)
                    dlg.Destroy()
                else:
                    dlg.Destroy()
                    return

        else:

            dlg = TeamDialog(self, -1, "FFA Mech Selection")

            if dlg.ShowModal() == wx.ID_OK:

                t = 1

                for s in dlg.MechChoice.GetSelections():
                    m = self.ScoreServer.MechList.MechByID(
                        int(dlg.MechChoice.GetString(s).split(":")[0]))
                    m.Team = t
                    MechList.append(m)
                    t += 1

                dlg.Destroy()

            else:
                dlg.Destroy()
                return

        data = {
            "MatchLength": MatchLength,
            "MatchType": MatchType,
            "NumTeams": NumTeams,
            "MatchRuleSet": MatchRuleSet,
            "MechList": MechList
        }
        f = open("last-match.pkl", "wb")
        pickle.dump(data, f)
        f.close()

        # Stop the frame update timer and current match thread.
        self.Timer.Stop()
        self.ScoreServer.Match.KillThread()

        # Create the new match.
        self.ScoreServer.Match = MWScore.Match(self.ScoreServer, MatchType,
                                               MatchLength, MatchRuleSet,
                                               MechList)

        # Destroy and recreate a new match panel.
        self.Panel.Destroy()
        self.Panel = MatchPanel(self, -1)

        # Resume the fram update timer.
        self.Timer.Start()
Ejemplo n.º 9
0
def main(server):
    print("Connecting to host: " + server)
    conn = MWScore.SocketClient(server, 2525, fn)
    # run whatever GUI you want here
    time.sleep(10)
    conn.ThreadKill = True