示例#1
0
    def __init__(self, engine, **params):
        self.engine = engine

        self._count = 0

        title = gui.Label("Open Item")

        t = gui.Table()

        t.tr()
        t.td(gui.Label('Select an item:'), colspan=2)

        t.tr()
        t.td(gui.Spacer(10, 20))

        t.tr()
        self.itemList = gui.List(width=200, height=140)
        t.td(self.itemList, colspan=2)

        t.tr()
        t.td(gui.Spacer(10, 20))

        t.tr()
        e = gui.Button('Open item')
        e.connect(gui.CLICK, self.openItem, None)
        t.td(e)

        e = gui.Button('Cancel')
        e.connect(gui.CLICK, self.close, None)
        t.td(e)

        t.tr()
        t.td(gui.Spacer(10, 10))

        gui.Dialog.__init__(self, title, t)
示例#2
0
	def __init__(self, **params):
		gui.Table.__init__(self, **params)
		self.value = gui.Form()
		self.engine = None

		self._data = ''

		self._count = 1
		self.focused = False

		self.tr()
		self.chatMsg = gui.Input(size=52, focusable=False)
		self.chatMsg.connect(gui.KEYDOWN, self.lkey)
		self.td(self.chatMsg)

		self.tr()
		self.chatList = gui.List(width=480, height=170)
		self.td(self.chatList)

		self.tr()
		class Hack(gui.Spacer):
			def resize(self, width=None, height=None):
				#self.chatListBox.set_vertical_scroll(65535)
				return 1, 1

		self.td(Hack(1, 1))
示例#3
0
    def __init__(self, inputfield, **params):
        self.inpField = inputfield

        self._count = 1

        title = gui.Label("Map Selector")

        t = gui.Table()

        t.tr()
        t.td(gui.Label('Select a map:'), colspan=2)

        t.tr()
        t.td(gui.Spacer(10, 20))

        t.tr()
        self.mapList = gui.List(width=200, height=140)
        t.td(self.mapList, colspan=2)

        t.tr()
        t.td(gui.Spacer(10, 20))

        t.tr()
        e = gui.Button('Choose map')
        e.connect(gui.CLICK, self.setInput, None)
        t.td(e)

        e = gui.Button('Cancel')
        e.connect(gui.CLICK, self.close, None)
        t.td(e)

        t.tr()
        t.td(gui.Spacer(10, 10))

        gui.Dialog.__init__(self, title, t)
示例#4
0
    def __init__(self, title_txt, button_txt, allow_new, cls="dialog"):
        self.value = None
        self.save_folder = config.config.save_folder

        self.save_games = {}
        self._populate_save_games()

        if allow_new:
            self.name_input = gui.Input()
        else:
            self.name_input = None

        td_style = {
            'padding_left': 4,
            'padding_right': 4,
            'padding_top': 2,
            'padding_bottom': 2,
        }

        self.save_list = gui.List(width=350, height=250)
        games = self.save_games.keys()
        games.sort()
        for name in games:
            self.save_list.add(name, value=name)
        self.save_list.set_vertical_scroll(0)
        self.save_list.connect(gui.CHANGE, self._save_list_change)

        self.image_container = gui.Container()

        button_ok = gui.Button(button_txt)
        button_ok.connect(gui.CLICK, self._click_ok)

        button_cancel = gui.Button("Cancel")
        button_cancel.connect(gui.CLICK, self._click_cancel)

        body = gui.Table()
        body.tr()
        body.td(self.save_list, style=td_style, colspan=2)
        body.td(self.image_container, style=td_style, colspan=2)
        body.tr()
        if self.name_input:
            body.td(gui.Label("Save as:"), style=td_style, align=1)
            body.td(self.name_input, style=td_style)
        else:
            body.td(gui.Spacer(0, 0), style=td_style, colspan=2)
        body.td(button_ok, style=td_style, align=1)
        body.td(button_cancel, style=td_style, align=1)

        title = gui.Label(title_txt, cls=cls + ".title.label")
        gui.Dialog.__init__(self, title, body)

        if games:
            self.save_list.group.value = games[0]
示例#5
0
    def __init__(self, **params):
        gui.Table.__init__(self, **params)

        self.listCount = 0

        # dialogs
        openNpcDialog = OpenNPCDialog(self)

        self.value = gui.Form()

        self.tr()
        self.td(gui.Label("Map Name:", color=UI_FONT_COLOR))
        self.td(gui.Input("", size=16, name="inpMapName"))

        self.tr()
        self.td(gui.Label("Warp Up:", color=UI_FONT_COLOR))
        self.td(gui.Input("0", size=4, name="inpMapUp"))

        self.tr()
        self.td(gui.Label("Warp Down:", color=UI_FONT_COLOR))
        self.td(gui.Input("0", size=4, name="inpMapDown"))

        self.tr()
        self.td(gui.Label("Warp Left:", color=UI_FONT_COLOR))
        self.td(gui.Input("0", size=4, name="inpMapLeft"))

        self.tr()
        self.td(gui.Label("Warp Right:", color=UI_FONT_COLOR))
        self.td(gui.Input("0", size=4, name="inpMapRight"))

        self.tr()
        self.td(gui.Spacer(10, 10))

        # npc list
        self.tr()
        e = gui.Button('Add NPC...', width=80)
        e.connect(gui.CLICK, openNpcDialog.openDialog, None)
        self.td(e)

        e = gui.Button('Remove', width=80)
        e.connect(gui.CLICK, self.removeNpc, None)
        self.td(e)

        self.tr()
        self.npcList = gui.List(width=200, height=80, name='lstNpcs')
        self.td(self.npcList, colspan=2)

        self.loadProperties()
示例#6
0
    def __init__(self, n=None):

        main = gui.Table()
        gui.Dialog.__init__(self, gui.Label(lang.settings), main)

        liste = gui.List(200, 114)
        liste.value = themename
        themes = "themes"
        for dire in os.listdir(themes):
            liste.add(str(dire), value=dire)
        self.liste = liste

        liste = gui.Select()
        liste.value = cache["columns"]
        for x in (1, 2, 3, 4, 5):
            liste.add(str(x), value=x)
        self.columns = liste

        backupswitch = gui.Switch()
        backupswitch.value = cache["do_backup"]
        self.backup = backupswitch
        sizelist = gui.Select(value=thumbsize)
        sizelist.add(lang.none, 0)
        sizelist.add(lang.small, (420.0, 120.0))
        sizelist.add(lang.medium, (630.0, 180.0))
        sizelist.add(lang.large, (840.0, 240.0))
        sizelist.add(lang.very_large, (1260.0, 360.0))
        self.sizelist = sizelist
        main.td(gui.Label(lang.warning, color=(127, 0, 0)), colspan=2)
        main.tr()
        main.td(gui.Label(lang.theme_select))
        main.td(gui.Label(lang.thumbsize))
        main.tr()
        main.td(self.liste, rowspan=5)
        main.td(sizelist)
        main.tr()
        main.td(gui.Label(lang.world_columns), col=1, row=3)
        main.tr()
        main.td(self.columns, col=1, row=4)
        main.tr()
        main.td(gui.Label(lang.mk_backups), col=1, row=5)
        main.tr()
        main.td(backupswitch, col=1, row=6)

        self.open()
示例#7
0
    def __init__(self, n=None):
        main = gui.Table()
        gui.Dialog.__init__(self, gui.Label("Language"), main)

        liste = gui.List(200, 150)
        langs = [
            "german", "english", "portuguese", "czech", "spanish", "french",
            "norwegian", "japanese", "danish", "italian", "hungarian",
            "russian", "chinese"
        ]
        langnames = [lang.capitalize() for lang in langs]
        for name, dire in zip(langnames, langs):
            liste.add(name, value=dire)
        self.liste = liste
        self.liste.value = cache["lang"]
        main.td(self.liste)

        self.open()
示例#8
0
    def gen_gui(self):
        #get theme, language and end process function from omnitool API
        from omnitool.shared import lang, theme, exit_prog, exit_prog
        from omnitool.pgu_override import Quitbutton

        #initilize pygame renderer
        pygame.display.init()
        #set window title to Flatworld, from language file
        pygame.display.set_caption(lang.flat)
        #application interface
        app = gui.Desktop(theme=theme)
        #main container, table
        main = gui.Table(width=800)
        #connect the QUIT event with Omnitool API exit_prog
        app.connect(gui.QUIT, exit_prog, None)
        #add label size to table
        main.td(gui.Label(lang.fw_size))
        #size drop down selection
        size = gui.Select(width=300)
        size.add(lang.fw_tiny, 4)
        size.add(lang.fw_small, 0)
        size.add(lang.fw_medium, 1)
        size.add(lang.fw_large, 2)
        size.add(lang.fw_square, 3)
        size.value = 0
        #add it to the table
        main.td(size)
        #surface label
        main.td(gui.Label(lang.fw_surf))

        surf = [
            "Grass Block", "Corrupt Grass Block", "Jungle Grass Block",
            "Mushroom Grass Block", "Hallowed Grass Block"
        ]
        #surface drop down menu
        sur = gui.Select(width=300)
        sur.add("None", None)
        for grass in surf:
            sur.add(grass, tiles.index(grass))
        sur.value = None
        #add surface selection to table
        main.td(sur)

        #go to next line in table
        main.tr()
        #add tile label to table
        main.td(gui.Label(lang.fw_tile))
        #create tile list
        tiles_ = gui.List(300, 150)
        for tile in tiles:
            if tiles.index(tile) not in multitiles:
                tiles_.add(gui.Label(tile), value=tiles.index(tile))
        #add tile list to table
        main.td(tiles_)
        #add wall label to table
        main.td(gui.Label(lang.fw_wall))
        #create wall list
        guiwalls = gui.List(300, 150)
        for wall in walls:
            guiwalls.add(gui.Label(wall), value=walls.index(wall))
        #add wall list to table
        main.td(guiwalls)
        #next row
        main.tr()
        #Generate! button
        main.td(Quitbutton(app, lang.pt_start), colspan=4)
        #run the application and open the window
        app.run(main)
        #when it's done, instruct pygame to clean up
        pygame.display.quit()
        #attach data to plugin, to be used in run()
        self.surface = sur.value
        self.wall = guiwalls.value
        self.tile = tiles_.value
        self.size = size.value
        if self.wall == 0:
            self.wall = None
示例#9
0
    def genGui(self):
        from omnitool import themename, Theme, lang, exit_prog

        theme = Theme(themename)

        class Quitbutton(gui.Button):
            def __init__(self, value="Finish"):
                gui.Button.__init__(self, value, width=60, height=40)
                try:
                    self.connect(gui.CLICK, app.quit, None)
                except AttributeError:
                    self.connect(gui.CLICK, app.close, None)

        pygame.display.init()

        pygame.display.set_caption("Header Modifier")

        app = gui.Desktop(theme=theme)

        main = gui.Table(width=300)

        app.connect(gui.QUIT, exit_prog, None)

        main.td(gui.Label("Spawn Point: "))
        X = gui.Input(value=self.header["spawn"][0], size=5)
        Y = gui.Input(value=self.header["spawn"][1], size=4)
        main.td(X)
        main.td(Y)
        main.tr()

        main.td(gui.Label("Hardmode: "))
        hardmode = gui.Switch(self.header["hardmode"])
        main.td(hardmode)

        main.td(gui.Label("Day: "))
        daytime = gui.Switch(self.header["is_day"])
        main.td(daytime)
        main.tr()

        main.td(gui.Label("Eye of Cthulhu killed: "))
        eoc = gui.Switch(self.header["bosses_slain"][0])
        main.td(eoc)

        main.td(gui.Label("Eater of Worlds killed: "))
        eow = gui.Switch(self.header["bosses_slain"][1])
        main.td(eow)
        main.tr()

        main.td(gui.Label("Skeletron killed: "))
        skelly = gui.Switch(self.header["bosses_slain"][2])
        main.td(skelly)

        main.td(gui.Label("Saved Goblin Tinkerer: "))
        tinkerbell = gui.Switch(self.header["npcs_saved"][0])
        main.td(tinkerbell)
        main.tr()

        main.td(gui.Label("Saved Mechanic: "))
        mech = gui.Switch(self.header["npcs_saved"][1])
        main.td(mech)

        main.td(gui.Label("Saved Wizard: "))
        wizziewizz = gui.Switch(self.header["npcs_saved"][2])
        main.td(wizziewizz)
        main.tr()

        main.td(gui.Label("Bloodmoon: "))
        bloodz = gui.Switch(self.header["is_bloodmoon"])
        main.td(bloodz)

        main.td(gui.Label("World Name: "))
        worldName = gui.Input(value=self.header["name"], size=8)
        main.td(worldName)
        main.tr()

        main.td(gui.Label("Invasion Type: "))
        # invasion = gui.Select()
        #invasion.add("None",0)
        #invasion.add("Goblin Invasion",1)
        #invasion.add("Frost Legion",2)
        invType = gui.List(110, 50)
        invType.add("None", value=0)
        invType.add("Goblin Invasion", value=1)
        invType.add("Frost Legion", value=2)

        if invType.value == None:
            invType.value = 0

        #main.td(invasion)
        main.td(invType)

        main.td(gui.Label("Invasion Amount (0-1000): "))
        invSize = (gui.Input(value=self.header["gob_inv_size"], size=8))
        main.td(invSize)
        main.tr()

        main.tr()

        main.td(Quitbutton(), colspan=4)

        app.run(main)

        pygame.display.quit()

        bosses = (int(eoc.value), int(eow.value), int(skelly.value))
        npcSaved = (int(tinkerbell.value), int(mech.value),
                    int(wizziewizz.value))

        self.header["spawn"] = (int(X.value), int(Y.value))
        self.header["hardmode"] = int(hardmode.value)
        self.header["is_day"] = int(daytime.value)
        self.header["bosses_slain"] = bosses
        self.header["is_bloodmoon"] = int(bloodz.value)
        self.header["name"] = worldName.value
        self.header["gob_inv_size"] = int(invSize.value)
        self.header["gob_inv_type"] = int(invType.value)
        self.header["npcs_saved"] = npcSaved
示例#10
0
    global _count
    my_list.add("item " + str(_count), value=_count)
    my_list.resize()
    my_list.repaint()
    _count += 1


#gui.theme.load('../data/themes/default')
app = gui.Desktop()
app.connect(gui.QUIT, app.quit, None)

main = gui.Container(width=500, height=400)  #, background=(220, 220, 220) )

main.add(gui.Label("List Example", cls="h1"), 20, 20)

my_list = gui.List(width=150, height=100)
main.add(my_list, 250, 100)

b = gui.Button("add item", width=150)
main.add(b, 40, 110)
b.connect(gui.CLICK, add_list_item, None)

b = gui.Button("remove selected", width=150)
main.add(b, 40, 140)
b.connect(gui.CLICK, remove_list_item, None)

b = gui.Button("clear", width=150)
main.add(b, 40, 170)
b.connect(gui.CLICK, clear_list, None)

app.run(main)
示例#11
0
    def gen_gui(self):
        from omnitool.shared import theme, lang, exit_prog
        from omnitool.pgu_override import Quitbutton
        pygame.display.init()
        pygame.display.set_caption("Maze World Generator")
        app = gui.Desktop(theme=theme)
        main = gui.Table(width=800)
        app.connect(gui.QUIT, exit_prog, None)

        main.td(gui.Label("Maze Blocks: "))
        tileFrom = gui.List(300, 150)
        for tile in db.tiles:
            if db.tiles.index(tile) not in db.multitiles and db.tiles.index(
                    tile) in clib.data:
                tileFrom.add(gui.Label(tile), value=db.tiles.index(tile))
        main.td(tileFrom)

        #        main.td(gui.Label("Light up maze?"))
        #        polkaDotButton = (gui.Switch(False))
        #        main.td(polkaDotButton)

        main.tr()

        main.td(gui.Label("Maze BackWalls: "))
        tileInto = gui.List(300, 150)
        for wall in db.walls:
            if db.walls.index(wall) in clib.walldata:
                tileInto.add(gui.Label(wall), value=db.walls.index(wall))
        main.td(tileInto)

        #        main.td(gui.Label("View generation?"))
        viewGenButton = (gui.Switch(False))
        #        main.td(viewGenButton)

        main.tr()

        main.td(gui.Label("World Size: "))
        size = gui.List(110, 50)
        size.add("Tiny", value=3)
        size.add("Small", value=0)
        size.add("Medium", value=1)
        size.add("Large", value=2)
        main.td(size)

        main.td(gui.Label("Complexity: "))
        scale = gui.List(110, 50)
        scale.add("Insane", value=3)
        scale.add("Medium", value=6)
        scale.add("Easy", value=9)
        main.td(scale)

        main.tr()
        main.td(Quitbutton(app, lang.pt_start), colspan=4)

        app.run(main)
        pygame.display.quit()

        self.tileFrom = clib.data[tileFrom.value]
        self.tileInto = clib.walldata[tileInto.value]
        self.size2 = size.value
        self.scale2 = scale.value
        self.viewGen = viewGenButton.value
示例#12
0
#zremesher
ctnZR = gui.Container()
ctn.add(ctnZR, 0, 35)

btn = gui.Button("ZRemesher")
btn.connect(gui.CLICK, cb)
ctnZR.add(btn, 0, 0)

ctnZR.add(gui.Label("Polygons count "), 5, 25)
ctnZR.add(gui.HSlider(value=2, min=2, max=20, size=20, width=250), 5, 50)
#zdynamesh

ctnZD = gui.Container()
ctn.add(ctnZD, 0, 125)

btn = gui.Button("ZDynamesh")
btn.connect(gui.CLICK, cb)
ctnZD.add(btn, 0, 0)

ctnZD.add(gui.Label("Resolution "), 5, 25)
ctnZD.add(gui.HSlider(value=2, min=2, max=20, size=20, width=250), 5, 50)
###### object list
objList = gui.List(width=150, height=550)
ctn.add(objList, 280, 35)

#####
global screen
pygame.display.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT), pygame.DOUBLEBUF)
app.run(ctn)
示例#13
0
    def __init__(self, MainGui):
        title = gui.Label("PiCore Program Selector")
        self.programNames = []
        self.programPaths = []
        self.mainGui = MainGui

        def clear_list(arg):
            my_list.clear()
            my_list.resize()
            my_list.repaint()
            self.programNames = []
            self.programPaths = []

        def remove_list_item(arg):
            v = my_list.value
            if v:
                item = v

                for i in my_list.items:
                    if i.value == item: theItem = i

                my_list.remove(item)
                my_list.resize()
                my_list.repaint()

                self.programNames.remove(theItem.widget.value)
                self.programPaths.remove(item)

        def add_list_item(arg, path):
            my_list.add(arg, value=path)
            self.programNames.append(arg)
            self.programPaths.append(path)
            my_list.resize()
            my_list.repaint()

        ##Open File Dialog - to load user programs
        def open_file_browser(arg):
            fileDialog = gui.FileDialog()
            fileDialog.connect(gui.CHANGE, handle_file_browser_closed,
                               fileDialog)
            fileDialog.open()

        def handle_file_browser_closed(dlg):
            if dlg.value:
                #input_file.value = dlg.value
                progName = dlg.input_file.value.split(".")[0]

                if not progName == "":
                    add_list_item(progName, dlg.value)

        def handle_submit(arg):
            print "Submit button pressed"
            self.mainGui.programNames = self.programNames
            self.mainGui.programPaths = self.programPaths
            #self.mainGui.engine.
            self.close(self)

        #List selector
        listContainer = gui.Container(width=400, height=150)
        my_list = gui.List(width=210, height=125)
        listContainer.add(my_list, 185, 10)

        button = gui.Button("Add program", width=150)
        listContainer.add(button, 10, 20)
        button.connect(gui.CLICK, open_file_browser, None)

        button = gui.Button("Remove selected", width=150)
        listContainer.add(button, 10, 50)
        button.connect(gui.CLICK, remove_list_item, None)

        button = gui.Button("Clear", width=150)
        listContainer.add(button, 10, 80)
        button.connect(gui.CLICK, clear_list, None)

        button = gui.Button("Load", width=150)
        listContainer.add(button, 10, 110)
        button.connect(gui.CLICK, handle_submit, None)

        gui.Dialog.__init__(self, title, listContainer)
示例#14
0
def run(worlds, Plugin, ptype):
    # pygame.quit()
    from .shared import lang, theme

    class Quitbutton(gui.Button):
        def __init__(self, value=lang.pl_start):
            gui.Button.__init__(self, value, width=250, height=40)
            try:
                self.connect(gui.CLICK, app.quit, None)
            except AttributeError:
                self.connect(gui.CLICK, app.close, None)

    pygame.display.init()
    pygame.display.set_caption("Plugin World Selector")

    app = gui.Desktop(theme=theme)
    trans = False
    colspan = 1
    if ptype == "rec":
        tlabel = gui.Label(lang.pl_rec)
    elif ptype == "mod":
        tlabel = gui.Label(lang.pl_mod)
    else:
        trans = True
        tlabel = gui.Label(lang.pl_trans)
        colspan = 2
    main = gui.Table()
    app.connect(gui.QUIT, exit_prog, None)
    main.td(gui.Label(Plugin.config["name"], cls="h1"), colspan=colspan)
    for line in Plugin.config["description"]:
        main.tr()
        main.td(gui.Label(line), colspan=colspan)
    main.tr()
    main.td(gui.Spacer(12, 12))
    main.tr()
    main.td(tlabel, colspan=colspan)
    main.tr()
    main.td(gui.Spacer(12, 12))
    main.tr()
    if trans:
        main.td(gui.Label(lang.pl_trans_source))
        main.td(gui.Label(lang.pl_trans_target))
        main.tr()
        data = []
        liste2 = gui.List(250, 250)
        for w in worlds:
            with w.open("rb") as f:
                name = get_name(f)
            liste2.add(name, value=w)
        main.td(liste2)
    data = []
    liste = gui.List(250, 250)
    for w in worlds:
        with w.open("rb") as f:
            name = get_name(f)
        liste.add(name, value=w)
    main.td(liste)
    main.tr()
    main.td(gui.Spacer(12, 12))
    main.tr()
    main.td(Quitbutton(), colspan=colspan)
    app.run(main)
    pygame.display.quit()
    if trans:
        return liste.value, liste2.value
    return liste.value
示例#15
0
    def __init__(self, interface=None, **params):
        gui.Container.__init__(self, **params)

        self.Interface = interface
        self.add(
            gui.Label("Microscope Analyzer - HMNL (tm) 2016",
                      color=colors.red), 95, 5)

        # Select joystick GUI
        self.add(gui.Label("Select joystick"), 7, 32)
        self.joystick_selection = gui.Select()
        # self.joystick_selection.add("None",'None')
        self.joystick_selection.add("Shenzhen", 'Shenzhen')
        self.joystick_selection.add("The unworking backup",
                                    "The unworking backup")
        self.joystick_selection.add("Xbox >>>>> Playstation",
                                    "Xbox >>>>> Playstation")
        self.add(self.joystick_selection, 150, 30)

        # Update joystick button
        def UpdateJoystickButtonCallBack():
            if self.joystick_selection.value == "Shenzhen" or self.joystick_selection.value == "Xbox >>>>> Playstation":
                self.Interface.initialize_joystick()
            else:
                self.Interface.initialize_joystick(self,
                                                   a_button_num=0,
                                                   x_button_num=2,
                                                   y_button_num=3,
                                                   b_button_num=1,
                                                   rb_button_num=5,
                                                   start_button_num=7,
                                                   lx_axis=0,
                                                   ly_axis=1,
                                                   trigger_axis=2,
                                                   rx_axis=3,
                                                   ry_axis=4,
                                                   rt_button_num=None,
                                                   lt_button_num=None)

        self.update_joystick_button = gui.Button("Update JS")
        self.update_joystick_button.connect(gui.CLICK,
                                            UpdateJoystickButtonCallBack)
        self.add(self.update_joystick_button, 400, 32)

        # Input FMSPE directory / internal callback functions to handle buttons being clicked
        self.add(gui.Label("FMPSE directory", color=colors.black), 7, 62)

        def handle_fmspe_file_browser_closed(dlg):
            if dlg.value: self.fmspe_dir_input.value = dlg.value

        def open_fmspe_file_browser(arg):
            d = gui.FileDialog(path=root_dir)
            # d = gui.FileDialog(path = "C:\\Users\\HMNL Leica\\Documents\\Filmmetrics\\Measurements")
            d.connect(gui.CHANGE, handle_fmspe_file_browser_closed, d)
            d.open()

        self.fmspe_dir_input = gui.Input(size=25)
        self.add(self.fmspe_dir_input, 150, 60)
        self.fmspe_browse_button = gui.Button("Browse...")
        self.fmspe_browse_button.connect(gui.CLICK, open_fmspe_file_browser,
                                         None)
        self.add(self.fmspe_browse_button, 400, 62)

        # Input XML directory / internal callback functions to handle buttons being clicked
        self.add(gui.Label("XML directory", color=colors.black), 7, 92)

        def handle_xml_file_browser_closed(dlg):
            if dlg.value: self.xml_dir_input.value = dlg.value

        def open_xml_file_browser(arg):
            d = gui.FileDialog(path=root_dir)
            # d = gui.FileDialog(path = "C:\\Users\\HMNL Leica\\Documents\\Filmmetrics\\Measurements")
            d.connect(gui.CHANGE, handle_xml_file_browser_closed, d)
            d.open()

        self.xml_dir_input = gui.Input(size=25)
        self.add(self.xml_dir_input, 150, 90)
        self.xml_browse_button = gui.Button("Browse...")
        self.xml_browse_button.connect(gui.CLICK, open_xml_file_browser, None)
        self.add(self.xml_browse_button, 400, 92)

        # Input image directory / internal callback functions to handle buttons being clicked
        self.add(gui.Label("Image directory", color=colors.black), 7, 122)

        def handle_image_file_browser_closed(dlg):
            if dlg.value: self.image_dir_input.value = dlg.value

        def open_image_file_browser(arg):
            d = gui.FileDialog(path=root_dir)
            # d = gui.FileDialog(path = "C:\\Users\\HMNL Leica\\Documents\\Filmmetrics\\Measurements")
            d.connect(gui.CHANGE, handle_image_file_browser_closed, d)
            d.open()

        self.image_dir_input = gui.Input(size=25)
        self.add(self.image_dir_input, 150, 120)
        self.image_browse_button = gui.Button("Browse...")
        self.image_browse_button.connect(gui.CLICK, open_image_file_browser,
                                         None)
        self.add(self.image_browse_button, 400, 122)

        # Get the name that the user wants the map to be called
        self.add(gui.Label("Map name"), 7, 152)
        self.map_name_input = gui.Input(size=25)
        self.add(self.map_name_input, 107, 150)

        # Get the units of measurement
        self.add(gui.Label("Units"), 365, 152)
        self.unit_selection = gui.Select()
        self.unit_selection.add("um", 'um')
        self.unit_selection.add("mm", 'mm')
        self.add(self.unit_selection, 425, 150)

        # Inputs for the mapping function
        self.add(gui.Label("Number Points X"), 7, 182)
        self.num_pts_x_input = gui.Input(size=5)
        self.add(self.num_pts_x_input, 155, 180)

        self.add(gui.Label("Distance b/w Points X"), 237, 182)
        self.distance_bw_pts_x_input = gui.Input(size=5)
        self.add(self.distance_bw_pts_x_input, 425, 180)

        self.add(gui.Label("Number Points Y"), 7, 212)
        self.num_pts_y_input = gui.Input(size=5)
        self.add(self.num_pts_y_input, 155, 210)

        self.add(gui.Label("Distance b/w Points Y"), 237, 212)
        self.distance_bw_pts_y_input = gui.Input(size=5)
        self.add(self.distance_bw_pts_y_input, 425, 210)

        # Measure, Start/Pause, Stop buttons
        def MeasureOnceButtonCallback():
            self.Interface.message1 = "Taking measurement!"
            self.Interface.take_measurement()

        self.take_measurement_button = gui.Button("Measure once")
        self.take_measurement_button.connect(gui.CLICK,
                                             MeasureOnceButtonCallback)
        self.add(self.take_measurement_button, 17, 242)

        def StartOrPauseButtonCallback():
            print "Map started!"
            if not self.started_map:  # If it's the first time, then start taking the map
                self.started_map = True
                try:
                    self.Interface.take_map(
                        self.map_name_input.value,
                        int(self.num_pts_x_input.value),
                        int(self.distance_bw_pts_x_input.value),
                        int(self.num_pts_y_input.value),
                        int(self.distance_bw_pts_y_input.value),
                        self.unit_selection.value, self.Microscope_Base)
                    self.started_map = False
                except Exception:
                    print "Error with taking map!"

            else:  # If a map is already in progress, pause it
                self.Interface.pause_button_pressed = True

        self.start_or_pause_button = gui.Button("Start / Pause Map")
        self.start_or_pause_button.connect(gui.CLICK,
                                           StartOrPauseButtonCallback)
        self.add(self.start_or_pause_button, 190, 242)

        def StopButtonCallback():
            self.Interface.stop_button_pressed = True

        self.stop_button = gui.Button("Stop map")
        self.stop_button.connect(gui.CLICK, StopButtonCallback)
        self.add(self.stop_button, 390, 242)

        # ----------------------------------------------- Post Processing GUI Components -------------------------------------------------------------------------------

        xalign = 830  # Alignment between standalone program and the final program
        attribute_items = [
            "Layer Roughnesses", "Layer Thicknesses", "Measured FFT Intensity",
            "Measured FFT Thickness"
        ]  # Attributes that are available to write to .txt file
        cart_items = {}

        self.add(gui.Label("Post Processing Shopping Cart", color=colors.red),
                 xalign + 85, 10)

        # Attributes list from which the user can pick out items
        initial_attributes_list_object = gui.List(width=180, height=140)
        for i in range(len(attribute_items)):
            item = attribute_items[i]
            initial_attributes_list_object.add(item, value=i)
        self.add(initial_attributes_list_object, xalign + 10, 40)

        # List of items that the user selected into their carts
        cart_items_object = gui.List(width=180, height=140)
        self.add(cart_items_object, xalign + 210, 40)

        # Functions to add/remove items from cart
        def add_item_to_cart(arg):
            v = initial_attributes_list_object.value
            if v != None and v not in cart_items:
                cart_items[v] = attribute_items[v]
                index = v
                cart_items_object.add(attribute_items[index], value=index)
                cart_items_object.resize()
                cart_items_object.repaint()

        def remove_item_from_cart(arg):
            v = cart_items_object.value
            if v != None:
                cart_items.pop(v)
                cart_items_object.remove(v)
                cart_items_object.resize()
                cart_items_object.repaint()
                cart_items_object.value = None

        # Performs analysis and saves it as a .txt file in the out directory that the user specifies
        def check_out(arg):
            self.Interface.PostProcessAndSave(
                xml_directory_post_processing.value, text_dir_input.value,
                post_map_name_input.value, cart_items)

        # Cart button GUI objects... the functions are defined above
        add_to_cart_button = gui.Button("Add to cart", width=90)
        add_to_cart_button.connect(gui.CLICK, add_item_to_cart, None)
        self.add(add_to_cart_button, xalign + 10, 190)

        remove_from_cart_button = gui.Button("Remove from cart", width=90)
        remove_from_cart_button.connect(gui.CLICK, remove_item_from_cart, None)
        self.add(remove_from_cart_button, xalign + 125, 190)

        save_analysis_button = gui.Button("Checkout", width=85)
        save_analysis_button.connect(gui.CLICK, check_out, None)
        self.add(save_analysis_button, xalign + 290, 190)

        # The name of the map that we should be looking for
        self.add(gui.Label("Map name"), xalign + 7, 222)
        post_map_name_input = gui.Input(size=28)
        post_map_name_input.value = "Columbus"
        self.add(post_map_name_input, xalign + 125, 220)

        # Post processing XML directory input
        def handle_xml_post_file_browser_closed(dlg):
            if dlg.value: xml_directory_post_processing.value = dlg.value

        def open_xml_post_file_browser(arg):
            d = gui.FileDialog(
                path="C:\\Users\\HMNL-Filmmetrics\\Measurements\\")
            d.connect(gui.CHANGE, handle_xml_post_file_browser_closed, d)
            d.open()

        xml_directory_post_processing = gui.Input(size=19)
        xml_directory_post_processing.value = "{}XML\\".format(root_dir)
        self.add(gui.Label("XML Directory"), xalign + 7, 252)
        self.add(xml_directory_post_processing, xalign + 125, 250)
        post_browse_button = gui.Button("Browse", width=50)
        self.add(post_browse_button, xalign + 315, 252)
        post_browse_button.connect(gui.CLICK, open_xml_post_file_browser, None)

        # Output file directory
        def handle_text_browser_closed(dlg):
            if dlg.value: text_dir_input.value = dlg.value

        def open_text_file_browser(arg):
            d = gui.FileDialog(path=root_dir)
            d.connect(gui.CHANGE, handle_text_browser_closed, d)
            d.open()

        text_dir_input = gui.Input(size=19)
        text_dir_input.value = "{}AnalysisFiles\\".format(root_dir)
        self.add(gui.Label("Out Directory"), xalign + 7, 282)
        self.add(text_dir_input, xalign + 125, 280)
        text_dir_browse_button = gui.Button("Browse", width=50)
        self.add(text_dir_browse_button, xalign + 315, 282)
        text_dir_browse_button.connect(gui.CLICK, open_text_file_browser, None)

        # ------------------------------------------------------- View / Delete Map History -----------------------------------------------------------------

        yalign = 325  # Alignment between standalone program and the final program
        cart_items = {}

        self.add(gui.Label("Map History", color=colors.red), 575, yalign - 10)
        lines = [line.rstrip('\n') for line in open("History/map_history.txt")]

        # Attributes list from which the user can pick out items
        maps_in_history_list = gui.List(width=200, height=270)
        for i in range(len(lines)):
            vals_array = lines[i].split(" ")
            new_map_info = FinishedMap(vals_array[0], vals_array[1],
                                       vals_array[2], vals_array[3],
                                       vals_array[4], vals_array[5],
                                       vals_array[6], vals_array[7],
                                       vals_array[8], vals_array[9],
                                       vals_array[10])
            self.Interface.map_history.append(new_map_info)

            maps_in_history_list.add(new_map_info.map_name, value=i)

        self.add(maps_in_history_list, 310, yalign + 30)

        MapNameLabel = gui.Input(size=40)
        FMSPEDirLabel = gui.Input(size=40)
        XMLDirLabel = gui.Input(size=40)
        ImageDirLabel = gui.Input(size=40)
        NumMeasurementsXLabel = gui.Input(size=40)
        DistanceMeasurementsXLabel = gui.Input(size=40)
        NumMeasurementsYLabel = gui.Input(size=40)
        DistanceMeasurementsYLabel = gui.Input(size=40)
        DateTakenLabel = gui.Input(size=40)
        TimeTakenLabel = gui.Input(size=40)
        UnitsLabel = gui.Input(size=40)

        self.add(gui.Label("Map name : "), 535, yalign + 30)
        self.add(gui.Label("FMSPE Dir : "), 535, yalign + 55)
        self.add(gui.Label("XML Dir : "), 535, yalign + 80)
        self.add(gui.Label("Image Dir : "), 535, yalign + 105)
        self.add(gui.Label("# Measurements x : "), 535, yalign + 130)
        self.add(gui.Label("Distance b/w x meas. : "), 535, yalign + 155)
        self.add(gui.Label("# Measurements y : "), 535, yalign + 180)
        self.add(gui.Label("Distance b/w y meas.: "), 535, yalign + 205)
        self.add(gui.Label("Date taken : "), 535, yalign + 230)
        self.add(gui.Label("Time taken : "), 535, yalign + 255)
        self.add(gui.Label("Units: "), 535, yalign + 280)

        self.add(MapNameLabel, 720, yalign + 30)
        self.add(FMSPEDirLabel, 720, yalign + 55)
        self.add(XMLDirLabel, 720, yalign + 80)
        self.add(ImageDirLabel, 720, yalign + 105)
        self.add(NumMeasurementsXLabel, 720, yalign + 130)
        self.add(DistanceMeasurementsXLabel, 720, yalign + 155)
        self.add(NumMeasurementsYLabel, 720, yalign + 180)
        self.add(DistanceMeasurementsYLabel, 720, yalign + 205)
        self.add(DateTakenLabel, 720, yalign + 230)
        self.add(TimeTakenLabel, 720, yalign + 255)
        self.add(UnitsLabel, 720, yalign + 280)

        def show_info():
            v = maps_in_history_list.value
            if v == None:
                return
            try:
                MapNameLabel.value = "{}".format(
                    self.Interface.map_history[v].map_name)
                FMSPEDirLabel.value = "{}".format(
                    self.Interface.map_history[v].fmspedir)
                XMLDirLabel.value = "{}".format(
                    self.Interface.map_history[v].xmldir)
                ImageDirLabel.value = "{}".format(
                    self.Interface.map_history[v].imagedir)
                NumMeasurementsXLabel.value = "{}".format(
                    self.Interface.map_history[v].numx)
                DistanceMeasurementsXLabel.value = "{}".format(
                    self.Interface.map_history[v].distbwx)
                NumMeasurementsYLabel.value = "{}".format(
                    self.Interface.map_history[v].numy)
                DistanceMeasurementsYLabel.value = "{}".format(
                    self.Interface.map_history[v].distbwy)
                DateTakenLabel.value = "{}".format(
                    self.Interface.map_history[v].date)
                TimeTakenLabel.value = "{}".format(
                    self.Interface.map_history[v].time)
                UnitsLabel.value = "{}".format(
                    self.Interface.map_history[v].units)
            except BaseException:
                pass

            # print v
            # print MapNameLabel.value

        maps_in_history_list.connect(gui.CLICK, show_info)

        # Implementing delete
        def delete():
            v = maps_in_history_list.value
            if v == None:
                return

            # Get directories and map name
            map_name = self.Interface.map_history[v].map_name

            fmspe_dir = self.Interface.map_history[v].fmspedir
            xml_dir = self.Interface.map_history[v].xmldir
            image_dir = self.Interface.map_history[v].imagedir

            # Gather all relevant files
            try:
                fmspe_files = [
                    filename for filename in os.listdir(fmspe_dir)
                    if filename.startswith(map_name)
                    and filename.endswith(".fmspe")
                ]
                xml_files = [
                    filename for filename in os.listdir(xml_dir) if
                    filename.startswith(map_name) and filename.endswith(".xml")
                ]
                image_files = [
                    filename for filename in os.listdir(image_dir) if
                    filename.startswith(map_name) and filename.endswith(".bmp")
                ]
            except WindowsError:
                fmspe_files = []
                xml_files = []
                image_files = []

            # Delete all these relevant files
            for file in fmspe_files:
                try:
                    os.remove(fmspe_dir + file)
                except WindowsError:
                    print "Couldn't find {}!".format(file)
            for file in xml_files:
                try:
                    os.remove(xml_dir + file)
                except WindowsError:
                    print "Couldn't find {}!".format(file)
            for file in image_files:
                try:
                    os.remove(image_dir + file)
                except WindowsError:
                    print "Couldn't find {}!".format(file)

            # Remove the map from the text file
            old_lines = [
                line.rstrip('\n') for line in open("History/map_history.txt")
            ]

            with open("History/map_history.txt", "w") as f:
                map_name = self.Interface.map_history[v].map_name
                fmspe_dir = self.Interface.map_history[v].fmspedir
                xml_dir = self.Interface.map_history[v].xmldir
                image_dir = self.Interface.map_history[v].imagedir
                num_pts_x = self.Interface.map_history[v].numx
                dist_bw_x = self.Interface.map_history[v].distbwx
                num_pts_y = self.Interface.map_history[v].numy
                dist_bw_y = self.Interface.map_history[v].distbwy
                date = self.Interface.map_history[v].date
                time = self.Interface.map_history[v].time
                units = self.Interface.map_history[v].units

                for line in old_lines:
                    # print line
                    compare_line = "{} {} {} {} {} {} {} {} {} {} {}".format(
                        map_name, fmspe_dir, xml_dir, image_dir, num_pts_x,
                        dist_bw_x, num_pts_y, dist_bw_y, date, time, units)
                    # print compare_line
                    if line != compare_line:
                        f.write("{}\n".format(line))

            # The lines present in the file afterwards... Now we refill the list with these values
            new_lines = [
                line.rstrip('\n') for line in open("History/map_history.txt")
            ]

            # Reset map history
            self.Interface.map_history = []
            maps_in_history_list.clear()

            for i in range(len(new_lines)):
                vals_array = new_lines[i].split(" ")
                new_map_info = FinishedMap(vals_array[0], vals_array[1],
                                           vals_array[2], vals_array[3],
                                           vals_array[4], vals_array[5],
                                           vals_array[6], vals_array[7],
                                           vals_array[8], vals_array[9],
                                           vals_array[10])
                self.Interface.map_history.append(new_map_info)

                maps_in_history_list.add(new_map_info.map_name, value=i)

        delete_button = gui.Button("Delete Map", width=50)
        self.add(delete_button, 1110, yalign + 30)
        delete_button.connect(gui.CLICK, delete)

        # -------------- UPDATE THE LIST -----------------------------------
        def update_list():
            new_lines = [
                line.rstrip('\n') for line in open("History/map_history.txt")
            ]

            # Reset map history
            self.Interface.map_history = []
            maps_in_history_list.clear()

            for i in range(len(new_lines)):
                vals_array = new_lines[i].split(" ")
                new_map_info = FinishedMap(vals_array[0], vals_array[1],
                                           vals_array[2], vals_array[3],
                                           vals_array[4], vals_array[5],
                                           vals_array[6], vals_array[7],
                                           vals_array[8], vals_array[9],
                                           vals_array[10])
                self.Interface.map_history.append(new_map_info)

                maps_in_history_list.add(new_map_info.map_name, value=i)

        update_button = gui.Button("Update List", width=50)
        self.add(update_button, 1110, yalign + 65)
        update_button.connect(gui.CLICK, update_list)

        #
        # # List of items that the user selected into their carts
        # cart_items_object = gui.List(width = 180, height = 140)
        # self.add(cart_items_object, xalign + 210, 40)
        #
        # # Functions to add/remove items from cart
        # def add_item_to_cart(arg):
        #     v = initial_attributes_list_object.value
        #     if v != None and v not in cart_items:
        #         cart_items[v] = attribute_items[v]
        #         index = v
        #         cart_items_object.add(attribute_items[index], value = index)
        #         cart_items_object.resize()
        #         cart_items_object.repaint()
        #
        # def remove_item_from_cart(arg):
        #     v = cart_items_object.value
        #     if v != None:
        #         cart_items.pop(v)
        #         cart_items_object.remove(v)
        #         cart_items_object.resize()
        #         cart_items_object.repaint()
        #         cart_items_object.value = None

        # ------------------------------------------------------- Fun -------------------------------------------------------

        # Change theme button
        def change_theme(arg):
            self.Interface.set_theme()

        self.change_theme_button = gui.Button("New Theme")
        self.change_theme_button.connect(gui.CLICK, change_theme, None)
        self.add(self.change_theme_button, 110, 320)
示例#16
0
    def __init__(self):
        self.basepath = os.path.join(os.path.dirname(__file__), "..")
        #map Vars
        self.name = ""
        self.dimensions = [0, 0]
        self.tiles = {}
        #background (wird manuell eingefuegt erstmal
        self.music = ""
        self.grid = []
        self.entityFile = "DUMMY"
        self.nextLevel = ""
        #END map Vars

        self.cur_Tile = 1
        self.camera = util.Vector(0, 0)

        self.rightMouseDown = False
        self.firstKoord = util.Vector(0, 0)

        self.screen = pygame.display.set_mode((1150, 630))

        self.mapSurface = pygame.Surface((800, 480))

        self.layerMenuBG = pygame.Surface((150, 630))
        self.layerMenuBG.fill((0, 200, 200))
        self.tilesMenuBG = pygame.Surface((200, 630))
        self.tilesMenuBG.fill((200, 200, 0))
        self.topMenuBG = pygame.Surface((800, 150))
        self.topMenuBG.fill((155, 0, 155))

        self.editApp = gui.App()
        self.editApp.connect(gui.QUIT, self.editApp.quit, None)

        self.Bt_applyOpt = gui.Button("Apply Options")
        self.Bt_applyOpt.connect(gui.CLICK, self.BUTTONapplyOpt, None)
        self.Bt_newMap = gui.Button("New Map")
        self.Bt_newMap.connect(gui.CLICK, self.BUTTONnewMap, None)
        self.Bt_loadMap = gui.Button("Load Map")
        self.Bt_loadMap.connect(gui.CLICK, self.BUTTONloadMap, None)
        self.Bt_saveMap = gui.Button("Save Map")
        self.Bt_saveMap.connect(gui.CLICK, self.BUTTONsaveMap, None)
        self.Bt_resetCam = gui.Button("reset Cam")
        self.Bt_resetCam.connect(gui.CLICK, self.BUTTONresetCam, None)

        self.Lb_Layer_Topic = gui.Label("Layer-Menu")
        self.Lb_layer1 = gui.Label("Layer 1 visible?: ")
        self.Lb_layer2 = gui.Label("Layer 2 visible?: ")
        self.Lb_layer3 = gui.Label("Layer 3 visible?: ")
        self.Lb_Tiles_Topic = gui.Label("Tiles-Menu")
        self.Lb_Tiles = gui.Label("Tiles: ")
        self.Lb_curT_index = gui.Label("Index: ")
        self.Lb_curT_name = gui.Label("Name: ")
        self.Lb_curT_type = gui.Label("Type: ")
        self.Lb_curT_image = gui.Label("Image: ")
        self.Lb_curT_access = gui.Label("Access.: ")
        self.Lb_curT_danger = gui.Label("Dangerous.: ")
        self.Lb_map_name = gui.Label("Map-Name: ")
        self.Lb_map_dimH = gui.Label("dimH: ")
        self.Lb_map_dimV = gui.Label("dimV: ")
        self.Lb_map_bgMusic = gui.Label("bgMusic: ")
        self.Lb_map_entityFile = gui.Label("entityFile: ")
        self.Lb_map_nextLvl = gui.Label("nextLvl: ")

        self.Inp_map_name = gui.Input(size=8)
        self.Inp_map_dimH = gui.Input(size=8)
        self.Inp_map_dimV = gui.Input(size=8)
        self.Inp_map_bgMusic = gui.Input(size=8)
        self.Inp_map_entityFile = gui.Input(size=8)
        self.Inp_map_nextLvl = gui.Input(size=8)

        self.Li_Tile_select = gui.List(width=100, height=300)
        for i in range(len(self.tiles)):
            self.Li_Tile_select.add(self.tiles[i][0], value=i)

        self.Sw_layer1_vis = gui.Switch(True)
        self.Sw_layer2_vis = gui.Switch(True)
        self.Sw_layer3_vis = gui.Switch(True)

        self.container = gui.Container(width=1150, height=630)

        self.layerTable = gui.Table(width=150, height=630, align=-1)
        self.tilesTable = gui.Table(width=200, height=630, align=1)
        self.topTable = gui.Table(width=30)

        self.container.add(self.layerTable, 0, 0)
        self.container.add(self.tilesTable, 950, 0)
        self.container.add(self.topTable, 150, 0)

        self.editApp.init(self.container, self.screen)
        self.running = True

        self.initNewMap()

        self.transpColor = ()  # layer1: (255,0,255)   layer2: (0,255,0)