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('', font='Helvetica 25', 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, location=(0, 0)).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 event, values = window.Read(timeout=500) 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()
def __init__(self, core: CoreBI): self.core = core layout = [[ sg.Text('', key=self.msgKey, size=(20, 1), auto_size_text=True, font=(self.font, 20), justification='center') ], [ sg.Text('Current time: '), sg.Text('', key=self.currentTimeKey, size=(20, 1)) ], [ sg.Text('Full time: '), sg.Input(self.core.getSetting("timer_time"), key=self.durationKey, tooltip=f"in the format {self.durationFormat}", enable_events=True), sg.Button('Set', button_color=('white', '#FF8800'), bind_return_key=True) ], [ sg.Button('Start', button_color=('white', '#00FF00')), sg.Button('Stop', button_color=('white', '#FF0000')), sg.Button('Reset', button_color=('white', '#FF8800')) ], [sg.Quit()]] self.window = sg.Window(title='Simple Clock', layout=layout, keep_on_top=self.core.keepOnTop, icon=get_abs_path("icon-play.png")) # , icon=) self.normalFontColor = self.window[self.currentTimeKey].TextColor self.run_window_loop()
random.seed() cute.theme("DarkBlack") layout = [ [ cute.Text( "Press the button when you're ready. The button will go dark.") ], [cute.Text("Then, after some time, it will light up for you to click.")], [ cute.Text( "Your reaction time to click the button will be compared to the speed of light!" ) ], [cute.Button("Ready", key="-BUTTON-"), cute.Quit()], [cute.Text("Results will appear here.", key="-RES1-")], [cute.Text("", key="-RES2-")] ] window = cute.Window("The Speed Of Light", layout) def startGame(): state.pop(0) state.append(State.PREPARING) while True: event, values = window.read(timeout=1000) if state[0] == State.PREPARING: