当前位置: 首页>>代码示例>>Python>>正文


Python albow.TableView类代码示例

本文整理汇总了Python中albow.TableView的典型用法代码示例。如果您正苦于以下问题:Python TableView类的具体用法?Python TableView怎么用?Python TableView使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TableView类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, tool):
        Panel.__init__(self)
        self.tool = tool
        level = tool.editor.level
        if hasattr(level, 'players'):
            players = level.players or ["[No players]"]
        else:
            players = ["Player"]
        self.players = players
        tableview = TableView(columns=[
            TableColumn("Player Name", 200),
        ])
        tableview.index = 0
        tableview.num_rows = lambda: len(players)
        tableview.row_data = lambda i: (players[i],)
        tableview.row_is_selected = lambda x: x == tableview.index
        tableview.zebra_color = (0, 0, 0, 48)

        def selectTableRow(i, evt):
            tableview.index = i

        tableview.click_row = selectTableRow
        self.table = tableview
        l = Label("Player: ")
        col = [l, tableview]

        gotoButton = Button("Goto Player", action=self.tool.gotoPlayer)
        gotoCameraButton = Button("Goto Player's View", action=self.tool.gotoPlayerCamera)
        moveButton = Button("Move Player", action=self.tool.movePlayer)
        moveToCameraButton = Button("Align Player to Camera", action=self.tool.movePlayerToCamera)
        col.extend([gotoButton, gotoCameraButton, moveButton, moveToCameraButton])

        col = Column(col)
        self.add(col)
        self.shrink_wrap()
开发者ID:s32ialx,项目名称:mcedit,代码行数:35,代码来源:player.py

示例2: __init__

    def __init__(self, tool):
        Panel.__init__(self)
        self.tool = tool
        self.player_UUID = {}
        self.level = tool.editor.level
        if hasattr(self.level, 'players'):
            players = self.level.players or ["[No players]"]
            if not self.level.oldPlayerFolderFormat:
                for player in players:
                    if player != "Player" and player != "[No players]":
                        self.player_UUID[version_utils.getPlayerNameFromUUID(player)] = player
                if "Player" in players:
                    self.player_UUID["Player"] = "Player"
                if "[No players]" not in players:
                    players = sorted(self.player_UUID.keys(), key=lambda x: False if x == "Player" else x.lower())

        else:
            players = ["Player"]
        self.players = players

        max_height = self.tool.editor.mainViewport.height - self.tool.editor.netherPanel.height - self.tool.editor.subwidgets[0].height - self.margin - 2

        addButton = Button("Add Player", action=self.tool.addPlayer)
        removeButton = Button("Remove Player", action=self.tool.removePlayer)
        gotoButton = Button("Goto Player", action=self.tool.gotoPlayer)
        gotoCameraButton = Button("Goto Player's View", action=self.tool.gotoPlayerCamera)
        moveButton = Button("Move Player", action=self.tool.movePlayer)
        moveToCameraButton = Button("Align Player to Camera", action=self.tool.movePlayerToCamera)
        reloadSkin = Button("Reload Skins", action=self.tool.reloadSkins, tooltipText="This pulls skins from the online server, so this may take a while")

        print max_height
        max_height -= sum((a.height for a in (addButton, removeButton, gotoButton, gotoCameraButton, moveButton, moveToCameraButton, reloadSkin)))
        print max_height

        tableview = TableView(columns=[
            TableColumn("Player Name(s):", 200),
        ], height=max_height)
        tableview.index = 0
        tableview.num_rows = lambda: len(players)
        tableview.row_data = lambda i: (players[i],)
        tableview.row_is_selected = lambda x: x == tableview.index
        tableview.zebra_color = (0, 0, 0, 48)

        def selectTableRow(i, evt):
            tableview.index = i

        tableview.click_row = selectTableRow
        self.table = tableview
        col = [self.table]

        col.extend([addButton, removeButton, gotoButton, gotoCameraButton, moveButton, moveToCameraButton, reloadSkin])

        col = Column(col, margin=0, spacing=2)
        col.shrink_wrap()
        self.add(col)
        self.shrink_wrap()
开发者ID:Alexhb61,项目名称:MCEdit-Unified,代码行数:56,代码来源:player.py

示例3: removePreset

    def removePreset(self):
        """
        Brings up a panel to remove presets.
        """
        panel = Dialog()
        p = self.getBrushFileList()
        if not p:
            alert('No presets saved')
            return

        def okPressed():
            panel.dismiss()
            name = p[presetTable.selectedIndex] + ".preset"
            os.remove(os.path.join(directories.brushesDir, name))
            self.tool.showPanel()

        def selectTableRow(i, evt):
            presetTable.selectedIndex = i
            if evt.num_clicks == 2:
                okPressed()

        presetTable = TableView(columns=(TableColumn("", 200),))
        presetTable.num_rows = lambda: len(p)
        presetTable.row_data = lambda i: (p[i],)
        presetTable.row_is_selected = lambda x: x == presetTable.selectedIndex
        presetTable.click_row = selectTableRow
        presetTable.selectedIndex = 0
        choiceCol = Column((ValueDisplay(width=200, get_value=lambda: "Select preset to delete"), presetTable))
        okButton = Button("OK", action=okPressed)
        cancelButton = Button("Cancel", action=panel.dismiss)
        row = Row([okButton, cancelButton])
        panel.add(Column((choiceCol, row)))
        panel.shrink_wrap()
        panel.present()
开发者ID:fhfuih,项目名称:MCEdit-Unified,代码行数:34,代码来源:brush.py

示例4: __init__

    def __init__(self, tool):
        Panel.__init__(self)
        self.tool = tool
        self.player_UUID = {}
        self.level = tool.editor.level
        if hasattr(self.level, 'players'):
            players = self.level.players or ["[No players]"]
            if not self.level.oldPlayerFolderFormat:
                for player in players:
                    if player != "Player":
                        self.player_UUID[version_utils.getPlayerNameFromUUID(player)] = player
                self.player_UUID["Player"] = "Player"
                players = self.player_UUID.keys()

        else:
            players = ["Player"]
        self.players = players
        tableview = TableView(columns=[
            TableColumn("Player Name", 200),
        ])
        tableview.index = 0
        tableview.num_rows = lambda: len(players)
        tableview.row_data = lambda i: (players[i],)
        tableview.row_is_selected = lambda x: x == tableview.index
        tableview.zebra_color = (0, 0, 0, 48)

        def selectTableRow(i, evt):
            tableview.index = i

        tableview.click_row = selectTableRow
        self.table = tableview
        l = Label("Player: ")
        col = [l, self.table]

        addButton = Button("Add Player", action=self.tool.addPlayer)
        removeButton = Button("Remove Player", action=self.tool.removePlayer)
        gotoButton = Button("Goto Player", action=self.tool.gotoPlayer)
        gotoCameraButton = Button("Goto Player's View", action=self.tool.gotoPlayerCamera)
        moveButton = Button("Move Player", action=self.tool.movePlayer)
        moveToCameraButton = Button("Align Player to Camera", action=self.tool.movePlayerToCamera)
        col.extend([addButton, removeButton, gotoButton, gotoCameraButton, moveButton, moveToCameraButton])

        col = Column(col)
        self.add(col)
        self.shrink_wrap()
开发者ID:freundTech,项目名称:MCEdit-Unified,代码行数:45,代码来源:player.py

示例5: __init__

    def __init__(self, tool):
        Panel.__init__(self, name='Panel.PlayerPositionPanel')
        self.tool = tool
        self.player_UUID = {"UUID": [], "Name": []}
        self.level = tool.editor.level
        self.playercache = PlayerCache()
        # Add this instance to PlayerCache 'targets'. PlayerCache generated processes will call
        # this instance 'update_player' method when they have finished their execution.
        self.playercache.add_target(self.update_player)
        
        if hasattr(self.level, 'players'):
            players = self.level.players or ["[No players]"]
            if not self.level.oldPlayerFolderFormat:
                for player in players:
                    if player != "Player" and player != "[No players]":
                        if len(player) > 4 and player[4] == "-":
                            os.rename(os.path.join(self.level.worldFolder.getFolderPath("playerdata"), player+".dat"), os.path.join(self.level.worldFolder.getFolderPath("playerdata"), player.replace("-", "", 1)+".dat"))
                            player = player.replace("-", "", 1)
#                         print 5
                        data = self.playercache.getPlayerInfo(player, use_old_data=True)
                        #self.player_UUID[data[0]] = data[1]
                        self.player_UUID["UUID"].append(data[0])
                        self.player_UUID["Name"].append(data[1])
                        #self.player_UUID[player] = data
                if "Player" in players:
                    #self.player_UUID["Player (Single Player)"] = "Player"
                    self.player_UUID["UUID"].append("Player")
                    self.player_UUID["Name"].append("Player (Single Player)")
                if "[No players]" not in players:
                    self.player_names = sorted(self.player_UUID.values(), key=lambda x: False if x == "Player (Single Player)" else x)
                else:
                    self.player_UUID["UUID"].append("[No players]")
                    self.player_UUID["Name"].append("[No players]")

        else:
            players = ["Player (Single Player)"]
        self.players = players
        
        if 'Player' in self.player_UUID['UUID'] and 'Player (Single Player)' in self.player_UUID['Name']:
            self.player_UUID['UUID'].insert(0, self.player_UUID['UUID'].pop(self.player_UUID['UUID'].index('Player')))
            self.player_UUID['Name'].insert(0, self.player_UUID['Name'].pop(self.player_UUID['Name'].index('Player (Single Player)')))

        self.pages = TabPanel()
        tab_height = self.pages.tab_height

        max_height = tab_height + self.tool.editor.mainViewport.height - self.tool.editor.toolbar.height - self.tool.editor.subwidgets[0].height - self.pages.margin * 2
        #-# Uncomment the following line to have a maximum height for this panel.
        # max_height = min(max_height, 500)

        self.editNBTDataButton = Button("Edit NBT", action=self.editNBTData, tooltipText="Open the NBT Explorer to edit player's attributes and inventory")
        addButton = Button("Add", action=self.tool.addPlayer)
        removeButton = Button("Remove", action=self.tool.removePlayer)
        gotoButton = Button("Goto", action=self.tool.gotoPlayer)
        gotoCameraButton = Button("Goto View", action=self.tool.gotoPlayerCamera)
        moveButton = Button("Move", action=self.tool.movePlayer)
        moveToCameraButton = Button("Align to Camera", action=self.tool.movePlayerToCamera)
        reloadSkin = Button("Reload Skins", action=self.tool.reloadSkins, tooltipText="This pulls skins from the online server, so this may take a while")

        btns = [self.editNBTDataButton]
        if not isinstance(self.level, pymclevel.leveldbpocket.PocketLeveldbWorld):
            btns.extend([addButton, removeButton])
        btns.extend([gotoButton, gotoCameraButton, moveButton, moveToCameraButton, reloadSkin])
        btns = Column(btns, margin=0, spacing=2)
        h = max_height - btns.height - self.pages.margin * 2 - 2 - self.font.get_linesize() * 2

        col = Label('')

        def close():
            self.pages.show_page(col)
        self.nbttree = NBTExplorerToolPanel(self.tool.editor, nbtObject={}, height=max_height, \
                                            close_text="Go Back", no_header=True, close_action=close,
                                            load_text=None)
        self.nbttree.shrink_wrap()

        self.nbtpage = Column([self.nbttree])
        self.nbtpage.shrink_wrap()
        self.pages.add_page("NBT Data", self.nbtpage)
        self.pages.set_rect(map(lambda x:x+self.margin, self.nbttree._rect))

        tableview = TableView(nrows=(h - (self.font.get_linesize() * 2.5)) / self.font.get_linesize(),
                              header_height=self.font.get_linesize(),
                              columns=[TableColumn("Player Name(s):", (self.nbttree.width - (self.margin * 3)) / 3),
                                       TableColumn("Player UUID(s):", (self.nbttree.width - (self.margin * 3)))],
                              )
        tableview.index = 0
        tableview.num_rows = lambda: len(self.player_UUID["UUID"])
        tableview.row_data = lambda i: (self.player_UUID["Name"][i],self.player_UUID["UUID"][i])
        tableview.row_is_selected = lambda x: x == tableview.index
        tableview.zebra_color = (0, 0, 0, 48)

        def selectTableRow(i, evt):
            tableview.index = i

        tableview.click_row = selectTableRow

        def mouse_down(e):
            if e.button == 1 and e.num_clicks > 1:
                self.editNBTData()
            TableRowView.mouse_down(tableview.rows, e)

#.........这里部分代码省略.........
开发者ID:Iciciliser,项目名称:MCEdit-Unified,代码行数:101,代码来源:player.py

示例6: build_inventory

    def build_inventory(self, items):
        inventory = self.data.get('Player', {}).get('Inventory', TAG_List()) or self.data.get('Inventory', TAG_List())
        rows = []
        items = items[0]
        slots = [["%s"%i,"","0","0"] for i in range(36)]
        slots += [["%s"%i,"","0","0"] for i in range(100, 104)]
        slots_set = []
        for item in items:
            #&# Prototype for blocks/items names
            item_dict = mcitems.items.get(item['id'].value, None)
            if item_dict == None:
                name = item['id'].value
            else:
                if type(item_dict['name']) == list:
                    if int(item['Damage'].value) >= len(item_dict['name']):
                        block_id = map_block.get(item['id'].value, None)
                        name = alphaMaterials.get((int(block_id), int(item['Damage'].value))).name.rsplit('(', 1)[0].strip()
                    else:
                        name = item_dict['name'][int(item['Damage'].value)]
                else:
                    name = item_dict['name']
            s = int(item['Slot'].value)
            slots_set.append(s)
            if s >= 100:
                s = s - 100 + 36
            slots[s] = item['Slot'].value, mclangres.translate(name), item['Count'].value, item['Damage'].value
            #slots[s] = item['Slot'].value, item['id'].value.split(':')[-1], item['Count'].value, item['Damage'].value
            #&#
        width = self.side_panel_width - self.margin * 5
        c0w = max(15, self.font.size("000")[0]) + 4
        c2w = max(15, self.font.size("00")[0]) + 4
        c3w = max(15, self.font.size("000")[0]) + 4
        c1w = width - c0w - c2w - c3w
        font_height = self.font.size("qd")[1]
        tableCols = [TableColumn("#", c0w),
                     TableColumn("ID", c1w),
                     TableColumn("C", c2w),
                     TableColumn("D", c3w),
                     ]
        height = self.displayRow.subwidgets[0].height
        table = TableView(height=height - (self.margin * 2),
                          width=width,
                          nrows=((height - (self.margin * 2) - font_height / 2) / font_height),
                          columns=tableCols,
                          row_height=font_height,
                          header_height=font_height / 2)
        table.rows.tooltipText = "Double-click to edit"
        table.selected_row = None
        table.slots = slots

        def num_rows():
            return len(slots)
        table.num_rows = num_rows

        def row_data(n):
            return slots[n]
        table.row_data = row_data

        def click_row(n, e):
            table.selected_row = n
            if e.num_clicks > 1:
                SlotEditor(table, row_data(n)).present()
        table.click_row = click_row

        def row_is_selected(n):
            return n == table.selected_row
        table.row_is_selected = row_is_selected

        def change_value(data):
            s, i, c, d = data
            s = int(s)
            s_idx = 0
            #&# Prototype for blocks/items names
            name, state = map_items.get(mclangres.untranslate(i), (i, '0'))
            if ':' not in name:
                name = 'minecraft:%s'%name
            #&#

            if s in slots_set:
                for slot in inventory:
                    if slot['Slot'].value == s:
                        if not i or int(c) < 1:
                            del inventory[s_idx]
                            i = ""
                            c = u'0'
                            d = u'0'
                        else:
                            #&# Prototype for blocks/items names
                            #slot['id'].value = 'minecraft:%s'%i
                            slot['id'].value = name
                            #&#
                            slot['Count'].value = int(c)
                            slot['Damage'].value = int(state)
                        break
                    s_idx += 1
            else:
                new_slot = TAG_Compound()
                new_slot['Slot'] = TAG_Byte(s)
                #&# Prototype for blocka/items names
                #new_slot['id'] = TAG_String('minecraft:%s'%i)
#.........这里部分代码省略.........
开发者ID:vongola12324,项目名称:MCEdit-Unified,代码行数:101,代码来源:nbtexplorer.py

示例7: build_inventory

    def build_inventory(self, items):
        print "build_inventory"
        print "Inventory" in self.data.keys()
#        print type(self.data['Inventory'])
        inventory = self.data.get('Player', {}).get('Inventory', TAG_List()) or self.data.get('Inventory', TAG_List())
        rows = []
        items = items[0]
        slots = [["%s"%i,"","0","0"] for i in range(36)]
        slots_set = []
        for item in items:
            s = int(item['Slot'].value)
            slots_set.append(s)
            slots[s] = item['Slot'].value, item['id'].value.split(':')[-1], item['Count'].value, item['Damage'].value
        width = self.width / 2 - self.margin * 4
        c0w = max(15, self.font.size("00")[0]) + 4
        c2w = max(15, self.font.size("00")[0]) + 4
        c3w = max(15, self.font.size("000")[0]) + 4
        c1w = width - c0w - c2w - c3w
        font_height = self.font.size("qd")[1]
        tableCols = [TableColumn("#", c0w),
                     TableColumn("ID", c1w),
                     TableColumn("C", c2w),
                     TableColumn("D", c3w),
                     ]
        height = self.displayRow.subwidgets[0].height
        table = TableView(height=height - (self.margin * 2),
                          width=width,
                          nrows=((height - (self.margin * 2) - font_height / 2) / font_height),
                          columns=tableCols,
                          row_height=font_height,
                          header_height=font_height / 2)
        table.rows.tooltipText = "Double-click to edit"
        table.selected_row = None
        table.slots = slots

        def num_rows():
            return len(slots)
        table.num_rows = num_rows

        def row_data(n):
            return slots[n]
        table.row_data = row_data

        def click_row(n, e):
            table.selected_row = n
            if e.num_clicks > 1:
                SlotEditor(table, row_data(n)).present()
        table.click_row = click_row

        def row_is_selected(n):
            return n == table.selected_row
        table.row_is_selected = row_is_selected

        def change_value(data):
            s, i, c, d = data
            s = int(s)
            s_idx = 0
            if s in slots_set:
#                for slot in self.data['Player']['Inventory']:
                for slot in inventory:
                    if slot['Slot'].value == s:
                        if not i or int(c) < 1:
                            del inventory[s_idx]
                            i = ""
                            c = u'0'
                            d = u'0'
                        else:
                            slot['id'].value = 'minecraft:%s'%i
                            slot['Count'].value = int(c)
                            slot['Damage'].value = int(d)
                        break
                    s_idx += 1
            else:
                new_slot = TAG_Compound()
                new_slot['Slot'] = TAG_Byte(s)
                new_slot['id'] = TAG_String('minecraft:%s'%i)
                new_slot['Count'] = TAG_Byte(int(c))
                new_slot['Damage'] = TAG_Short(int(d))
                idx = s
                for slot in inventory:
                    if slot['Slot'].value >= s:
                        idx = slot['Slot'].value
                        break
                inventory.insert(s, new_slot)
                slots_set.append(s)
            table.slots[s] = slots[s] = s, i, c, d

        table.change_value = change_value
        rows.append(table)
        return rows
开发者ID:Estevo-Aleixo,项目名称:MCEdit-Unified,代码行数:90,代码来源:nbtexplorer.py

示例8: build_inventory

    def build_inventory(self, items):
        if 'playerGameType' in self.tree.get_item_parent(self.displayed_item)[9].keys():
            player = True
        else:
            player = False
        inventory = self.tree.get_item_parent(self.displayed_item)[9].get('Inventory', TAG_List())
        rows = []
        items = items[0]
        slots = [["%s"%i,"","0","0"] for i in range(36)]
        slots += [["%s"%i,"","0","0"] for i in range(100, 104)]
        slots_set = []
        for item, i in zip(items, range(len(items))):
            #&# Prototype for blocks/items names
            item_dict = mcitems.items.get(item['id'].value, None)
            if item_dict == None:
                name = item['id'].value
            else:
                if type(item_dict['name']) == list:
                    if int(item['Damage'].value) >= len(item_dict['name']):
                        block_id = map_block.get(item['id'].value, None)
                        name = alphaMaterials.get((int(block_id), int(item['Damage'].value))).name.rsplit('(', 1)[0].strip()
                    else:
                        name = item_dict['name'][int(item['Damage'].value)]
                else:
                    name = item_dict['name']
            s = i
            _s = 0 + i
            if player:
                s = int(item['Slot'].value)
                _s = 0 + s
            slots_set.append(s)
            if s >= 100:
                s = s - 100 + 36
            slots[s] = _s, mclangres.translate(name), item['Count'].value, item['Damage'].value
            #slots[s] = item['Slot'].value, item['id'].value.split(':')[-1], item['Count'].value, item['Damage'].value
            #&#
        width = self.side_panel_width - self.margin * 5
        c0w = max(15, self.font.size("000")[0]) + 4
        c2w = max(15, self.font.size("00")[0]) + 4
        c3w = max(15, self.font.size("000")[0]) + 4
        c1w = width - c0w - c2w - c3w
        font_height = self.font.size("qd")[1]
        tableCols = [TableColumn("#", c0w),
                     TableColumn("ID", c1w),
                     TableColumn("C", c2w),
                     TableColumn("D", c3w),
                     ]
        height = self.displayRow.subwidgets[0].height
        table = TableView(height=height - (self.margin * 2),
                          width=width,
                          nrows=((height - (self.margin * 2) - font_height / 2) / font_height),
                          columns=tableCols,
                          row_height=font_height,
                          header_height=font_height / 2)
        table.rows.tooltipText = "Double-click to edit"
        table.selected_row = None
        table.slots = slots

        def num_rows():
            return len(slots)
        table.num_rows = num_rows

        def row_data(n):
            return slots[n]
        table.row_data = row_data

        def click_row(n, e):
            table.focus()
            table.selected_row = n
            if e.num_clicks > 1:
                SlotEditor(table, row_data(n)).present()
        table.click_row = click_row

        def row_is_selected(n):
            return n == table.selected_row
        table.row_is_selected = row_is_selected

        def change_value(data):
            s, i, c, d = data
            s = int(s)
            s_idx = 0
            #&# Prototype for blocks/items names
            name, state = map_items.get(mclangres.untranslate(i), (i, '0'))
            if ':' not in name:
                name = 'minecraft:%s'%name
            #&#

            if s in slots_set:
                for slot in inventory:
                    ok1 = False
                    if player:
                        ok1 = slot['Slot'].value == s
                    else:
                        ok1 = inventory.index(slot) == s
                    if ok1:
                        if not i or int(c) < 1:
                            del inventory[s_idx]
                            i = ""
                            c = u'0'
                            d = u'0'
#.........这里部分代码省略.........
开发者ID:violine1101,项目名称:MCEdit-Unified,代码行数:101,代码来源:nbtexplorer.py

示例9: __init__

    def __init__(self, tool):
        Panel.__init__(self)
        self.tool = tool
        self.player_UUID = {}
        self.level = tool.editor.level
        if hasattr(self.level, 'players'):
            players = self.level.players or ["[No players]"]
            if not self.level.oldPlayerFolderFormat:
                for player in players:
                    if player != "Player" and player != "[No players]":
                        if len(player) > 4 and player[4] == "-":
                            os.rename(os.path.join(self.level.worldFolder.getFolderPath("playerdata"), player+".dat"), os.path.join(self.level.worldFolder.getFolderPath("playerdata"), player.replace("-", "", 1)+".dat"))
                            player = player.replace("-", "", 1)
                        data = version_utils.playercache.getPlayerInfo(player)
                        if isinstance(data, tuple):
                            self.player_UUID[data[1]] = data[0]
                        else:
                            self.player_UUID[player] = data
                if "Player" in players:
                    self.player_UUID["Player (Single Player)"] = "Player"
                if "[No players]" not in players:
                    players = sorted(self.player_UUID.keys(), key=lambda x: False if x == "Player (Single Player)" else x)

        else:
            players = ["Player (Single Player)"]
        self.players = players

        self.pages = TabPanel()
        tab_height = self.pages.tab_height

        max_height = tab_height + self.tool.editor.mainViewport.height - self.tool.editor.toolbar.height - self.tool.editor.subwidgets[0].height - self.pages.margin * 2
        #-# Uncomment the following line to have a maximum height for this panel.
        # max_height = min(max_height, 500)

        self.editNBTDataButton = Button("Edit NBT", action=self.editNBTData, tooltipText="Open the NBT Explorer to edit player's attributes and inventory")
        addButton = Button("Add", action=self.tool.addPlayer)
        removeButton = Button("Remove", action=self.tool.removePlayer)
        gotoButton = Button("Goto", action=self.tool.gotoPlayer)
        gotoCameraButton = Button("Goto View", action=self.tool.gotoPlayerCamera)
        moveButton = Button("Move", action=self.tool.movePlayer)
        moveToCameraButton = Button("Align to Camera", action=self.tool.movePlayerToCamera)
        reloadSkin = Button("Reload Skins", action=self.tool.reloadSkins, tooltipText="This pulls skins from the online server, so this may take a while")

        btns = Column([self.editNBTDataButton, addButton, removeButton, gotoButton, gotoCameraButton, moveButton, moveToCameraButton, reloadSkin], margin=0, spacing=2)
        h = max_height - btns.height - self.pages.margin * 2 - 2 - self.font.get_linesize() * 2

        col = Label('')
        def close():
            self.pages.show_page(col)
        self.nbttree = NBTExplorerToolPanel(self.tool.editor, nbtObject={}, height=max_height, \
                                            close_text="Go Back", no_header=True, close_action=close,
                                            load_text=None)
        self.nbttree.shrink_wrap()

        self.nbtpage = Column([self.nbttree,])
        self.nbtpage.shrink_wrap()
        self.pages.add_page("NBT Data", self.nbtpage)
        self.pages.set_rect(map(lambda x:x+self.margin, self.nbttree._rect))

        tableview = TableView(nrows=(h - (self.font.get_linesize() * 2.5)) / self.font.get_linesize(),
                              header_height=self.font.get_linesize(),
                              columns=[TableColumn("Player Name(s):", self.nbttree.width - (self.margin * 3)),],
                             )
        tableview.index = 0
        tableview.num_rows = lambda: len(players)
        tableview.row_data = lambda i: (players[i],)
        tableview.row_is_selected = lambda x: x == tableview.index
        tableview.zebra_color = (0, 0, 0, 48)

        def selectTableRow(i, evt):
            tableview.index = i

        tableview.click_row = selectTableRow

        def mouse_down(e):
            if e.button == 1 and e.num_clicks > 1:
                self.editNBTData()
            TableRowView.mouse_down(tableview.rows, e)

        tableview.rows.mouse_down = mouse_down

        tableview.rows.tooltipText = "Double-click or use the button below to edit the NBT Data."

        self.table = tableview

        col.set_parent(None)
        self.col = col = Column([tableview, btns], spacing=2)

        self.pages.add_page("Players", col, 0)

        self.pages.shrink_wrap()
        self.pages.show_page(col)
        self.add(self.pages)
        self.shrink_wrap()
        self.max_height = max_height
开发者ID:Estevo-Aleixo,项目名称:MCEdit-Unified,代码行数:95,代码来源:player.py

示例10: __init__old

    def __init__old(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

        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)
            if block.aka:
                r += " [{0}]".format(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
        icons = Column(tableicons, spacing=2)

        # 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"
#.........这里部分代码省略.........
开发者ID:violine1101,项目名称:MCEdit-Unified,代码行数:101,代码来源:blockpicker.py

示例11: editContainer

    def editContainer(self, point, containerID):
        tileEntityTag = self.editor.level.tileEntityAt(*point)
        if tileEntityTag is None:
            tileEntityTag = pymclevel.TileEntity.Create(containerID)
            pymclevel.TileEntity.setpos(tileEntityTag, point)
            self.editor.level.addTileEntity(tileEntityTag)

        if tileEntityTag["id"].value != containerID:
            return

        undoBackupEntityTag = copy.deepcopy(tileEntityTag)

        def itemProp(key):
            # xxx do validation here
            def getter(self):
                if 0 == len(tileEntityTag["Items"]):
                    return 0
                return tileEntityTag["Items"][self.selectedItemIndex][key].value

            def setter(self, val):
                if 0 == len(tileEntityTag["Items"]):
                    return
                self.dirty = True
                tileEntityTag["Items"][self.selectedItemIndex][key].value = val

            return property(getter, setter)

        class ChestWidget(Widget):
            dirty = False
            Slot = itemProp("Slot")
            id = itemProp("id")
            Damage = itemProp("Damage")
            Count = itemProp("Count")
            itemLimit = pymclevel.TileEntity.maxItems.get(containerID, 26)

        def slotFormat(slot):
            slotNames = pymclevel.TileEntity.slotNames.get(containerID)
            if slotNames:
                return slotNames.get(slot, slot)
            return slot

        chestWidget = ChestWidget()
        chestItemTable = TableView(columns=[
            TableColumn("Slot", 60, "l", fmt=slotFormat),
            TableColumn("ID / ID Name", 345, "l"),
            TableColumn("DMG", 50, "l"),
            TableColumn("Count", 65, "l"),

            TableColumn("Name", 260, "l"),
        ])

        def itemName(id, damage):
            try:
                return pymclevel.items.items.findItem(id, damage).name
            except pymclevel.items.ItemNotFound:
                return "Unknown Item"

        def getRowData(i):
            item = tileEntityTag["Items"][i]
            slot, id, damage, count = item["Slot"].value, item["id"].value, item["Damage"].value, item["Count"].value
            return slot, id, damage, count, itemName(id, damage)

        chestWidget.selectedItemIndex = 0

        def selectTableRow(i, evt):
            chestWidget.selectedItemIndex = i

        chestItemTable.num_rows = lambda: len(tileEntityTag["Items"])
        chestItemTable.row_data = getRowData
        chestItemTable.row_is_selected = lambda x: x == chestWidget.selectedItemIndex
        chestItemTable.click_row = selectTableRow

        fieldRow = (
            mceutils.IntInputRow("Slot: ", ref=AttrRef(chestWidget, 'Slot'), min=0, max=26),
            mceutils.TextInputRow("ID / ID Name: ", ref=AttrRef(chestWidget, 'id'), width=300),
            # Text to allow the input of internal item names
            mceutils.IntInputRow("DMG: ", ref=AttrRef(chestWidget, 'Damage'), min=-32768, max=32767),
            mceutils.IntInputRow("Count: ", ref=AttrRef(chestWidget, 'Count'), min=-64, max=64),
        )

        def deleteFromWorld():
            i = chestWidget.selectedItemIndex
            item = tileEntityTag["Items"][i]
            id = item["id"].value
            Damage = item["Damage"].value

            deleteSameDamage = mceutils.CheckBoxLabel("Only delete items with the same damage value")
            deleteBlocksToo = mceutils.CheckBoxLabel("Also delete blocks placed in the world")
            if id not in (8, 9, 10, 11):  # fluid blocks
                deleteBlocksToo.value = True

            w = wrapped_label(
                "WARNING: You are about to modify the entire world. This cannot be undone. Really delete all copies of this item from all land, chests, furnaces, dispensers, dropped items, item-containing tiles, and player inventories in this world?",
                60)
            col = (w, deleteSameDamage)
            if id < 256:
                col += (deleteBlocksToo,)

            d = Dialog(Column(col), ["OK", "Cancel"])

#.........这里部分代码省略.........
开发者ID:Dominic001,项目名称:MCEdit-Unified,代码行数:101,代码来源:camera.py

示例12: editMonsterSpawner

    def editMonsterSpawner(self, point):
        mobs = self.mobs

        tileEntity = self.editor.level.tileEntityAt(*point)
        undoBackupEntityTag = copy.deepcopy(tileEntity)

        if not tileEntity:
            tileEntity = pymclevel.TAG_Compound()
            tileEntity["id"] = pymclevel.TAG_String("MobSpawner")
            tileEntity["x"] = pymclevel.TAG_Int(point[0])
            tileEntity["y"] = pymclevel.TAG_Int(point[1])
            tileEntity["z"] = pymclevel.TAG_Int(point[2])
            tileEntity["Delay"] = pymclevel.TAG_Short(120)
            tileEntity["EntityId"] = pymclevel.TAG_String(mobs[0])

        self.editor.level.addTileEntity(tileEntity)

        panel = Dialog()

        def addMob(id):
            if id not in mobs:
                mobs.insert(0, id)
                mobTable.selectedIndex = 0

        def selectTableRow(i, evt):
            if mobs[i] == "[Custom]":
                id = input_text("Type in an EntityID for this spawner. Invalid IDs may crash Minecraft.", 150)
                if id:
                    addMob(id)
                else:
                    return
                mobTable.selectedIndex = mobs.index(id)
            else:
                mobTable.selectedIndex = i

            if evt.num_clicks == 2:
                panel.dismiss()

        mobTable = TableView(columns=(
            TableColumn("", 200),
        )
        )
        mobTable.num_rows = lambda: len(mobs)
        mobTable.row_data = lambda i: (mobs[i],)
        mobTable.row_is_selected = lambda x: x == mobTable.selectedIndex
        mobTable.click_row = selectTableRow
        mobTable.selectedIndex = 0

        def selectedMob():
            return mobs[mobTable.selectedIndex]

        id = tileEntity["EntityId"].value
        addMob(id)

        mobTable.selectedIndex = mobs.index(id)

        choiceCol = Column((ValueDisplay(width=200, get_value=lambda: selectedMob() + " spawner"), mobTable))

        okButton = Button("OK", action=panel.dismiss)
        panel.add(Column((choiceCol, okButton)))
        panel.shrink_wrap()
        panel.present()

        class MonsterSpawnerEditOperation(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))

        if id != selectedMob():
            tileEntity["EntityId"] = pymclevel.TAG_String(selectedMob())
            op = MonsterSpawnerEditOperation(self.editor, self.editor.level)
            self.editor.addOperation(op)
            if op.canUndo:
                self.editor.addUnsavedEdit()
开发者ID:Dominic001,项目名称:MCEdit-Unified,代码行数:92,代码来源:camera.py


注:本文中的albow.TableView类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。