예제 #1
0
파일: main.py 프로젝트: vranki/lazortouch
class LazorTouch:
	def __init__(self):
		self.laser_ready = False
		self.vplayer = VideoPlayer()
		self.laser = Laser()
		self.buttons = None
		self.oldbuttons = None
# poll interval in msec. 40 would be good in use, 1000 when testing
		gobject.timeout_add(1000, self.poll_laser)

	def poll_laser(self):
		if not self.laser_ready:
			self.laser_ready = self.laser.is_ready()
#			print 'poll - laser not ready'
			return True
		self.oldbuttons = self.buttons
		self.buttons = self.laser.scan()
		if(self.oldbuttons is None):
			self.oldbuttons = self.buttons
#		print 'poll - buttons: ' + str(self.buttons)
		for i in range(len(self.buttons)):
#			print 'idx ' + str(i) + " is " + str(self.buttons[i]) + " was " + str(self.oldbuttons[i])
			if self.oldbuttons[i] is 0 and self.buttons[i] is 1:
				self.button_pressed(i)
		return True

	def button_pressed(self, number):
		print 'button ' + str(number) + " pressed!"
		self.vplayer.play_video(number)
예제 #2
0
파일: main.py 프로젝트: vranki/lazortouch
	def __init__(self):
		self.laser_ready = False
		self.vplayer = VideoPlayer()
		self.laser = Laser()
		self.buttons = None
		self.oldbuttons = None
# poll interval in msec. 40 would be good in use, 1000 when testing
		gobject.timeout_add(1000, self.poll_laser)
예제 #3
0
    def __init__(self, parent, size, clbEnd = None, eventparent = None):
        """Initiate the player
        
        Arguments
        parent -- the parent frame of this player
        size -- a tuple containing the size of this player
        clbEnd -- a callback that will be called when a media item has stopped playing
        eventparent -- Tkinter object used for binding and generating events

        """
        #Initiate widget
        tki.Frame.__init__(self, parent, width = size[0], height = size[1], bg="black")
        #self.grid(row = 0, column = 0)
        self.grid_propagate(0)
        self.rowconfigure(0, weight = 1)
        self.columnconfigure(0, weight = 1)
        
        self._clbEnd = clbEnd
        self._currentMediaType = ''
        self._clbClicked = None
        
        if(eventparent is not None):
            self._eventparent = eventparent
        else:
            self._eventparent = parent
            
        l = tki.Label(self, bd = 0, highlightthickness = 0)
        l.bind("<Button-1>", self._ehClick)
        self._il = l
        
        v = VideoPlayer(self, size[0], size[1])
        v.bind("<Button-1>", self._ehClick)
        self._video = v
        
        self._media = None
        
        self._initSound()
예제 #4
0
from flask import Flask, render_template, redirect, url_for, session, request
from flask_bootstrap import Bootstrap

from youtube import YouTubeApi
from videoplayer import VideoPlayer

api = YouTubeApi()
player = VideoPlayer()

users = {"admin": {"username": "******", "password": "******"}}
host = {"localhost": "127.0.0.1", "networkhost": "0.0.0.0"}


class Webserver():
    app = Flask(__name__,
                static_url_path='/static',
                template_folder='templates')
    Bootstrap(app)

    def __init__(self, playlist):
        player.init(playlist)

# sites

    @app.route('/')
    @app.route('/index')
    def index(self=None):
        return render_template('index.html')

    @app.route('/admin')
    def admin(self=None):
예제 #5
0
    blank[480:720, :] = (0, 0, 0xff)
    cv2.imshow("test", blank)
    cv2.waitKey(0)
    exit()


def attach_audio(afile, vfile):
    os.system(
        f"ffmpeg -i {vfile} -i {afile} -c copy -map 0:v:0 -map 1:a:0 final_{vfile}"
    )


# test()

main_video = VideoClip(_G.SourceFilename)
player = VideoPlayer(main_video, _G.TrackbarName, _G.SourceFilename)


def main_loop():
    player.start()
    while not _G.FLAG_STOP and not player.is_ended():
        player.update()


def terminate():
    videoclip.termiante()
    cv2.destroyAllWindows()


main_loop()
terminate()
예제 #6
0
파일: test.py 프로젝트: adamhb123/PygMov
import pygame
from videoplayer import VideoPlayer
import random

pygame.init()
# todo create GUOI bindings

screen = pygame.display.set_mode((500, 500))
video = VideoPlayer("a.mp4",
                    path="resources",
                    resolution=(500, 500),
                    position=(0, 0))
print(video.video_data)
video.play()
# try multiprocessing
clock = pygame.time.Clock()
press = False
lowest = 100000
highest = 0
loops = 0
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            print(highest)
            print(lowest)
            pygame.quit()
            quit()

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_s:
                if video.isplaying:
예제 #7
0
 def __init__(self):
     app = QApplication(sys.argv)
     app.setApplicationName('OpenDev Player')
     player = VideoPlayer()
     player.show()
     app.exec_()
예제 #8
0
    def __init__(self, glade_file, css_file, dir_config):
        VideoPlayer.__init__(self)

        # store init parameters
        self.glade_file = glade_file
        self.css_file = css_file
        self.dir_config = dir_config

        # set up Glade builder
        builder = Gtk.Builder()
        builder.add_from_file(glade_file)
        builder.connect_signals(self)
        self.builder = builder

        # get elements by ID
        self.video_store = builder.get_object("video_store")
        self.kinematic_store = builder.get_object("kinematic_store")
        self.gesture_store = builder.get_object("gesture_store")
        self.main_window = builder.get_object("main_window")
        self.scale_video_position = builder.get_object("scale_video_position")
        self.video_player = builder.get_object("video_player")
        self.label_subject = builder.get_object("label_subject")
        self.gesture_diagram_box = builder.get_object("gesture_diagram_box")
        self.gesture_playlist_selection = builder.get_object("gesture_playlist_selection")
        self.export_dialog = builder.get_object("export_dialog")
        self.export_query = builder.get_object("export_query")
        self.export_filetype_default = builder.get_object("export_filetype_default")

        self.ksp_checkbuttons = builder.get_object("ksp_box").get_children()

        # gui styling
        css_provider = Gtk.CssProvider()
        css_provider.load_from_path(css_file)
        style_context = self.main_window.get_style_context()
        screen = self.main_window.get_screen()
        style_context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

        # gui binding
        self.register("video_name", self.main_window, set_converter=lambda x: '{} - staej'.format(x) if x else 'staej')
        self.register_widget("task_name", "label_task_name")
        self.register_widget("video_name", "label_video_name")
        self.register_widget("video_length", "label_video_length", set_converter=framesToMinutesStr)
        self.register_widget("video_position", "scale_video_position")
        self.register_widget("video_search", "entry_video_search")

        playpause_image = builder.get_object("button_playpause").get_child()
        self.register("video_playing", lambda value: playpause_image.set_from_icon_name(
            'media-playback-pause' if value else 'media-playback-start', Gtk.IconSize.BUTTON))

        self.register("app_status", builder.get_object("status").get_children()[0].get_child().get_children()[0])
        self.app_status = READY

        getGestureConverter = lambda n, f = str, d = '' : lambda value :\
            ([f(x[n] if n else i) for i, x in enumerate(self.gesture_spans) if
            x[GESTURE_START] <= value // Gst.FRAME <= x[GESTURE_END]] or [d])[0]
        self.getGestureIndex = getGestureConverter(None, int, 0)

        self.register_widget("video_position", "current_gesture_name", set_converter=getGestureConverter(GESTURE_NAME))
        self.register_widget("video_position", "current_gesture_start",
                             set_converter=getGestureConverter(GESTURE_START, framesToMinutesStr))
        self.register_widget("video_position", "current_gesture_end",
                             set_converter=getGestureConverter(GESTURE_END, framesToMinutesStr))
        self.register("video_position", self.updateTime)

        self.register_widget("export_filename_filter")
        self.register_widget("export_filename_filter_regex")

        # gui additional
        self.live_diagram = livediagram.LiveDiagram(builder.get_object("live_diagram"))
        self.gesture_plot = TrajectoryPlot().pack_into(self.gesture_diagram_box)
        self.main_window.show_all()


        # set up video store filter
        self.video_store.filter = self.video_store.filter_new()
        builder.get_object("treeview_video").set_model(self.video_store.filter)
        self.video_store.filter.set_visible_func(self.videoStoreFilter)

        # get task list
        self.tasks = dict()
        for task in model.database.Task.select():
            self.tasks[task.id] = task.name

        # fill list view with video names
        root_iter = self.video_store.get_iter_first()
        video_store_tasks = dict()
        for task_id in self.tasks :
            video_store_tasks[task_id] = self.video_store.append(root_iter, [self.tasks[task_id], task_id, False])
        for video in model.database.Video.select():
            if video.file_name :
                self.video_store.append(video_store_tasks[video.task_id], [video.file_name, video.id, True])

        # set up gesture dict
        self.gestures = dict()
        for x in model.database.Gesture.select():
            self.gestures[x.id] = x.description
        self.gesture_spans = list()

        # kinematics
        self.kinematics = dict()

        # which kinematics trajectory to display (MTM or PSM; MTM is default)
        self.arm_type = 'mtm'

        # finalization
        self.main_window.show_all()
        self.main_window.maximize()
        self.main_window.set_title('staej')
        self.onKspToggled(checkbox_only=True)

        # init export dialog
        self.export_dialog.set_transient_for(self.main_window)
        self.export_dialog.set_modal(self.main_window)
        #self.export_dialog.run()
        #self.export_dialog.hide()
        self.export_accordion = Accordion(self.builder.get_object('export_builder_accordion'), True)
예제 #9
0
파일: main.py 프로젝트: deciament/software
    def __init__(self):
        self.init = False
        self.gladefile = os.path.join(__location__, "gui/cave.glade")
        self.builder = Gtk.Builder()
        self.builder.add_from_file(self.gladefile)

        # Automatically connect signals to functions defined above
        self.builder.connect_signals(self)

        #Set up the video tree
        self.video_tree = self.builder.get_object("videoTreeView")
        self.video_tree_manager = VideoTreeManager(self.video_tree, self)

        #Set up the filter box
        self.filter_box = self.builder.get_object("filterEntry")

        #Create & link video display widget
        self.video_box_container = self.builder.get_object("videoBox")
        self.video_box = VideoBox(self)
        self.video_box.show()
        self.video_box_container.pack_start(self.video_box, True, True, 0)

        #Create & Link timeline widget
        self.timeline_box = self.builder.get_object("timelineBox")
        self.timeline = Timeline(self)
        self.timeline.show()
        self.timeline_box.pack_start(self.timeline, True, True, 0)

        self.timeline.cursor_change = self._change_frame  #Register listener

        self.video_box.length_listener = self.timeline.set_length  #Register listener

        #Initialize shared memory blocks for all cameras
        CameraLink.preinit()

        #Log playback
        filter_file = os.path.expanduser(args.filter) if args.filter else ''
        self.logplayer = LogPlayer(filter=filter_file)

        # Get the main window
        self.window = self.builder.get_object("caveWindow")
        self.window.show()

        #Initialize gtk's thread engine; add any threads after these lines
        Gdk.threads_init()
        GLib.threads_init()

        #Start video player thread
        self.video_player = VideoPlayer(self)
        self.play_button = self.builder.get_object("playButton")

        self.enable_button = self.builder.get_object("enableButton")
        self.toggle_all_button = self.builder.get_object("toggleAllButton")

        #Start video rendering thread
        self.video_box.start_thread()

        #Start video preview manager
        self.video_preview_manager = VideoPreviewManager(
            self.video_box.vmt)  #link w/ video manager thread
        self.video_preview_manager.register_callback(
            self.timeline.preview_callback)
        self.timeline.set_preview_manager(self.video_preview_manager)

        #Create statusbar display thread
        self.statusbar = StatusBarManager(self.builder.get_object("statusBar"))
        self.statusbar.display("Welcome to CAVE!", 2)

        self.db = None

        self.loop_button = self.builder.get_object("loopButton")

        #Load database file from arguments if present
        if args.database:
            self.load_db(args.database)
        elif os.path.exists(os.path.expanduser(self.config_file)):
            f = open(os.path.expanduser(self.config_file), "r")
            self.load_db(f.read())

        #Ctrl+C handling
        def handler(signum, frame):
            self.log.warning("INTERRUPT; stopping CAVE")
            self.window_destroy(None)

        signal.signal(signal.SIGTERM, handler)
        signal.signal(signal.SIGINT, handler)

        #This fairly pointless function is necessary to periodically wake up
        #the gtk main thread to detect system interrupts even when not focused
        #I believe this is due to a Gtk bug
        GLib.timeout_add(500, lambda: True)

        #Make the window more shrinkable
        self.window.set_size_request(400, 400)

        #Fire up the main window
        self.log.info("Launching GUI. Welcome to CAVE!")
        self.init = True
        Gdk.threads_enter()
        Gtk.main()
        Gdk.threads_leave()
예제 #10
0
    global ix, iy, drawing, mode
    #Click
    if event == cv2.EVENT_LBUTTONDOWN:
        drawing = True
        ix, iy = x, y
        print("ix=", ix, "iy=", iy)

    elif event == cv2.EVENT_LBUTTONUP:
        drawing = False
        if mode == True:
            print("fx=", x, "fy=", y)
            cv2.rectangle(frame, (ix, iy), (x, y), (0, 255, 255), 1)


player = VideoPlayer("video.mp4")

global px, py
drawing = False  # true if mouse is pressed
mode = True  # if True, draw rectangle. Press 'm' to toggle to curve
ix, iy = -1, -1

cv2.namedWindow('frame')
cv2.setMouseCallback('frame', draw_circle)

if __name__ == '__main__':
    # 下面是使用PyQt5的固定用法
    app = QApplication(sys.argv)
    main_win = mainWin()
    while (1):
        if player.isStop == False:
예제 #11
0
import numpy as np
import re
import time

from videograbber import VideoGrabber
from videoplayer import VideoPlayer
import logger as Logger
# import encoder as encoder
# import buttons as buttons

log = Logger.new()

cam = VideoGrabber(0)
cam.start()

player = VideoPlayer(1)
player.start()

# available outputs to be rendered
outputs = [cam, player]
# output index
output = outputs[1]

draw_text = True


def destroy(args):
    """Exit the program."""
    log.info("Closing app.")
    cam.stop()
    player.stop()
예제 #12
0
    def __init__(self):
        '''Initializes the client.'''

        self.mode = "client"

        self.oP = OutPipe("Client", 0)

        self.eI = EngineInterface(objectMode=True)
        self.vP = VideoPlayer()
        self.sE = ScriptExecuter()
        self.iR = InputReceiver()
        self.l = Localizer(self)
        self.pA = PhysicsApplicator(self)
        self.sH = ShaderHandler()
        self.nC = None

        self.sE.addContext("Client", self)

        self.cvars = {
            #Low level settings
            "cl_update": 1,
            "cl_synced": 0,
            "cl_addr": "0.0.0.0",
            "cl_oport": 7777,
            "cl_iport": 7778,
            "cl_netlog": 0,
            "cl_game": 0,
            "cl_startscript": "",
            "cl_master": 0,
            "cl_predict": 1,
            "cl_smooth": 0,
            "cl_name": "Player",
            "cl_password": "",
            "cl_camera": "",
            "cl_lockcontrols": 1,
            "cl_showmouse": 1,
            "cl_xsens": 50,
            "cl_ysens": 50,
            "cl_inverted": 0,
            "cl_netping": 0,

            #High level settings
            "cl_language": "en",
            "cl_subtitles": 1,
            "cl_width": 1280,
            "cl_height": 720,
            "cl_fullscreen": 0,
            "cl_motionblur": 0,
            "cl_motionblur_amount": 0,
            "cl_anisotropic": 1,
            "cl_mipmap": "none",
            "cl_vsync": "off",
            "cl_musicvolume": 10,
            "cl_dialogvolume": 10,
            "cl_soundvolume": 10,
            "cl_mastervolume": 10,

            #Server shared settings
            "sv_level": "",
            "sv_gamemode": "",
            "sv_game": 0,
            "sv_background_red": 0,
            "sv_background_green": 0,
            "sv_background_blue": 0,
            "sv_background_alpha": 0,
        }

        self.netVars = {}

        self.chatMessages = []

        self.interfaces = []
        self.entities = []
        self.level = None

        self.gameEvents = []
        self.updateNetwork()

        #self.startLoop()
        self.forceUpdateCVars()

        self.keepAliveTicker = 0
        self.trackedProperties = []

        loadClient(self)

        self.oP("Initialized.")
예제 #13
0
class Client(GameSide):
    def __init__(self):
        '''Initializes the client.'''

        self.mode = "client"

        self.oP = OutPipe("Client", 0)

        self.eI = EngineInterface(objectMode=True)
        self.vP = VideoPlayer()
        self.sE = ScriptExecuter()
        self.iR = InputReceiver()
        self.l = Localizer(self)
        self.pA = PhysicsApplicator(self)
        self.sH = ShaderHandler()
        self.nC = None

        self.sE.addContext("Client", self)

        self.cvars = {
            #Low level settings
            "cl_update": 1,
            "cl_synced": 0,
            "cl_addr": "0.0.0.0",
            "cl_oport": 7777,
            "cl_iport": 7778,
            "cl_netlog": 0,
            "cl_game": 0,
            "cl_startscript": "",
            "cl_master": 0,
            "cl_predict": 1,
            "cl_smooth": 0,
            "cl_name": "Player",
            "cl_password": "",
            "cl_camera": "",
            "cl_lockcontrols": 1,
            "cl_showmouse": 1,
            "cl_xsens": 50,
            "cl_ysens": 50,
            "cl_inverted": 0,
            "cl_netping": 0,

            #High level settings
            "cl_language": "en",
            "cl_subtitles": 1,
            "cl_width": 1280,
            "cl_height": 720,
            "cl_fullscreen": 0,
            "cl_motionblur": 0,
            "cl_motionblur_amount": 0,
            "cl_anisotropic": 1,
            "cl_mipmap": "none",
            "cl_vsync": "off",
            "cl_musicvolume": 10,
            "cl_dialogvolume": 10,
            "cl_soundvolume": 10,
            "cl_mastervolume": 10,

            #Server shared settings
            "sv_level": "",
            "sv_gamemode": "",
            "sv_game": 0,
            "sv_background_red": 0,
            "sv_background_green": 0,
            "sv_background_blue": 0,
            "sv_background_alpha": 0,
        }

        self.netVars = {}

        self.chatMessages = []

        self.interfaces = []
        self.entities = []
        self.level = None

        self.gameEvents = []
        self.updateNetwork()

        #self.startLoop()
        self.forceUpdateCVars()

        self.keepAliveTicker = 0
        self.trackedProperties = []

        loadClient(self)

        self.oP("Initialized.")

    def forceUpdateCVars(self):
        '''Forces all the cVars to run their updaters as though they had just been set.'''
        for key in self.cvars.keys():
            if not "sv_" == key[:3]:
                self.configure(key, self.get(key), override=True)
        self.oP("Force updated cVars.")

    def configure(self, key, val, fromServer=False, override=False):
        '''Configure a cVar.'''
        changed = False

        if key in self.cvars.keys() and (not "sv_" == key[:3] or fromServer):
            #Switch for int
            if type(self.cvars[key]) == type(0):
                val = int(val)

            #Used for functions
            if type(self.cvars[key]) == type(self.configure):
                self.cvars[key](val)
                self.oP("CVar %s executed." % key)
            else:
                if val != self.cvars[key] or override:
                    changed = True
                    self.cvars[key] = val
                    self.oP("CVar %s configured to %s (%s)." %
                            (key, val, str(type(val)).replace(
                                "<class '", "").replace("'>", "")))
        elif "sv_" == key[:3] and not fromServer and key in self.cvars.keys(
        ) and self.cvars[key] != val:
            self.sendEvent(["SYSTEM", "CVARS", [key, val]])
            self.oP("Asking server to change CVar %s." % key)
        else:
            self.oP("CVar %s not present." % key)

        if changed:
            self.updateGame(key)

    def connectGame(self):
        '''Connects to a game.'''
        self.oP("Connecting to game.")
        self.nC.connect((self.get("cl_addr"), self.get("cl_oport")))
        self.configure("cl_game", 1)
        self.configure("cl_synced", 0)

    def disconnectGame(self):
        '''Disconnects from a game.'''
        self.oP("Disconnecting from a game.")
        self.updateNetwork()
        self.configure("cl_game", 0)
        self.configure("cl_synced", 0)
        self.configure("cl_update", 1)
        self.oP("Disconnected from game.")

    def updateGame(self, key):
        '''Reacts to changes to the cVars.'''
        if key == "cl_startscript":
            self.sE.addContext("Client", self)
            self.sE.execute(self.get("cl_startscript"))

        elif key in ["cl_iport"]:
            self.updateNetwork()

        elif key == "cl_addr":
            if self.get("cl_addr") == "0.0.0.0":
                self.configure("cl_addr", "127.0.0.1")

        elif key == "cl_name":
            self.sendEvent(["SYSTEM", "NAME", self.get("cl_name")])

        elif key == "sv_level" and not self.get("cl_master"):
            if self.get("sv_game"):
                self.setLevel(self.get("sv_level"))

        elif key == "sv_game" and not self.get("cl_master"):
            if self.get("sv_game"):
                self.setLevel(self.get("sv_level"))
            else:
                self.endLevel()

        elif key in [
                "sv_background_red", "sv_background_green",
                "sv_background_blue", "sv_background_alpha"
        ] and not self.get("cl_master"):
            self.eI.setBackgroundColor((self.getBackgroundColor()))

        elif key == "cl_width" or key == "cl_height":
            self.eI.setResolution(self.get("cl_width"), self.get("cl_height"))
        elif key == "cl_fullscreen":
            self.eI.setFullscreen(self.get("cl_fullscreen"))
        elif key == "cl_motionblur" or key == "cl_motionblur_amount":
            self.eI.setMotionBlur(self.get("cl_motionblur"),
                                  self.get("cl_motionblur_amount"))
        elif key == "cl_anisotropic":
            self.eI.setAnisotropic(self.get("cl_anisotropic"))
        elif key == "cl_mipmap":
            self.eI.setMipmapping(self.get("cl_mipmap"))
        elif key == "cl_vsync":
            self.eI.setVSync(self.get("cl_vsync"))
        elif key == "cl_camera" and self.get("cl_camera") != "":
            self.eI.setCamera(self.get("cl_camera"))

        elif key == "cl_mastervolume":
            launcher = self.eI.getGlobal("launcher")

            if launcher:
                launcher.sound.setMasterVolume(self.get("cl_mastervolume"))

        elif key == "cl_musicvolume":
            launcher = self.eI.getGlobal("launcher")

            if launcher:
                launcher.sound.setMusicVolume(self.get("cl_musicvolume"))

        elif key == "cl_dialogvolume":
            launcher = self.eI.getGlobal("launcher")

            if launcher:
                launcher.sound.setDialogVolume(self.get("cl_dialogvolume"))

        elif key == "cl_soundvolume":
            launcher = self.eI.getGlobal("launcher")

            if launcher:
                launcher.sound.setSoundVolume(self.get("cl_soundvolume"))

        elif key == "cl_subtitles":
            launcher = self.eI.getGlobal("launcher")

            if launcher:
                launcher.sound.subtitles = self.get("cl_subtitles")

        elif key == "cl_language":
            launcher = self.eI.getGlobal("launcher")

            if launcher:
                launcher.sound.language = self.get("cl_language")

        elif key == "cl_lockcontrols":
            self.iR.locked = self.get("cl_lockcontrols")

        elif key == "cl_showmouse":
            self.eI.setMouseState(self.get("cl_showmouse"))

        elif key == "cl_xsens":
            self.iR.xsens = self.get("cl_xsens")

        elif key == "cl_ysens":
            self.iR.ysens = self.get("cl_ysens")

        elif key == "cl_inverted":
            self.iR.inverted = self.get("cl_inverted")

        elif key == "cl_predict":
            self.iR.predict = self.get("cl_predict")

            if not self.get("cl_predict"):
                for GUID in self.pA.blacklistedGUIDs:
                    self.removeFromRotationBlacklist(GUID)

        elif key == "cl_smooth":
            self.pA.smooth = self.get("cl_smooth")

        elif key == "cl_netlog":
            if self.get("cl_netlog"):
                self.nC.configure("DEBUG", True)
                self.nC.configure("VERBOSE", True)
            else:
                self.nC.configure("DEBUG", False)
                self.nC.configure("VERBOSE", False)

        elif key == "cl_netping":
            self.nC.pingcount = self.get("cl_netping")

    def updateNetwork(self):
        '''Update the network module for changes to port or addr'''
        self.purgeNetwork()

        self.nC = NetCore()
        if self.get("cl_netlog"):
            self.nC.configure("DEBUG", True)
            self.nC.configure("VERBOSE", True)
        else:
            self.nC.configure("DEBUG", False)
            self.nC.configure("VERBOSE", False)

        self.nC.pingcount = self.get("cl_netping")

        self.nC.configure("NAME", "Client")
        self.nC.setProtocol("UDP")
        self.nC.configure("PORT", self.get("cl_iport"))
        self.nC.initialize()

    def purgeNetwork(self):
        '''Destroys the NetCore once and for all.'''
        if self.nC:
            self.nC.clear()
            self.nC.destroy()
            self.nC = None

    def startGameRemote(self):
        '''Used to connect to another person's game.'''
        self.oP("Starting game (remote)...")
        self.configure("cl_master", 0)
        self.configure("cl_update", 1)
        self.configure("cl_predict", 1)

        self.connectGame()

    def startGameFull(self):
        '''Used if you want the lobby when you start up a game.'''
        self.oP("Starting game (full)...")
        self.configure("cl_master", 1)
        self.configure("cl_update", 0)
        self.configure("cl_predict", 0)

        launcher = self.eI.getGlobal("launcher")

        if launcher:
            launcher.bootServer()
            self.oP("Booted server from client (Full).")
            self.configure("cl_addr", launcher.s.get("sv_addr"))
            self.connectGame()

    def startGameFast(self, level, gamemode, singleplayer=True):
        '''Used if you want to go straight to the game, usually used for singleplayer.'''
        self.oP("Starting game (fast)...")
        self.configure("cl_master", 1)
        self.configure("cl_update", 0)
        self.configure("cl_predict", 0)
        self.configure("cl_game", 1)

        self.updateNetwork()

        launcher = self.eI.getGlobal("launcher")

        if launcher:
            launcher.bootServer()
            self.oP("Booted server from client (Fast).")
            launcher.s.configure("sv_level", level)
            launcher.s.configure("sv_gamemode", gamemode)
            launcher.s.configure("sv_game", 1)
            if singleplayer:
                launcher.s.configure("sv_singleplayer", 1)
            else:
                launcher.s.configure("sv_singleplayer", 0)
            self.configure("cl_addr", launcher.s.get("sv_addr"))
            self.connectGame()

    def endGame(self):
        '''Ends the game instance and disconnects.'''
        self.oP("Ending game session...")
        self.disconnectGame()

        self.endLevel()

        launcher = self.eI.getGlobal("launcher")

        if launcher and self.get("cl_master") and launcher.s:
            launcher.s.quitGame()
            launcher.s = None

    def quitGame(self):
        '''Quits the game completely.'''
        self.oP("Shutting down...")
        self.endGame()
        self.purgeNetwork()
        self.eI.quitGame()

    def setMusic(self, music):
        '''Sets the music track.'''
        launcher = self.eI.getGlobal("launcher")

        launcher.sound.playMusic(music)
        self.oP("Set music to %s." % music)

    def stopMusic(self):
        '''Stops the music track.'''
        launcher = self.eI.getGlobal("launcher")

        launcher.sound.stopMusic()
        self.oP("Stopped music.")

    def playSound(self, sound, emitter=None):
        '''Plays the sound.'''
        launcher = self.eI.getGlobal("launcher")

        if emitter:
            launcher.sound.playSound(sound, emitter.gameObject)
        else:
            launcher.sound.playSound(sound)

        self.oP("Started playing sound %s." % sound)

    def stopSound(self, handle):
        '''Stops a sound.'''
        launcher = self.eI.getGlobal("launcher")

        GUID, name = launcher.sound.stopSound(handle)

        self.oP("Stopped sound %s." % name)

    def stopSoundByGUID(self, GUID, name):
        '''Stops a sound.'''
        launcher = self.eI.getGlobal("launcher")

        launcher.sound.stopSoundByGUID(GUID, name)
        self.oP("Stopped sound %s." % name)

    def playDialog(self, sound, emitter):
        '''Plays a dialog line.'''
        launcher = self.eI.getGlobal("launcher")

        if emitter:
            launcher.sound.playDialog(sound, emitter.gameObject)
        else:
            launcher.sound.playDialog(sound)

        self.oP("Playing dialog %s." % sound)

    def stopDialog(self, handle):
        '''Stops a dialog line.'''
        launcher = self.eI.getGlobal("launcher")

        GUID, name = launcher.sound.stopDialog(handle)

        self.oP("Stopped dialog %s." % name)

    def stopDialogByGUID(self, GUID, name):
        '''Stops a dialog line.'''
        launcher = self.eI.getGlobal("launcher")

        launcher.sound.stopDialogByGUID(GUID, name)

        self.oP("Stopped dialog %s." % name)

    def enableShader(self, index, name, mode):
        '''Enables a shader as a filter for the entire screen.'''
        self.sH.enableShader(index, name, mode)

    def disableShader(self, index):
        '''Disables a shader that was filtering the entire screen.'''
        self.sH.disableShader(index)

    def playVideo(self, video):
        '''Plays a video.'''
        self.vP.playVideo(video)
        self.oP("Started video %s." % video)

    def stopVideo(self):
        '''Stops a video.'''
        self.vP.stopVideo()
        self.oP("Stopped video.")

    def replaceMesh(self, ent, meshName):
        '''Replaces the mesh of an Entity.'''
        cR = self.load("Mesh", meshName)

        name = cR.get("name")
        resourcePath = cR.get("resourcePath")

        self.loadLibrary("Mesh", resourcePath, mesh=True)

        ent.gameObject.replaceMesh(meshName, True, True)
        self.oP("Replaced mesh of %s with %s." % (ent.GUID, meshName))

    def addInterface(self, name):
        '''Adds an interface.'''
        if not self.getInterfaceByName(name):
            cR = self.load("UI", name)

            name = cR.get("name")
            resource = cR.get("resourcePath")
            scriptName = cR.get("scriptPath")

            #self.loadLibrary("UI", resource)

            self.oP("Creating interface %s." % name)
            self.interfaces.append(Interface(name, resource, scriptName))
        else:
            self.oP("Interface %s already exists, not created." % name)

    def removeInterface(self, name):
        '''Removes an interface.'''
        interface = self.getInterfaceByName(name)

        if interface:
            self.oP("Removing interface %s." % name)
            self.interfaces.remove(interface)
            interface.kill()

    def removeAllInterfaces(self):
        '''Removes all interfaces.'''
        self.oP("Removing all interfaces.")
        names = []
        for interface in self.interfaces:
            names.append(interface.name)

        for name in names:
            self.removeInterface(name)

    def getInterfaceByName(self, name):
        '''Gets an interface by name.'''
        for interface in self.interfaces:
            if interface.name == name:
                return interface

    def addMarker(self, name, GUID):
        '''Adds a marker tracking the specified Entity.'''
        cR = self.load("UI", name)

        name = cR.get("name")
        resource = cR.get("resourcePath")

        self.eI.getGlobal("addToWaypoints")(resource, name, GUID)

        self.oP("Added waypoint %s tracking %s." % (name, GUID))

    def removeMarker(self, GUID):
        '''Removes all markers tracking an Entity.'''
        for obj in self.eI.getWaypointsScene().objects:
            if "targetGUID" in obj and obj["targetGUID"] == GUID:
                obj.endObject()

        self.oP("Removed waypoints tracking %s." % GUID)

    def inputClick(self, keyCode, pos):
        '''Checks for the interface clicks.'''
        obj, scene = self.eI.getMouseOverObjectScene(pos)

        if obj and scene:
            for interface in self.interfaces:
                if interface.name == self.eI.getTerminalParent(obj).name:
                    interface.onClick(obj.name)
                    return True

            for i in self.entities:
                if obj == i.gameObject or obj in i.gameObject.childrenRecursive:
                    i.onClick(obj.name)
                    return True

        return False

    def getDisconnectReaction(self):
        '''Gets the reaction function for disconnecting from the server.'''
        self.sE.execute(NETSCRIPT_PATH + "disconnect")
        return self.disconnectReaction

    def addToRotationBlacklist(self, GUID):
        '''Adds a GUID to the rotation blacklist.'''
        if not GUID in self.pA.blacklistedGUIDs:
            self.pA.blacklistedGUIDs.append(GUID)

    def removeFromRotationBlacklist(self, GUID):
        '''Removes a GUID from the rotation blacklist.'''
        if GUID in self.pA.blacklistedGUIDs:
            self.pA.blacklistedGUIDs.remove(GUID)

    def sendInterfaceEvent(self, event, aux=None):
        '''Sends an interface event.'''
        self.sendEvent(["INPUT", "INTERFACE", [event, aux]])

    def sendChatMessage(self, msg):
        '''Sends a chat message.'''
        self.sendEvent(["SYSTEM", "CHAT", msg])

    def sendGameEvent(self, mode, data):
        '''Sends a game event.'''
        self.sendEvent(["GAME", mode, data])

    def sendEvent(self, event):
        '''Sends an event to the server.'''
        if event[0] == "INPUT" or event == "KEEPALIVE":
            mode = "FAF"
        elif event[0] in ["SYSTEM", "GAME", "NETWORK"]:
            mode = "RT"

        if self.nC.clients:
            server = self.nC.clients[0]
            server.send(event, mode)

    def recvEvent(self, event):
        '''Handles an event from the server.'''
        if event[0] == "PHYSICS" and self.get("cl_update"):
            self.pA.update(event)
        if event[0] == "SYSTEM":
            if event[1] == "CVARS":
                self.configure(event[2][0], event[2][1], fromServer=True)
            elif event[1] == "NETVARS":
                self.netVars[event[2][0]] = event[2][1]

            elif event[1] == "SOUND_PLAY" and self.get("cl_update"):
                entity = self.getEntityByGUID(event[2][0])
                self.playSound(event[2][1], entity)
            elif event[1] == "SOUND_STOP" and self.get("cl_update"):
                self.stopSoundByGUID(event[2][0], event[2][1])

            elif event[1] == "DIALOG_PLAY" and self.get("cl_update"):
                entity = self.getEntityByGUID(event[2][0])
                self.playDialog(event[2][1], entity)
            elif event[1] == "DIALOG_STOP" and self.get("cl_update"):
                self.stopDialogByGUID(event[2][0], event[2][1])

            elif event[1] == "MUSIC_PLAY" and self.get("cl_update"):
                self.setMusic(event[2][0])
            elif event[1] == "MUSIC_STOP" and self.get("cl_update"):
                self.stopMusic()

            elif event[1] == "SET_CAMERA":
                self.configure("cl_camera", event[2])

            elif event[1] == "INTERFACE_CREATE":
                self.addInterface(event[2])
            elif event[1] == "INTERFACE_REMOVE":
                self.removeInterface(event[2])

            elif event[1] == "CHAT":
                self.chatMessages.append(event[2])

    def loop(self):
        '''Does everything basically.'''

        #cl = OptiClock()

        #Detector Index
        if not self.get("cl_master"):
            self.updateDetectorIndex()

        #cl.clockIn("DetectorIndex")

        #KEEP ALIVE
        self.keepAliveTicker += 1
        if self.keepAliveTicker % 600 == 0:
            self.sendEvent("KEEPALIVE")

        #cl.clockIn("KeepAlive")

        #Do Things#######################

        #Read in controls

        self.iR.checkControls()

        #cl.clockIn("Input")

        #Update Video Player

        self.vP.loop()

        #cl.clockIn("VideoPlayer")

        if self.get("cl_update"):
            #Update localization
            self.l.loop()

            #cl.clockIn("Localization")
            #Apply shaders
            self.sH.loop()

        #cl.clockIn("Shaders")
        #Run object code

        for ent in self.entities:
            if hasattr(ent, "loop"):
                ent.checkAnimation()
                ent.loop(self, "client")
        #Run interface code

        #cl.clockIn("Entities")

        if self.level:
            if hasattr(self.level, "loop"):
                self.level.loop(self, "client")

        #cl.clockIn("Level")

        for interface in self.interfaces:
            if hasattr(interface, "loop"):
                try:
                    interface.loop()
                except:
                    pass

        #cl.clockIn("Interface")

        if self.nC:
            #Send Things#####################
            for key in self.iR.keyEvents:
                self.sendEvent(key)

            for event in self.gameEvents:
                self.sendEvent(event)

            self.gameEvents = []
            self.iR.keyEvents = []

            #cl.clockIn("SendLoop")

            #Recv Things#####################

            if self.nC.clients:
                server = self.nC.clients[0]

                packet = server.recv()

                if packet:
                    payload = packet.getPayload()

                    try:
                        data = eval(payload)
                    except:
                        data = None

                    if data:
                        self.recvEvent(data)

            #cl.clockIn("RecvLoop")

            #Initial sync
            if self.nC.clients:
                server = self.nC.clients[0]

                if not self.get("cl_synced"):
                    server.disconnectFunc = self.getDisconnectReaction()
                    self.sendEvent(["SYSTEM", "NAME", self.get("cl_name")])
                    self.sendEvent(
                        ["SYSTEM", "PASSWORD",
                         self.get("cl_password")])
                    self.sendEvent(["SYSTEM", "PHYSICS", "FORCEUPDATE"])
                    self.configure("cl_synced", 1)

            #cl.clockIn("Sync")

            #KILL THINGS###################################################
            kill = self.nC.pullKillQueue()

            if kill:
                kill()

            #cl.clockIn("Kill")

            self.nC.loop()