def CheckBoxLabel(title, *args, **kw): tooltipText = kw.pop('tooltipText', None) cb = CheckBox(*args, **kw) lab = Label(title, fg_color=cb.fg_color) lab.mouse_down = cb.mouse_down if tooltipText: cb.tooltipText = tooltipText lab.tooltipText = tooltipText class CBRow(Row): margin = 0 @property def value(self): return self.checkbox.value @value.setter def value(self, val): self.checkbox.value = val row = CBRow((lab, cb)) row.checkbox = cb return row
def mouse_down(e): CheckBox.mouse_down(useImagesBox.subwidgets[1], e) for sub in bulletFilePath.subwidgets: sub.enabled = config.nbtTreeSettings.useBulletImages.get() if type(sub) == TextFieldWrapped: if config.nbtTreeSettings.useBulletImages.get(): sub.fg_color = fg_color else: sub.fg_color = disabled_color
def mouse_down(e): CheckBox.mouse_down(useImagesBox.subwidgets[1], e) for sub in defaultBulletImagesBox.subwidgets: sub.enabled = config.nbtTreeSettings.useBulletImages.get() if type(sub) in (CheckBox, TextFieldWrapped): if config.nbtTreeSettings.useBulletImages.get(): sub.fg_color = fg_color else: sub.fg_color = disabled_color if type(sub) == CheckBox: sub.set_enabled(config.nbtTreeSettings.useBulletImages.get()) self.defaultBulletImagesBox_click(None)
def __init__(self, tool): Panel.__init__(self) self.tool = tool self.autoPlaceCheckBox = CheckBox( ref=AttrRef(tool, "placeImmediately")) self.autoPlaceLabel = Label("Place Immediately") self.autoPlaceLabel.mouse_down = self.autoPlaceCheckBox.mouse_down tooltipText = "When the clone tool is chosen, place the clone at the selection right away." self.autoPlaceLabel.tooltipText = self.autoPlaceCheckBox.tooltipText = tooltipText spaceLabel = Label("") cloneNudgeLabel = Label("Clone Fast Nudge Settings") cloneNudgeCheckBox = CheckBoxLabel( "Move by the width of selection ", ref=config.fastNudgeSettings.cloneWidth, tooltipText="Moves clone by his width") cloneNudgeNumber = IntInputRow( "Width of clone movement: ", ref=config.fastNudgeSettings.cloneWidthNumber, width=100, min=2, max=50) row = Row((self.autoPlaceCheckBox, self.autoPlaceLabel)) col = Column((Label("Clone Options"), row, spaceLabel, cloneNudgeLabel, cloneNudgeCheckBox, cloneNudgeNumber, Button("OK", action=self.dismiss))) self.add(col) self.shrink_wrap()
def __init__(self, tool): Panel.__init__(self) self.tool = tool self.autoPlaceCheckBox = CheckBox(ref=AttrRef(tool, "placeImmediately")) self.autoPlaceLabel = Label("Place Immediately") self.autoPlaceLabel.mouse_down = self.autoPlaceCheckBox.mouse_down tooltipText = "When the clone tool is chosen, place the clone at the selection right away." self.autoPlaceLabel.tooltipText = self.autoPlaceCheckBox.tooltipText = tooltipText row = Row((self.autoPlaceCheckBox, self.autoPlaceLabel)) col = Column((Label("Clone Options"), row, Button("OK", action=self.dismiss))) self.add(col) self.shrink_wrap()
def __init__(self, tool): Panel.__init__(self) self.tool = tool self.spawnProtectionCheckBox = CheckBox(ref=AttrRef(tool, "spawnProtection")) self.spawnProtectionLabel = Label("Spawn Position Safety") self.spawnProtectionLabel.mouse_down = self.spawnProtectionCheckBox.mouse_down tooltipText = "Minecraft will randomly move your spawn point if you try to respawn in a column where there are no blocks at Y=63 and Y=64. Only uncheck this box if Minecraft is changed." self.spawnProtectionLabel.tooltipText = self.spawnProtectionCheckBox.tooltipText = tooltipText row = Row((self.spawnProtectionCheckBox, self.spawnProtectionLabel)) col = Column((Label("Spawn Point Options"), row, Button("OK", action=self.dismiss))) self.add(col) self.shrink_wrap()
def mouse_down(e): CheckBox.mouse_down(defaultBulletImagesBox.subwidgets[1], e) self.defaultBulletImagesBox_click(e)
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)
def makeTabPage(self, tool, inputs, trn=None, **kwargs): page = Widget(**kwargs) page.is_gl_container = True rows = [] cols = [] max_height = tool.editor.mainViewport.height - tool.editor.toolbar.height - tool.editor.subwidgets[0].height -\ self._parent.filterSelectRow.height - self._parent.confirmButton.height - self.pages.tab_height page.optionDict = {} page.tool = tool title = "Tab" for optionSpec in inputs: optionName = optionSpec[0] optionType = optionSpec[1] if trn is not None: n = trn._(optionName) else: n = optionName if n == optionName: oName = _(optionName) else: oName = n if isinstance(optionType, tuple): if isinstance(optionType[0], (int, long, float)): if len(optionType) == 3: val, min, max = optionType increment = 0.1 elif len(optionType) == 2: min, max = optionType val = min increment = 0.1 else: val, min, max, increment = optionType rows.append( addNumField(page, optionName, oName, val, min, max, increment)) 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 try: v = int(splitWord[1]) except ValueError: pass key = splitWord[0] if v is not None: if key == "width": wid = v else: if key == "value": val = "=".join(splitWord[1:]) if val is None: val = "" if wid is None: wid = 200 field = TextFieldWrapped(value=val, width=wid) page.optionDict[optionName] = AttrRef(field, 'value') row = Row((Label(oName, doNotTranslate=True), field)) rows.append(row) else: isChoiceButton = True if isChoiceButton: if trn is not None: __ = trn._ else: __ = _ choices = [__("%s" % a) for a in optionType] choiceButton = ChoiceButton(choices, doNotTranslate=True) page.optionDict[optionName] = AttrRef( choiceButton, 'selectedChoice') rows.append( Row((Label(oName, doNotTranslate=True), choiceButton))) elif isinstance(optionType, bool): cbox = CheckBox(value=optionType) page.optionDict[optionName] = AttrRef(cbox, 'value') row = Row((Label(oName, doNotTranslate=True), cbox)) rows.append(row) elif isinstance(optionType, (int, float)): rows.append(addNumField(self, optionName, oName, 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(oName, doNotTranslate=True), blockButton)) page.optionDict[optionName] = AttrRef(blockButton, 'blockInfo') rows.append(row) elif optionType == "label": rows.append(wrapped_label(oName, 50, doNotTranslate=True)) elif optionType == "string": inp = None # not sure how to pull values from filters, # but leaves it open for the future. Use this variable to set field width. if inp is not None: size = inp else: size = 200 field = TextFieldWrapped(value="") row = TextInputRow(oName, ref=AttrRef(field, 'value'), width=size, doNotTranslate=True) page.optionDict[optionName] = AttrRef(field, 'value') rows.append(row) elif optionType == "title": title = oName elif type( optionType) == list and optionType[0].lower() == "nbttree": kw = {'close_text': None, 'load_text': None} if len(optionType) >= 3: def close(): self.pages.show_page(self.pages.pages[optionType[2]]) kw['close_action'] = close kw['close_text'] = "Go Back" if len(optionType) >= 4: if optionType[3]: kw['load_text'] = optionType[3] if hasattr(self.module, 'nbt_ok_action'): kw['ok_action'] = getattr(self.module, 'nbt_ok_action') self.nbttree = NBTExplorerToolPanel(self.tool.editor, nbtObject=optionType[1], height=max_height, no_header=True, copy_data=False, **kw) self.module.set_tree(self.nbttree.tree) for meth_name in dir(self.module): if meth_name.startswith('nbttree_'): setattr(self.nbttree.tree.treeRow, meth_name.split('nbttree_')[-1], getattr(self.module, meth_name)) # elif meth_name.startswith('nbt_'): # setattr(self.nbttree, meth_name.split('nbt_')[-1], getattr(self.module, meth_name)) page.optionDict[optionName] = AttrRef(self, 'rebuildTabPage') rows.append(self.nbttree) self.nbttree.page = len(self.pgs) else: raise ValueError(("Unknown option type", optionType)) height = sum(r.height for r in rows) + (len(rows) - 1) * self.spacing if height > max_height: h = 0 for i, r in enumerate(rows): h += r.height if h > height / 2: if rows[:i]: cols.append(Column(rows[:i], spacing=0)) rows = rows[i:] break if len(rows): cols.append(Column(rows, spacing=0)) if len(cols): page.add(Row(cols, spacing=0)) page.shrink_wrap() return title, page, page._rect
def __init__(self, tool, editor, _parent=None): Panel.__init__(self) self.tool = tool rotaterollRow = Row(( Label(config.keys.rotateClone.get()), Button("Rotate", width=80, action=tool.rotate, enable=self.transformEnable), Label(config.keys.rollClone.get()), Button("Roll", width=80, action=tool.roll, enable=self.transformEnable), )) flipmirrorRow = Row(( Label(config.keys.flip.get()), Button("Flip", width=80, action=tool.flip, enable=self.transformEnable), Label(config.keys.mirror.get()), Button("Mirror", width=80, action=tool.mirror, enable=self.transformEnable), )) self.alignCheckBox = CheckBox(ref=AttrRef(self.tool, 'chunkAlign')) self.alignLabel = Label("Chunk Align") self.alignLabel.mouse_down = self.alignCheckBox.mouse_down alignRow = Row((self.alignCheckBox, self.alignLabel)) # headerLabel = Label("Clone Offset") if self.useOffsetInput: self.offsetInput = CoordsInput(editor) self.offsetInput.coordsChanged = tool.offsetChanged self.offsetInput.nudgeButton.bg_color = tool.color self.offsetInput.nudge = tool.nudge else: self.nudgeButton = NudgeButton(editor) self.nudgeButton.bg_color = tool.color self.nudgeButton.nudge = tool.nudge repeatField = IntField(ref=AttrRef(tool, 'repeatCount')) repeatField.min = 1 repeatField.max = 1000 repeatRow = Row((Label("Repeat"), repeatField)) self.repeatField = repeatField scaleField = FloatField(ref=AttrRef(tool, 'scaleFactor')) scaleField.min = 0.1 scaleField.max = 8 if self.transformEnable(): scaleRow = Row((Label("Scale Factor"), scaleField)) else: scaleRow = Row((Label("Scale Factor: 1.0"), )) self.scaleField = scaleField self.copyAirCheckBox = CheckBox(ref=AttrRef(self.tool, "copyAir")) self.copyAirLabel = Label("Copy Air") self.copyAirLabel.mouse_down = self.copyAirCheckBox.mouse_down self.copyAirLabel.tooltipText = "Shortcut: Alt-1" self.copyAirCheckBox.tooltipText = self.copyAirLabel.tooltipText copyAirRow = Row((self.copyAirCheckBox, self.copyAirLabel)) self.copyWaterCheckBox = CheckBox(ref=AttrRef(self.tool, "copyWater")) self.copyWaterLabel = Label("Copy Water") self.copyWaterLabel.mouse_down = self.copyWaterCheckBox.mouse_down self.copyWaterLabel.tooltipText = "Shortcut: Alt-2" self.copyWaterCheckBox.tooltipText = self.copyWaterLabel.tooltipText copyWaterRow = Row((self.copyWaterCheckBox, self.copyWaterLabel)) self.copyBiomesCheckBox = CheckBox( ref=AttrRef(self.tool, "copyBiomes")) self.copyBiomesLabel = Label("Copy Biomes") self.copyBiomesLabel.mouse_down = self.copyBiomesCheckBox.mouse_down self.copyBiomesLabel.tooltipText = "Shortcut: Alt-3" self.copyBiomesCheckBox.tooltipText = self.copyBiomesLabel.tooltipText copyBiomesRow = Row((self.copyBiomesCheckBox, self.copyBiomesLabel)) self.staticCommandsCheckBox = CheckBox( ref=AttrRef(self.tool, "staticCommands")) self.staticCommandsLabel = Label("Change Coordinates") self.staticCommandsLabel.mouse_down = self.staticCommandsCheckBox.mouse_down self.staticCommandsLabel.tooltipText = "Check to automatically change command block static coordinates when moved.\nShortcut: Alt-4" self.staticCommandsCheckBox.tooltipText = self.staticCommandsLabel.tooltipText staticCommandsRow = Row( (self.staticCommandsCheckBox, self.staticCommandsLabel)) self.moveSpawnerPosCheckBox = CheckBox( ref=AttrRef(self.tool, "moveSpawnerPos")) self.moveSpawnerPosLabel = Label("Change Spawners") self.moveSpawnerPosLabel.mouse_down = self.moveSpawnerPosCheckBox.mouse_down self.moveSpawnerPosLabel.tooltipText = "Check to automatically change the position of the mobs in spawners when moved.\nShortcut: Alt-5" self.moveSpawnerPosCheckBox.tooltipText = self.moveSpawnerPosLabel.tooltipText moveSpawnerPosRow = Row( (self.moveSpawnerPosCheckBox, self.moveSpawnerPosLabel)) self.regenerateUUIDCheckBox = CheckBox( ref=AttrRef(self.tool, "regenerateUUID")) self.regenerateUUIDLabel = Label("Regenerate UUID") self.regenerateUUIDLabel.mouse_down = self.regenerateUUIDCheckBox.mouse_down self.regenerateUUIDLabel.tooltipText = "Check to automatically generate new UUIDs for entities.\nShortcut: Alt-6" self.regenerateUUIDCheckBox.tooltipText = self.regenerateUUIDLabel.tooltipText regenerateUUIDRow = Row( (self.regenerateUUIDCheckBox, self.regenerateUUIDLabel)) self.performButton = Button("Clone", width=100, align="c") self.performButton.tooltipText = "Shortcut: Enter" self.performButton.action = tool.confirm self.performButton.enable = lambda: (tool.destPoint is not None) max_height = self.tool.editor.mainViewport.height - self.tool.editor.toolbar.height - self.tool.editor.subwidgets[ 0].height # - self.performButton.height - 2 def buildPage(*items): height = 0 cls = [] idx = 0 for i, r in enumerate(items): r.margin = 0 r.shrink_wrap() height += r.height if height > max_height: cls.append(Column(items[idx:i], spacing=2, margin=0)) idx = i height = 0 cls.append(Column(items[idx:], spacing=2, margin=0)) return cls if self.useOffsetInput: cols = buildPage(rotaterollRow, flipmirrorRow, alignRow, self.offsetInput, repeatRow, scaleRow, copyAirRow, copyWaterRow, copyBiomesRow, staticCommandsRow, moveSpawnerPosRow, regenerateUUIDRow) else: cols = buildPage(rotaterollRow, flipmirrorRow, alignRow, self.nudgeButton, scaleRow, copyAirRow, copyWaterRow, copyBiomesRow, staticCommandsRow, moveSpawnerPosRow, regenerateUUIDRow) row = Row(cols, spacing=0, margin=2) row.shrink_wrap() col = Column((row, self.performButton), spacing=2) self.add(col) self.anchor = "lwh" self.shrink_wrap()
def mouse_down(e): CheckBox.mouse_down(useStyleBox.subwidgets[1], e) useImagesBox.mouse_down(e) self.useStyleBox_click(e)
def __init__(self, tool): Panel.__init__(self) self.tool = tool rotateRow = Row(( Label(config.config.get("Keys", "Rotate").upper()), Button("Rotate", width=80, action=tool.rotate, enable=self.transformEnable), )) rollRow = Row(( Label(config.config.get("Keys", "Roll").upper()), Button("Roll", width=80, action=tool.roll, enable=self.transformEnable), )) flipRow = Row(( Label(config.config.get("Keys", "Flip").upper()), Button("Flip", width=80, action=tool.flip, enable=self.transformEnable), )) mirrorRow = Row(( Label(config.config.get("Keys", "Mirror").upper()), Button("Mirror", width=80, action=tool.mirror, enable=self.transformEnable), )) alignRow = Row((CheckBox(ref=AttrRef(self.tool, 'chunkAlign')), Label("Chunk Align"))) # headerLabel = Label("Clone Offset") if self.useOffsetInput: self.offsetInput = CoordsInput() self.offsetInput.coordsChanged = tool.offsetChanged self.offsetInput.nudgeButton.bg_color = tool.color self.offsetInput.nudge = tool.nudge else: self.nudgeButton = NudgeButton() self.nudgeButton.bg_color = tool.color self.nudgeButton.nudge = tool.nudge repeatField = IntField(ref=AttrRef(tool, 'repeatCount')) repeatField.min = 1 repeatField.max = 50 repeatRow = Row((Label("Repeat"), repeatField)) self.repeatField = repeatField scaleField = FloatField(ref=AttrRef(tool, 'scaleFactor')) scaleField.min = 0.125 scaleField.max = 8 dv = scaleField.decrease_value iv = scaleField.increase_value def scaleFieldDecrease(): if scaleField.value > 1 / 8.0 and scaleField.value <= 1.0: scaleField.value *= 0.5 else: dv() def scaleFieldIncrease(): if scaleField.value < 1.0: scaleField.value *= 2.0 else: iv() scaleField.decrease_value = scaleFieldDecrease scaleField.increase_value = scaleFieldIncrease scaleRow = Row((Label("Scale Factor"), scaleField)) self.scaleField = scaleField self.copyAirCheckBox = CheckBox(ref=AttrRef(self.tool, "copyAir")) self.copyAirLabel = Label("Copy Air") self.copyAirLabel.mouse_down = self.copyAirCheckBox.mouse_down self.copyAirLabel.tooltipText = "Shortcut: ALT-1" self.copyAirCheckBox.tooltipText = self.copyAirLabel.tooltipText copyAirRow = Row((self.copyAirCheckBox, self.copyAirLabel)) self.copyWaterCheckBox = CheckBox(ref=AttrRef(self.tool, "copyWater")) self.copyWaterLabel = Label("Copy Water") self.copyWaterLabel.mouse_down = self.copyWaterCheckBox.mouse_down self.copyWaterLabel.tooltipText = "Shortcut: ALT-2" self.copyWaterCheckBox.tooltipText = self.copyWaterLabel.tooltipText copyWaterRow = Row((self.copyWaterCheckBox, self.copyWaterLabel)) self.copyBiomesCheckBox = CheckBox( ref=AttrRef(self.tool, "copyBiomes")) self.copyBiomesLabel = Label("Copy Biomes") self.copyBiomesLabel.mouse_down = self.copyBiomesCheckBox.mouse_down self.copyBiomesLabel.tooltipText = "Shortcut: ALT-3" self.copyBiomesCheckBox.tooltipText = self.copyBiomesLabel.tooltipText copyBiomesRow = Row((self.copyBiomesCheckBox, self.copyBiomesLabel)) self.staticCommandsCheckBox = CheckBox( ref=AttrRef(self.tool, "staticCommands")) self.staticCommandsLabel = Label("Change Coordinates") self.staticCommandsLabel.mouse_down = self.staticCommandsCheckBox.mouse_down self.staticCommandsLabel.tooltipText = "Check to automatically change command block static coordinates when moved.\nShortcut: ALT-4" self.staticCommandsCheckBox.tooltipText = self.staticCommandsLabel.tooltipText staticCommandsRow = Row( (self.staticCommandsCheckBox, self.staticCommandsLabel)) self.performButton = Button("Clone", width=100, align="c") self.performButton.tooltipText = "Shortcut: ENTER" self.performButton.action = tool.confirm self.performButton.enable = lambda: (tool.destPoint is not None) if self.useOffsetInput: col = Column((rotateRow, rollRow, flipRow, mirrorRow, alignRow, self.offsetInput, repeatRow, scaleRow, copyAirRow, copyWaterRow, copyBiomesRow, staticCommandsRow, self.performButton)) else: col = Column( (rotateRow, rollRow, flipRow, mirrorRow, alignRow, self.nudgeButton, copyAirRow, copyWaterRow, copyBiomesRow, staticCommandsRow, self.performButton)) self.add(col) self.anchor = "lwh" self.shrink_wrap()
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 editCommandBlock(self, point): panel = Dialog() block = self.editor.level.blockAt(*point) blockData = self.editor.level.blockDataAt(*point) tileEntity = self.editor.level.tileEntityAt(*point) undoBackupEntityTag = copy.deepcopy(tileEntity) if not tileEntity: tileEntity = pymclevel.TAG_Compound() tileEntity["id"] = pymclevel.TAG_String("Control") tileEntity["x"] = pymclevel.TAG_Int(point[0]) tileEntity["y"] = pymclevel.TAG_Int(point[1]) tileEntity["z"] = pymclevel.TAG_Int(point[2]) tileEntity["Command"] = pymclevel.TAG_String() tileEntity["CustomName"] = pymclevel.TAG_String("@") tileEntity["TrackOutput"] = pymclevel.TAG_Byte(0) self.editor.level.addTileEntity(tileEntity) titleLabel = Label("Edit Command Block") commandField = TextField(width=200) nameField = TextField(width=100) trackOutput = CheckBox() commandField.value = tileEntity["Command"].value oldCommand = commandField.value trackOutput.value = tileEntity["TrackOutput"].value oldTrackOutput = trackOutput.value nameField.value = tileEntity["CustomName"].value oldNameField = nameField.value class CommandBlockEditOperation(Operation): def __init__(self, tool, level): self.tool = tool self.level = level self.undoBackupEntityTag = undoBackupEntityTag self.canUndo = False def perform(self, recordUndo=True): if self.level.saving: alert("Cannot perform action while saving is taking place") return self.level.addTileEntity(tileEntity) self.canUndo = True def undo(self): self.redoBackupEntityTag = copy.deepcopy(tileEntity) self.level.addTileEntity(self.undoBackupEntityTag) return pymclevel.BoundingBox(pymclevel.TileEntity.pos(tileEntity), (1, 1, 1)) def redo(self): self.level.addTileEntity(self.redoBackupEntityTag) return pymclevel.BoundingBox(pymclevel.TileEntity.pos(tileEntity), (1, 1, 1)) def updateCommandBlock(): if oldCommand != commandField.value or oldTrackOutput != trackOutput.value or oldNameField != nameField.value: tileEntity["Command"] = pymclevel.TAG_String(commandField.value) tileEntity["TrackOutput"] = pymclevel.TAG_Byte(trackOutput.value) tileEntity["CustomName"] = pymclevel.TAG_String(nameField.value) op = CommandBlockEditOperation(self.editor, self.editor.level) self.editor.addOperation(op) if op.canUndo: self.editor.addUnsavedEdit() chunk = self.editor.level.getChunk(int(int(point[0]) / 16), int(int(point[2]) / 16)) chunk.dirty = True panel.dismiss() okBTN = Button("OK", action=updateCommandBlock) cancel = Button("Cancel", action=panel.dismiss) column = [titleLabel, Row((Label("Command"), commandField)), Row((Label("Custom Name"), nameField)), Row((Label("Track Output"), trackOutput)), okBTN, cancel] panel.add(Column(column)) panel.shrink_wrap() panel.present() return