def __init__(self, directory=None): super(PlayerUI, self).__init__(parent=None, title="YouStream", size=(DEFAULT_WIDTH, DEFAULT_HEIGHT)) self.directory = utils.make_directory(directory) self.build_UI() self.Show() self.panel.Layout() # self.Maximize() self.player_manager = PlayerManager(self.media_player, self.directory) self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.on_timer) self.timer.Start(TIMER_INTERVAL * 1000)
def Init(self): """ """ from GSManager import GSManager self.gconfig = GlobalConfig.instance() #start server znetlib = self.gconfig.GetValue('CONFIG', 'net-lib') csip = self.gconfig.GetValue('CONFIG', 'clients-server-address') csport = self.gconfig.GetValue('CONFIG', 'clients-server-port') self.nserver = net_server(znetlib) ns_arg = ns_arg_t() ns_arg.ip = csip ns_arg.port = csport self.nserver.ns_start(ns_arg) self.playermanager = PlayerManager.instance() self.playermanager.Init() self.gsmanager = GSManager.instance() return True
def Init(self): """ """ from GSManager import GSManager self.gconfig = GlobalConfig.instance() #start server znetlib = self.gconfig.GetValue('CONFIG','net-lib') csip = self.gconfig.GetValue('CONFIG','clients-server-address') csport = self.gconfig.GetValue('CONFIG','clients-server-port') self.nserver = net_server(znetlib) ns_arg = ns_arg_t() ns_arg.ip = csip ns_arg.port = csport self.nserver.ns_start(ns_arg) self.playermanager = PlayerManager.instance() self.playermanager.Init() self.gsmanager = GSManager.instance() return True
def __init__(self, game_name): package = "Games" self.settings = getattr(import_module(package + "." + game_name), "options").collapse() self.players = PlayerManager( self.settings["Players"] ) self.players.on_overflow(self.next_rnd) functions = Subset( self.players.__len__, self.players.index, self.players.next, self.players.on_player_change, self.players.on_overflow, self.players.player, self.players.to_dict, ) self.settings.pop("Players") self.game = getattr(import_module(package + "." + game_name), game_name)(functions, **self.settings) self.rnd = 0
def Init(self): from ClientManager import ClientManager from PlayerManager import PlayerManager self.uuid = uuid.instance() self.gconfig = GlobalConfig.instance() znetlib = self.gconfig.GetValue('CONFIG','net-lib') sqlip = self.gconfig.GetValue('CONFIG','sqlstore-address') sqlport = self.gconfig.GetValue('CONFIG','sqlstore-port') #connect to sqlstore self.nclient = net_client(znetlib) nc_arg = nc_arg_t() nc_arg.ip = sqlip nc_arg.port = sqlport rv = self.nclient.nc_connect(nc_arg) if not rv: PutLogList("(*) Connect to sqlstore IP:%s PORT:%d failed!"\ % (sqlip,sqlport)) return False self.client_manager = ClientManager.instance() self.player_manager = PlayerManager.instance() return True
import sys from Player import Player from GameOfDice import GameOfDice from GameState import GameState from PlayerManager import PlayerManager from assign_order_strategy import assign_strategy_factory from dice_roll_strategy import dice_roll_strategy_factory args = sys.argv number_of_players = int(args[1]) winning_score = int(args[2]) player_manager = PlayerManager() game_state = GameState(winning_score) assign_strategy_factory = assign_strategy_factory.AssignOrderStrategyFactory() assign_strategy = assign_strategy_factory.get_assign_order_strategy("random") dice_roll_strategy_factory = dice_roll_strategy_factory.DiceRollStrategyFactory() dice_roll_strategy = dice_roll_strategy_factory.get_dice_roll_strategy("random") game = GameOfDice(number_of_players, player_manager, assign_strategy, dice_roll_strategy, game_state) for i in range(1, number_of_players+1): p = Player(str(i)) game.add_player(p) status = game.start_game()
class PlayerUI(wx.Frame): def __init__(self, directory=None): super(PlayerUI, self).__init__(parent=None, title="YouStream", size=(DEFAULT_WIDTH, DEFAULT_HEIGHT)) self.directory = utils.make_directory(directory) self.build_UI() self.Show() self.panel.Layout() # self.Maximize() self.player_manager = PlayerManager(self.media_player, self.directory) self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.on_timer) self.timer.Start(TIMER_INTERVAL * 1000) def build_UI(self): self.CreateStatusBar() self.create_menu() self.create_player_and_buttons() def create_menu(self): filemenu = wx.Menu() menuOpen = filemenu.Append(wx.NewId(), "&Open", "Open a file") menuAbout = filemenu.Append(wx.ID_ABOUT, "&About", "Information about this program!") menuExit = filemenu.Append(wx.ID_EXIT, "&Exit", "Exit this program") self.Bind(wx.EVT_MENU, self.on_open, menuOpen) self.Bind(wx.EVT_MENU, self.on_about, menuAbout) self.Bind(wx.EVT_MENU, self.on_exit, menuExit) menuBar = wx.MenuBar() menuBar.Append(filemenu, "&File") self.SetMenuBar(menuBar) def create_player_and_buttons(self): self.panel = wx.Panel(parent=self) # Make sizer outerBoxSizer = wx.BoxSizer(wx.VERTICAL) searchInputSizer = self.create_search_input_sizer() gaugeBarSizer = self.make_gauge_bar_sizer() playerButtonsSizer = self.make_player_button_sizer() # Add player and events mplayer_controller = mpc.MplayerCtrl(self.panel, -1, 'mplayer') self.media_player = MediaPlayer(mplayer_controller) self.bind_events_to_media_player() # Add sizer to outer sizer outerBoxSizer.Add(searchInputSizer, 0, wx.ALL | wx.EXPAND, 5) outerBoxSizer.Add(mplayer_controller, 1, wx.ALL | wx.EXPAND, 5) outerBoxSizer.Add(gaugeBarSizer, 0, wx.ALL | wx.EXPAND, 5) outerBoxSizer.Add(playerButtonsSizer, 0, wx.BOTTOM | wx.LEFT | wx.RIGHT, 5) self.panel.SetSizer(outerBoxSizer) def bind_events_to_media_player(self): self.panel.Bind(mpc.EVT_MEDIA_STARTED, self.on_media_started) self.panel.Bind(mpc.EVT_MEDIA_FINISHED, self.on_media_finished) def make_gauge_bar_sizer(self): self.gauge_bar = wx.Gauge(self.panel, style=2) gauge_bar_sizer = wx.BoxSizer(wx.HORIZONTAL) gauge_bar_sizer.Add(self.gauge_bar, proportion=1, flag=wx.ALL, border=5) return gauge_bar_sizer def make_player_button_sizer(self): """ Creates all the buttons for the player: previous, play, pause, reset and next. """ player_flow_sizer = wx.BoxSizer(wx.HORIZONTAL) data_list = [{'label': 'Previous', 'handler': self.on_previous}, {'label': 'Play', 'handler': self.on_play}, {'label': 'Pause', 'handler': self.on_pause}, {'label': 'Reset', 'handler': self.on_reset}, {'label': 'Next', 'handler': self.on_next}] for button_properties in data_list: button = self.make_button(button_properties) player_flow_sizer.Add(button, 0, wx.ALL, 3) return player_flow_sizer def make_button(self, button_properties): button = wx.Button(self.panel, label=button_properties['label']) button.SetInitialSize() button.Bind(wx.EVT_BUTTON, button_properties['handler']) return button def create_search_input_sizer(self): self.search_terms_input = wx.TextCtrl(self.panel) search_button = wx.Button(self.panel, label='Watch') self.Bind(wx.EVT_BUTTON, self.on_search, search_button) # todo: currently doesn't work. Pressing a key has no effect # todo: also we must do this only for the return key, not just any key pressed # todo: becayse otherwise we simply would search at every keystroke # self.Bind(wx.EVT_KEY_DOWN, self.on_search, self.search_terms_input) # Add controls to sizer search_box_sizer = wx.BoxSizer(wx.HORIZONTAL) search_box_sizer.Add(self.search_terms_input, proportion=1, flag=wx.ALL, border=10) search_box_sizer.Add(search_button, 0, flag=wx.ALL, border=8) return search_box_sizer # -------- Event Handlers --------------------------------- def on_open(self, evt): dialog = wx.FileDialog(self, message="Choose a file", defaultDir=os.getcwd(), defaultFile="", wildcard="*.*", style=wx.OPEN | wx.CHANGE_DIR) if dialog.ShowModal() == wx.ID_OK: path = dialog.GetPath() self.player_manager.open(path) dialog.Destroy() def on_about(self, evt): dialog = wx.MessageDialog(self, "A video streaming service", "About streaming service", wx.OK) dialog.ShowModal() dialog.Destroy() def on_media_started(self, evt): self.update_gauge() self.player_manager.on_media_started() length = self.player_manager.get_current_video_length() print("Length of file: %d" % length) def on_media_finished(self, evt): self.set_gauge_bar_empty() self.player_manager.on_media_finished() def on_exit(self, evt): self.media_player.destroy() self.player_manager.destroy() self.Close(True) def on_previous(self, evt): self.player_manager.on_previous() def on_pause(self, evt): self.player_manager.on_pause() def on_play(self, evt): self.player_manager.on_play() def on_reset(self, evt): self.player_manager.on_reset() def on_next(self, evt): self.player_manager.on_next() def on_search(self, evt): search_terms = self.get_search_terms() self.player_manager.on_search(search_terms) def on_timer(self, evt): # todo: if, for some reason (SLOW internet), the media player goes to the end of the file # todo: it will stop and dont try to continue when new contents are ready. Fix this! must_restart_video = self.must_restart_video() if must_restart_video: print "Restarting video." self.restart_video() if self.player_manager.is_video_playing(): self.video_time_position = self.player_manager.get_current_video_time_position() self.update_gauge() self.player_manager.on_timer() # Helper function def get_search_terms(self): return self.search_terms_input.GetValue().split() def restart_video(self): path = self.player_manager.get_current_video_file_path() video_time_position = self.player_manager.get_current_video_time_position() self.media_player.play_current_video_at_time_position(path, video_time_position) def must_restart_video(self): is_downloading = self.player_manager.is_downloading() is_video_playing = self.player_manager.is_video_playing() current_time_position = self.player_manager.get_current_video_time_position() return not is_video_playing and is_downloading and current_time_position > 2 def raise_error_window(self, path): message = "Unable to load %s: Unsupported format?" % path wx.MessageBox(message, "ERROR", wx.ICON_ERROR | wx.OK) # Gauge def update_gauge(self): if self.player_manager.is_video_playing(): self.adjust_gauge() def adjust_gauge(self): if self.must_adjust_gauge(): self.adjust_gauge_range() self.adjust_gauge_value() def must_adjust_gauge(self): return self.gauge_bar.GetRange() == 0 or self.gauge_bar.GetRange() == BIG_VALUE def adjust_gauge_range(self): length = self.player_manager.get_current_video_length() if length == 0: self.set_gauge_bar_empty() else: self.gauge_bar.SetRange(length) def set_gauge_bar_empty(self): self.gauge_bar.SetRange(BIG_VALUE) self.gauge_bar.SetValue(0) def adjust_gauge_value(self): video_time_position = self.player_manager.get_current_video_time_position() self.gauge_bar.SetValue(video_time_position)
class GameManager(): # intialize the game with the specified number of players def __init__(self, game_name): package = "Games" self.settings = getattr(import_module(package + "." + game_name), "options").collapse() self.players = PlayerManager( self.settings["Players"] ) self.players.on_overflow(self.next_rnd) functions = Subset( self.players.__len__, self.players.index, self.players.next, self.players.on_player_change, self.players.on_overflow, self.players.player, self.players.to_dict, ) self.settings.pop("Players") self.game = getattr(import_module(package + "." + game_name), game_name)(functions, **self.settings) self.rnd = 0 def interface_data(self): if self.game.throw >= 3: return ["ent_light 1", "sel_light 0", "remove_light 0", "throw_light 0"] else: return ["ent_light 0", "sel_light 0", "remove_light 0", "throw_light 1"] def next_rnd(self): self.rnd += 1 if (hasattr(self.game, 'on_round_change')): self.game.on_round_change(self.rnd) def gui_data(self): temp = self.game.gui_data() temp["Round"] = self.rnd return temp # a dart was thrown. # @param: button - button dart hit # mult - multiplyer hit # @return: true or false if throw is valid def throw_dart(self, button, mult): # TODO: add exit case exception if (button == "Bullseye" and (int(mult) == 0 or int(mult) == 1)): # for bullseye case pass elif (not (int(button) <= 20 and int(button) >= 1)): raise Exception("passed button value " + str(button) + "is not valid") elif (not (int(mult) <= 2 and int(mult) >= 0)): raise Exception("passed mult value " + str(mult) + "is not valid") self.game.throw_dart(str(button), mult) def allowed_functions(self): return Subset( self.throw_dart, self.game.next_player ) # @return: name of winner if game is over. None if game continues def exit_case(self): return self.game.winner def format_str(self, level = 0, indent = " "): string = (indent * level) + "[\n" string += (indent * (level + 1)) + "Round: " + str(self.rnd) + "\n" string += (indent * (level + 1)) + "Game: \n" string += self.game.format_str(level + 2, indent) string += (indent * level) + "]\n" return string