def update_side_panel(self, item): if item == self.displayed_item: return self.displayed_item = item if self.side_panel: self.side_panel.set_parent(None) items = [a for a in item[1]] rows = [] if config.nbtTreeSettings.showAllTags.get(): meth = None else: meth = getattr(self, 'build_%s' % item[3].lower(), None) col = True if meth and len(items) == 1: rows = meth(items) else: height = 0 for itm in items: t = itm.__class__.__name__ rows.append(Row([Label("Data Type:"), Label(t)], margin=1)) fields = self.build_field(itm) for field in fields: if type(field) == TextFieldWrapped: field.set_size_for_text(self.side_panel_width) row = Row([ field, ], margin=1) rows.append(row) height += row.height if height > self.displayRow.height: col = False if rows: if col: col = Column(rows, align='l', spacing=0, height=self.displayRow.height) else: col = ScrollPanel(rows=rows, align='l', spacing=0, height=self.displayRow.height, draw_zebra=False, inner_width=self.side_panel_width - scroll_button_size) col.set_parent(self.displayRow) col.top = self.displayRow.top col.left = self.displayRow.subwidgets[0].right col.bottom = self.displayRow.subwidgets[0].bottom col.shrink_wrap() self.side_panel = col
def update_side_panel(self, item): if item == self.displayed_item: return self.displayed_item = item if self.side_panel: self.side_panel.set_parent(None) items = [a for a in item[1]] rows = [] if config.nbtTreeSettings.showAllTags.get(): meth = None else: meth = getattr(self, "build_%s" % item[3].lower(), None) col = True if meth and len(items) == 1: rows = meth(items) else: height = 0 for itm in items: t = itm.__class__.__name__ rows.append(Row([Label("Data Type:"), Label(t)], margin=1)) fields = self.build_field(itm) for field in fields: if type(field) == TextFieldWrapped: field.set_size_for_text(self.side_panel_width) row = Row([field], margin=1) rows.append(row) height += row.height if height > self.displayRow.height: col = False if rows: if col: col = Column(rows, align="l", spacing=0, height=self.displayRow.height) else: col = ScrollPanel( rows=rows, align="l", spacing=0, height=self.displayRow.height, draw_zebra=False, inner_width=self.side_panel_width - scroll_button_size, ) col.set_parent(self.displayRow) col.top = self.displayRow.top col.left = self.displayRow.subwidgets[0].right col.bottom = self.displayRow.subwidgets[0].bottom col.shrink_wrap() self.side_panel = col
def __init__(self, blockInfo, materials, *a, **kw): self.root = get_root() self.allowWildcards = False Dialog.__init__(self, *a, **kw) panelWidth = 518 self.click_outside_response = 0 self.materials = materials self.anySubtype = blockInfo.wildcard self.matchingBlocks = materials.allBlocks #&# self.searchNames = [ mclangres.translate(a.name).lower() for a in self.matchingBlocks ] #&# try: self.selectedBlockIndex = self.matchingBlocks.index(blockInfo) except ValueError: self.selectedBlockIndex = 0 for i, b in enumerate(self.matchingBlocks): if blockInfo.ID == b.ID and blockInfo.blockData == b.blockData: self.selectedBlockIndex = i break lbl = Label("Search") # lbl.rect.topleft = (0,0) fld = TextFieldWrapped(300) # fld.rect.topleft = (100, 10) # fld.centery = lbl.centery # fld.left = lbl.right fld.change_action = self.textEntered fld.enter_action = self.ok fld.escape_action = self.cancel fld.attention_lost = fld.commit self.awesomeField = fld searchRow = Row((lbl, fld)) def formatBlockName(x): block = self.matchingBlocks[x] #&# #r = "{name}".format(name=block.name) r = u"{name}".format(name=mclangres.translate(block.name)) #&# if block.aka: #&# #r += " [{0}]".format(block.aka) r += u" [{0}]".format(mclangres.translate(block.aka)) #&# return r def formatBlockID(x): block = self.matchingBlocks[x] ident = "({id}:{data})".format(id=block.ID, data=block.blockData) return ident tableview = TableView(columns=[ TableColumn(" ", 24, "l", lambda x: ""), TableColumn("Name", 415, "l", formatBlockName), TableColumn("ID", 45, "l", formatBlockID) ]) tableicons = [ blockview.BlockView(materials) for i in xrange(tableview.rows.num_rows()) ] for t in tableicons: t.size = (16, 16) t.margin = 0 spacing = max(tableview.font.get_linesize() - 16, 2) icons = Column(tableicons, spacing=spacing) # tableview.margin = 5 tableview.num_rows = lambda: len(self.matchingBlocks) tableview.row_data = lambda x: (self.matchingBlocks[x], x, x) tableview.row_is_selected = lambda x: x == self.selectedBlockIndex tableview.click_row = self.selectTableRow draw_table_cell = tableview.draw_table_cell def draw_block_table_cell(surf, i, data, cell_rect, column): if isinstance(data, Block): tableicons[i - tableview.rows.scroll].blockInfo = data else: draw_table_cell(surf, i, data, cell_rect, column) tableview.draw_table_cell = draw_block_table_cell tableview.width = panelWidth tableview.anchor = "lrbt" # self.add(tableview) self.tableview = tableview tableWidget = Widget() tableWidget.add(tableview) tableWidget.shrink_wrap() def wdraw(*args): for t in tableicons: t.blockInfo = materials.Air tableWidget.draw = wdraw self.blockButton = blockView = thumbview.BlockThumbView( materials, self.blockInfo) blockView.centerx = self.centerx blockView.top = tableview.bottom # self.add(blockview) but = Button("OK") but.action = self.ok but.top = blockView.bottom but.centerx = self.centerx but.align = "c" but.height = 30 if self.allowWildcards: # self.add(but) anyRow = CheckBoxLabel( "Any Subtype", ref=AttrRef(self, 'anySubtype'), tooltipText= "Replace blocks with any data value. Only useful for Replace operations." ) col = Column((searchRow, tableWidget, anyRow, blockView, but)) else: col = Column((searchRow, tableWidget, blockView, but)) col.anchor = "wh" self.anchor = "wh" panel = GLBackground() panel.bg_color = [i / 255. for i in self.bg_color] panel.anchor = "tlbr" self.add(panel) self.add(col) self.add(icons) icons.left += tableview.margin + tableWidget.margin + col.margin icons.top = tableWidget.top + tableview.top + tableview.header_height + tableview.header_spacing + tableWidget.margin + tableview.margin + tableview.subwidgets[ 1].margin + (spacing / 2) self.shrink_wrap() panel.size = self.size try: self.tableview.rows.scroll_to_item(self.selectedBlockIndex) except: pass
def __init__(self, blockInfo, materials, *a, **kw): self.root = get_root() self.allowWildcards = False Dialog.__init__(self, *a, **kw) panelWidth = 518 self.click_outside_response = 0 self.materials = materials self.anySubtype = blockInfo.wildcard self.matchingBlocks = materials.allBlocks #&# self.searchNames = [mclangres.translate(a.name).lower() for a in self.matchingBlocks] #&# try: self.selectedBlockIndex = self.matchingBlocks.index(blockInfo) except ValueError: self.selectedBlockIndex = 0 for i, b in enumerate(self.matchingBlocks): if blockInfo.ID == b.ID and blockInfo.blockData == b.blockData: self.selectedBlockIndex = i break lbl = Label("Search") # lbl.rect.topleft = (0,0) fld = TextFieldWrapped(300) # fld.rect.topleft = (100, 10) # fld.centery = lbl.centery # fld.left = lbl.right fld.change_action = self.textEntered fld.enter_action = self.ok fld.escape_action = self.cancel self.awesomeField = fld searchRow = Row((lbl, fld)) def formatBlockName(x): block = self.matchingBlocks[x] #&# #r = "{name}".format(name=block.name) r = u"{name}".format(name=mclangres.translate(block.name)) #&# if block.aka: #&# #r += " [{0}]".format(block.aka) r += u" [{0}]".format(mclangres.translate(block.aka)) #&# return r def formatBlockID(x): block = self.matchingBlocks[x] ident = "({id}:{data})".format(id=block.ID, data=block.blockData) return ident tableview = TableView(columns=[TableColumn(" ", 24, "l", lambda x: ""), TableColumn("Name", 415, "l", formatBlockName), TableColumn("ID", 45, "l", formatBlockID) ]) tableicons = [blockview.BlockView(materials) for i in range(tableview.rows.num_rows())] for t in tableicons: t.size = (16, 16) t.margin = 0 spacing = max(tableview.font.get_linesize() - 16, 2) icons = Column(tableicons, spacing=spacing) # tableview.margin = 5 tableview.num_rows = lambda: len(self.matchingBlocks) tableview.row_data = lambda x: (self.matchingBlocks[x], x, x) tableview.row_is_selected = lambda x: x == self.selectedBlockIndex tableview.click_row = self.selectTableRow draw_table_cell = tableview.draw_table_cell def draw_block_table_cell(surf, i, data, cell_rect, column): if isinstance(data, Block): tableicons[i - tableview.rows.scroll].blockInfo = data else: draw_table_cell(surf, i, data, cell_rect, column) tableview.draw_table_cell = draw_block_table_cell tableview.width = panelWidth tableview.anchor = "lrbt" # self.add(tableview) self.tableview = tableview tableWidget = Widget() tableWidget.add(tableview) tableWidget.shrink_wrap() def wdraw(*args): for t in tableicons: t.blockInfo = materials.Air tableWidget.draw = wdraw self.blockButton = blockView = thumbview.BlockThumbView(materials, self.blockInfo) blockView.centerx = self.centerx blockView.top = tableview.bottom # self.add(blockview) but = Button("OK") but.action = self.ok but.top = blockView.bottom but.centerx = self.centerx but.align = "c" but.height = 30 if self.allowWildcards: # self.add(but) anyRow = CheckBoxLabel("Any Subtype", ref=AttrRef(self, 'anySubtype'), tooltipText="Replace blocks with any data value. Only useful for Replace operations.") col = Column((searchRow, tableWidget, anyRow, blockView, but)) else: col = Column((searchRow, tableWidget, blockView, but)) col.anchor = "wh" self.anchor = "wh" panel = GLBackground() panel.bg_color = [i / 255. for i in self.bg_color] panel.anchor = "tlbr" self.add(panel) self.add(col) self.add(icons) icons.left += tableview.margin + tableWidget.margin + col.margin icons.top = tableWidget.top + tableview.top + tableview.header_height + tableview.header_spacing + tableWidget.margin + tableview.margin + tableview.subwidgets[1].margin + (spacing / 2) self.shrink_wrap() panel.size = self.size try: self.tableview.rows.scroll_to_item(self.selectedBlockIndex) except: pass