Example #1
0
 def __init__(self,
              width,
              height,
              timePtr,
              timeSpan=100,
              background_color=None):
     """
     timespan: displayed timewindow
     xMin, xMax = xScale
     """
     self.gridConfig = {'xStepCnt': 0, 'yStepCnt': 0}
     self.bordersize = 5
     self.xLimit = 100
     self.yLimit = 100
     self.labelWindowWidth = 10
     self.right_border = timeSpan
     self.timeScale = self.xLimit / timeSpan
     self.labelGraphLeft = sg.Graph(
         (64, height), (self.labelWindowWidth, -self.bordersize),
         (0, self.yLimit + self.bordersize),
         background_color,
         pad=(0, 0),
         key='labelDisplayLeft')
     self.labelGraphRight = sg.Graph(
         (64, height), (-1, -self.bordersize),
         (self.labelWindowWidth - 1, self.yLimit + self.bordersize),
         background_color,
         pad=(0, 0),
         key='labelDisplayRight')
     self.graph = sg.Graph((width, height), (-2, -self.bordersize),
                           (self.xLimit + 2, self.yLimit + self.bordersize),
                           background_color,
                           pad=(0, 0),
                           key='mDisplay1')
     self.timePtr = timePtr
Example #2
0
    def set_layout(self):
        menu_definition = [
            ['File', [
                'Open',
                'Save',
                'Exit',
            ]],
            [
                'Edit',
                ['Paste', [
                    'Special',
                    'Normal',
                ], 'Undo'],
            ],
            ['Help', 'About...'],
        ]

        self.layout = [
            [sg.Menu(menu_definition)],
            [sg.Text('Nonogram'),
             sg.Text('', key='-OUTPUT-')],
            [
                sg.Graph((self.TIP_SIZE + self.WINDOW_SIZE_X, self.TIP_SIZE),
                         (0, self.TIP_SIZE),
                         (self.TIP_SIZE + self.WINDOW_SIZE_X, 0),
                         key='-COLUMNS-',
                         change_submits=True,
                         drag_submits=False)
            ],
            [
                sg.Graph((self.TIP_SIZE, self.WINDOW_SIZE_Y),
                         (0, self.WINDOW_SIZE_Y), (self.TIP_SIZE, 0),
                         key='-ROWS-',
                         change_submits=True,
                         drag_submits=False),
                sg.Graph((self.WINDOW_SIZE_X, self.WINDOW_SIZE_Y),
                         (-1, self.WINDOW_SIZE_Y + 1),
                         (self.WINDOW_SIZE_X + 1, -1),
                         key='-GRAPH-',
                         change_submits=True,
                         drag_submits=False)
            ],
            [
                sg.Button('Check'),
                sg.Button('Exit'),
                sg.FileBrowse('Load file', target='-FILEBROWSE-'),
                sg.Button('Load from database'),
                sg.Button('Solve with DFS')
            ],
            [sg.Input(key='-FILEBROWSE-', enable_events=True, visible=False)]
        ]

        self.window = sg.Window('Window Title',
                                self.layout,
                                finalize=True,
                                resizable=True)
        self.puzzle = self.window['-GRAPH-']
        self.row_hints = self.window['-ROWS-']
        self.col_hints = self.window['-COLUMNS-']
Example #3
0
    def __create_window(self):
        top_view_column_layout = [[sgui.Text('Top', font=("Helvetica", 13))], [sgui.Graph(canvas_size=(400, 300), graph_bottom_left=(0, 0), graph_top_right=(400, 300), background_color='black', key='top_graph')]]
        front_view_column_layout = [[sgui.Text('Front', font=("Helvetica", 13))], [sgui.Graph(canvas_size=(400, 300), graph_bottom_left=(0, 0), graph_top_right=(400, 300), background_color='black', key='front_graph')]]
        left_view_column_layout = [[sgui.Text('Left', font=("Helvetica", 13))], [sgui.Graph(canvas_size=(400, 300), graph_bottom_left=(0, 0), graph_top_right=(400, 300), background_color='black', key='left_graph')]]

        layout = [[sgui.Column(top_view_column_layout), sgui.Column(front_view_column_layout)], [sgui.Column(left_view_column_layout)]]

        self.__window = self.__window_manager.create_window('World Viewer', layout, self.__event_callback)
Example #4
0
def main_layout():
	sg.theme('DarkAmber')
	layout = [
				[sg.Graph((500,500), (0,0), (500,500), background_color='#3296A5', enable_events=True, key='board_a', visible=True),
			 	sg.VerticalSeparator(pad=(25,25)),
			 	sg.Graph((250,50),(0,0), (250,50), background_color='#AC0E47', enable_events=True, key='board_b', visible=True)]
				]
	return layout
Example #5
0
def getLayout():
	column1 = [[sg.Text('Channel 1', background_color='lightgreen', justification='center', size=(8, 1)), chantype],
				[sg.InputCombo(('VCO'), size=(20, 5), key='inst1',enable_events=True),sButton('M1'),sButton('S1')],
				[sg.Slider(range=(1, 100), key='chan1', orientation='h', size=(15, 20), default_value=85, \
						enable_events=True), MyButton('Detail1')]]

	column2 = [[sg.Text('Channel 2', background_color='#d3dfda', justification='center', size=(8, 1)), chantype],
				[sg.InputCombo((instlist), size=(20, 5), key='inst2',enable_events=True),sButton('M2'),sButton('S2')],
				[sg.Slider(range=(1, 100), key='chan2', orientation='h', size=(15, 20), default_value=85, \
						enable_events=True), MyButton('Detail2')]]

	column3 = [[sg.Text('Channel 3', background_color='#d3dfda', justification='center', size=(8, 1)), chantype],
				[sg.InputCombo((instlist), size=(20, 5), key='inst3'),sButton('M3'),sButton('S3')],
				[sg.Slider(range=(1, 100), key='chan3', orientation='h', size=(15, 20), default_value=85, \
						enable_events=True), MyButton('Detail3')]]

	column4 = [[sg.Text('Channel 4', background_color='#d3dfda', justification='center', size=(8, 1)), chantype],
				[sg.InputCombo((instlist), size=(20, 5), key='inst4'),sButton('M4'),sButton('S4')],
				[sg.Slider(range=(1, 100), key='chan4', orientation='h', size=(15, 20), default_value=85, \
						enable_events=True), MyButton('Detail4')]]

	track1 = [sg.Column(column1, background_color='lightgreen'),
		sg.Graph(canvas_size=(900, 100), graph_bottom_left=(0, 0), graph_top_right=(900, 100),
			background_color='grey', key='graphch1')]

	track2 = [sg.Column(column2, background_color='#d3dfda'),
		sg.Graph(canvas_size=(900, 100), graph_bottom_left=(0, 0), graph_top_right=(900, 100),
			background_color='grey', key='graphch2')]

	track3 = [sg.Column(column3, background_color='#d3dfda'),
		sg.Graph(canvas_size=(900, 100), graph_bottom_left=(0, 0), graph_top_right=(900, 100),
			background_color='grey', key='graphch3')]

	track4 = [sg.Column(column4, background_color='#d3dfda'),
		sg.Graph(canvas_size=(900, 100), graph_bottom_left=(0, 0), graph_top_right=(900, 100),
			background_color='grey', key='graphch4')]

	transcol = [[sg.Text('', size=(20, 2), font=('Helvetica', 20), justification='center', key='secs')],
		[MyButton('Record'), MyButton('Play'), MyButton('Stop'), MyButton('Reset')],
		[sg.Checkbox('Metronome', key='metro', default=True)],
		recordto]

	op=[[sg.Output(size=(80,15), background_color='black', text_color='yellow')]]
	#op = [[sg.Output(size=(80, 10))]]

	layout = [track1,track2,track3,track4,
		[sg.Text('_' * 210)],
		[sg.Text('     revLev        HFdamp     roomSize   Master')],
		[sg.Slider(range=(1, 100), orientation='v', size=(8, 20), key='revLev', default_value=22),
		sg.Slider(range=(1, 100), orientation='v', size=(8, 20), key='HFdamp',default_value=55),
		sg.Slider(range=(1, 100), orientation='v', size=(8, 20), key='roomSize',default_value=22),
		sg.Slider(range=(1, 100), orientation='v', size=(8, 20), key='Master',default_value=50),
		sg.Graph(canvas_size=(40, 160), graph_bottom_left=(0, 0), graph_top_right=(80, 100), background_color='red', key='graph'),
		sg.VerticalSeparator(pad=None), sg.Column(transcol), sg.VerticalSeparator(pad=None), sg.Column(op)]]

	return layout
Example #6
0
    def __init__(self, colorSus, colorAdj, colorVerb, orientacion, cantSus,
                 cantAdj, cantVerb, capsLock):
        #Representacion logica de la sopa de letras resuelta y de la sopa de letras actual
        self.__logicBoardSolution = {}
        self.__logicBoardAttempt = {}

        #Colores asignados a cada tipo de palabra
        self.__colorSus = colorSus
        self.__colorAdj = colorAdj
        self.__colorVerb = colorVerb

        #Vertical/Horizontal y Mayus/Minus
        self.__orientacion = orientacion
        self.__capsLock = capsLock

        #Cant de palabras por tipo
        self.__cantSus = int(cantSus)
        self.__cantAdj = int(cantAdj)
        self.__cantVerb = int(cantVerb)

        #Diccionario de palabras a enviar a game logic, forma numero:(palabra,color)
        self.__wordDict = {}
        self.makeWordDict()

        self.__gameLogicInstance = gameLogic(self.__wordDict, self.__capsLock,
                                             self.__orientacion)

        layout = [[sg.Button(button_text='Checkear', enable_events='True')],
                  [
                      sg.Graph(
                          canvas_size=(1200, 1200),
                          graph_bottom_left=(-1, 0),
                          graph_top_right=(
                              self.__gameLogicInstance.getBoardLength() * 20,
                              self.__gameLogicInstance.getBoardLength() * 20 +
                              1),
                          enable_events=True,
                          pad=(50, 50),
                          background_color='white',
                          key='graph'),
                      sg.Graph(canvas_size=(150, 50),
                               graph_bottom_left=(-2, 0),
                               graph_top_right=(150, 52),
                               enable_events=True,
                               background_color='white',
                               key='color')
                  ]]

        self.window = sg.Window('Windwow', layout,
                                grab_anywhere=True).Finalize()

        self.graph = self.window.Element('graph')
        self.color = self.window.Element('color')
        self.pointerDesignationColor = 'No color'
Example #7
0
def screen(orientacion, colores_mostrar, tamX, tamY, dic_color_cantPalabras):
    '''
        Dibuja el layout dependiendo de la orientacion elegida.
        Retorna el layout
    '''
    ayuda = ['Cantidad Tipos', 'Definiciones', 'Lista de palabras']
    if (orientacion == 'Horizontal'):
        #aux es una variable que indica la orientación
        aux = 1
        layout = [[
            sg.T('Tipo de Palabra'),
            sg.InputCombo(colores_mostrar, size=(20, 20), key='combo')
        ],
                  [
                      sg.T('Seleccione el tipo de ayuda'),
                      sg.InputCombo(ayuda, key='ayuda'),
                      sg.Submit('Ayuda')
                  ],
                  [
                      sg.Graph(canvas_size=(tamX, tamY),
                               graph_bottom_left=(0, tamY),
                               graph_top_right=(tamX, 0),
                               enable_events=True,
                               key='graph')
                  ], [sg.Submit('Terminar')]]
    else:
        aux = 2
        layout = [[
            sg.T('Tipo de Palabra'),
            sg.InputCombo(colores_mostrar, size=(20, 20), key='combo')
        ],
                  [
                      sg.T('Seleccione el tipo de ayuda'),
                      sg.InputCombo(ayuda, key='ayuda'),
                      sg.Submit('Ayuda')
                  ],
                  [
                      sg.Graph(canvas_size=(tamY, tamX),
                               graph_bottom_left=(0, tamX),
                               graph_top_right=(tamY, 0),
                               enable_events=True,
                               key='graph')
                  ], [sg.Submit('Terminar')]]
    window = sg.Window('Sopa').Layout(layout)
    window.Finalize()
    graph = window.FindElement('graph')

    return (layout, window, graph)
Example #8
0
    def set_layout(self):
        self.layout = [
            [
                sg.Text('Nonogram           f', key='-GAME_ID-'),
                sg.Text('', key='-OUTPUT-')
            ],
            [
                sg.Graph((self.TIP_SIZE + self.WINDOW_SIZE_X, self.TIP_SIZE),
                         (0, self.TIP_SIZE),
                         (self.TIP_SIZE + self.WINDOW_SIZE_X, 0),
                         key='-COLUMNS-',
                         change_submits=True,
                         drag_submits=False)
            ],
            [
                sg.Graph((self.TIP_SIZE, self.WINDOW_SIZE_Y),
                         (0, self.WINDOW_SIZE_Y), (self.TIP_SIZE, 0),
                         key='-ROWS-',
                         change_submits=True,
                         drag_submits=False),
                sg.Graph((self.WINDOW_SIZE_X, self.WINDOW_SIZE_Y),
                         (-5, self.WINDOW_SIZE_Y + 5),
                         (self.WINDOW_SIZE_X + 5, -5),
                         key='-GRAPH-',
                         change_submits=True,
                         drag_submits=False)
            ],
            [
                sg.Button('CHECK', button_color=('white', 'red')),
                sg.FileBrowse('Load file', target='-FILEBROWSE-'),
                sg.Button('Load from database')
            ],
            [
                sg.Button('Solve with DFS'),
                sg.Button('Solve with Logic Heuristics'),
                sg.Button('Solve with random'),
                sg.Button('Solve with GA')
            ],
            [sg.Input(key='-FILEBROWSE-', enable_events=True, visible=False)]
        ]

        self.window = sg.Window('Single game',
                                self.layout,
                                finalize=True,
                                resizable=True)
        self.puzzle = self.window['-GRAPH-']
        self.row_hints = self.window['-ROWS-']
        self.col_hints = self.window['-COLUMNS-']
    def initGraph(self):
        width = self.width
        height = self.height

        playerLayout = [[
            sg.Graph(key="canvas",
                     canvas_size=(min(width, 1280), min(height, 720)),
                     graph_bottom_left=(-width, -height),
                     graph_top_right=(width, height),
                     background_color="white")
        ], [sg.Text("", key="play-time", size=(50, 1))
            ], [sg.Text("Rendering...", key="rendering", size=(50, 1))],
                        [
                            sg.Button(key="play-pause",
                                      button_text="Pause",
                                      enable_events=True)
                        ]]

        playerWindow = sg.Window(title="nbody output", layout=playerLayout)
        playerWindow.Finalize()

        self.window = playerWindow

        # Set the initial state of the playback text.
        self.updatePlaybackText()

        self.imager.generateGif(self.srcPath, self.iterations,
                                self.frameLength)
        playerWindow["rendering"].update(f"Animation saved")
def main(location):
    sg.theme(THEME)
    gsize = (100, 55)
    layout = [
        [sg.T('CPU', font='Any 20', background_color='black')],
        [sg.Graph(gsize, (-gsize[0] // 2, 0), (gsize[0] // 2, gsize[1]), key='-Graph-')],
        [sg.T(size=(5, 1), font='Any 20', justification='c', background_color='black', k='-gauge VALUE-')]]


    window = sg.Window('CPU Usage Widget Square', layout, location=location, no_titlebar=True, grab_anywhere=True, margins=(0, 0), element_padding=(0, 0), alpha_channel=ALPHA, background_color='black', element_justification='c', finalize=True, right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_EXIT)

    gauge = Gauge(pointer_color=sg.theme_text_color(), clock_color=sg.theme_text_color(), major_tick_color=sg.theme_text_color(),
                  minor_tick_color=sg.theme_input_background_color(), pointer_outer_color=sg.theme_text_color(), major_tick_start_radius=45,
                  minor_tick_start_radius=45, minor_tick_stop_radius=50, major_tick_stop_radius=50, major_tick_step=30, clock_radius=50, pointer_line_width=3, pointer_inner_radius=10, pointer_outer_radius=50, graph_elem=window['-Graph-'])

    gauge.change(degree=0)

    while True:  # Event Loop
        cpu_percent = psutil.cpu_percent(interval=1)

        if gauge.change():
            new_angle = cpu_percent*180/100
            window['-gauge VALUE-'].update(f'{int(cpu_percent)}%')
            gauge.change(degree=new_angle, step=180)
            gauge.change()
        # ----------- update the graphics and text in the window ------------
        # update the window, wait for a while, then check for exit
        event, values = window.read(timeout=UPDATE_FREQUENCY_MILLISECONDS)
        if event == sg.WIN_CLOSED or event == 'Exit':
            break
        if event == 'Edit Me':
            sg.execute_editor(__file__)
    window.close()
def main(location):
    graph = sg.Graph(GSIZE, (0, 0), GSIZE, key='-GRAPH-', enable_events=True)
    layout = [[graph]]

    window = sg.Window('CPU Usage Widget Square', layout, location=location, no_titlebar=True, grab_anywhere=True, margins=(0, 0), element_padding=(0, 0), alpha_channel=ALPHA, finalize=True, right_click_menu=[[''], 'Exit'])

    text_id2 = graph.draw_text(f'CPU', (GSIZE[0] // 2, GSIZE[1] // 4), font='Any 20', text_location=sg.TEXT_LOCATION_CENTER,                               color=sg.theme_button_color()[0])


    while True:  # Event Loop
        # ----------- update the graphics and text in the window ------------
        cpu_percent = psutil.cpu_percent(interval=1)
        # Draw the filled rectangle
        rect_height = int(GSIZE[1] * float(cpu_percent) / 100)
        rect_id = graph.draw_rectangle((0, rect_height), (GSIZE[0], 0), fill_color=sg.theme_button_color()[1], line_width=0)
        # Draw the % used text and the close "X" on bottom
        text_id1 = graph.draw_text(f'{int(cpu_percent)}%', (GSIZE[0] // 2, GSIZE[1] // 2), font='Any 40', text_location=sg.TEXT_LOCATION_CENTER, color=sg.theme_button_color()[0])
        # text_id3 = graph.draw_text('❎', (0, 0), font='Any 8', text_location=sg.TEXT_LOCATION_BOTTOM_LEFT, color=sg.theme_button_color()[0])
        # put the bar behind everything else
        graph.send_figure_to_back(rect_id)

        # update the window, wait for a while, then check for exit
        event, values = window.read(timeout=UPDATE_FREQUENCY_MILLISECONDS)
        if event == sg.WIN_CLOSED or event == 'Exit':
            break
        if event == '-GRAPH-':  # exit if clicked in the bottom left 20 x 20 pixel area
            if values['-GRAPH-'][0] < 20 and values['-GRAPH-'][1] < 20:
                break
        # erase figures so they can be redrawn
        graph.delete_figure(rect_id)
        graph.delete_figure(text_id1)
        # graph.delete_figure(text_id3)
    window.close()
Example #12
0
 def __init__(self):
     menu_def = [
         ['File', ['Open', 'Save', 'Exit']],
         [
             'Edit',
             ['Paste', [
                 'Special',
                 'Normal',
             ], 'Undo'],
         ],
         ['Help', 'About...'],
     ]
     layout = [[sg.Menu(menu_def)],
               [
                   sg.Graph(canvas_size=(600, 600),
                            graph_bottom_left=(-10, 0),
                            graph_top_right=(210, 200),
                            enable_events=True,
                            pad=(50, 50),
                            background_color='white',
                            key='graph')
               ]]
     self.window = sg.Window('Windwow', layout,
                             grab_anywhere=True).Finalize()
     self.graph = self.window.Element('graph')
Example #13
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.width, self.height = 1800, 900
        self.BAR_HEIGHT = 10
        self.MAX_LENGTH = self.width // 4
        self.V_DISTANCE = 10

        layout = [
            [
                sg.Graph(
                    canvas_size=(self.width, self.height),
                    graph_bottom_left=(0, 0),
                    graph_top_right=(self.width, self.height),
                    key="graph",
                )
            ]
        ]

        self.window = sg.Window("Hanoi", layout)
        self.window.Finalize()

        self.graph = self.window.Element("graph")
        self.piles = {}
        num = self.model.num

        for disc in range(num):
            rect_id = self.graph.DrawRectangle(
                (0, 0),
                (int(self.MAX_LENGTH * (num - disc) / num), self.BAR_HEIGHT),
                fill_color=get_random_color(),
            )
            self.piles[disc] = rect_id
Example #14
0
def gui_choose_points(points_num):
    path = Path([])
    BOX_SIZE = 25
    DIM = 450
    layout = [[sg.Text(f"Choose {points_num} points", key="-OUTPUT-")],
              [
                  sg.Graph((800, 800), (0, DIM), (DIM, 0),
                           key="-GRAPH-",
                           change_submits=True,
                           drag_submits=False)
              ], [sg.Button("Show"), sg.Button("Exit")]]
    window = sg.Window("THE GREAT G.A.T.S.PY", layout, finalize=True)
    g, t = window["-GRAPH-"], window["-OUTPUT-"]
    g.draw_rectangle((BOX_SIZE, BOX_SIZE), (BOX_SIZE, BOX_SIZE))
    while len(path) < points_num:
        event, values = window.read()
        if event in (None, "Exit"):
            break
        mouse = values["-GRAPH-"]
        if event == "-GRAPH-":
            if mouse == (None, None):
                continue
            box_x, box_y = mouse[0], mouse[1]
            path.append(Point(1 - box_x / DIM, 1 - box_y / DIM))
            g.draw_circle((box_x, box_y),
                          5,
                          fill_color="black",
                          line_color="white")
            t.update(value=f"Choose {points_num - len(path)} points")
    window.close()
    return path
Example #15
0
def new_layout(
    window_count
):  # Create the virtual HMI interfacce with user inputs buttons and controller + state feedback text objects
    layout = [[
        sg.Graph(canvas_size=(1050, 1050),
                 graph_bottom_left=(-25, -25),
                 graph_top_right=(1025, 1025),
                 key='-GRAPH-' + str(window_count),
                 change_submits=True,
                 drag_submits=False)
    ],
              [
                  sg.Text('CONTROLLER STATUS: OFF',
                          size=(50, 1),
                          justification='left',
                          key='controller-state'),
                  sg.Text('PROCESS STATE: RESET',
                          size=(50, 1),
                          justification='left',
                          key='process-state')
              ],
              [
                  sg.T('Commands:'),
                  sg.Button('Start'),
                  sg.Button('Pause'),
                  sg.Button('Reset'),
                  sg.Text("Location of Click: "),
                  sg.Text(size=(100, 1),
                          justification='left',
                          key='mouse-click')
              ]]
    return layout
    def __init__(self):
        sg.change_look_and_feel('GreenMono')

        layout = [[
            sg.Graph(canvas_size=(1000, 400),
                     graph_bottom_left=(0, 0),
                     graph_top_right=(1000, 400),
                     key='graph',
                     enable_events=True)
        ],
                  [
                      sg.Text('Enter Expression:'),
                      sg.Input(size=(100, 1),
                               justification='left',
                               key='Expression'),
                      sg.Button('Make Tree'),
                      sg.Button('Clear'),
                      sg.Button('Exit')
                  ]]

        self.window = sg.Window('Syntax Tree', layout)
        self.window.finalize()
        self.graph = self.window['graph']
        self.parser = calc.InputParser()
        self.figures = {'nodes': [], 'text': [], 'lines': []}
        self.draw_tree = None
        self._event_loop()
        self.window.close()
    def init_graphics(self):
        self.graph = sg.Graph((600, 600), (0, 0), (450, 450),
                              key='-GRAPH-',
                              change_submits=True,
                              drag_submits=False,
                              background_color='lightblue')
        layout = [[
            sg.Text('Game of Life', font='ANY 15'),
            sg.Text('', key='-OUTPUT-', size=(30, 1), font='ANY 15')
        ], [self.graph],
                  [
                      sg.Button('Go!', key='-DONE-'),
                      sg.Text('  Delay (ms)'),
                      sg.Slider([0, 800],
                                orientation='h',
                                key='-SLIDER-',
                                enable_events=True,
                                size=(15, 15)),
                      sg.Text('', size=(3, 1), key='-S1-OUT-'),
                      sg.Text('  Num Generations'),
                      sg.Slider([0, 20000],
                                default_value=4000,
                                orientation='h',
                                size=(15, 15),
                                enable_events=True,
                                key='-SLIDER2-'),
                      sg.Text('', size=(3, 1), key='-S2-OUT-')
                  ]]

        self.window = sg.Window('Window Title', layout, finalize=True)
        event, values = self.window.read(timeout=0)
        self.delay = values['-SLIDER-']
        self.window['-S1-OUT-'].update(values['-SLIDER-'])
        self.window['-S2-OUT-'].update(values['-SLIDER2-'])
Example #18
0
def get_layout():
    boutons = [[sg.InputText(key="__NOM__", size=(
        20, 1)), sg.OK()]] + [[
            sg.Text("", size=(30, 5), auto_size_text=True, key="__MESSAGE__")
        ]] + [[
            sg.Button(button_text="BOUTON" + str(0),
                      key="BOUTON" + str(0),
                      size=(40, 2),
                      visible=False,
                      bind_return_key=True)
        ]] + [[
            sg.Button(button_text="BOUTON" + str(i),
                      key="BOUTON" + str(i),
                      size=(40, 2),
                      visible=False)
        ] for i in range(1, 6)]
    colonne = sg.Column(boutons, key="__COLONNE__")
    layout = [[
        sg.Menu([], key="__MENU__"),
    ],
              [
                  sg.Graph((WIDTH, HEIGHT), (0, HEIGHT), (WIDTH, 0),
                           background_color='green',
                           key='__TAPIS__',
                           float_values=True,
                           enable_events=True,
                           drag_submits=False), colonne
              ]]

    return layout
Example #19
0
def bar_graph():
    BAR_WIDTH = 50
    BAR_SPACING = 75
    EDGE_OFFSET = 3
    GRAPH_SIZE = (500, 500)
    DATA_SIZE = (500, 500)

    sg.theme('Light Brown 1')

    graph = sg.Graph(GRAPH_SIZE, (0, 0), DATA_SIZE)

    layout = [[sg.Text('Labelled Bar graphs using PySimpleGUI')], [graph],
              [sg.Button('OK'),
               sg.T('Click to display more data'),
               sg.Exit()]]

    window = sg.Window('Window Title', layout)

    while True:
        event, values = window.read()
        if event in (None, 'Exit'):
            break

        graph.erase()
        for i in range(7):
            graph_value = random.randint(0, 400)
            graph.draw_rectangle(
                top_left=(i * BAR_SPACING + EDGE_OFFSET, graph_value),
                bottom_right=(i * BAR_SPACING + EDGE_OFFSET + BAR_WIDTH, 0),
                fill_color='blue')
            graph.draw_text(text=graph_value,
                            location=(i * BAR_SPACING + EDGE_OFFSET + 25,
                                      graph_value + 10))
    window.close()
Example #20
0
    def __init__(self, width=850, height=400):
        self._width = width
        self._height = height
        self.graph = sg.Graph((self._width, self._height), (0, 0),
                              (self._width, self._height),
                              background_color='#fff',
                              float_values=True)

        self.sorter = Sorter(self.graph)
        self.algorithms = {}

        self.layout = [
            [sg.Button('Start')],
            [
                sg.Slider(range=(10, 200),
                          orientation='horizontal',
                          key='slider',
                          change_submits=True,
                          disable_number_display=True),
                sg.Text('Array access: 0    ', key='text')
            ],
            [self.graph],
        ]

        self.started = False
        self.slider_value = 0
Example #21
0
    def layout_theme1(self):
        preview_size=self.preview_size

        folder_choose = [ 
            [sg.Text("缺陷相片資料夾")],
            [sg.In(size=(25, 1), enable_events=True, key="-FOLDER_PATH-"), sg.FolderBrowse()],
            [sg.Listbox( values=[], enable_events=True, size=(35, 30), key="-FILE_LIST-" )],
            [sg.Button('自動辨識' ,key='-AUTO_LABEL-'), sg.Button('完成' ,key='-Finished-')]
        ]


        #left_col = [folder_choose , sg.Text('_'  * 150), file_list ]
        preview = [ [sg.Text("圖片張數:          ", key="-COUNTS-")],
                    [sg.Graph(
                        canvas_size=preview_size,
                        graph_bottom_left=(0, 0),
                        graph_top_right=self.preview_size,
                        key="-img_preview-",
                        enable_events=True,
                        background_color='black',
                        drag_submits=True,
                        right_click_menu=[[],['Erase item',]]
                        )]
                    #[sg.Image(data=self.get_img_data('images/empty.png', re_size=self.preview_size, first=True), enable_events=True, key='-img_preview-')]
                ]


        layout = [ [ sg.Column(folder_choose, vertical_alignment='top', justification='center') ,sg.Column(preview, vertical_alignment='top', justification='center')   ]]

        return layout
Example #22
0
def main():
    global g_exit, g_response_time

    layout = [[sg.T('Enter width, height of graph')],
              [sg.In(size=(6, 1)), sg.In(size=(6, 1))], [sg.Ok(),
                                                         sg.Cancel()]]

    window = sg.Window('Enter graph size').Layout(layout)
    b, v = window.Read()
    if b is None or b == 'Cancel':
        sys.exit(69)
    w, h = int(v[0]), int(v[1])
    CANVAS_SIZE = (w, h)

    # start ping measurement thread

    sg.ChangeLookAndFeel('Black')
    sg.SetOptions(element_padding=(0, 0))

    layout = [
        [sg.Quit(button_color=('white', 'black'))],
        [
            sg.Graph(CANVAS_SIZE, (0, 0), (SAMPLES, SAMPLE_MAX),
                     background_color='black',
                     key='graph')
        ],
    ]

    window = sg.Window('Canvas test',
                       grab_anywhere=True,
                       background_color='black',
                       no_titlebar=False,
                       use_default_focus=False).Layout(layout).Finalize()
    graph = window.FindElement('graph')

    prev_response_time = None
    i = 0
    prev_x, prev_y = 0, 0
    graph_value = 250
    while True:
        # time.sleep(.2)
        event, values = window.ReadNonBlocking()
        print(event, values)
        if event == 'Quit' or values is None:
            break
        graph_offset = random.randint(-10, 10)
        graph_value = graph_value + graph_offset
        if graph_value > SAMPLE_MAX:
            graph_value = SAMPLE_MAX
        if graph_value < 0:
            graph_value = 0
        new_x, new_y = i, graph_value
        prev_value = graph_value
        if i >= SAMPLES:
            graph.Move(-STEP_SIZE, 0)
            prev_x = prev_x - STEP_SIZE
        graph.DrawLine((prev_x, prev_y), (new_x, new_y), color='white')
        # window.FindElement('graph').DrawPoint((new_x, new_y), color='red')
        prev_x, prev_y = new_x, new_y
        i += STEP_SIZE if i < SAMPLES else 0
Example #23
0
    def init_graphics(self):
        self.graph = sg.Graph((600, 600), (0, 0), (450, 450),
                              key='_GRAPH_',
                              change_submits=True,
                              drag_submits=False,
                              background_color='lightblue')
        layout = [[
            sg.Text('Game of Life    ', font='ANY 15'),
            sg.Text('', key='_OUTPUT_', size=(30, 1), font='ANY 15')
        ], [self.graph],
                  [
                      sg.Button('Go!', key='_DONE_'),
                      sg.Text('  Delay (ms)'),
                      sg.Slider([0, 400],
                                orientation='h',
                                key='_SLIDER_',
                                size=(15, 15)),
                      sg.Text('  Num Generations'),
                      sg.Slider([0, 3000],
                                default_value=400,
                                orientation='h',
                                size=(15, 15),
                                key='_SLIDER2_')
                  ]]

        self.window = sg.Window('Window Title', ).Layout(layout).Finalize()
        event, values = self.window.Read(timeout=0)
        self.delay = values['_SLIDER_']
Example #24
0
def _create_recording_window(screen_size, trial_id, target_id, target, target_repeat_number):

    commands = [
        sg.Button('(S)tart acquisition', key='start_acquire'),
        sg.Button('(A)ccept and proceed', key='accept'),
        sg.Button('(R)erun trial', key='rerun_trial'),
        sg.Button('(P)revious trial', key='prev_trial'),
        sg.Button('S(k)ip this trial', key='skip_trial'),
        sg.Button('(F)ailed trial, rerun later', key='fail_trial'),
        sg.Button('(G)to to specific trial', key='choose_trial'),
        sg.Button('(Q)uit experiment', key='quit'),
    ]

    repeat_text = "" if target_repeat_number == 1 else _repeat_text(target_repeat_number)
    title = 'Target #{:}{:}: {:}'.format(target_id, repeat_text, target)

    layout = [
        [sg.Text(title, text_color='green', font=('Arial', 24))],
        [sg.Graph(screen_size, (0, screen_size[1]), (screen_size[0], 0), background_color='Black', key='graph', enable_events=True)],
        commands
    ]

    window = sg.Window('Trial #{:}'.format(trial_id), layout, return_keyboard_events=True)
    window.Finalize()

    return window
Example #25
0
def main():



    # -------------------  Build and show the GUI Window -------------------
    graph_elem = sg.Graph((600, 400), (0, 400), (600, 0),
                          enable_events=True, key='-GRAPH-', background_color='lightblue')

    hostname = socket.gethostbyname(socket.gethostname())
    layout = [[sg.Text('Ball Test'), sg.Text('My IP '+hostname)],
              [graph_elem],
              # [sg.Up(), sg.Down()],
              [sg.Button('Kick'), sg.Button('Exit')]]

    window = sg.Window('Window Title', layout, finalize=True)

    area = Playfield(graph_elem)
    area.add_balls()

    # ------------------- GUI Event Loop -------------------
    while True:  # Event Loop
        event, values = window.read(timeout=0)
        # print(event, values)
        if event in (sg.WIN_CLOSED, 'Exit'):
            break
        area.space.step(0.02)

        for ball in area.arena_balls:
            if event == 'Kick':
                ball.body.position = ball.body.position[0], ball.body.position[1]-random.randint(
                    1, 200)
            graph_elem.RelocateFigure(
                ball.gui_circle_figure, ball.body.position[0], ball.body.position[1])

    window.close()
Example #26
0
def main():
    global g_exit, g_response_time
    # start ping measurement thread

    sg.theme('Black')
    sg.set_options(element_padding=(0, 0))

    layout = [[
        sg.Quit(button_color=('white', 'black')),
        sg.Text('', pad=((100, 0), 0), font='Any 15', key='output')
    ],
              [
                  sg.Graph(CANVAS_SIZE, (0, 0), (SAMPLES, SAMPLE_MAX),
                           background_color='black',
                           key='graph')
              ]]

    window = sg.Window('CPU Graph',
                       layout,
                       grab_anywhere=True,
                       keep_on_top=True,
                       background_color='black',
                       no_titlebar=True,
                       use_default_focus=False)

    graph = window['graph']
    output = window['output']
    # start cpu measurement thread
    thread = Thread(target=CPU_thread, args=(None, ))
    thread.start()

    last_cpu = i = 0
    prev_x, prev_y = 0, 0
    while True:  # the Event Loop
        event, values = window.read(timeout=500)
        if event in ('Quit', None):  # always give ths user a way out
            break
        # do CPU measurement and graph it
        current_cpu = int(g_cpu_percent * 10)

        if current_cpu == last_cpu:
            continue
        # show current cpu usage at top
        output.update(current_cpu / 10)

        if current_cpu > SAMPLE_MAX:
            current_cpu = SAMPLE_MAX
        new_x, new_y = i, current_cpu

        if i >= SAMPLES:
            # shift graph over if full of data
            graph.move(-STEP_SIZE, 0)
            prev_x = prev_x - STEP_SIZE
        graph.draw_line((prev_x, prev_y), (new_x, new_y), color='white')
        prev_x, prev_y = new_x, new_y
        i += STEP_SIZE if i < SAMPLES else 0
        last_cpu = current_cpu

    g_exit = True
    window.close()
Example #27
0
 def layout(self):
     layout = [[
         sg.Graph((300, 300), (0, 500), (500, 0),
                  key='-GRAPH-',
                  change_submits=True,
                  drag_submits=False)
     ]]
     return layout
Example #28
0
File: gui.py Project: wweng3/PyLogo
    def make_window(self, caption, model_gui_elements, screen_shape_width_height, bounce=True, fps=None):
        """
        Create the window, including sg.Graph, the drawing surface.
        """
        # --------------------- PySimpleGUI window layout and creation --------------------
        bounce_checkbox_line = ''
        if bounce is not None:
            bounce_checkbox_line = [sg.Checkbox('Bounce?', key='Bounce?', default=bounce,
                                    tooltip='Bounce back from the edges of the screen?')]

        fps_combo_line = ''
        if fps:
            fps_combo_line = [sg.Text('Frames/second', tooltip='The maximum frames/second.', pad=((0, 10), (10, 0))),
                              sg.Combo(key='fps', values=[1, 3, 6, 10, 15, 25, 40, 60],
                                       background_color='limegreen', default_value=fps,
                                       tooltip='The maximum frames/second.', pad=((0, 0), (10, 0)))
                              ]

        setup_go_line = [
            sg.Button(self.SETUP, pad=((0, 10), (10, 0))),
            sg.Button(self.GO_ONCE, disabled=True, button_color=('white', 'green'), pad=((0, 10), (10, 0))),
            sg.Button(self.GO, disabled=True, button_color=('white', 'green'), pad=((0, 30), (10, 0)),
                      key=self.GOSTOP)   ]


        exit_button_line = [sg.Exit(button_color=('white', 'firebrick4'), key=self.EXIT, pad=((70, 0), (10, 0)))]

        col1 = [ *model_gui_elements,
                 gui.HOR_SEP(),
                 setup_go_line,
                 bounce_checkbox_line,
                 fps_combo_line,
                 gui.HOR_SEP(),
                 exit_button_line
                 ]

        lower_left_pixel_xy = (0, screen_shape_width_height[1]-1)
        upper_right_pixel_xy = (screen_shape_width_height[0]-1, 0)
        col2 = [[sg.Graph(screen_shape_width_height, lower_left_pixel_xy, upper_right_pixel_xy,
                          background_color='black', key='-GRAPH-', enable_events=True)]]

        # layout is the actual layout of the window. The stuff above organizes it into component parts.
        # col1 is the control buttons, sliders, etc.
        # col2 is the screen on which the model is portrayed, i.e., the patches and the agents.
        # layout is a single "GUI line" with these two components in sequence.
        layout = [[sg.Column(col1), sg.Column(col2)]]

        window: sg.PySimpleGUI.Window = sg.Window(caption, layout, margins=(5, 20),
                                                  use_default_focus=False,
                                                  return_keyboard_events=True, finalize=True)
        graph: sg.PySimpleGUI.Graph = window['-GRAPH-']

        # -------------- Magic code to integrate PyGame with tkinter -------
        embed: tk.Canvas = graph.TKCanvas
        os.environ['SDL_WINDOWID'] = str(embed.winfo_id( ))
        os.environ['SDL_VIDEODRIVER'] = 'windib'  # change this to 'x11' to make it work on Linux

        return window
Example #29
0
 def GraphColumn(name, key):
     layout = [
         [sg.Text(name, size=(18,1), font=('Helvetica 8'), key=key+'TXT_')],
         [sg.Graph((GRAPH_WIDTH, GRAPH_HEIGHT),
                   (0, 0),
                   (GRAPH_WIDTH, 100),
                   background_color='black',
                   key=key+'GRAPH_')]]
     return sg.Col(layout, pad=(2, 2))
Example #30
0
def main():
    global g_exit, g_response_time
    # start ping measurement thread

    sg.ChangeLookAndFeel('Black')
    sg.SetOptions(element_padding=(0, 0))

    layout = [
        [
            sg.Quit(button_color=('white', 'black')),
            sg.T('', pad=((100, 0), 0), font='Any 15', key='output')
        ],
        [
            sg.Graph(CANVAS_SIZE, (0, 0), (SAMPLES, SAMPLE_MAX),
                     background_color='black',
                     key='graph')
        ],
    ]

    window = sg.Window('CPU Graph',
                       grab_anywhere=True,
                       keep_on_top=True,
                       background_color='black',
                       no_titlebar=True,
                       use_default_focus=False).Layout(layout)

    graph = window.FindElement('graph')
    output = window.FindElement('output')
    # start cpu measurement thread
    thread = Thread(target=CPU_thread, args=(None, ))
    thread.start()

    last_cpu = i = 0
    prev_x, prev_y = 0, 0
    while True:  # the Event Loop
        time.sleep(.5)
        event, values = window.Read(timeout=0)
        if event == 'Quit' or event is None:  # always give ths user a way out
            break
        # do CPU measurement and graph it
        current_cpu = int(g_cpu_percent * 10)
        if current_cpu == last_cpu:
            continue
        output.Update(current_cpu / 10)  # show current cpu usage at top
        if current_cpu > SAMPLE_MAX:
            current_cpu = SAMPLE_MAX
        new_x, new_y = i, current_cpu
        if i >= SAMPLES:
            graph.Move(-STEP_SIZE, 0)  # shift graph over if full of data
            prev_x = prev_x - STEP_SIZE
        graph.DrawLine((prev_x, prev_y), (new_x, new_y), color='white')
        prev_x, prev_y = new_x, new_y
        i += STEP_SIZE if i < SAMPLES else 0
        last_cpu = current_cpu

    g_exit = True
    window.Close()