示例#1
0
    def __init__(self, **params):
        gui.Desktop.__init__(self, **params)

        self.connect(gui.QUIT, self.quit, None)

        c = gui.Container(width=1000, height=600)

        self.fname = None

        self.open_d = gui.FileDialog()
        self.open_d.connect(gui.CHANGE, self.action_open, self.open_d)
        self.save_d = gui.FileDialog()
        self.save_d.connect(gui.CHANGE, self.action_save_close, self.save_d)

        menus = gui.Menus([('Archivo/Nuevo', self.action_new, None),
                           ('Archivo/Abrir', self.open_d.open, None),
                           ('Archivo/Guardar', self.action_save, self.fname),
                           ('Archivo/Guardar como...', self.save_d.open, None),
                           ('Archivo/Salir', self.quit, None)])
        c.add(menus, 0, 0)
        menus.rect.w, menus.rect.h = menus.resize()

        change_b = gui.Button("Cambiar Fondo")
        change_b.connect(gui.CLICK, self.action_open_background, None)
        c.add(change_b, 0, 100)

        self.editor = Editor(width=800, height=600, style={'border': 1})

        c.add(self.editor, 200, 0)
        self.editor.resize()
        self.widget = c
示例#2
0
文件: gui.py 项目: trimlab/microMVP
 def SetupMenus(self):
     self.menus = menus = gui.Menus([
         ('File/Exit', self.quit_d.open, None),
         ('Help/Help', self.help_d.open, None),
         ('Help/About', self.about_d.open, None),
     ])
     return menus
示例#3
0
    def __init__(self, init_cb, save, load, set_ai_cb, font):
        self.app = gui.App()
        self.app.connect(gui.QUIT, self.app.quit, None)
        container = gui.Container(align=-1, valign=-1)
        self.font = font

        self.save_dlg = SaveDialog(save)
        self.load_dlg = LoadDialog(load)
        self.about_dlg = AboutDialog()
        self.dialogs = (self.save_dlg, self.load_dlg, self.about_dlg)

        menus = gui.Menus([
            ('Game/New', init_cb, True),
            ('Game/Save', self.save_dlg.open, None),
            ('Game/Load', self.load_dlg.open, None),
            ('Game/Quit', self.quit, None),
            ('AI Level/Dumb', set_ai_cb, AI_Level.dumb),
            ('AI Level/Smart', set_ai_cb, AI_Level.smart),
            ('Help/About', self.about_dlg.open, None),
        ])
        menus.rect.w, menus.rect.h = menus.resize()
        self.doc = gui.Document(width=0, height=0)  # TODO: vertical?
        self.log_box = gui.ScrollArea(self.doc,
                                      SCREEN_WIDTH,
                                      100,
                                      hscrollbar=False)
        self.log("Welcome to Battleships!")

        container.add(menus, 0, 0)
        container.add(self.log_box, 0, SCREEN_HEIGHT - 100)
        self.menus = menus
        self.elements = (menus, self.log_box)
        self.app.init(container)
示例#4
0
def init_app(data):
	global app
	app = _app(data)
	
	#
	ss = 8
		
	#--- top
	x,y,h = 0,0,0
		
	#menus
	e = gui.Menus(menus)
	e.rect.w,e.rect.h = e.resize()
	app.add(e,x,y)
	menus_height = e.rect.h
	h = max(h,menus_height)
		
	#--- row
	x,y,h = ss,y+h+ss,0

	#vdraw
	dw = app.screen_w - (app.tiles_w+ss*4)
	dh = app.screen_h - (menus_height+ss*2)
	app.view_init(dw,dh)
	
	e = app.vdraw = vdraw(width=app.view_w, height=app.view_h)
	e.rect.w,e.rect.h = e.resize()
	app.add(e,x,y)
	x,h = x+e.rect.w,max(h,e.rect.h)
	
	#--- hspace
	x += ss
	
	#tpicker
	e = app.tpicker = tpicker()
	e.rect.w,e.rect.h = e.resize()
	#--- right
	x = app.screen_w-e.rect.w-ss
	app.add(e,x,y)
	x,h = x+e.rect.w,max(h,e.rect.h)
	tpicker_height = e.rect.h
	
	#cpicker
	e = app.cpicker = cpicker()
	e.rect.w,e.rect.h = e.resize()
	#--- right
	x = app.screen_w-e.rect.w-ss
	app.add(e,x,y+tpicker_height+ss)
	x,h = x+e.rect.w,max(h,e.rect.h)
	
	pygame.key.set_repeat(500,30)
	
	app.screen.fill((255,255,255,255))
示例#5
0
    def __init__(self,**params):
        gui.Desktop.__init__(self,**params)

        self.connect(gui.QUIT,self.quit,None)

        c = gui.Container(width=940,height=980)
        spacer = 8

        self.fname = 'untitled.tga'

        self.new_d = NewDialog()
        self.new_d.connect(gui.CHANGE,self.action_new,None)
        self.open_d = OpenDialog()
        self.open_d.connect(gui.CHANGE,self.action_open,None)
        self.save_d = SaveDialog()
        self.save_d.connect(gui.CHANGE,self.action_saveas,None)
        self.quit_d = QuitDialog()
        self.quit_d.connect(QUIT,self.quit,None)

        self.help_d = HelpDialog()
        self.about_d = AboutDialog()

        ##Initializing the Menus, we connect to a number of Dialog.open methods for each of the dialogs.
        ##::
        menus = gui.Menus([
            ('File/New',self.new_d.open,None),
            ('File/Open',self.open_d.open,None),
            ('File/Save',self.action_save,None),
            ('File/Save As',self.save_d.open,None),
            ('File/Exit',self.quit_d.open,None),
            ('Help/Help',self.help_d.open,None),
            ('Help/About',self.about_d.open,None),
            ])
        ##
        c.add(menus,0,0)
        menus.rect.w,menus.rect.h = menus.resize()
        #print 'menus',menus.rect

        ##We utilize a Toolbox.  The value of this widget determins how drawing is done in the Painter class.
        ##::
        self.mode = mode = gui.Toolbox([
            ('Draw','draw'),
            ('Box','box'),
            ('Circle','circle'),
            ('Cuzco','cuzco'),
            ],cols=1,value='draw')
        ##
        c.add(mode,0,menus.rect.bottom+spacer)
        mode.rect.x,mode.rect.y = mode.style.x,mode.style.y
        mode.rect.w,mode.rect.h = mode.resize()
        #mode._resize()

        default = "#000000"
        self.color = color = gui.Color(default,width=mode.rect.w,height=mode.rect.w)
        self.color_d = ColorDialog(default)

        color.connect(gui.CLICK,self.color_d.open,None)

        # Updates the toolbox color picker with the value in the color dialog box
        def change_cb(*args):
            self.color.value = self.color_d.value
        self.color_d.connect(gui.CHANGE, change_cb)

        c.add(self.color,0,mode.rect.bottom+spacer)
        self.color.rect.w,self.color.rect.h = self.color.resize()
        #self.color._resize()

        self.painter = Painter(width=c.rect.w-mode.rect.w-spacer*2,height=c.rect.h-menus.rect.h-spacer*2,style={'border':1})
        c.add(self.painter,mode.rect.w+spacer,menus.rect.h+spacer)
        self.painter.init({'width':956,'height':956,'color':'#ffffff'})
        self.painter.rect.w,self.painter.rect.h = self.painter.resize()
        #self.painter._resize()

        welcome_d = WelcomeDialog()
        self.connect(gui.INIT,welcome_d.open,None)

        self.widget = c
示例#6
0
def run():
    global app
    global worldnames
    global worlds
    global display_worlds

    try:
        loc = myterraria / "Game Launcher" / "omnitool.gli3"
        data = {
            "appAuthor": __author__ + " (Berserker66)",
            "appName": "Omnitool",
            "appPath": os.path.abspath(sys.argv[0]),
            "appVersion": __version__.__repr__()
        }
        with loc.open("wt") as f:
            f.write(json.dumps(data, indent=4))
    except:
        import traceback

        print(
            "Could not register to GameLauncher 3. Maybe it just isn't installed. Exception:"
        )
        traceback.print_exc()

    try:
        worldnames = list(get_worlds())
    except FileNotFoundError:
        worldnames = []
        print("Omnitool has found no worlds")

    use_override = True
    if use_override:
        app = MyApp(theme=theme)
    else:
        import pgu
        app = pgu.gui.App(theme=theme)
    worlds = []
    ts = [
        threading.Thread(target=get_world, args=(world, worlds))
        for world in worldnames
    ]
    tuple(t.start() for t in ts)
    pad = 10
    x = 0

    data = [
        ("Omnitool/" + lang.settings, Settings, None),
        ("Omnitool/" + "Language", Language, None),
        ("Omnitool/" + lang.report_issue, webbrowser.open,
         "https://github.com/Berserker66/omnitool/issues"),
        ("Omnitool/" + lang.exit, exit_prog, None),
        (lang.start + "/" + lang.terraria, webbrowser.open,
         "steam://rungameid/105600"),
    ]

    if "tedit" in cache and os.path.exists(cache["tedit"]):

        def run_tedit(n):
            subprocess.Popen(cache["tedit"],
                             cwd=os.path.split(cache["tedit"])[0])

        data.append((lang.start + "/TEdit", run_tedit, None))
    if "terrafirma" in cache:
        if os.path.exists(cache["terrafirma"]):

            def run_terrafirma(n):
                subprocess.Popen(cache["terrafirma"],
                                 cwd=os.path.split(cache["terrafirma"])[0])

            data.append((lang.start + "/Terrafirma", run_terrafirma, None))
    data.extend([
        (lang.open + "/" + lang.imagefolder, open_dir, images),
        (lang.open + "/" + lang.backupfolder, open_dir,
         myterraria / "WorldsBackup"),
        (lang.open + "/" + lang.themes, open_dir, Path.cwd() / "themes"),
        (lang.visit + "/" + lang.donate, webbrowser.open,
         r"https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=JBZM8LFAGDK4N"
         ),
        (lang.visit + "/Patreon", webbrowser.open,
         r"https://www.patreon.com/Berserker55"),
        (lang.visit + "/" + lang.homepage, webbrowser.open,
         r"http://forums.terraria.org/index.php?threads/omnitool-world-creation-mapping-backups-and-more.14664/"
         ),
        (lang.visit + "/" + lang.wiki, webbrowser.open,
         "http://terraria.gamepedia.com/Terraria_Wiki"),
        (lang.visit + "/GameLauncher GUI", webbrowser.open,
         "http://forums.terraria.org/index.php?threads/game-launcher-3-2-1-5.1061/"
         ),
    ])
    forbidden = ["flatworld", "planetoids", "worldify", "arena"]
    for plug in plugins_:
        if plug[0] not in forbidden and plug[2] != "injector":
            data.append(("Plugins/%s" % plug[1], start_proc,
                         (relay_launch_plugin, [plug[1], plug])))
    os.environ["SDL_VIDEO_WINDOW_POS"] = "20,50"

    app.connect(gui.QUIT, exit_prog, None)
    main = gui.Table()

    menu = gui.Menus(data)
    main.td(gui.Spacer(pad, pad))
    main.td(menu, colspan=5, align=-1)
    main.td(gui.Spacer(pad, pad))
    main.tr()
    update = gui.Table()
    update.td(gui.Label(""))
    main.td(update, col=1, colspan=5, align=-1)

    main.tr()
    width = 190
    worldify = GenButton(lang.worldify, IMAGE, width=width)
    planetoids = GenButton(lang.planetoids, PLANET, width=width)
    dungeon = GenButton(lang.arena, DUNGEON, width=width)
    flat = GenButton(lang.flat, FLAT, width=width)

    tuple(t.join() for t in ts)
    expected_h = 170 * len(worlds) // cache["columns"] + 100
    pygame.display.init()
    available_h = max([res[1] for res in pygame.display.list_modes()])
    if expected_h > available_h:
        print("GUI expected to be higher than monitor height, adding columns")
        cache["columns"] = max(cache["columns"] + 1,
                               1 + (170 * len(worlds)) // (available_h - 100))
    del (ts)
    newworldtable = gui.Table()
    newworldtable.td(gui.Spacer(10, 10))
    newworldtable.td(gui.Label(lang.new), align=-1)
    newworldtable.tr()
    newworldtable.td(gui.Spacer(10, 10))
    newworldtable.td(worldify)
    newworldtable.td(gui.Spacer(10, 10))
    newworldtable.td(planetoids)
    newworldtable.td(gui.Spacer(10, 10))
    newworldtable.td(dungeon)
    newworldtable.td(gui.Spacer(10, 10))
    newworldtable.td(flat)
    newworldtable.tr()
    newworldtable.td(gui.Spacer(10, 10))
    main.td(newworldtable, colspan=6)
    main.tr()
    worldtable = gui.Table()
    main.td(worldtable, colspan=6)

    def display_worlds(optionchange=False):
        worldtable.clear()
        x = 0
        for w in worlds:
            if x % cache["columns"] == 0:
                worldtable.tr()
            wtab = gui.Table()
            wtab.td(w.info, colspan=2)
            wtab.tr()
            if thumbsize:
                wtab.td(w.image, colspan=2)
            else:
                wtab.td(gui.Spacer(1, 20))
            wtab.tr()
            wtab.td(gui.Spacer(pad, pad))
            wtab.tr()

            wtab.td(gui.Spacer(420, 25), colspan=2)
            wtab.tr()

            worldtable.td(gui.Spacer(pad, 1))
            worldtable.td(wtab)

            x += 1
        if x % cache["columns"] == 0:
            worldtable.tr()

        worldtable.td(gui.Spacer(12, 12))
        if app.widget:
            print("Window Reset!")
            app.resize()
            app.repaint()
            size = pygame.display.get_surface().get_size()
            data = {
                "size": size,
                "w": size[0],
                "h": size[1],
                "reload": True if optionchange else False
            }

            pygame.event.post(pygame.event.Event(pygame.VIDEORESIZE, data))

    display_worlds()
    print("GUI Matrix created, initializing..")
    pygame.display.quit()
    pygame.display.init()
    pygame.display.set_caption("Terraria Omnitool V%s | %d Bit" %
                               (__version__.__repr__(), bit))

    def make_resize(worlds, app, main):
        def resize(self, ev):
            if app.first and not app.zoomed:
                app.first = False
            else:
                padding = 50
                if hasattr(ev, "reload") and ev.reload == True:
                    thumb_w, thumb_h = cache["thumbsize"]
                    for w in worlds:
                        w.override_thumb((thumb_w, thumb_h))
                        w.info.style.width = thumb_w
                        w.thumbsize = (thumb_w, thumb_h)
                else:
                    thumb_w = max((ev.w - padding) // cache["columns"], 420)
                    thumb_h = int(thumb_w / 3.5)

                    for w in worlds:
                        w.override_thumb((thumb_w, thumb_h))
                        w.info.style.width = thumb_w
                        w.thumbsize = (thumb_w, thumb_h)

                app.rect.size = main.rect.size = main.w, main.h = main.resize()
                if sys.platform.startswith("win"):
                    if windll.user32.IsZoomed(
                            pygame.display.get_wm_info()['window']):
                        s = pygame.display.set_mode(ev.size, pygame.RESIZABLE)
                        app.rect.size = pygame.display.get_surface().get_size()
                        app.zoomed = True
                    else:
                        s = pygame.display.set_mode((main.w, main.h),
                                                    pygame.RESIZABLE)
                        app.zoomed = False
                else:
                    s = pygame.display.set_mode((main.w, main.h),
                                                pygame.RESIZABLE)
                    app.zoomed = False

                app.screen = s
                app.first = True

        return resize

    app.on_resize = make_resize(worlds, app, main)
    app.init(main, None)

    main.rect.h = max(main.rect.height, 250)
    if cache["thumbsize"]:
        pygame.display.set_mode((main.rect.size[0] - 2, main.rect.size[1] - 2),
                                pygame.SWSURFACE | pygame.RESIZABLE)
    else:
        pygame.display.set_mode(main.rect.size, pygame.SWSURFACE)
    info = Info()
    info.name = "Info"
    info.daemon = False

    updater = Updater(update)
    updater.daemon = False

    if cache["do_backup"]:
        b = Backupper()
        b.name = "Backup"
        b.start()
    redrawer = Redrawer()
    redrawer.start()
    info.start()
    updater.start()
    app.run(main)
示例#7
0
def init_app():
    global app
    app = _app()

    #
    ss = 8

    # --- top
    x, y, h = 0, 0, 0

    # menus
    e = gui.Menus(menus)
    e.rect.w, e.rect.h = e.resize()
    app.add(e, x, y)
    x, h = x + e.rect.w, max(h, e.rect.h)
    menus_height = e.rect.h

    # --- row
    x, y, h = 0, y + h, 0

    # --- vspace
    y += ss

    # --- hspace
    x += ss

    # tools
    e = gui.Toolbox(tools, 1, 0, value='tile')  # ,"icons48")
    e.rect.w, e.rect.h = e.resize()

    def _set_mode(value):
        cmd_mode(value.value)

    e.connect(gui.CHANGE, _set_mode, e)
    app.add(e, x, y)
    app.tools = e.tools
    x, h = x + e.rect.w, max(h, e.rect.h)
    toolbox_width = e.rect.w

    # --- hspace
    x += ss

    # vdraw
    dw = app.screen_w - (toolbox_width + app.tiles.get_width() + ss * 4)
    dh = app.screen_h - (menus_height + ss * 2)
    app.view_init(dw, dh)

    e = app.vwrap = vwrap()
    app.vdraw = e.vdraw
    e.rect.w, e.rect.h = e.resize()
    app.add(e, x, y)
    x, h = x + e.rect.w, max(h, e.rect.h)

    # --- hspace
    x += ss

    # tpicker
    e = app.tpicker = tpicker()
    e.rect.w, e.rect.h = e.resize()
    # --- right
    x = app.screen_w - e.rect.w - ss
    app.add(e, x, y)
    x, h = x + e.rect.w, max(h, e.rect.h)
    tpicker_height = e.rect.h

    # cpicker
    e = app.cpicker = cpicker()
    e.rect.w, e.rect.h = e.resize()
    # --- right
    x = app.screen_w - e.rect.w - ss
    app.add(e, x, y + tpicker_height + ss)
    x, h = x + e.rect.w, max(h, e.rect.h)

    pygame.key.set_repeat(500, 30)

    app.screen.fill((255, 255, 255, 255))
示例#8
0
def init_app():
    global app
    app = _app()

    #
    colors_height = 64
    ss = 8

    #--- top
    x, y, h = 0, 0, 0

    #menus
    e = gui.Menus(menus)
    e.rect.w, e.rect.h = e.resize()
    app.add(e, x, y)
    x, h = x + e.rect.w, max(h, e.rect.h)
    menus_height = e.rect.h

    #--- row
    x, y, h = 0, y + h, 0

    #--- vspace
    y += ss

    #--- hspace
    x += ss

    #tools
    e = gui.Toolbox(tools, 1, 0, value='draw')  #,"icons48")
    e.rect.w, e.rect.h = e.resize()

    def _set_mode(value):
        cmd_mode(value.value)

    e.connect(gui.CHANGE, _set_mode, e)
    app.add(e, x, y)

    #--- vspace
    y += ss

    #--- switchbox for saving.
    sx, sy = x, y + (max(h, e.rect.h))

    savelabel = gui.Label("Save on")
    app.add(savelabel, sx, sy)
    savelabel2 = gui.Label("focus:")
    app.add(savelabel2, sx, sy + (ss * 2))

    #--- vspace
    y += (ss * 5)
    sy += (ss * 5)

    save_activeevent_switch = gui.Switch(False)
    app.add(save_activeevent_switch, sx, sy)
    app.save_activeevent_switch = save_activeevent_switch

    x, h = x + e.rect.w, max(h, e.rect.h)
    toolbox_width = e.rect.w

    #--- hspace
    x += ss
    y -= ss * 6  #undo what was done above to the y val

    #tdraw
    #tdraw-calcs
    dw = app.screen_w - (toolbox_width + app.tiles.get_width() + ss * 4)
    dh = app.screen_h - (menus_height + colors_height + ss * 2)
    if dw / float(app.tile_w) > dh / float(app.tile_h):
        dw = dh / float(app.tile_h) * app.tile_w
    else:
        dh = dw / float(app.tile_w) * app.tile_h
    e = app.tdraw = tdraw(dw, dh)
    app.add(e, x, y)
    x, h = x + e.rect.w, max(h, e.rect.h)

    #--- hspace
    x += ss

    #tpicker
    e = app.tpicker = tpicker()
    e.rect.w, e.rect.h = e.resize()
    #--- right
    x = app.screen_w - e.rect.w - ss
    app.add(e, x, y)
    h = max(h, e.rect.h)

    #tpreview
    y = y + e.rect.h
    e = app.tpreview = tpreview()
    e.rect.w, e.rect.h = e.resize()
    app.add(e, x, y)

    #--- bottom
    x, y, h = 0, app.screen_h - colors_height, 0

    #cpreview
    colors_width = toolbox_width + ss * 2
    e = app.cpreview = cpreview(colors_width, colors_height)
    e.rect.w, e.rect.h = e.resize()
    app.add(e, x, y)
    x, h = x + e.rect.w, max(h, e.rect.h)

    #cpicker
    if os.path.isfile(cfg['palette']):
        pal = pygame.image.load(cfg['palette'])
    else:
        #default to EGA / NES palette

        pw, ph = 16, 6
        pdata = [
            (0, 0, 0, 255), (0, 0, 170, 255), (0, 170, 0, 255),
            (0, 170, 170, 255), (170, 0, 0, 255), (170, 0, 170, 255),
            (170, 85, 0, 255), (170, 170, 170, 255), (85, 85, 85, 255),
            (85, 85, 255, 255), (85, 255, 85, 255), (85, 255, 255, 255),
            (255, 85, 85, 255), (255, 85, 255, 255), (255, 255, 85, 255),
            (255, 255, 255, 255), (0, 0, 0, 255), (0, 0, 0, 255),
            (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255),
            (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255),
            (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255),
            (0, 0, 0, 255), (0, 0, 0, 255), (255, 255, 255, 255),
            (173, 243, 255, 255), (223, 214, 255, 255), (255, 190, 255, 255),
            (255, 176, 255, 255), (255, 177, 237, 255), (255, 191, 185, 255),
            (255, 217, 145, 255), (237, 246, 128, 255), (185, 255, 138, 255),
            (145, 255, 173, 255), (128, 255, 223, 255), (138, 255, 255, 255),
            (197, 197, 197, 255), (0, 0, 0, 255), (0, 0, 0, 255),
            (255, 255, 255, 255), (129, 200, 255, 255), (179, 171, 255, 255),
            (231, 146, 255, 255), (255, 132, 244, 255), (255, 133, 194, 255),
            (255, 148, 141, 255), (244, 173, 101, 255), (194, 202, 84, 255),
            (141, 227, 94, 255), (101, 240, 129, 255), (84, 240, 179, 255),
            (94, 225, 231, 255), (120, 120, 120, 255), (0, 0, 0, 255),
            (0, 0, 0, 255), (192, 192, 192, 255), (57, 128, 200, 255),
            (108, 99, 217, 255), (160, 74, 207, 255), (200, 61, 172, 255),
            (217, 61, 122, 255), (207, 76, 70, 255), (172, 102, 30, 255),
            (122, 130, 13, 255), (70, 155, 23, 255), (30, 169, 57, 255),
            (13, 168, 108, 255), (23, 153, 160, 255), (61, 61, 61, 255),
            (0, 0, 0, 255), (0, 0, 0, 255), (128, 128, 128, 255),
            (16, 87, 159, 255), (67, 58, 176, 255), (119, 34, 166, 255),
            (159, 20, 131, 255), (176, 20, 81, 255), (166, 35, 29, 255),
            (131, 61, 0, 255), (81, 89, 0, 255), (29, 114, 0, 255),
            (0, 128, 16, 255), (0, 127, 67, 255), (0, 112, 119, 255),
            (0, 0, 0, 255), (0, 0, 0, 255), (0, 0, 0, 255)
        ]

        pal = pygame.Surface((pw, ph), SWSURFACE, 32)
        n = 0
        for py in range(0, ph):
            for px in range(0, pw):
                pal.set_at((px, py), pdata[n])
                n += 1

    e = app.cpicker = cpicker(app.screen_w - colors_width, colors_height, pal)
    e.rect.w, e.rect.h = e.resize()
    app.add(e, x, y)
    x, h = x + e.rect.w, max(h, e.rect.h)

    pygame.key.set_repeat(500, 30)

    app.screen.fill((255, 255, 255, 255))
示例#9
0
    def __init__(self, zoom):
        pygame.init()
        size = self.can_width, self.can_height = 1000, 700
        self.sgc_screen = sgc.surface.Screen(size)

        self.game_screen = pygame.display.set_mode(size)
        global version
        pygame.display.set_caption("Robosim " + version)
        background_colour = (255, 255, 255)
        self.game_screen.fill(background_colour)

        panel_colour = (200, 200, 200)
        self.manual_panel = pygame.Surface((1000, 100))
        self.manual_panel.set_alpha(200)
        self.manual_panel.fill(panel_colour)

        self.app = gui.App()
        self.app.connect(gui.QUIT, self.app.quit, None)
        self.c = gui.Container(width=1000, height=700)
        menus = gui.Menus([
            ('File/Load Scenery', self.load_pressed, None),
            ('File/Quit', self.quit_button, None),
            #            ('Controls/Keep Centered', self.foo, None),
            ('Controls/Simulation Preferences', self.sim_prefs, None),
            ('Controls/Reset Robot Position', self.reset_posn, None)
        ])
        ##
        self.c.add(menus, 0, 0)
        menus.rect.w, menus.rect.h = menus.resize()
        self.app.init(self.c)

        self.top_panel = pygame.Surface((1000, 50))
        self.top_panel.set_alpha(200)
        self.top_panel.fill(panel_colour)

        self.clock = pygame.time.Clock()

        self.manual_enabled = False
        self.manual_switch = sgc.Switch(pos=(400, 10),
                                        label=" Manual Controls",
                                        label_col=(0, 0, 0),
                                        state=False)
        self.manual_switch.add(order=3)
        self.manual_switch.on_click = self.set_manual

        t = "Noise Model: None"
        self.noise_label = sgc.Label(pos=(600, 12), text=t, col=(0, 0, 0))
        self.noise_label.add()

        self.front_ir_switch = sgc.Switch(pos=(100, 605),
                                          label=" Front IR",
                                          label_col=(0, 0, 0),
                                          state=False)
        self.front_ir_switch.on_click = self.set_ir_front

        self.side_ir_switch = sgc.Switch(pos=(430, 605),
                                         label=" Side IR",
                                         label_col=(0, 0, 0),
                                         state=False)
        self.side_ir_switch.on_click = self.set_ir_side

        self.us_switch = sgc.Switch(pos=(430, 660),
                                    label=" Ultrasound",
                                    label_col=(0, 0, 0),
                                    state=False)
        self.us_switch.on_click = self.set_us

        self.left_ir_scale = sgc.Scale(pos=(10, 655),
                                       min=-90,
                                       max=90,
                                       label="Left IR Angle",
                                       label_col=(0, 0, 0),
                                       show_value=0,
                                       label_side="top")
        self.left_ir_scale.on_drag = self.lservo_set
        self.left_ir_scale.value = 0

        self.right_ir_scale = sgc.Scale(pos=(210, 655),
                                        min=-90,
                                        max=90,
                                        label="Right IR Angle",
                                        label_col=(0, 0, 0),
                                        show_value=0,
                                        label_side="top")
        self.right_ir_scale.on_drag = self.rservo_set
        self.right_ir_scale.value = 0

        zoom_scale = sgc.Scale(pos=(150, 5),
                               min=4,
                               max=20,
                               label="Zoom",
                               label_col=(0, 0, 0),
                               show_value=0)
        zoom_scale.value = 10
        zoom_scale.add(order=4)
        zoom_scale.on_drag = self.set_zoom

        self.joystick = sgc.Joystick(pos=(700, 600),
                                     min=-10,
                                     max=10,
                                     label="Joystick",
                                     label_col=(0, 0, 0),
                                     show_value=False)
        #self.joystick.value=0,0
        self.joystick.default_value = 0, 0
        self.joystick.on_drag = self.jb_set

        #fps = sgc.FPSCounter(pos=(300,300), clock=self.clock, label="FPS")
        #fps.add(0)

        self.count = 0
        self.zoom = zoom
        self.x_offset = 0
        self.y_offset = 0
        self.ir_front_used = False
        self.ir_side_used = False
        self.us_used = False
        self.noise_model = SAMPLED_NOISE
        self.noise_value = 0
        self.rand_under = False
        self.display_text = ["UCL", "RoboSim"]
        self.create_display()
        self.active = True
        self.timenow = 0
        self.last_active = 0