读书人

[D]大侠请留步!关于 wxpython 中获取

发布时间: 2012-05-09 12:13:59 作者: rapoo

[D]大侠请留步!!!关于 wxpython 中获取文件路径的问题
将某个文件夹遍历生成了一个目录树显示在界面上
然后鼠标双击可以选中某个文件,弹出个对话框
在对话框上显示出这个文件的内容

请问各位大侠,改怎么实现!!!
-------------------------
Double行动:
原帖分数:40
帖子加分:40

[解决办法]

Python code
#!/usr/bin/python# coding=utf-8import wximport wx.aui;import wx.grid;import mainUIHelper;import start;import os;import re;class AutoTestFrame(wx.Frame):        def __init__(self):        wx.Frame.__init__(self, None, -1, "Produce Auto Test Paltform",pos=wx.DefaultPosition,                                size = (700,500),                                 style=wx.DEFAULT_FRAME_STYLE |wx.SUNKEN_BORDER |wx.CLIP_CHILDREN )        #?????        mainUIHelper.MainUIHelper(self);                        #?????        self.Helper.CreateAuiManager([            mainUIHelper.AuiConfigModel(self.CreateLeft(), wx.aui.AuiPaneInfo()                                .Name("left").Caption("Script Folder").Left()                                .CloseButton(False)                                .MaximizeButton(True)),             mainUIHelper.AuiConfigModel(self.CreateGrid(), wx.aui.AuiPaneInfo()                                .Name("gridContent").CenterPane()),]);    def CreateLeft(self):        s = "";        #?????????        defaultScriptFolder = os.path.join(start.GetExecutePath(),"script");        if not os.path.exists(defaultScriptFolder):            os.mkdir(defaultScriptFolder);                        self.scriptTree = wx.TreeCtrl(self, -1, (0,0), wx.DefaultSize,                    wx.TR_DEFAULT_STYLE );               self.Bind(wx.EVT_TREE_ITEM_ACTIVATED,self.OnDclick)#guoli        currentRoot = self.scriptTree.AddRoot(os.path.basename(defaultScriptFolder));                #Key : path of folder        #Node: TreeNode        cacheNode = { defaultScriptFolder: currentRoot };                           def CreateNode(path, isdir, level):            if path != defaultScriptFolder:                parentDirName = os.path.dirname(path);                testItem = os.path.basename(path)                                tempNode = self.scriptTree.AppendItem(cacheNode[parentDirName],                                         testItem);                if isdir:                    cacheNode.setdefault(path, tempNode);                else :                    pass                    self.ListFile(defaultScriptFolder, CreateNode);                #???        cacheNode.clear();                return self.scriptTree;        def ListFile(self, path, action, level=0):        if os.path.isdir(path):                    action(path, True, level);                    for subPath in os.listdir(path):            fullPath = os.path.join(path, subPath);            print '-->',fullPath            if os.path.isdir(fullPath):                self.ListFile(fullPath, action, level + 1);            else :                            action(fullPath, False, level);                    def CreateGrid(self):        grid = wx.grid.Grid(self, -1, wx.Point(0, 0), wx.Size(150, 250),                            wx.NO_BORDER | wx.WANTS_CHARS)        grid.CreateGrid(50, 20)        return grid        def OnDclick(self,event):        item = event.GetItem()        self.list = self.GetItemText(item)        self.GetCurrentPath(item)        print "OnActivated: ", os.path.join(start.GetExecutePath(),self.list)            def GetCurrentPath(self, item):        ItemParent = self.scriptTree.GetItemParent(item)        itemtext = self.GetItemText(ItemParent)        print "-->",itemtext        if itemtext == None:            return        self.list = itemtext + "\\"+ self.list        self.GetCurrentPath(ItemParent)        def GetItemText(self,item):        if item:            return self.scriptTree.GetItemText(item)        else:            "return"            if __name__ == '__main__':        app = wx.PySimpleApp()    frame = AutoTestFrame()    frame.Show(True)    app.MainLoop() 

读书人网 >perl python

热点推荐