コード例 #1
0
    def __init__(self, client, screen):
        self.client = client
        self.screen = screen
        self.userControl = GUI.UserControl(hidden=True)
        self.rooms = []
        self.page = 1

        self.title = GUI.Text('Room Picker', (400, 50), 30, (0, 0, 0))
        self.l1 = GUI.Text('Name', (20, 100), 20, (0, 0, 0))
        self.l2 = GUI.Text('Players', (400, 100), 20, (0, 0, 0))
        self.l3 = GUI.Text('Spectators', (600, 100), 20, (0, 0, 0))
        self.lp = GUI.Text('1', (610, 510), 30, (0, 0, 0))
        self.refreshB = GUI.Button(button, (90, 500), (200, 60), text = 'Refresh', onClick=self.refresh)
        self.newRoom = GUI.Button(button, (300, 500), (200, 60), text = 'Create Room', onClick=self.createNewRoom)
        self.leftB = GUI.Button(button, (530, 500), (60, 60), text = '<-', onClick=self.left)
        self.rightB = GUI.Button(button, (650, 500), (60, 60), text = '->', onClick=self.right)

        self.userControl.labels.append(self.title)
        self.userControl.labels.append(self.l1)
        self.userControl.labels.append(self.l2)
        self.userControl.labels.append(self.l3)
        self.userControl.labels.append(self.lp)
        self.userControl.buttons.append(self.refreshB)
        self.userControl.buttons.append(self.newRoom)
        self.userControl.buttons.append(self.leftB)
        self.userControl.buttons.append(self.rightB)
コード例 #2
0
ファイル: main.py プロジェクト: zsmeton/PhysicsSimulator
def introScreen():
    buttons = []
    random_button = GUI.Button("Random Generation", WIDTH / 2 - 500, HEIGHT / 2 + 100, 200, 50, INACTIVE, ACTIVE, random_loop)
    buttons.append(random_button)
    galaxy_button = GUI.Button("Galaxy Creation", WIDTH / 2 - 100, HEIGHT / 2 + 100, 200, 50, INACTIVE, ACTIVE, galaxy_creator)
    buttons.append(galaxy_button)
    quit_button = GUI.Button("Quit", WIDTH / 2 + 300, HEIGHT / 2 + 100, 200, 50, INACTIVE, ACTIVE, quit)
    buttons.append(quit_button)
    settings_button = GUI.Button("Settings", WIDTH - 350, HEIGHT - 200, 100, 50, INACTIVE, ACTIVE, set_page)
    buttons.append(settings_button)
    intro = True
    while intro:
        for event in pg.event.get():
            for button in buttons:
                button.handle_event(event)
            # print(event)
            if event.type == pg.QUIT:
                pg.quit()
                quit()
        screen.fill(BLACK)
        screen.blit(BackGround.image, BackGround.rect)
        large_text = pg.font.Font(None, 120)
        text_surf, text_rect = GUI.text_objects("PHYSICS SIMULATOR PRO: 2018", large_text)
        text_rect.center = ((WIDTH / 2), (HEIGHT / 2) - 200)
        screen.blit(text_surf, text_rect)
        for button in buttons:
            button.check_hover()
            button.draw(screen)

        pg.display.update()
        clock.tick(60)
コード例 #3
0
    def __init__(self):

        GUI.GUI.__init__(self, (800, 600), "This is a smaller test")
        self.time_end = 0

        exit_button = GUI.Button((700, 10), (50, 30), "EXIT", (0, 100, 200))
        exit_button.onclick = self.exit
        self.buttons.append(exit_button)

        reset_button = GUI.Button((645, 10), (55, 30), "RESET", (0, 200, 100))
        reset_button.onclick = self.reset_button_clicked
        self.buttons.append(reset_button)

        self.info_caption = GUI.Caption((10, 10), (300, 50), "", 1, (0, 0, 0),
                                        (255, 255, 200))
        self.captions.append(self.info_caption)

        self.time_caption = GUI.Caption((10, 70), (250, 50), "0 seconds", 1,
                                        (0, 0, 0), (200, 255, 255))
        self.captions.append(self.time_caption)

        self.wordCount_caption = GUI.Caption((300, 10), (250, 50), "0 words out of " + str(len(self.words)) + " correct",  \
                  1, (0,0,0), (200,255,255))
        self.captions.append(self.wordCount_caption)

        self.WPM_caption = GUI.Caption((300, 70), (300, 50), "0 WPM", 1,
                                       (0, 0, 0), (255, 255, 200))
        self.captions.append(self.WPM_caption)

        self.input_word = GUI.TypeTextInput()
        self.input_word.active = True
        self.text_inputs.append(self.input_word)
コード例 #4
0
ファイル: Scenes.py プロジェクト: Pappet/Pygame-Template
    def __init__(self):
        super(TitleScene, self).__init__()

        self.playButton = GUI.Button("Play", 75, Settings.ScreenWidth / 2,
                                     Settings.ScreenHeight / 6)
        self.optionsButton = GUI.Button("Options", 75,
                                        Settings.ScreenWidth / 2,
                                        Settings.ScreenHeight / 3)
        self.exitButton = GUI.Button("Exit", 75, Settings.ScreenWidth / 2,
                                     Settings.ScreenHeight / 2)

        self.allButtons = (self.playButton, self.optionsButton,
                           self.exitButton)
コード例 #5
0
    def __init__(self, client):
        self.client = client
        self.userControl = GUI.UserControl(hidden=True)

        self.title = GUI.Text('Create Room', (400, 50), 30, (0, 0, 0))
        self.l1 = GUI.Text('Room Name', (450, 170), 20, (0, 0, 0))
        self.l2 = GUI.Text('', (300, 260), 20, (255, 0, 0))
        self.t = GUI.Textbox(button, (300, 200), (400, 60))
        self.newRoom = GUI.Button(button, (400, 300), (200, 60), text = 'Create Room', onClick=self.createNewRoom)
        self.backB = GUI.Button(button, (400, 400), (200, 60), text = 'Back', onClick=self.back)

        self.userControl.labels.append(self.title)
        self.userControl.labels.append(self.l1)
        self.userControl.labels.append(self.l2)
        self.userControl.buttons.append(self.newRoom)
        self.userControl.buttons.append(self.backB)
        self.userControl.textboxes.append(self.t)
コード例 #6
0
    def __init__(self, client):
        self.client = client
        self.userControl = GUI.UserControl(hidden=True)
        self.t = GUI.Textbox(button, (300, 200), (400, 60))
        self.b1 = GUI.Button(button, (400, 320), (200, 60), text = 'Login', onClick=self.login)
        self.b2 = GUI.Button(button, (400, 420), (200, 60), text = 'Connect', onClick=self.connect, hidden=True)
        self.s = GUI.Text('Enter Name:', (300, 160), 20, (0, 0, 0))
        self.s1 = GUI.Text('', (300, 270), 20, (255, 0, 0))
        self.s2 = GUI.Text('', (0, 550), 20, (255, 0, 0))

        self.userControl.textboxes.append(self.t)
        self.userControl.buttons.append(self.b1)
        self.userControl.buttons.append(self.b2)
        self.userControl.labels.append(self.s)
        self.userControl.labels.append(self.s1)
        self.userControl.labels.append(self.s2)

        self.connect()
コード例 #7
0
    def __init__(self, client, screen, name, anchor, addr, players, spectators):
        self.userControl = GUI.UserControl()
        self.name = name
        self.anchor = anchor
        self.addr = addr
        self.players = players
        self.spectators = spectators
        self.screen = screen
        self.client = client

        self.l1 = GUI.Text(name, (20, anchor), 20, (0, 0, 0))
        self.l2 = GUI.Text(str(players), (400, anchor), 20, (0, 0, 0))
        self.l3 = GUI.Text(str(spectators), (600, anchor), 20, (0, 0, 0))
        self.b1 = GUI.Button(button, (700, anchor), (100, 30), text = 'Play', onClick=self.play)
        self.b2 = GUI.Button(button, (810, anchor), (100, 30), text = 'Spectate', onClick=self.specate)

        self.userControl.labels.append(self.l1)
        self.userControl.labels.append(self.l2)
        self.userControl.labels.append(self.l3)
        self.userControl.buttons.append(self.b1)
        self.userControl.buttons.append(self.b2)
コード例 #8
0
ファイル: Main.py プロジェクト: BlaXun/PET-Project
    def onInit(self):

        pygame.init()
        pygame.display.set_caption("P.E.T")

        self._display_surf = pygame.display.set_mode(
            self.size, pygame.DOUBLEBUF | pygame.HWSURFACE)
        #self._display_surf = pygame.display.set_mode(self.size, pygame.FULLSCREEN)

        self.currentBackground = GFX.Background(
            self._display_surf, 'ressources/backgrounds/bg01.png', [0, 0])
        self.loadGUI()

        self._running = True

        self.exitButton = GUI.Button('button.png', [0, 0])
        self.exitButton.onPress = self.exitButtonPressed
コード例 #9
0
    def __init__(self):
        # stylize the title bar
        self.gui_window.wm_title("Record Viewer")
        self.gui_window.iconbitmap("favicon.ico")
        self.gui_window.geometry('1200x500')
        #self.gui_window.minsize(700, 730)
        self.gui_window.minsize(0, 0)

        # opened file panel
        frame = GUI.Frame(self.gui_window)
        button_open = GUI.Button(frame, text="Open", command=self.open_command)
        button_open.pack(side='left')
        self.button_qopen = GUI.Button(frame,
                                       text="Quick Open",
                                       command=self.quick_open_command)
        self.button_qopen.pack(side='left')
        self.open_file_display = GUI.EditBox(frame)
        self.open_file_display.configure(state='readonly')
        self.open_file_display.set_cursor(0)
        self.open_file_display.value = ""
        self.open_file_display.pack(side='left', fill='x', expand=1)
        self.button_export = GUI.Button(frame,
                                        text="Export Data",
                                        command=self.export_menu)
        self.button_export.pack(side='left')
        self.button_export_image = GUI.Button(frame,
                                              text="Export Image",
                                              command=self.export_image_menu)
        self.button_export_image.pack(side='left')
        button_close = GUI.Button(frame, text="Close", command=self.close_file)
        button_close.pack(side='left')
        frame.pack(fill='x')

        # renderer panel
        frame = GUI.Frame(self.gui_window)
        self.button_scan = GUI.Button(frame,
                                      text="Precalculate",
                                      command=self.scan_opened_file)
        self.button_scan.pack(side='left')
        self.raw_labels = GUI.CheckBox(frame, text="Raw Labels")
        self.raw_labels.config(command=lambda: self.configure_plot(
            'raw_labels', self.raw_labels.value))
        self.raw_labels.pack(side='left')
        self.snap_size = GUI.CheckBox(frame, text="Snap Size")
        self.snap_size.pack(side='left')
        self.button_connect = GUI.Button(
            frame,
            text="Connect",
            command=lambda: communication.open_gui(self.gui_window))
        self.button_connect.pack(side='right')
        frame.pack(fill='x')

        # graph viewing area
        w = GUI.Canvas(self.gui_window,
                       borderwidth=1,
                       relief='sunken',
                       bg='white')
        w.pack(fill='both', expand=1, padx=2, pady=2)
        self.canvas_widget = w
        self.canvas_interface = CanvasTkinterAdapter(w)

        # redraw request might be issued very often consecutively, so we should collect it
        self.redraw_canvas = GUI.CombineCall(w, self.collected_redraw_canvas)
        self.collected_redraw_call.function_to_call = self.redraw_canvas

        def on_canvas_resize(event):
            # store the dimensions inside the widget itself
            # snap if necessary
            if self.snap_size.value:
                self.canvas_widget.width = snap(event.width)
                self.canvas_widget.height = snap(event.height)
            else:
                self.canvas_widget.width = event.width
                self.canvas_widget.height = event.height

            self.redraw_canvas()

        w.bind('<Configure>', on_canvas_resize)

        # init with preliminary values, in case the system doesn't generate Configure events
        self.canvas_widget.width = 1200
        self.canvas_widget.height = 800

        GUI.bind_mouse_events(w)

        # render empty plot
        self.redraw_canvas()
コード例 #10
0
ファイル: GCS.py プロジェクト: NielsHokke/DroneController
def init_gui():
    global safe_bt
    global panic_bt 
    global man_bt
    global cal_bt
    global yaw_bt
    global full_bt
    global raw_bt

    #name,top,left,hor,uns,trim:
    GUI.Guibar("Roll",440,60,True,False,True)
    GUI.Guibar("Pitch",500,60,True,False,True)
    GUI.Guibar("Yaw",560,60,True,False,True)
    GUI.Guibar("Lift",620,60,True,True,True)

    GUI.Guibar("M1",440,300,False,True,False,1000)
    GUI.Guibar("M2",440,340,False,True,False,1000)
    GUI.Guibar("M3",440,380,False,True,False,1000)
    GUI.Guibar("M4",440,420,False,True,False,1000)

    GUI.Guibar("Pitch",200,500,True,False,False, 12000, 133)
    GUI.Guibar("Yaw",260,500,True,False,False, 2**16, 182)
    GUI.Guibar("Roll",320,500,True,False,False, 12000, 133)

    GUI.Guibar("",175,410,False,True,False,numscale=100, bat=True, size=160, minr=1000,maxr=1300)
    
    #name,top,left,width,height,function
    safe_bt = GUI.Button("0: SAFE",720,60,80,40,8,12)
    safe_bt.set_selected()
    panic_bt = GUI.Button("1: PANIC",720,150,80,40,8,8)
    panic_bt.set_enable(False)
    man_bt = GUI.Button("2: MAN",720,240,80,40,8,12)
    cal_bt = GUI.Button("3: CAL",720,330,80,40,8,16)
    yaw_bt = GUI.Button("4: YAW",720,420,80,40,8,15)
    full_bt = GUI.Button("5: FULL",720,510,80,40,8,14)
    raw_bt = GUI.Button("6: RAW",720,600,80,40,8,12)

    GUI.Button("SEND",625,600,80,25,2,18)

    P_H = 415

    #P_YAW buttons
    GUI.Button("<<",P_H,600,20,20,-1,4)
    GUI.Button("<",P_H,620,20,20,-1,6)
    GUI.Button(">",P_H,640,20,20,-1,2)
    GUI.Button(">>",P_H,660,20,20,-1,2)
    #P1buttons
    GUI.Button("<<",P_H+30,600,20,20,-1,4)
    GUI.Button("<",P_H+30,620,20,20,-1,6)
    GUI.Button(">",P_H+30,640,20,20,-1,2)
    GUI.Button(">>",P_H+30,660,20,20,-1,2)
    #P2buttons
    GUI.Button("<<",P_H+60,600,20,20,-1,4)
    GUI.Button("<",P_H+60,620,20,20,-1,6)
    GUI.Button(">",P_H+60,640,20,20,-1,2)
    GUI.Button(">>",P_H+60,660,20,20,-1,2)
    #Y+ buttons
    GUI.Button("<<",P_H+90,600,20,20,-1,4)
    GUI.Button("<",P_H+90,620,20,20,-1,6)
    GUI.Button(">",P_H+90,640,20,20,-1,2)
    GUI.Button(">>",P_H+90,660,20,20,-1,2)
    #Y- buttons
    GUI.Button("<<",P_H+120,600,20,20,-1,4)
    GUI.Button("<",P_H+120,620,20,20,-1,6)
    GUI.Button(">",P_H+120,640,20,20,-1,2)
    GUI.Button(">>",P_H+120,660,20,20,-1,2)
    #Y+ buttons
    GUI.Button("<<",P_H+150,600,20,20,-1,4)
    GUI.Button("<",P_H+150,620,20,20,-1,6)
    GUI.Button(">",P_H+150,640,20,20,-1,2)
    GUI.Button(">>",P_H+150,660,20,20,-1,2)
    #Y- buttons
    GUI.Button("<<",P_H+180,600,20,20,-1,4)
    GUI.Button("<",P_H+180,620,20,20,-1,6)
    GUI.Button(">",P_H+180,640,20,20,-1,2)
    GUI.Button(">>",P_H+180,660,20,20,-1,2)
コード例 #11
0
def connect(tk_parent, host):
    try:
        c = PowerGraphConnection(host)

        # create window
        window = GUI.Toplevel(tk_parent)
        window.wm_title("Raspberry Control")
        window.iconbitmap("favicon.ico")
        window.transient(tk_parent)
        window.resizable(0, 0)
        window.lift()
        window.grab_set()
        window.focus_set()

        # buttons
        frame = GUI.Frame(window)
        GUI.Button(frame,
                   text="Configure Hardware",
                   command=lambda: configure_hardware(window, c)).pack(
                       side='left', padx=2, pady=2)
        GUI.Button(frame,
                   text="Download Records",
                   command=lambda: download(window, c)).pack(side='left',
                                                             padx=2,
                                                             pady=2)
        frame2 = GUI.Frame(frame, relief='sunken', borderwidth=0)
        GUI.Button(frame2,
                   text="Start Measurement",
                   command=lambda: c.start_measurement()).pack(padx=2, pady=2)
        GUI.Button(frame2,
                   text="Stop Measurement",
                   command=lambda: c.stop_measurement()).pack(padx=2, pady=2)
        frame2.pack(side='top', padx=2, pady=2)
        frame.grid(row=0, columnspan=2)

        # creating settings widgets line by line
        def add_labeled_widget(new_widget, label):
            GUI.Label(window,
                      text=label).grid(row=add_labeled_widget.grid_row,
                                       column=0,
                                       sticky=GUI.align_option('right'))
            new_widget.grid(row=add_labeled_widget.grid_row,
                            column=1,
                            sticky=GUI.align_option('left', 'right'))
            add_labeled_widget.grid_row += 1
            return new_widget

        add_labeled_widget.grid_row = 1

        w_downsampling = add_labeled_widget(
            GUI.EditBox(window), "combine n samples into 1 (downsampling):")
        w_resulting_rate = add_labeled_widget(GUI.Label(window),
                                              "resulting sample rate:")
        w_filename_counter = add_labeled_widget(GUI.EditBox(window),
                                                "filename counter:")

        # load config from tool and display it in the dialog
        config = c.get_config()
        w_downsampling.value = config.compound_count
        w_resulting_rate.value = config.frequency // config.compound_count
        w_filename_counter.value = config.filename_counter

        # apply button
        def apply_settings():
            try:
                downsampling = int(w_downsampling.value)
                if downsampling < 1:
                    raise ValueError("downsampling value must be 1 or higher")
                config.compound_count = downsampling
                config.filename_counter = int(w_filename_counter.value)
                c.set_config(config)
            except Exception as e:
                GUI.messagebox.showwarning("Error", str(e))

        GUI.Button(window, text="Apply Settings", command=apply_settings).grid(
            row=add_labeled_widget.grid_row,
            column=0,
            columnspan=2,
            padx=2,
            pady=2)

        # show window
        GUI.center_window(window, tk_parent)
        tk_parent.wait_window(window)

        c.close()

    except ConnectionRefusedError as e:
        GUI.messagebox.showwarning("Error", str(e))
        return
    except Exception as e:
        GUI.messagebox.showwarning("Error", str(e))
        return
コード例 #12
0
def configure_hardware(tk_parent, connection):
    from signal_diagram import SignalDiagram
    c = connection

    # we need a dry run. stop any existing measurements
    c.stop_measurement()
    c.start_dry_run()

    # create window
    window = GUI.Toplevel(tk_parent)
    window.wm_title("Raspberry Control")
    window.iconbitmap("favicon.ico")
    window.transient(tk_parent)
    window.resizable(0, 0)
    window.lift()
    window.grab_set()
    window.focus_set()

    # fill GUI line by line
    def next_row():
        next_row.row += 1
        return next_row.row

    next_row.row = -1

    # creating settings widgets line by line
    def add_labeled_widget(new_widget, label):
        row = next_row()
        GUI.Label(window, text=label).grid(row=row,
                                           column=0,
                                           sticky=GUI.align_option('right'))
        new_widget.grid(row=row,
                        column=1,
                        sticky=GUI.align_option('left', 'right'))
        return new_widget

    w_device_name = add_labeled_widget(GUI.EditBox(window), "device name:")
    w_unit_name = add_labeled_widget(GUI.EditBox(window),
                                     "physical unit name (A):")
    w_unit_range = add_labeled_widget(
        GUI.EditBox(window), "physical unit for ADC max (e.g. 120m):")
    w_sample_rate = add_labeled_widget(GUI.ComboBoxEx(window),
                                       "samples per second:")
    w_ADC_min = add_labeled_widget(GUI.EditBox(window), "ADC min value (hex):")
    w_ADC_max = add_labeled_widget(GUI.EditBox(window), "ADC max value (hex):")
    w_SPI_output = add_labeled_widget(GUI.EditBox(window),
                                      "SPI output pattern (hex):")
    w_SPI_clock_invert = add_labeled_widget(GUI.CheckBox(window),
                                            "SPI clock inverted")
    w_SPI_clock_delay = add_labeled_widget(GUI.CheckBox(window),
                                           "SPI clock delayed")
    w_bit_shift = add_labeled_widget(GUI.EditBox(window),
                                     "ADC data bit position:")
    w_digital_shift = add_labeled_widget(GUI.EditBox(window),
                                         "digital channel bit position:")

    # load config from tool and display it in the dialog
    config = c.get_config()
    w_device_name.value = config.device_name
    w_unit_name.value = config.unit_name
    w_unit_range.value = format_significand_exponent(config.unit_significand,
                                                     config.unit_exponent)
    w_sample_rate.values = [
        '488281', '244140', '122070', '61035', '30517', '15258', '7629',
        '3814', '1907', '953'
    ]
    w_sample_rate.value = config.frequency
    w_ADC_min.value = "{:04X}".format(config.ADC_min)
    w_ADC_max.value = "{:04X}".format(config.ADC_max)
    w_SPI_output.value = "{:08X}".format(config.SPI_output_pattern)
    w_SPI_clock_invert.value = (config.SPI_clock_mode & 0x1) != 0
    w_SPI_clock_delay.value = (config.SPI_clock_mode & 0x2) != 0
    w_bit_shift.value = config.bit_shift
    w_digital_shift.value = config.digital_bit_shift

    # create diagram
    diagram = SignalDiagram(window, config)
    diagram.grid(row=0, column=3, rowspan=next_row(), sticky='wens')

    # update diagram with live data
    def tick():
        raw = c.get_raw_SPI_block()
        #print("{:08X}".format(raw))
        diagram.live_data = raw
        diagram.redraw()
        diagram.update()
        tick.timer = tk_parent.after(300, tick)

    tick()

    # completion
    def apply_action():
        c.stop_measurement()
        with dialogs.ProgressDialog(window, "Please wait..") as dialog:
            dialog.set_maximum(2)
            dialog.set_progress(0)
            # this simple statement will wait for Raspberry to stop the measurement, which can take a while depending on the configuration
            c.is_measurement_running()
        try:
            new_config = copy(config)
            current_entry = "device name"
            if len(w_device_name.value) > 31:
                raise ValueError("too long")
            new_config.device_name = w_device_name.value
            current_entry = "unit name"
            if len(w_unit_name.value) > 15:
                raise ValueError("too long")
            new_config.unit_name = w_unit_name.value
            current_entry = "unit range"
            new_config.unit_significand, config.unit_exponent = read_format_significand_exponent(
                w_unit_range.value)
            current_entry = "sample rate"
            new_config.frequency = int(w_sample_rate.value)
            current_entry = "ADC min"
            new_config.ADC_min = int(w_ADC_min.value, 16)
            current_entry = "ADC max"
            new_config.ADC_max = int(w_ADC_max.value, 16)
            current_entry = "SPI clock mode"
            new_config.SPI_output_pattern = int(w_SPI_output.value, 16)
            current_entry = "SPI clock mode"
            new_config.SPI_clock_mode = (1 if w_SPI_clock_invert.value else
                                         0) + (2 if w_SPI_clock_delay.value
                                               else 0)
            current_entry = "ADC bit position"
            new_config.bit_shift = int(w_bit_shift.value)
            current_entry = "digital channel position"
            new_config.digital_bit_shift = int(w_digital_shift.value)
            current_entry = "unknown"
            c.set_config(config)
            diagram.config = new_config
            c.start_dry_run()
        except (ValueError, struct.error) as e:
            GUI.messagebox.showwarning(
                "Error",
                "Invalid entry in {}\n{}".format(current_entry, str(e)))
            return

    frame = GUI.Frame(window)
    GUI.Button(window, text="Apply Changes",
               command=apply_action).grid(column=0,
                                          row=next_row(),
                                          columnspan=2)

    # show window
    GUI.center_window(window, tk_parent)
    tk_parent.wait_window(window)
    tk_parent.after_cancel(tick.timer)

    c.stop_measurement()
コード例 #13
0
def choose_host(tk_parent):
    # create window
    window = GUI.Toplevel(tk_parent)
    window.wm_title("Connect...")
    window.iconbitmap("favicon.ico")
    window.transient(tk_parent)
    window.resizable(0, 0)
    window.lift()
    window.grab_set()
    window.focus_set()

    # listbox for display of raspberry-pi devices found in local network
    listbox = GUI.Listbox(window)
    listbox.pack(fill='both', expand=1, padx=2, pady=2)

    # edit box for input of custom address
    editbox = GUI.EditBox(window)
    editbox.configure(state='active')
    editbox.set_cursor(0)
    editbox.pack(side='left', fill='x', expand=1)

    # load initial value from last time
    try:
        with open("saved_address.txt", 'r') as address_file:
            editbox.value = address_file.read()
    except:
        pass

    # button to connect to custom input
    custom_go = GUI.Button(window, text="Connect")
    custom_go.pack(side='left')

    GUI.center_window(window, tk_parent)

    # keep track of beacons (name, host)
    beacons = []

    listbox.delete(0, GUI.END)

    def add_beacon(device_name, host):
        if host not in beacons:
            beacons.append(host)
            listbox.insert(GUI.END, "{} - {}".format(device_name, host))

    # start listening for UDP broadcasts
    global broadcast_socket
    broadcast_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    broadcast_socket.setblocking(0)
    broadcast_socket.bind(('', PORT))  # listen to every network interface

    def tick():
        try:
            while True:
                data, (host, port) = broadcast_socket.recvfrom(256)
                if data.startswith(b'PowerGraph beacon '):
                    data = data[18:]
                    device_name = data[:data.find(b'\x00')].decode()
                    add_beacon(device_name, host)
                else:
                    print("weird broadcast message received on correct port")
        except BlockingIOError:
            tick.timer_id = window.after(500, tick)
        except OSError:
            print("unexpected: received message that was too big\n")

    def tick_stop():
        window.after_cancel(tick.timer_id)
        broadcast_socket.close()

    tick()

    # handle listbox click events
    def on_select(e):
        select_index = listbox.curselection()
        if len(select_index) > 0:
            editbox.value = beacons[int(select_index[0])]

    listbox.bind('<<ListboxSelect>>', on_select)

    # on button click
    def on_click(*discard):
        if editbox.value != "":
            # save user's choice so we can load it next time
            with open("saved_address.txt", 'w') as address_file:
                address_file.write(editbox.value)

            on_click.result = editbox.value
            window.destroy()

    on_click.result = None
    custom_go.configure(command=on_click)
    listbox.bind('<Double-Button-1>', on_click)

    # redraw everything
    tk_parent.wait_window(window)
    tick_stop()
    print("user choice: {}".format(on_click.result))

    return on_click.result
コード例 #14
0
import pygame  # Импорт PyGame
import GUI  # Наш модуль с GUI
import sys

pygame.init()

screen = pygame.display.set_mode((192, 300))

pygame.display.set_caption('калькулятор')
clock = pygame.time.Clock()

# Кнопки, и другие виджеты
i = []  # Создаем массив, чтоб легче было хранить виджеты

i.append(GUI.Button(screen, '0', width=32, height=32, y=268,
                    x=32))  # Создаём кнопку
i.append(GUI.Button(screen, '1', width=32, height=32, y=236,
                    x=0))  # Ещё кнопка :)
i.append(GUI.Button(screen, '2', width=32, height=32, y=236, x=32))
i.append(GUI.Button(screen, '3', width=32, height=32, y=236, x=64))
i.append(GUI.Button(screen, '4', width=32, height=32, y=204, x=0))
i.append(GUI.Button(screen, '5', width=32, height=32, y=204, x=32))
i.append(GUI.Button(screen, '6', width=32, height=32, y=204, x=64))
i.append(GUI.Button(screen, '7', width=32, height=32, y=172, x=0))
i.append(GUI.Button(screen, '8', width=32, height=32, y=172, x=32))
i.append(GUI.Button(screen, '9', width=32, height=32, y=172, x=64))

i.append(GUI.Button(screen, '.', width=32, height=32, y=268, x=64))
i.append(
    GUI.Button(screen,
               '=',
コード例 #15
0
ファイル: main.py プロジェクト: zsmeton/PhysicsSimulator
def set_page():
    global settings
    buttons = []
    setting_texts = []
    x_pos = -500
    y_sep = 100
    width = 200
    height = 50
    walls_button = GUI.Button("Walls", WIDTH / 2 + x_pos, HEIGHT / 2 - 2 * y_sep, width, height, INACTIVE, ACTIVE, state=settings['walls'], state_name='walls')
    buttons.append(walls_button)

    trails_button = GUI.Button("Trails", WIDTH / 2 + x_pos, HEIGHT / 2 - y_sep, width, height, INACTIVE, ACTIVE, state=settings['trails'], state_name='trails')
    buttons.append(trails_button)

    cool_trail_button = GUI.Button("Cool Trails", WIDTH / 2 + x_pos, HEIGHT / 2, width, height, INACTIVE, ACTIVE, state=settings['cool_trail'], state_name='cool_trail')
    buttons.append(cool_trail_button)

    strobe_button = GUI.Button("Strobe", WIDTH / 2 + x_pos, HEIGHT / 2 + y_sep, width, height, INACTIVE, ACTIVE, state=settings['strobe'], state_name='strobe')
    buttons.append(strobe_button)

    aa_button = GUI.Button("Anti-Aliasing", WIDTH / 2 + x_pos, HEIGHT / 2 + 2 * y_sep, width, height, INACTIVE, ACTIVE, state=settings['aa'], state_name='aa')
    buttons.append(aa_button)

    t_step_button = GUI.Button("Speed", WIDTH / 2 + x_pos, HEIGHT / 2 + 3 * y_sep, width, height, INACTIVE, ACTIVE, state=settings['t_step'], state_name='t_step')
    buttons.append(t_step_button)

    in_settings = True
    while in_settings:
        # --- Set Up --- #
        # Create Planets
        for event in pg.event.get():
            for button in buttons:
                output = button.handle_event(event)
                if output is not None:
                    print("the output is :", output)
            if event.type == pg.KEYUP:
                if event.key == pg.K_ESCAPE:
                    introScreen()
        screen.fill(BLACK)
        screen.blit(BackGround.image, BackGround.rect)
        settings_text = pg.font.Font(None, 120)
        text_surf, text_rect = GUI.text_objects("Settings", settings_text)
        text_rect.center = ((WIDTH / 2), (HEIGHT / 2) - 500)
        screen.blit(text_surf, text_rect)
        for button in buttons:
            setting = button.variable
            settings[setting] = button.state
            button.check_hover()
            button.draw(screen)

        with open("settings.txt", 'w+') as data:
            for setting in settings:
                    # change the contents of the line
                    if isinstance(settings[setting], bool):
                        line = "%s: %r\n" % (setting, settings[setting])
                    else:
                        line = "%s: %.1f\n" % (setting, settings[setting])
                    print(line)
                    # write line to file
                    data.write(line)

        for text in setting_texts:
            text.draw(screen)

        pg.display.update()
        clock.tick(60)
コード例 #16
0
        # Menu stuff
        Utility.LogMessage("Initializing image assets...", "LOADINGINFO")
        Title = pygame.image.load("Assets/GUI/Title.png")

        ScoreIndicatorImage = pygame.image.load(
            "Assets/GUI/score_indicator.png")
        HighScoreIndicatorImage = pygame.image.load(
            "Assets/GUI/highscore_indicator.png")

        Text2 = pygame.image.load("Assets/GUI/Text2.png")

        # Pause menu stuff
        Pause_Title = pygame.image.load("Assets/GUI/PauseMenu/title.png")

        Pause_Button_Resume = GUI.Button(
            "Assets/GUI/PauseMenu/resume_normal.png",
            "Assets/GUI/PauseMenu/resume_hover.png", (325, 250))
        Pause_Button_Quit = GUI.Button("Assets/GUI/PauseMenu/quit_normal.png",
                                       "Assets/GUI/PauseMenu/quit_hover.png",
                                       (325, 350))

        # The buttons of the Game
        Utility.LogMessage("Initializing buttons...", "LOADINGINFO")
        Button_Play = GUI.Button("Assets/GUI/PlayButton.png",
                                 "Assets/GUI/PlayButtonHover.png", (50, 200))
        Button_Settings = GUI.Button("Assets/GUI/OptionsButton.png",
                                     "Assets/GUI/OptionsButtonHover.png",
                                     (50, 300))
        Button_Credits = GUI.Button("Assets/GUI/CreditsButton.png",
                                    "Assets/GUI/CreditsButtonHover.png",
                                    (50, 400))