Exemple #1
0
    def waitlong(self):

        if self.erasize == 4:
            Wait(598)
        elif self.erasize == 3:
            Wait(58)
        elif self.erasize == 2:
            Wait(8)
def ProfileTestRun(ProfilingTime=10):

    t0 = getTime()
    while getTime() - t0 < ProfilingTime:
        PrintTest("Profiling t-" +
                  str(round(ProfilingTime - (getTime() - t0), 2)) + " s")
        Wait(0.1)
    def Profile(self,
                ProfilingCommand=None,
                FileName="ProfilingResults.pstats",
                ctx=False,
                delay=0,
                AutoVisualize=True,
                PrintInfo=True,
                PrintStats=True,
                PrintTime=True,
                ShowFullGraph=False):

        #========================================================================================
        # Initialization
        #========================================================================================

        #+++++++++++++++++++++++++++++++++++++++++++
        # Check Results Folder
        #+++++++++++++++++++++++++++++++++++++++++++

        if (not ("/" in FileName)) and (not ("\\" in FileName)):
            if not os.path.exists(DefaultProfilingFolder):
                os.makedirs(DefaultProfilingFolder)
            FileName = DefaultProfilingFolder + FileName

        #-------------------------------------------
        # Fix Filename
        #-------------------------------------------

        ForbiddenChars = []
        ForbiddenChars.append([" ", "_"])  # Remove Spaces!
        ForbiddenChars.append(["=", "_"])  # Equal signs are not allowed!
        if 1:  # These are guesses! (Not sure whether they cause problems...)
            ForbiddenChars.append(["#", "Nr"])
            # ForbiddenChars.append(["-","_"])
            #ForbiddenChars.append([".",","])

        for ForbiddenCharPair in ForbiddenChars:
            B, G = ForbiddenCharPair
            if B in FileName:
                #if PrintInfo: print("CAUTION: '"+B+"' in FileName (not allowed) will be replaced by '"+G+"'")
                FileName = FileName.replace(B, G)

        if " " in FileName:
            print("WARNING: The profiling Filename contains spaces! '" +
                  str(FileName) + "' causes issues when calling cmd commands!")

        #+++++++++++++++++++++++++++++++++++++++++++
        # Default TestRun
        #+++++++++++++++++++++++++++++++++++++++++++

        if ProfilingCommand == None:
            DefaultProfilingTime = 10
            ProfilingCommand = "ProfileTestRun(" + str(
                DefaultProfilingTime) + ")"

        #+++++++++++++++++++++++++++++++++++++++++++
        # MasterClass
        #+++++++++++++++++++++++++++++++++++++++++++

        if self.MasterClass != None and type(ProfilingCommand) == str:
            ProfilingCommand = ProfilingCommand.replace(
                "self.", "self.MasterClass.")

        #========================================================================================
        # Start Profiling
        #========================================================================================

        if PrintInfo:
            print("=" * 50)
            print(">>>!!!Starting Profiling!!!<<<")
            ProfCMD = str(ProfilingCommand)
            if len(ProfCMD) < 100:
                print(">>>'" + ProfCMD + "'<<<")
            else:
                print(">>>'" + ProfCMD[:100] + "[...]" + "'<<<")
            print("=" * 50)

        t0 = getTime()

        if type(ProfilingCommand) == str:
            if ctx:
                Result = cProfile.runctx(ProfilingCommand, globals(), locals(),
                                         FileName)
            else:
                Result = cProfile.run(ProfilingCommand, FileName)
        else:
            Result = self.Profile_Function(ProfilingCommand, FileName)

        t_Profiling = getTime() - t0

        if PrintInfo:
            print("=" * 50)
            print(">>>!!!Profiling Finished (in " +
                  str(round(t_Profiling, 1)) + "s" + ")!!!<<<")
            print(">>>Writing Results to: " + FileName)
            print("=" * 50)
        elif PrintTime:
            print(">>>!!!Profiling of '" + str(ProfilingCommand) +
                  "' Finished (in " + str(round(t_Profiling, 1)) + "s" +
                  ")!!!<<<")

        #--- Delay ---
        if delay > 0:
            Wait(delay)

        #========================================================================================
        # Print Stats
        #========================================================================================

        if PrintStats:
            if 1:  #Threaded:
                PrintCurrentThreads()
            if 0:
                raw_input("View Profiling Results?")

            self.PrintStats(FileName)

        #+++++++++++++++++++++++++++++++++++++++++++
        # Visualize
        #+++++++++++++++++++++++++++++++++++++++++++

        if AutoVisualize:  #and os.name!="nt":
            self.Visualize(FileName, ShowFullGraph=ShowFullGraph)

        # print("ProfilingResult:",Result)
        return Result
def maingame(screen):  # 游戏主循环
    alist = puzzleinit()
    picindex = Randint(1, 4)
    # 游戏主循环
    while True:
        endcircle = 0
        cursor_x = 0
        cursor_y = 0
        flag = 0  #没有鼠标点击事件
        for event in pygame.event.get():
            if event.type == QUIT:
                # 接收到退出时间后退出程序
                exit(0)
            if event.type == MOUSEBUTTONDOWN:
                flag = 1  # 有鼠标点击事件
                cursor_x, cursor_y = pygame.mouse.get_pos()  # 获得鼠标位置

        if flag == 1:
            if (cursor_x >= 149 and cursor_x < 149 + 92 * 2 and cursor_y >= 564
                    and cursor_y <= 564 + 45):
                endcircle = 1
                break
            elif ((cursor_x - 57) // 92 in range(0, 4)
                  and (cursor_y - 170) // 92 in range(0, 4)):
                a = (cursor_x - 57) // 92
                b = (cursor_y - 170) // 92
                switchpos(alist, b, a)

        # 将背景图画上去
        screen.blit(background, (0, 0))

        # 画小方块
        for i in range(0, 4):
            for j in range(0, 4):
                image_name = './klotski_image/pics/pic_0' + str(
                    picindex) + '/' + str(alist[i][j]) + '.png'
                im = pygame.image.load(image_name)
                screen.blit(im, (58 + j * 92, 170 + i * 92))

        # 画格子
        imgrid_name = './klotski_image/grid.png'
        imgrid = pygame.image.load(imgrid_name)
        screen.blit(imgrid, (57, 170))

        # 画缩略图
        image_name = './klotski_image/pics/pic_0' + str(
            picindex) + '/' + 'small.jpg'
        im = pygame.image.load(image_name)
        screen.blit(im, (320, 43))
        image_name = './klotski_image/Rect_origin.png'
        im = pygame.image.load(image_name)
        screen.blit(im, (320, 43))

        # 画重新开始按钮
        x, y = pygame.mouse.get_pos()
        if (x >= 149 and x < 149 + 92 * 2 and y >= 564 and y <= 564 + 45):
            screen.blit(buttondown, (149, 564))
        else:
            screen.blit(buttonup, (149, 564))

        # cursor_x, cursor_y = pygame.mouse.get_pos()      # 获得鼠标位置
        # if(cursor_x>=149 and cursor_x < 58+92*2 and cursor_y):

        # 刷新画面
        flag = 0

        pygame.display.update()

        if ifsuccess(alist) == 1:
            endcircle = 1
            screen.blit(success, (0, 0))
            pygame.display.update()
            Wait(1)

        if endcircle == 1:
            break
Exemple #5
0
    def wait(self, seconds):

        Wait(seconds)
Exemple #6
0
    def waitshort(self):

        if self.erasize > 1:
            Wait(1)
    
    Analyzer = 1
    Mode = 3

    #+++++++++++++++++++++++++++++++++++++++++++
    # Initialization
    #+++++++++++++++++++++++++++++++++++++++++++
    
    OFA = OpticalFlowAnalyzer()

    Camera = cv2.VideoCapture(Source)
    try:
        CameraNr = int(Source)
        Camera.set(3,Resolution[0])
        Camera.set(4,Resolution[1])
        Wait(1.0) # Needed for Camera Initialization
    except:
        pass # VideoFile is used!

    ret,frame_old = Camera.read()

    #+++++++++++++++++++++++++++++++++++++++++++
    # Run Analysis
    #+++++++++++++++++++++++++++++++++++++++++++
    
    print Title

    t0 = getTime()
    t  = getTime()
    FrameCounter = 0
    while True:
Exemple #8
0
        end_user = Calc.add(user_a, user_b)
        print('Your answer is: ', end_user)

    elif user == '2':
        Calc.ask2()
        end_user = Calc.sub(user_a, user_b)
        print('Your answer is: ', end_user)

    elif user == '3':
        Calc.ask2()
        end_user = Calc.multi(user_a, user_b)
        print('Your answer is: ', end_user)

    elif user == '4':
        Calc.ask2()
        end_user = Calc.div(user_a, user_b)
        print('Your answer is: ', end_user)

    elif user == '5':  #this elfi statement is user to exit the entire program
        to_quit = str(input('Are you sure you want to quit? y/n'))
        to_quit = to_quit.lower()
        '''# debug zone for testing methodes typed on and other things that may be added. uses Db to 
		pull up
		elif user == 'Db':
			Calc.debug()'''

    else:
        Calc.try_a()
        Wait(1)
    #used to be more visually appealing between iterations and to help keep track of user answer visually with in the terminal.