class FilterToolPanel(Panel): def __init__(self, tool): Panel.__init__(self) self.savedOptions = {} self.tool = tool self.selectedFilterName = None if len(self.tool.filterModules): self.reload() def reload(self): for i in list(self.subwidgets): self.remove(i) tool = self.tool if len(tool.filterModules) is 0: self.add(Label("No filter modules found!")) self.shrink_wrap() return if self.selectedFilterName is None or self.selectedFilterName not in tool.filterNames: self.selectedFilterName = tool.filterNames[0] self.filterOptionsPanel = None while self.filterOptionsPanel is None: module = self.tool.filterModules[self.selectedFilterName] try: self.filterOptionsPanel = FilterModuleOptions(self.tool, module) except Exception, e: alert(_("Error creating filter inputs for {0}: {1}").format(module, e)) traceback.print_exc() self.tool.filterModules.pop(self.selectedFilterName) self.selectedFilterName = tool.filterNames[0] if len(tool.filterNames) == 0: raise ValueError("No filters loaded!") self.filterSelect = ChoiceButton(tool.filterNames, choose=self.filterChanged) self.filterSelect.selectedChoice = self.selectedFilterName self.confirmButton = Button("Filter", action=self.tool.confirm) filterLabel = Label("Filter:", fg_color=(177, 177, 255, 255)) filterLabel.mouse_down = lambda x: mcplatform.platform_open(mcplatform.filtersDir) filterLabel.tooltipText = "Click to open filters folder" filterSelectRow = Row((filterLabel, self.filterSelect)) self.add(Column((filterSelectRow, self.filterOptionsPanel, self.confirmButton))) self.shrink_wrap() if self.parent: self.centery = self.parent.centery if self.selectedFilterName in self.savedOptions: self.filterOptionsPanel.options = self.savedOptions[self.selectedFilterName]
def makeTabPage(self, tool, inputs): page = Widget() page.is_gl_container = True rows = [] cols = [] height = 0 max_height = 550 page.optionDict = {} page.tool = tool title = "Tab" for optionName, optionType in inputs: if isinstance(optionType, tuple): if isinstance(optionType[0], (int, long, float)): if len(optionType) > 2: val, min, max = optionType elif len(optionType) == 2: min, max = optionType val = min rows.append(addNumField(page, optionName, val, min, max)) if isinstance(optionType[0], (str, unicode)): isChoiceButton = False if optionType[0] == "string": kwds = [] wid = None val = None for keyword in optionType: if isinstance(keyword, (str, unicode)) and keyword != "string": kwds.append(keyword) for keyword in kwds: splitWord = keyword.split('=') if len(splitWord) > 1: v = None key = None try: v = int(splitWord[1]) except: pass key = splitWord[0] if v is not None: if key == "lines": lin = v elif key == "width": wid = v else: if key == "value": val = splitWord[1] if val is None: val = "" if wid is None: wid = 200 field = TextField(value=val, width=wid) page.optionDict[optionName] = AttrRef(field, 'value') row = Row((Label(optionName), field)) rows.append(row) else: isChoiceButton = True if isChoiceButton: choiceButton = ChoiceButton(map(str, optionType)) page.optionDict[optionName] = AttrRef(choiceButton, 'selectedChoice') rows.append(Row((Label(optionName), choiceButton))) elif isinstance(optionType, bool): cbox = CheckBox(value=optionType) page.optionDict[optionName] = AttrRef(cbox, 'value') row = Row((Label(optionName), cbox)) rows.append(row) elif isinstance(optionType, (int, float)): rows.append(addNumField(self, optionName, optionType)) elif optionType == "blocktype" or isinstance(optionType, pymclevel.materials.Block): blockButton = BlockButton(tool.editor.level.materials) if isinstance(optionType, pymclevel.materials.Block): blockButton.blockInfo = optionType row = Column((Label(optionName), blockButton)) page.optionDict[optionName] = AttrRef(blockButton, 'blockInfo') rows.append(row) elif optionType == "label": rows.append(wrapped_label(optionName, 50)) elif optionType == "string": input = None # not sure how to pull values from filters, but leaves it open for the future. Use this variable to set field width. if input != None: size = input else: size = 200 field = TextField(value="") row = TextInputRow(optionName, ref=AttrRef(field, 'value'), width=size) page.optionDict[optionName] = AttrRef(field, 'value') rows.append(row) elif optionType == "title": title = optionName else: raise ValueError(("Unknown option type", optionType)) height = sum(r.height for r in rows) if height > max_height: h = 0 for i, r in enumerate(rows): h += r.height if h > height / 2: break cols.append(Column(rows[:i])) rows = rows[i:] # cols.append(Column(rows)) if len(rows): cols.append(Column(rows)) if len(cols): page.add(Row(cols)) page.shrink_wrap() return (title, page, page._rect)
def GeneratorPanel(): panel = Widget() panel.chunkHeight = 64 panel.grass = True panel.simulate = False jarStorage = MCServerChunkGenerator.getDefaultJarStorage() if jarStorage: jarStorage.reloadVersions() generatorChoice = ChoiceButton(["Minecraft Server", "Flatland"]) panel.generatorChoice = generatorChoice col = [Row((Label("Generator:"), generatorChoice))] noVersionsRow = Label( "Will automatically download and use the latest version") versionContainer = Widget() heightinput = IntInputRow("Height: ", ref=AttrRef(panel, "chunkHeight"), min=0, max=128) grassinput = CheckBoxLabel("Grass", ref=AttrRef(panel, "grass")) flatPanel = Column([heightinput, grassinput], align="l") def generatorChoiceChanged(): serverPanel.visible = generatorChoice.selectedChoice == "Minecraft Server" flatPanel.visible = not serverPanel.visible generatorChoice.choose = generatorChoiceChanged versionChoice = None if len(jarStorage.versions): def checkForUpdates(): def _check(): yield jarStorage.downloadCurrentServer() yield showProgress("Checking for server updates...", _check()) versionChoice.choices = sorted(jarStorage.versions, reverse=True) versionChoice.choiceIndex = 0 versionChoice = ChoiceButton(sorted(jarStorage.versions, reverse=True)) versionChoiceRow = (Row( (Label("Server version:"), versionChoice, Label("or"), Button("Check for Updates", action=checkForUpdates)))) panel.versionChoice = versionChoice versionContainer.add(versionChoiceRow) else: versionContainer.add(noVersionsRow) versionContainer.shrink_wrap() menu = Menu("Advanced", [("Open Server Storage", "revealStorage"), ("Reveal World Cache", "revealCache"), ("Delete World Cache", "clearCache")]) def presentMenu(): i = menu.present(advancedButton.parent, advancedButton.topleft) if i != -1: (revealStorage, revealCache, clearCache)[i]() advancedButton = Button("Advanced...", presentMenu) @alertException def revealStorage(): mcplatform.platform_open(jarStorage.cacheDir) @alertException def revealCache(): mcplatform.platform_open(MCServerChunkGenerator.worldCacheDir) #revealCacheRow = Row((Label("Minecraft Server Storage: "), Button("Open Folder", action=revealCache, tooltipText="Click me to install your own minecraft_server.jar if you have any."))) @alertException def clearCache(): MCServerChunkGenerator.clearWorldCache() simRow = CheckBoxLabel( "Simulate world", ref=AttrRef(panel, "simulate"), tooltipText= "Simulate the world for a few seconds after generating it. Reduces the save file size by processing all of the TileTicks." ) simRow = Row((simRow, advancedButton), anchor="lrh") #deleteCacheRow = Row((Label("Delete Temporary World File Cache?"), Button("Delete Cache!", action=clearCache, tooltipText="Click me if you think your chunks are stale."))) serverPanel = Column([ versionContainer, simRow, ], align="l") col.append(serverPanel) col = Column(col, align="l") col.add(flatPanel) flatPanel.topleft = serverPanel.topleft flatPanel.visible = False panel.add(col) panel.shrink_wrap() def generate(level, arg): useServer = generatorChoice.selectedChoice == "Minecraft Server" if useServer: def _createChunks(): if versionChoice: version = versionChoice.selectedChoice else: version = None gen = MCServerChunkGenerator(version=version) if isinstance(arg, pymclevel.BoundingBox): for i in gen.createLevelIter(level, arg, simulate=panel.simulate): yield i else: for i in gen.generateChunksInLevelIter( level, arg, simulate=panel.simulate): yield i else: def _createChunks(): height = panel.chunkHeight grass = panel.grass and pymclevel.alphaMaterials.Grass.ID or pymclevel.alphaMaterials.Dirt.ID if isinstance(arg, pymclevel.BoundingBox): chunks = list(arg.chunkPositions) else: chunks = arg if level.dimNo in (-1, 1): maxskylight = 0 else: maxskylight = 15 for i, (cx, cz) in enumerate(chunks): yield i, len(chunks) #surface = blockInput.blockInfo #for cx, cz in : try: level.createChunk(cx, cz) except ValueError, e: # chunk already present print e continue else: ch = level.getChunk(cx, cz) if height > 0: stoneHeight = max(0, height - 5) grassHeight = max(0, height - 1) ch.Blocks[:, :, grassHeight] = grass ch.Blocks[:, :, stoneHeight: grassHeight] = pymclevel.alphaMaterials.Dirt.ID ch.Blocks[:, :, : stoneHeight] = pymclevel.alphaMaterials.Stone.ID ch.Blocks[:, :, 0] = pymclevel.alphaMaterials.Bedrock.ID ch.SkyLight[:, :, height:] = maxskylight if maxskylight: ch.HeightMap[:] = height else: ch.SkyLight[:] = maxskylight ch.needsLighting = False ch.dirty = True return _createChunks()
def __init__(self, value=None): Widget.__init__(self) self.choiceButton = ChoiceButton(self.choices) self.add(self.choiceButton) self.shrink_wrap()
def GeneratorPanel(): panel = Widget() panel.chunkHeight = 64 panel.grass = True panel.simulate = False panel.snapshot = False jarStorage = MCServerChunkGenerator.getDefaultJarStorage() if jarStorage: jarStorage.reloadVersions() generatorChoice = ChoiceButton(["Minecraft Server", "Flatland"]) panel.generatorChoice = generatorChoice col = [Row((Label("Generator:"), generatorChoice))] noVersionsRow = Label("Will automatically download and use the latest version") versionContainer = Widget() heightinput = IntInputRow("Height: ", ref=AttrRef(panel, "chunkHeight"), min=0, max=255) grassinput = CheckBoxLabel("Grass", ref=AttrRef(panel, "grass")) flatPanel = Column([heightinput, grassinput], align="l") def generatorChoiceChanged(): serverPanel.visible = generatorChoice.selectedChoice == "Minecraft Server" flatPanel.visible = not serverPanel.visible generatorChoice.choose = generatorChoiceChanged versionChoice = None if len(jarStorage.versions): def checkForUpdates(): def _check(): yield jarStorage.downloadCurrentServer(panel.snapshot) yield showProgress("Checking for server updates...", _check()) versionChoice.choices = sorted(jarStorage.versions, reverse=True) versionChoice.choiceIndex = 0 versionChoice = ChoiceButton(sorted(jarStorage.versions, reverse=True)) versionChoice.set_size_for_text(200) versionChoiceRow = (Row(( Label("Server version:"), versionChoice, Label("or"), Button("Check for Updates", action=checkForUpdates)))) panel.versionChoice = versionChoice versionContainer.add(versionChoiceRow) else: versionContainer.add(noVersionsRow) versionContainer.shrink_wrap() menu = Menu("Advanced", [ ("Open Server Storage", "revealStorage"), ("Reveal World Cache", "revealCache"), ("Delete World Cache", "clearCache") ]) def presentMenu(): i = menu.present(advancedButton.parent, advancedButton.topleft) if i != -1: (revealStorage, revealCache, clearCache)[i]() advancedButton = Button("Advanced...", presentMenu) @alertException def revealStorage(): mcplatform.platform_open(jarStorage.cacheDir) @alertException def revealCache(): mcplatform.platform_open(MCServerChunkGenerator.worldCacheDir) # revealCacheRow = Row((Label("Minecraft Server Storage: "), Button("Open Folder", action=revealCache, tooltipText="Click me to install your own minecraft_server.jar if you have any."))) @alertException def clearCache(): MCServerChunkGenerator.clearWorldCache() simRow = CheckBoxLabel("Simulate world", ref=AttrRef(panel, "simulate"), tooltipText="Simulate the world for a few seconds after generating it. Reduces the save file size by processing all of the TileTicks.") useSnapshotServer = CheckBoxLabel("Use snapshot versions", ref=AttrRef(panel, "snapshot"), tooltipText="Uses the Latest Snapshot Terrain Generation") simRow = Row((simRow, advancedButton), anchor="lrh") #deleteCacheRow = Row((Label("Delete Temporary World File Cache?"), Button("Delete Cache!", action=clearCache, tooltipText="Click me if you think your chunks are stale."))) serverPanel = Column([useSnapshotServer, versionContainer, simRow], align="l") col.append(serverPanel) col = Column(col, align="l") col.add(flatPanel) flatPanel.topleft = serverPanel.topleft flatPanel.visible = False panel.add(col) panel.shrink_wrap() def generate(level, arg): useServer = generatorChoice.selectedChoice == "Minecraft Server" if useServer: def _createChunks(): if versionChoice: version = versionChoice.selectedChoice else: version = None gen = MCServerChunkGenerator(version=version) if isinstance(arg, pymclevel.BoundingBox): for i in gen.createLevelIter(level, arg, simulate=panel.simulate): yield i else: for i in gen.generateChunksInLevelIter(level, arg, simulate=panel.simulate): yield i else: def _createChunks(): height = panel.chunkHeight grass = panel.grass and pymclevel.alphaMaterials.Grass.ID or pymclevel.alphaMaterials.Dirt.ID if isinstance(arg, pymclevel.BoundingBox): chunks = list(arg.chunkPositions) else: chunks = arg if level.dimNo in (-1, 1): maxskylight = 0 else: maxskylight = 15 for i, (cx, cz) in enumerate(chunks): yield i, len(chunks) #surface = blockInput.blockInfo #for cx, cz in : try: level.createChunk(cx, cz) except ValueError, e: # chunk already present print e continue else: ch = level.getChunk(cx, cz) if height > 0: stoneHeight = max(0, height - 5) grassHeight = max(0, height - 1) ch.Blocks[:, :, grassHeight] = grass ch.Blocks[:, :, stoneHeight:grassHeight] = pymclevel.alphaMaterials.Dirt.ID ch.Blocks[:, :, :stoneHeight] = pymclevel.alphaMaterials.Stone.ID ch.Blocks[:, :, 0] = pymclevel.alphaMaterials.Bedrock.ID ch.SkyLight[:, :, height:] = maxskylight if maxskylight: ch.HeightMap[:] = height else: ch.SkyLight[:] = maxskylight ch.needsLighting = False ch.dirty = True return _createChunks()
def makeTabPage(self, tool, inputs): page = Widget() page.is_gl_container = True rows = [] cols = [] height = 0 max_height = 550 page.optionDict = {} page.tool = tool title = "Tab" for optionName, optionType in inputs: if isinstance(optionType, tuple): if isinstance(optionType[0], (int, long, float)): if len(optionType) > 2: val, min, max = optionType elif len(optionType) == 2: min, max = optionType val = min rows.append(addNumField(page, optionName, val, min, max)) if isinstance(optionType[0], (str, unicode)): isChoiceButton = False if len(optionType) == 3: a,b,c = optionType if a == "strValSize": field = TextField(value=b, width=c) page.optionDict[optionName] = AttrRef(field, 'value') row = Row((Label(optionName), field)) rows.append(row) else: isChoiceButton = True elif len(optionType) == 2: a,b = optionType if a == "strVal": field = TextField(value=b, width=200) page.optionDict[optionName] = AttrRef(field, 'value') row = Row((Label(optionName), field)) rows.append(row) elif a == "strSize": field = TextField(value="Input String Here", width=b) page.optionDict[optionName] = AttrRef(field, 'value') row = Row((Label(optionName), field)) rows.append(row) else: isChoiceButton = True else: isChoiceButton = True if isChoiceButton: choiceButton = ChoiceButton(map(str, optionType)) page.optionDict[optionName] = AttrRef(choiceButton, 'selectedChoice') rows.append(Row((Label(optionName), choiceButton))) elif isinstance(optionType, bool): cbox = CheckBox(value=optionType) page.optionDict[optionName] = AttrRef(cbox, 'value') row = Row((Label(optionName), cbox)) rows.append(row) elif isinstance(optionType, (int, float)): rows.append(addNumField(self, optionName, optionType)) elif optionType == "blocktype" or isinstance(optionType, pymclevel.materials.Block): blockButton = BlockButton(tool.editor.level.materials) if isinstance(optionType, pymclevel.materials.Block): blockButton.blockInfo = optionType row = Column((Label(optionName), blockButton)) page.optionDict[optionName] = AttrRef(blockButton, 'blockInfo') rows.append(row) elif optionType == "label": rows.append(wrapped_label(optionName, 50)) elif optionType == "string": field = TextField(value="Input String Here", width=200) page.optionDict[optionName] = AttrRef(field, 'value') row = Row((Label(optionName), field)) rows.append(row) elif optionType == "title": title = optionName else: raise ValueError(("Unknown option type", optionType)) height = sum(r.height for r in rows) if height > max_height: h = 0 for i, r in enumerate(rows): h += r.height if h > height / 2: break cols.append(Column(rows[:i])) rows = rows[i:] #cols.append(Column(rows)) if len(rows): cols.append(Column(rows)) if len(cols): page.add(Row(cols)) page.shrink_wrap() return (title, page, page._rect)