self.kwargs[k]=line class EventFake(Event): def __init__(self, lines): Event.__init__(self,lines) self.parse() # :) To match The fake date Files:) self.name ='test' self.args =lines def parse(self): return self.lines host, port = 'localhost', 8085 mgr =EventManager(host, port) mgr.event_cls =EventFake handler = EventHandler() def callback(*args, **kwargs): print 'callbackargs', args print 'callbackkwargs', kwargs handler.events = {'test': callback} handler.register(mgr) while True: mgr.serve() mgr.monitor( error=True ,
"""Undocumented Module""" __all__ = ['eventMgr'] import EventManager eventMgr = EventManager.EventManager()
window.blit(self.screen, self.rect) if __name__ == "__main__": import os from EventManager import * running = True clock = pygame.time.Clock() os.environ['SDL_VIDEO_CENTERED'] = '1' pygame.init() pygame.font.init() pygame.display.set_caption("Menu Test") screen = pygame.display.set_mode(SCREEN_RES) eventManager = EventManager() menu = LandingMenu() eventManager.addGameMenu(menu) while running: # UPDATES running = eventManager.process_menu_input() if not running: break screen.fill(pygame.color.THECOLORS['black']) menu.draw(screen) pygame.display.update()
#! /usr/bin/env python # _*_ coding:utf8 _*_ import EventManager __all__ = ["EventManager"] global EVENT_MANAGER EVENT_MANAGER = EventManager.EventManager()
def tearDown(self): del self.evManager.initialized self.evManager = EventManager()
def __init__(self, recordTicks=False): self.events = [] EventManager().RegisterListener(self) self.recordTicks = recordTicks
def __init__(self, *args, **kwds): unittest.TestCase.__init__(self, *args, **kwds) self.evManager = EventManager()
def setUp(self): del self.evManager.initialized self.evManager = EventManager()
def generation(self, GM, nNode, nHost, nSwitch, graph, model, parameters, RL1, dotFormat): """ function to generate flows from a random source to a random destination. The traffic generation model is a Poission process (we fix lambda = arrival rate) Args: GM nNode graph model parameters RL1 """ now1 = time.time() EM = EventManager() i = 0 #generate random source and destination of a flow--------------- # sourceID = 2#random.randint(0, nNode-1) # destinationID = 3#random.randint(0, nNode-1) # #generate again the destination if it overlaps with the source------------------ # while(destinationID == sourceID): # destinationID = random.randint(0, nNode-1) # #flowID of the first flow generated: flowID = 0------------------- # flowID = flowID + 1 flowID = -1 #inizialization of the ID of flows that will be generated pkID = 0 #inizialization of the ID of first packet of the flow packetsize = 100 #array that stores all the paths of the other flows present in the system. We need it for the RL alghoritm # allpathsRL = [] allpaths = [] DemM = DemandMatrix(nHost) DemM.getDemandMatrix() # print('DM', DemM.getDemandMatrix()) #NOTE: all the packets belonging to the same flow follow the same path PathMODE = str(parameters[5]) #algorithm used to evaluate the path between source and destinatio #available options: #RL = reinforcement learning #OSPF = shortest path = path with the minimum weight = if all the weights are 1, it's the path with the minimum number of hops #ECMP = equal cost multi-path = all the shortest paths are evaluated, then, every time a new flow is generated, the shortest path is chosen according to the round-robin tecnique pathnotfoud = 0 #index to count how many times the RL algorithm didn't work #-------------------------------- allecmpPaths = all_ecmp_flow(nNode, graph, nHost) # print("allecmpPaths {}".format(allecmpPaths)) now = time.time() startTime = now istante = time.time() #end of the simulation: input parameter min = int(parameters[6]) timeout = time.time() + 60*min #tot minutes from now on # print("fine", time.ctime(timeout)) tempoOra = time.time() #----------------lambda!!!!!!!!!------------------------------------------------------------------------ interArrivalTime = np.random.poisson(50) # print("Poisson ", interArrivalTime) istante = tempoOra + interArrivalTime print("startTime {}, endtime {}, nextarrival {}".format( time.ctime(startTime), time.ctime(timeout), time.ctime(istante))) while (tempoOra < timeout): tempoOra = time.time() # print('now {}', tempoOra) # print('next istante {}', istante) if(tempoOra >= istante ): # print('qui') #generation of random source and destination (only hosts can be source or destination) sourceID = 0#random.randint(0, nHost-1) destinationID = 2#random.randint(0, nHost-1)#random.randint(0, nNode-1) while(destinationID == sourceID): destinationID = random.randint(0, nHost-1) if parameters[5] == 'so': #path semi-oblivious DemM.updateDemandMatrix(sourceID, destinationID, packetsize, 1) DM = [] DM = DemM.getDemandMatrix() # print('DM 2', DM) flowID = flowID + 1 GM.updatealiveflow(flowID) listSizeQueues = [] for queueNode in range(nNode): listSizeQueues.append(GM.showSizeQueue(queueNode)) print('size nodes', listSizeQueues) #evaluation of the flows/paths alive every time that a new flow is generated----- allpathsRL2 = [] allpathsRL2 = GM.getalivePaths() new_allpathsRL2 = list(allpathsRL2) #generation of the path according to the chosen MODE------------------------------ if( PathMODE == 'rl'): #dummy paths if the current number of active paths is lower than the maximum number of flows that can coexist in the system. if(len(allpathsRL2) < self.nFlow): #numero flussi totali previsti??????????????? for l in range(self.nFlow-len(new_allpathsRL2)-1):#numero flussi totali previsti??????????????? DummyPath = [0, 0] new_allpathsRL2.append(DummyPath) # print('....allpathsRL2', allpathsRL2) path, win, loop, fail = RL1.testAlgo(8, new_allpathsRL2, graph, model, sourceID, destinationID) if(loop == 1): path, win, loop, fail = RL1.testAlgo(8, new_allpathsRL2, graph, model, destinationID, sourceID) path = list(reversed(path)) print("path not found with RL 1") if(loop == 1): print("path not found with RL 2") path = nx.dijkstra_path(graph, sourceID, destinationID) pathnotfoud += 1 elif(PathMODE == 'ospf'): path = nx.dijkstra_path(graph, sourceID, destinationID) elif( PathMODE == 'ecmp'): allecmpPaths, pathIndex, indice_path2, path = ecmp_path(sourceID, destinationID, allecmpPaths) elif( PathMODE == 'so'): allSOpath(dotFormat, DemM.getDemandMatrix(), nHost) path = semi_oblivious(dotFormat, sourceID, destinationID, nHost) # print('alive paths 2.5', GM.getalivePaths()) # if(len(allpathsRL2) == 0): GM.updatealivePaths(path) # print('last found path', path) # print('alive paths 3', GM.getalivePaths()) # GM.updatealivepk(flowID, pkID) pkID = 0 # allpathsRL.append(path) # print('tutti i path vivi: ', allpathsRL) #evaluation of the collisions : overlapping links and nodes among the alive paths # allpaths.append(path) # min = int(parameters[6]) # istante += 10 interArrivalTime2 = np.random.poisson(50) # print("Poisson2 ", interArrivalTime2) istante += 3#interArrivalTime2 print('istante', istante) timeout2 = istante #time.time() + 60*2 #4 minutes from now tempoOra2 = time.time() istante2 = tempoOra2 + 1 print("timeStart {} timeEnd {} istante {}".format(time.ctime(tempoOra2), time.ctime(timeout2), time.ctime(istante2))) # allpaths = genPackets(flowID, tempoOra2, timeout2, EM, GM, allpaths) Npks = -1 numpackets = 10 while(Npks < numpackets): # print("time {}".format(time.ctime(istante2))) newpk = packet( flowID, pkID, sourceID, sourceID, destinationID, path) savept = path + [flowID, pkID] allpaths.append(path + [flowID, pkID]) newpk.updatepathID(flowID, pkID) GM.updatealivepk(flowID, pkID) pkID = pkID + 1 EM.GENERATE(GM, newpk, DemM, packetsize) Npks += 1 if parameters[5] == 'so': #path semi-oblivious DemM.updateDemandMatrix(sourceID, destinationID, packetsize, 1) DemM.getDemandMatrix() # print('DM', DemM.getDemandMatrix()) allpaths3 = GM.getalivePaths()#alivePaths(allpaths, GM) collisionLinks, numLinks, perc_collissionLink = collisions(allpaths3) # performanceStatistics() return pathnotfoud
def CreateWindowPanels(window): WINDOW_HEIGHT = 600 WINDOW_WIDTH = 1024 # ---------------------------------------------------------------------------------------------------------------------- # MAIN # ---------------------------------------------------------------------------------------------------------------------- app = wx.App(False) # Initialize the Main Window mainWindow = MainWindow(None, "Sample editor") # Initialize Event Manager eventManager = EventManager(mainWindow) # Create the Window Menu Bar CreateMenuBar(mainWindow) # Partition the window into panels panelManager = PanelManager(mainWindow) panelManager.PanelizeMainWindow() # Create Sequencer sequencer = Sequencer(mainWindow) sequencer.SetEventManager(eventManager) sequencer.CreateSequencer(panelManager.GetPanel("sequencer")) # Create Pianoroll Bitmaps bitmapA = CustomBitmap(panelManager.GetPanel("inputA"))
def init_events(): import EventManager Globals.EVENT_MANAGER = EventManager.EventManager()
def __init__(self, root_): super().__init__(root_) #initialize glfw window self.manager = EventManager() self.glfw_manager = GlfwWinManager.GlfwWinManager( "Main Window", [800, 600], [330, 30], self.manager.func_Ldown, self.manager.func_Lup, self.manager.func_Rdown, self.manager.func_Rup, self.manager.func_Mdown, self.manager.func_Mup, self.manager.func_mouse_move, self.manager.func_mouse_wheel, self.manager.func_draw_scene, self.manager.func_on_keydown, self.manager.func_on_keyup, self.manager.func_on_keykeep) #initialize tkinter Frame self.root = root_ self.pack() quit_btn = ttk.Button(self, text="Quit", command=self.quit_spintracker) quit_btn.pack(side="top", anchor=tk.E) #----frame_idx --- (slider) slider_frame = tk.Frame(self, pady=3) slider_frame.pack(side="top") num_frames = VideoManager.get_inst().num_frames() self.slider_val = tk.IntVar() self.slider = ttk.Scale(slider_frame, variable=self.slider_val, takefocus=1, length=280, from_=0, to=num_frames - 1, command=self.slider_changed) self.slider.pack(side="left") self.slider_label = ttk.Label(slider_frame, text="0000") self.slider_label.pack(side="right") spin_estim_frame = tk.Frame(self, pady=3, background="white") spin_estim_frame.pack(side="top") self.label_spinspeed = ttk.Label( spin_estim_frame, background="white", text="Spin Speed : XXX [RPS]revolution per second") self.label_spinaxis = ttk.Label( spin_estim_frame, background="white", text="Spin Axis : θ = XXX, φ=XXX [deg]") self.label_spinaxis3d = ttk.Label(spin_estim_frame, background="white", text="Spin Axis : (xx,xx,xx)[deg]") self.label_spinaxis_gyro = ttk.Label( spin_estim_frame, background="white", text="Gyro : XXX[deg], Spin Eff. XXX[%]") self.label_spinaxis_dir = ttk.Label(spin_estim_frame, background="white", text="Dir : XXX[deg], XXX[hh:mm]") self.label_spinaxis_tilt = ttk.Label(spin_estim_frame, background="white", text="Tilt: XXX[deg], XXX[hh:mm]") self.label_spinspeed.grid(row=0, column=0, sticky=tk.W) self.label_spinaxis.grid(row=1, column=0, sticky=tk.W) self.label_spinaxis3d.grid(row=2, column=0, sticky=tk.W) self.label_spinaxis_gyro.grid(row=3, column=0, sticky=tk.W) self.label_spinaxis_dir.grid(row=4, column=0, sticky=tk.W) self.label_spinaxis_tilt.grid(row=5, column=0, sticky=tk.W) #----fps---- (radio button) fps_frame = tk.Frame(self, pady=3) fps_frame.pack(side="top", anchor=tk.W) fps_label = ttk.Label(fps_frame, text="FPS of video:") self.fps_mode = tk.StringVar(None, '480') rb1 = ttk.Radiobutton(fps_frame, text='300', value='300', variable=self.fps_mode) rb2 = ttk.Radiobutton(fps_frame, text='480', value='480', variable=self.fps_mode) rb3 = ttk.Radiobutton(fps_frame, text='960', value='960', variable=self.fps_mode) rb4 = ttk.Radiobutton(fps_frame, text='1000', value='1000', variable=self.fps_mode) fps_label.pack(side="left") rb1.pack(side="left") rb2.pack(side="left") rb3.pack(side="left") rb4.pack(side="left") #----ball radius ---- (spin control memo:http://www.nct9.ne.jp/m_hiroi/light/py3tk05.html) ballrad_frame = tk.Frame(self, pady=5) ballrad_frame.pack(side="top", anchor=tk.W) self.radi_release = tk.StringVar(None, "28") self.radi_catch = tk.StringVar(None, "16") VideoManager.get_inst().set_ball_radius(28, 16) spinbox_release = ttk.Spinbox(ballrad_frame, from_=5, to=40, increment=1, width=5, state='readonly', textvariable=self.radi_release, command=self.spin_changed) spinbox_catch = ttk.Spinbox(ballrad_frame, from_=5, to=40, increment=1, width=5, state='readonly', textvariable=self.radi_catch, command=self.spin_changed) radi_label1 = ttk.Label(ballrad_frame, text="Radius at Release : ") radi_label2 = ttk.Label(ballrad_frame, text="Radius at Catch : ") radi_label1.grid(row=0, column=0) spinbox_release.grid(row=0, column=1) radi_label2.grid(row=1, column=0) spinbox_catch.grid(row=1, column=1) #-----background subtraction ---- backsubt_frame = tk.Frame(self, pady=5) backsubt_frame.pack(side="top", anchor=tk.W) self.backsubt_mode = tk.StringVar(None, 'mean') self.backsubt_thresh = tk.StringVar(None, "12") backsubt_label1 = ttk.Label( backsubt_frame, text="Background subtraction, mode and threshold") backsubt_rb1 = ttk.Radiobutton(backsubt_frame, text='mean', value='mean', variable=self.backsubt_mode) backsubt_rb2 = ttk.Radiobutton(backsubt_frame, text='first', value='first', variable=self.backsubt_mode) backsubt_rb3 = ttk.Radiobutton(backsubt_frame, text='last', value='last', variable=self.backsubt_mode) backsubt_thresh = ttk.Spinbox(backsubt_frame, from_=2, to=100, increment=1, width=5, state='readonly', textvariable=self.backsubt_thresh, command=self.spin_changed) backsubt_label1.pack(side="top") backsubt_rb1.pack(side="left") backsubt_rb2.pack(side="left") backsubt_rb3.pack(side="left") backsubt_thresh.pack(side="left") #----- Mask angle and size mask_frame = tk.Frame(self, pady=5) mask_frame.pack(side="top", anchor=tk.W) mask_label1 = ttk.Label(mask_frame, text="mask angle [deg]: ") mask_label2 = ttk.Label(mask_frame, text="mask size [-%-]: ") self.mask_angle_val = tk.StringVar(None, "90") self.mask_rate_val = tk.StringVar(None, "100") mask_angle = ttk.Spinbox(mask_frame, from_=-180, to=180, increment=1, width=5, state='readonly', textvariable=self.mask_angle_val, command=self.spin_mask_changed) mask_size = ttk.Spinbox(mask_frame, from_=0, to=100, increment=5, width=5, state='readonly', textvariable=self.mask_rate_val, command=self.spin_mask_changed) mask_label1.grid(row=0, column=0) mask_angle.grid(row=0, column=1) mask_label2.grid(row=1, column=0) mask_size.grid(row=1, column=1) #----- Morph. Ope. / template match interval ---- miscs_frame = tk.Frame(self, pady=5) miscs_frame.pack(side="top", anchor=tk.W) miscs_label1 = ttk.Label(miscs_frame, text="Morph. Ope. Size. : ") miscs_label2 = ttk.Label(miscs_frame, text="Templ. Match. interval : ") self.miscs_morpho = tk.StringVar(None, "2") self.miscs_tminterval = tk.StringVar(None, "2") miscs_morpho = ttk.Spinbox(miscs_frame, from_=1, to=10, increment=1, width=5, state='readonly', textvariable=self.miscs_morpho, command=self.spin_changed) miscs_tminter = ttk.Spinbox(miscs_frame, from_=1, to=10, increment=1, width=5, state='readonly', textvariable=self.miscs_tminterval, command=self.spin_changed) miscs_label1.grid(row=0, column=0) miscs_morpho.grid(row=0, column=1) miscs_label2.grid(row=1, column=0) miscs_tminter.grid(row=1, column=1) #---- Buttons ------ btn_frame = tk.Frame(self, pady=3) btn_frame.pack(side="top", anchor=tk.W) btn_import_conf = ttk.Button(btn_frame, text="Import config", command=self.import_config) btn_export_conf = ttk.Button(btn_frame, text="Export config", command=self.export_config) btn_run_tracking = ttk.Button(btn_frame, text="Run Tracking and Spin Analysis", command=self.run_tracking) btn_import_conf.grid(row=0, column=0, sticky=tk.E + tk.W) btn_export_conf.grid(row=0, column=1, sticky=tk.E + tk.W) btn_run_tracking.grid(columnspan=2, row=1, column=0, sticky=tk.E + tk.W) # set focus on slider self.slider.focus_set() VideoManager.get_inst().update_ballclip_mask( int(self.radi_release.get()), int(self.radi_catch.get()), int(self.mask_angle_val.get()), float(self.mask_rate_val.get()) / 100.0) #set camera position and scalling param H, W = VideoManager.get_inst().get_frame_uint8(0).shape self.glfw_manager.set_campos(W / 5 * 3, H / 5 * 3) self.glfw_manager.set_viewscale(W / 2)
import pygame, TileMap from ItemHandler import * from Player import * from Conveyor import * from Button import * from ImageCycler import * from pygame import mixer as mx from OrderHandler import * from EventManager import * # Window Setup pygame.init() EventMgr = EventManager("Core", 60) pygame.mixer.init() screen = pygame.display.set_mode((1260, 720)) screen.fill((0, 100, 0)) pygame.display.set_caption("Pizza Poppers") icon = pygame.image.load("Images/icon.png") pygame.display.set_icon(icon) screenState = "Title" paused = False warmup = False musicPlaying = False createItem((200, 300), "Chicken") createItem((250, 350), "Beef") createItem((300, 100), "Chicken") order1 = Order("Complete This Order", ("foo", "bar")) pbc = mx.Sound("Sound/PBC.ogg")
def __init__(self): self.evManager = EventManager() self.evManager.RegisterListener(self) self.state = KeyboardController.STATE_ACTION self.solution = "" self.solveTime = 0
def __init__(self): pygame.init() pygame.font.init() self.font16 = pygame.font.Font("PKMN RBYGSC.ttf", 16) self.font32 = pygame.font.Font("PKMN RBYGSC.ttf", 32) self.font64 = pygame.font.Font("PKMN RBYGSC.ttf", 64) #must be something real troll to use anything bigger than 64 self.font128 = pygame.font.Font("PKMN RBYGSC.ttf", 128) self.font256 = pygame.font.Font("PKMN RBYGSC.ttf", 256) self.rapper = pygame.image.load('NAKEDMAN2.png') self.rapperw = self.rapper.get_rect().width self.gangster = pygame.image.load('NAKEDMAN3.png') self.gangsterw = self.gangster.get_rect().width self.child = pygame.image.load('NAKEDMAN4.png') self.childw = self.child.get_rect().width self.hobo = pygame.image.load('NAKEDMAN.png') self.hobow = self.hobo.get_rect().width self.nerd = pygame.image.load('NAKEDMAN5.png') self.nerdw = self.nerd.get_rect().width self.select = pygame.image.load('select.png') self.selectw = self.select.get_rect().width self.wait = False # Processes events (essentially all inputs) self.eventManager = EventManager(self) # Brings up a TextInput that'll be used to enter in text self.textInput = TextInput(self) self.p1name = '' self.p2name = '' pygame.display.set_caption("POKEMANS") self.screen = pygame.display.set_mode((800, 600)) self.streak = 0 self.running = True self.state = "Pre-Login" self.battlestr = '' self.draft = [pokeman(1,0),pokeman(2,0),pokeman(3,0)] # The pokemans in the draft self.pokemans = [] # The pokemans selected self.gameState = [] # gameState in battle # Sends an alive packet periodically to the server to tell that a player is still online self.aliveClock = pygame.time.Clock() self.aliveTimer = 0 # Timer to keep track of the clock self.sel = 0 self.login = 0 self.timer1 = 0 self.preb_timer = 0 self.preb = True self.flash1 = False self.networkManager = NetworkManager(self) colorPicker = randint(0, 5) backgroundColor = None if colorPicker == 0: backgroundColor = (255, 0, 0) elif colorPicker == 1: backgroundColor = (0, 255, 0) elif colorPicker == 2: backgroundColor = (0, 0, 255) elif colorPicker == 3: backgroundColor = (255, 255, 0) elif colorPicker == 4: backgroundColor = (0, 255, 255) elif colorPicker == 5: backgroundColor = (255, 0, 255) self.background = pygame.Surface((800, 600)) self.background.set_alpha(50) self.background.fill(backgroundColor) self.textScroll = TextScroll(self)