python 基本功能手写的资源管理器

37 篇文章 1 订阅
21 篇文章 0 订阅
#-*- coding:utf-8 -*-

from  PyQt4.QtGui  import *
from  PyQt4.QtCore  import *
import math
import sys
import re
import os
import json
reload(sys)

sys.setdefaultencoding("utf-8")
global item_path
item_path=''
class ListView(QTreeWidget):
    def __init__(self,parent=None):
        super(ListView,self).__init__(parent=parent)
        self.setHeaderLabels([u'名称'])
        for d in self.getDrives():
            d.replace('/','')
            item = QTreeWidgetItem(self, [d])
            item.setIcon(0,QIcon('qudongqi.jpg'))
            item.path = d+'/'
    def getDrives(self):
        result = []
        for d in QDir.drives():
            result.append(d.filePath())
        return result            
    def showdir(self, item):
        self.clear()
        path=(item.path)
        path=str(path)
        path=path.decode('utf-8')
        if os.path.exists(path):
            if not os.path.isfile(path):
                allfiles = os.listdir(path)
                allfiles.sort()
                for f in allfiles:
                    if os.path.isfile(f):
                        type = [f,'','']
                        item = QTreeWidgetItem(self,type)
                        item.path = path+'/'+f
                        item.setIcon(0,QIcon('wenben.jpg'))
                    else:
                        type = [f,'','']
                        item = QTreeWidgetItem(self, type)
                        item.path = path+'/'+f
                        item.setIcon(0,QIcon('mulu.jpg'))

    def update(self,path):
        path=str(path).decode('utf-8')
        self.setWindowTitle(u"刷新窗口")
        self.clear()
        if os.path.exists(path):
            if not os.path.isfile(path):
                files = os.listdir(path)
                files.sort()
                for f in files:
                    if os.path.isfile(f):
                        text = [f, '', '','']
                        Item=QTreeWidgetItem(self, text)
                        Item.setIcon(0,QIcon('wenben.jpg'))
                    else:
                        text = [f, '', '','']
                        Item=QTreeWidgetItem(self, text)
                        Item.setIcon(0,QIcon('mulu.jpg'))
            self.show()
    def chazhao(self,path):
        self.clear()
        #path=str(path).decode('utf-8')
        for i in path:
            Item=QTreeWidgetItem(self, [i,'',''])
            if os.path.isfile(i):
                    Item.setIcon(0,QIcon('wenben.jpg'))
                    Item.path=''
            else:
                    Item.setIcon(0,QIcon('mulu.jpg'))
                    Item.path=''
    def fanhui(self,path):
        self.clear()
        path=str(path).decode('utf-8')
        if os.path.exists(path):
            if not os.path.isfile(path):
                files = os.listdir(path)
                files.sort()
                for i in files:
                    Item=QTreeWidgetItem(self, [[i],'','',''])
                    if os.path.isfile(i):
                        Item.setIcon(0,QIcon('wenben.jpg'))
                    else:
                        Item.setIcon(0,QIcon('mulu.jpg'))
    def qianjin(self,path):
        self.clear()
        path=str(path).decode('utf-8')
        if os.path.exists(path):
            if not os.path.isfile(path):
                files = os.listdir(path)
                files.sort()
                for i in files:
                    Item=QTreeWidgetItem(self, [[i],'','',''])
                    if os.path.isfile(i):
                            Item.setIcon(0,QIcon('wenben.jpg'))

                    else:
                            Item.setIcon(0,QIcon('mulu.jpg'))
    def shangji(self,path):
        self.clear()
        path=str(path).decode('utf-8')
        files = os.listdir(path)
        files.sort()
        for i in files:
            Item=QTreeWidgetItem(self, [i,'','',''])
            if os.path.isfile(i):
                    Item.setIcon(0,QIcon('wenben.jpg'))
            else:
                    Item.setIcon(0,QIcon('mulu.jpg'))   



class TreeView(QTreeWidget):
    def __init__(self,parent=None):
        super(QTreeView,self).__init__(parent=parent)
        self.itemExpanded.connect(self.expand)
        self.setHeaderLabels([u'系统目录'])
        self.path=""
        for d in self.getDrives():
            d.replace('/','')
            item = QTreeWidgetItem(self, [d])
            item.path = d+'/'
            item.path=str(item.path).decode('utf-8')
            item.setIcon(0,QIcon('qudongqi.jpg'))
            QTreeWidgetItem(item, '')      

    def getDrives(self):
        result = []
        for d in QDir.drives():
            result.append(d.filePath())
        return result
    def expand(self, item):
        print item.path#完整路径
        self.path = item.path
        self.path=str(self.path).decode('utf-8')
        global item_path
        item_path =self.path
        if hasattr(item, 'takeChildren'):
            item.takeChildren()

        files = os.listdir(item.path)
        files.sort()
        for f in files:
            path = item.path+'/'  + f
            if os.path.isdir(path):
                newItem = QTreeWidgetItem(item,[f])
                newItem.path = path
                newItem.setIcon(0,QIcon('mulu.jpg'))
                if os.path.isdir(newItem.path):

                    QTreeWidgetItem(newItem, '')
                    path = path
class Toollan1(QWidget):
    def __init__(self,parent=None):
        super(Toollan1,self).__init__(parent)
        tool1_1=QToolButton(self)
        tool1_1.setText((u"属性"))
        tool1_1.setIcon(QIcon("Icon/shuxing.jpg"))
        tool1_1.setIconSize(QSize(20,20))
        tool1_1.setAutoRaise(True)
        tool1_1.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)

        tool1_2=QToolButton(self)
        tool1_2.setText((u"打开"))
        tool1_2.setIcon(QIcon("Icon/dakai.png"))
        tool1_2.setIconSize(QSize(20,20))
        tool1_2.setAutoRaise(True)
        tool1_2.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)

        tool1_3=QToolButton(self)
        tool1_3.setText((u"重命名"))
        tool1_3.setIcon(QIcon("Icon/chongmingming.png"))
        tool1_3.setIconSize(QSize(20,20))
        tool1_3.setAutoRaise(True)
        tool1_3.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)


        lay=QHBoxLayout()
        lay.addWidget(tool1_1)
        lay.addWidget(tool1_2)
        lay.addWidget(tool1_3)
        self.setLayout(lay)
class Toollan2(QWidget):
    def __init__(self,parent=None):
        super(Toollan2,self).__init__(parent)
        tool1_1=QToolButton(self)
        tool1_1.setText((u"访问媒体"))
        tool1_1.setIcon(QIcon("Icon/fang.jpg"))
        tool1_1.setIconSize(QSize(20,20))
        tool1_1.setAutoRaise(True)
        tool1_1.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)

        tool1_2=QToolButton(self)
        tool1_2.setText((u"映射网络\n驱动器"))
        tool1_2.setIcon(QIcon("Icon/yingshe.png"))
        tool1_2.setIconSize(QSize(20,20))
        tool1_2.setAutoRaise(True)
        tool1_2.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)

        tool1_3=QToolButton(self)
        tool1_3.setText((u"添加一个\n网络位置"))
        tool1_3.setIcon(QIcon("Icon/tianjiawangluo.jpg"))
        tool1_3.setAutoRaise(True)
        tool1_3.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)


        lay=QHBoxLayout()
        lay.addWidget(tool1_1)
        lay.addWidget(tool1_2)
        lay.addWidget(tool1_3)
        self.setLayout(lay)

class Toollan3(QWidget):
    def __init__(self,parent=None):
        super(Toollan3,self).__init__(parent)
        tool1_1=QToolButton(self)
        tool1_1.setText((u"打开设置"))
        tool1_1.setIcon(QIcon("Icon/dakaishezhi.png"),)

        tool1_1.setIconSize(QSize(40,40))
        tool1_1.setAutoRaise(True)
        tool1_1.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        tool1_2=QToolButton(self)
        tool1_2.setText((u"卸载或更改\n应用程序"))
        tool1_2.setIcon(QIcon("Icon/dakai.png"))
        tool1_2.setIconSize(QSize(20,20))
        tool1_2.setAutoRaise(True)
        tool1_2.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        tool1_3=QToolButton(self)
        tool1_3.setText((u"系统属性"))
        tool1_3.setIcon(QIcon("Icon/chongmingming.png"))
        tool1_3.setIconSize(QSize(20,20))
        tool1_3.setAutoRaise(True)
        tool1_3.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        tool1_4=QToolButton(self)
        tool1_4.setText((u"管理"))
        tool1_4.setIcon(QIcon("Icon/chongmingming.png"))
        tool1_4.setIconSize(QSize(20,20))
        tool1_4.setAutoRaise(True)
        tool1_4.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        lay_l=QVBoxLayout()
        lay_l.addWidget(tool1_1)

        lay_r=QVBoxLayout()
        lay_r.addWidget(tool1_2)
        lay_r.addWidget(tool1_3)
        lay_r.addWidget(tool1_4)


        lay=QHBoxLayout()
        lay.addLayout(lay_l)
        lay.addLayout(lay_r)
        self.setLayout(lay)

class Toollan4(QWidget):
    def __init__(self,parent=None):
        super(Toollan4,self).__init__(parent)
        label1=QLabel()
        label2=QLabel()
        lay=QHBoxLayout()
        lay.addWidget(label1)
        lay.addWidget(label2)
        self.setLayout(lay)
class Toollans1(QWidget):
    def __init__(self,parent=None):
        super(Toollans1,self).__init__(parent)
        tool1_1=QToolButton(self)
        tool1_1.setText((u"导航窗格"))
        tool1_1.setIcon(QIcon("Icon/daohang.png"),)

        tool1_1.setIconSize(QSize(40,40))
        tool1_1.setAutoRaise(True)
        tool1_1.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)

        tool1_2=QToolButton(self)
        tool1_2.setText((u"预览窗格"))
        tool1_2.setIcon(QIcon("Icon/yulan.png"))
        tool1_2.setIconSize(QSize(20,20))
        tool1_2.setAutoRaise(True)
        tool1_2.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        tool1_3=QToolButton(self)
        tool1_3.setText((u"详细信息窗格"))
        tool1_3.setIcon(QIcon("Icon/detail.jpg"))
        tool1_3.setIconSize(QSize(20,20))
        tool1_3.setAutoRaise(True)
        tool1_3.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)


        lay_l=QVBoxLayout()
        lay_l.addWidget(tool1_1)

        lay_r=QVBoxLayout()
        lay_r.addWidget(tool1_2)
        lay_r.addWidget(tool1_3)


        lay=QHBoxLayout()
        lay.addLayout(lay_l)
        lay.addLayout(lay_r)
        self.setLayout(lay)

        pass
class Toollans2(QWidget):
    def __init__(self,parent=None):
        super(Toollans2,self).__init__(parent)
        tool1_1=QToolButton(self)
        tool1_1.setText((u"超大图标"))
        tool1_1.setIcon(QIcon("Icon/chaoda.jpg"))



        tool1_1.setIconSize(QSize(30,30))
        tool1_1.setAutoRaise(True)
        tool1_1.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        tool1_2=QToolButton(self)
        tool1_2.setText((u"小图标"))
        tool1_2.setIcon(QIcon("Icon/xiaotubiao.png"))
        tool1_2.setIconSize(QSize(20,20))
        tool1_2.setAutoRaise(True)
        tool1_2.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        tool1_3=QToolButton(self)
        tool1_3.setText((u"平铺"))
        tool1_3.setIcon(QIcon("Icon/pingpu.jpg"))
        tool1_3.setIconSize(QSize(20,20))
        tool1_3.setAutoRaise(True)
        tool1_3.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        tool2_1=QToolButton(self)
        tool2_1.setText((u"大图标"))
        tool2_1.setIcon(QIcon("Icon/datubiao.jpg"))

        tool2_1.setIconSize(QSize(30,30))
        tool2_1.setAutoRaise(True)
        tool2_1.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)


        tool2_2=QToolButton(self)
        tool2_2.setText((u"列表"))
        tool2_2.setIcon(QIcon("Icon/liebiao.png"))
        tool2_2.setIconSize(QSize(20,20))
        tool2_2.setAutoRaise(True)
        tool2_2.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        tool2_3=QToolButton(self)
        tool2_3.setText((u"内容"))
        tool2_3.setIcon(QIcon("Icon/neirong.PNG"))
        tool2_3.setIconSize(QSize(20,20))
        tool2_3.setAutoRaise(True)
        tool2_3.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)


        tool3_1=QToolButton(self)
        tool3_1.setText((u"中图标"))
        tool3_1.setIcon(QIcon("Icon/mtubiao.jpg"))

        tool3_1.setIconSize(QSize(30,30))
        tool3_1.setAutoRaise(True)
        tool3_1.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        tool3_2=QToolButton(self)
        tool3_2.setText((u"详细信息"))
        tool3_2.setIcon(QIcon("Icon/detaildata.png"))
        tool3_2.setIconSize(QSize(20,20))
        tool3_2.setAutoRaise(True)
        tool3_2.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)




        lay_l=QVBoxLayout()
        lay_l.addWidget(tool1_1)
        lay_l.addWidget(tool1_2)
        lay_l.addWidget(tool1_3)

        lay_m=QVBoxLayout()
        lay_m.addWidget(tool2_1)
        lay_m.addWidget(tool2_2)
        lay_m.addWidget(tool2_3)

        lay_r=QVBoxLayout()
        lay_r.addWidget(tool3_1)
        lay_r.addWidget(tool3_2)



        lay=QHBoxLayout()
        lay.addLayout(lay_l)
        lay.addLayout(lay_m)
        lay.addLayout(lay_r)
        self.setLayout(lay)
class Toollans3(QWidget):
    def __init__(self,parent=None):
        super(Toollans3,self).__init__(parent)
        tool1_1=QToolButton(self)
        tool1_1.setText((u"排序方式"))
        tool1_1.setIcon(QIcon("Icon/paixv.png"))

        tool1_1.setIconSize(QSize(30,30))
        tool1_1.setAutoRaise(True)
        tool1_1.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)

        tool1_2=QToolButton(self)
        tool1_2.setText((u"分组依据"))
        tool1_2.setIcon(QIcon("Icon/yulan.png"))
        tool1_2.setIconSize(QSize(20,20))
        tool1_2.setAutoRaise(True)
        tool1_2.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        tool1_3=QToolButton(self)
        tool1_3.setText((u"添加到列"))
        tool1_3.setIcon(QIcon("Icon/detail.jpg"))
        tool1_3.setIconSize(QSize(20,20))
        tool1_3.setAutoRaise(True)
        tool1_3.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        tool1_4=QToolButton(self)
        tool1_4.setText((u"将所有列调整到合适大小"))
        tool1_4.setIcon(QIcon("Icon/detail.jpg"))
        tool1_4.setIconSize(QSize(20,20))
        tool1_4.setAutoRaise(True)
        tool1_4.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)


        lay_l=QVBoxLayout()
        lay_l.addWidget(tool1_1)

        lay_r=QVBoxLayout()
        lay_r.addWidget(tool1_2)
        lay_r.addWidget(tool1_3)
        lay_r.addWidget(tool1_4)


        lay=QHBoxLayout()
        lay.addLayout(lay_l)
        lay.addLayout(lay_r)
        self.setLayout(lay)
class Toollans4(QWidget):
    def __init__(self,parent=None):
        super(Toollans4,self).__init__(parent)

        self.check_1 = QCheckBox(u"项目复选框", self) 
        self.check_2 = QCheckBox(u"文件扩展名", self) 
        self.check_3 = QCheckBox(u"隐藏的项目", self) 
        self.buttonBox=QButtonGroup()

        self.buttonBox.addButton(self.check_1,1)
        self.buttonBox.addButton(self.check_2,2)
        self.buttonBox.addButton(self.check_3,3)

        tool1_1=QToolButton(self)
        tool1_1.setText((u"隐藏所选项目"))
        tool1_1.setIcon(QIcon("Icon/yincang.png"),)
        tool1_1.setIconSize(QSize(40,40))
        tool1_1.setAutoRaise(True)
        tool1_1.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)

        lay_l=QVBoxLayout()
        lay_l.addWidget(self.check_1)
        lay_l.addWidget(self.check_2)
        lay_l.addWidget(self.check_3)

        lay_r=QVBoxLayout()
        lay_r.addWidget(tool1_1)

        lay=QHBoxLayout()
        lay.addLayout(lay_l)
        lay.addLayout(lay_r)
        self.setLayout(lay)

        pass
class Toollans5(QWidget):
    def __init__(self,parent=None):
        super(Toollans5,self).__init__(parent)
        tool1_1=QToolButton(self)
        tool1_1.setText((u"选项"))
        tool1_1.setIcon(QIcon("Icon/xuanxiang.png"),)
        tool1_1.setIconSize(QSize(40,40))
        tool1_1.setAutoRaise(True)
        tool1_1.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        lay=QHBoxLayout()
        lay.addWidget(tool1_1)
        self.setLayout(lay)
        pass
class Toollans6(QWidget):
    def __init__(self,parent=None):
        super(Toollans6,self).__init__(parent)
        label1=QLabel()
        label2=QLabel()
        lay=QHBoxLayout()
        lay.addWidget(label1)
        lay.addWidget(label2)
        self.setLayout(lay)
class Computer(QDialog):
    def __init__(self,parent=None):
        super(Computer,self).__init__(parent=parent)
        self.setWindowFlags(Qt.Popup)
        btn=MuluTree()
        mouse_xy = btn.combtn.mapToGlobal(btn.combtn.pos())
        x = mouse_xy.x() 
        y = mouse_xy.y()
        self.setGeometry(x+10,y+24,500,80)


        tool1=Toollan1()
        tool2=Toollan2()
        tool3=Toollan3()
        tool4=Toollan4()

        stack=QStackedWidget()
        stack.setFrameStyle(QFrame.Panel|QFrame.Raised)
        stack.addWidget(tool1)

        stack2=QStackedWidget()
        stack2.setFrameStyle(QFrame.Panel|QFrame.Raised)
        stack2.addWidget(tool2)


        stack3=QStackedWidget()
        stack3.setFrameStyle(QFrame.Panel|QFrame.Raised)
        stack3.addWidget(tool3)


        stack4=QStackedWidget()
        stack4.setFrameStyle(QFrame.Panel|QFrame.Raised)
        stack4.addWidget(tool4)

        lay=QHBoxLayout()
        lay.addWidget(stack,2)
        lay.addWidget(stack2,2)
        lay.addWidget(stack3,2)
        lay.addWidget(stack4,1)
        self.setLayout(lay)

class Lookview(QDialog):
    def __init__(self,parent=None):
        super(Lookview,self).__init__(parent=parent)
        self.setWindowFlags(Qt.Popup)
        btn=MuluTree()
        mouse_xy = btn.lookbtn.mapToGlobal(btn.lookbtn.pos())
        x = mouse_xy.x() 
        y = mouse_xy.y()
        self.setGeometry(x+10,y+24,500,80)


        tool1=Toollans1()
        tool2=Toollans2()
        tool3=Toollans3()
        tool4=Toollans4()
        tool5=Toollans5()
        tool6=Toollans6()

        stack=QStackedWidget()
        stack.setFrameStyle(QFrame.Panel|QFrame.Raised)
        stack.addWidget(tool1)

        stack2=QStackedWidget()
        stack2.setFrameStyle(QFrame.Panel|QFrame.Raised)
        stack2.addWidget(tool2)


        stack3=QStackedWidget()
        stack3.setFrameStyle(QFrame.Panel|QFrame.Raised)
        stack3.addWidget(tool3)


        stack4=QStackedWidget()
        stack4.setFrameStyle(QFrame.Panel|QFrame.Raised)
        stack4.addWidget(tool4)

        stack5=QStackedWidget()
        stack5.setFrameStyle(QFrame.Panel|QFrame.Raised)
        stack5.addWidget(tool5)

        stack6=QStackedWidget()
        stack6.setFrameStyle(QFrame.Panel|QFrame.Raised)
        stack6.addWidget(tool6)

        lay=QHBoxLayout()
        lay.addWidget(stack,2)
        lay.addWidget(stack2,2)
        lay.addWidget(stack3,2)
        lay.addWidget(stack4,2)
        lay.addWidget(stack5,1)
        lay.addWidget(stack6,4)
        self.setLayout(lay)

        pass
class FilemenuBar(QDialog):
    def __init__(self, parent=None):
        super(FilemenuBar,self).__init__(parent=parent)
        self.setWindowFlags(Qt.Popup)
        btn=MuluTree()
        mouse_xy = btn.filebtn.mapToGlobal(btn.filebtn.pos())
        x = mouse_xy.x() 
        y = mouse_xy.y()
        self.setGeometry(x+10,y+24,500,80)


        tool1_1=QToolButton(self)
        tool1_1.setText((u"打开新窗口"))
        tool1_1.setIcon(QIcon("Icon/yincang.png"),)
        tool1_1.setIconSize(QSize(20,20))
        tool1_1.setAutoRaise(True)
        tool1_1.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        tool1_2=QToolButton(self)
        tool1_2.setText((u"打开命令提示符"))
        tool1_2.setIcon(QIcon("Icon/yincang.png"),)
        tool1_2.setIconSize(QSize(20,20))
        tool1_2.setAutoRaise(True)
        tool1_2.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        tool1_3=QToolButton(self)
        tool1_3.setText((u"打开 windows powershell"))
        tool1_3.setIcon(QIcon("Icon/yincang.png"),)
        tool1_3.setIconSize(QSize(20,20))
        tool1_3.setAutoRaise(True)
        tool1_3.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        tool1_4=QToolButton(self)
        tool1_4.setText((u"删除历史记录"))
        tool1_4.setIcon(QIcon("Icon/yincang.png"),)
        tool1_4.setIconSize(QSize(20,20))
        tool1_4.setAutoRaise(True)
        tool1_4.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        tool1_5=QToolButton(self)
        tool1_5.setText((u"帮助"))
        tool1_5.setIcon(QIcon("Icon/yincang.png"),)
        tool1_5.setIconSize(QSize(20,20))
        tool1_5.setAutoRaise(True)
        tool1_5.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        tool1_6=QToolButton(self)
        tool1_6.setText((u"关闭"))
        tool1_6.setIcon(QIcon("Icon/yincang.png"),)
        tool1_6.setIconSize(QSize(20,20))
        tool1_6.setAutoRaise(True)
        tool1_6.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)


        lay=QVBoxLayout()
        lay.addWidget(tool1_1)
        lay.addWidget(tool1_2)
        lay.addWidget(tool1_3)
        lay.addWidget(tool1_4)
        lay.addWidget(tool1_5)
        lay.addWidget(tool1_6)
        self.setLayout(lay)



class MuluTree(QWidget):
    def __init__(self):
        super(MuluTree,self).__init__()
        self.initUI()
        title=self.setWindowTitle(u"这台电脑")
        win1=self.setWindowIcon(QIcon('Icon/det.jpg'))
    def initUI(self):

        self.index_address=0

#*******************************************************
        self.filebtn=QPushButton(u'文件')
        self.combtn=QPushButton(u'计算机')
        self.lookbtn=QPushButton(u'查看')
        nonebtn=QLabel()

        self.filebtn.clicked.connect(self.showFileMenu)
        self.combtn.clicked.connect(self.showcomMenu)
        self.lookbtn.clicked.connect(self.showlookMenu)


#*******************************************************

        tool1_1=QToolButton()
        tool1_1.setIcon(QIcon("Icon/tui.jpg"))

        tool1_1.setIconSize(QSize(15,15))
        tool1_1.setAutoRaise(True)

        tool1_2=QToolButton()
        tool1_2.setIcon(QIcon("Icon/jin.jpg"))
        tool1_2.setIconSize(QSize(15,15))
        tool1_2.setAutoRaise(True)

        tool1_3=QToolButton()
        tool1_3.setIcon(QIcon("Icon/xuan.png"))
        tool1_3.setIconSize(QSize(15,15))
        tool1_3.setAutoRaise(True)

        tool1_4=QToolButton()
        tool1_4.setIcon(QIcon("Icon/shang.png"))
        tool1_4.setIconSize(QSize(15,15))
        tool1_4.setAutoRaise(True)

        self.address=QLineEdit("")

        tool1_5=QToolButton()
        tool1_5.setIcon(QIcon("Icon/shua.png"))
        tool1_5.setIconSize(QSize(15,15))
        tool1_5.setAutoRaise(True)

        self.chazhao=QLineEdit()

        tool1_6=QToolButton()
        tool1_6.setIcon(QIcon("Icon/cha.png"))
        tool1_6.setIconSize(QSize(15,15))
        tool1_6.setAutoRaise(True)



#*******************************************************


        self._tree=TreeView()
        self._list=ListView()

        mainSplitter=QSplitter(Qt.Horizontal)
        mainSplitter.setOpaqueResize(1)
        mainSplitter.addWidget(self._tree)
        mainSplitter.addWidget(self._list)
        mainSplitter.setStretchFactor(0,1)
        mainSplitter.setStretchFactor(1,4)

#*******************************************************






        Layout=QHBoxLayout()
        Layout.addWidget(mainSplitter)

        Layt=QHBoxLayout()
        Layt.addWidget(self.filebtn,0)
        Layt.addWidget(self.combtn,1)
        Layt.addWidget(self.lookbtn,1)
        Layt.addWidget(nonebtn,20)

        Laytt=QHBoxLayout()
        Laytt.addWidget(tool1_1,0)
        Laytt.addWidget(tool1_2,1)
        Laytt.addWidget(tool1_3,2)
        Laytt.addWidget(tool1_4,3)
        Laytt.addWidget(self.address,8)
        Laytt.addWidget(tool1_5,7)
        Laytt.addWidget(self.chazhao,2)
        Laytt.addWidget(tool1_6,8)




        Lay=QVBoxLayout()
        Lay.addLayout(Layt,2)
        Lay.addLayout(Laytt,2)
        Lay.addLayout(Layout,20)
        self.setLayout(Lay)

        #self.tree.clicked.connect(self.showPath)
        #self.list.clicked.connect(self.showPath)
        path_json="Icon\\address.json"



        self._tree.itemDoubleClicked.connect(self._list.showdir)
        self._tree.itemClicked.connect(self.showPath)
        self._list.itemClicked.connect(self.showPath)

        self._list.itemDoubleClicked.connect(self._list.showdir)

        self._list.itemClicked.connect(self.showjilu)



        tool1_1.clicked.connect(self.houtui)
        tool1_2.clicked.connect(self.qianjin)

        tool1_4.clicked.connect(self.update)#正常

        tool1_5.clicked.connect(self.refresh)
        tool1_6.clicked.connect(self.refresh_c)

        self.setGeometry(50,50,800,600)

    def showFileMenu(self):
        dialog = FilemenuBar(self)
        dialog.show()
    def showcomMenu(self):
        dialog = Computer(self)
        dialog.show()
    def showlookMenu(self):
        dialog = Lookview(self)
        dialog.show()
    def showPath(self,item):
         global item_path
         path=item_path
         path.replace("//",'\\')
         path.replace("/",'\\')
         path=str(path).decode('utf-8')

         self.address.setText(path)
         print path
         path_json="address.json"

         if os.path.exists(path_json):
             pass
         else:
             f=open(path_json,"w")
             f.write("{\n}")
             f.close()
         with open(path_json) as file:
             dict_all = json.loads(file.read())
         self.lent=len(dict_all)
         dict_all["address"+str(self.lent)]=path
         if os.path.exists(path):
             if not os.path.isfile(path):
                 self.index_address=self.index_address+1
                 with open(path_json, "w") as films:
                     end = json.dumps(dict_all, indent=4)
                     films.write(end)
    def showjilu(self,item):
        address=self.address.text()
        path=item.path
        path=str(path)
        path=path.replace("//",'\\')
        path=path.replace('/','\\')
        path=str(path).decode('utf-8')

        self.address.setText(path)
        path_json="address.json"
        if os.path.exists(path_json):
             pass
        else:
             f=open(path_json,"w")
             f.write("{\n}")
             f.close()
             dict_all={}
             dict_all["address0"]=''
             with open(path_json, "w") as films:
                  end = json.dumps(dict_all, indent=4)
                  films.write(end)
        with open(path_json) as file:
             dict_all = json.loads(file.read())
        self.lent=len(dict_all)
        if os.path.exists(path):
            if not os.path.isfile(path):
                self.index_address=self.index_address+1
                dict_all["address"+str(self.lent)]=path
                with open(path_json, "w") as films:
                     end = json.dumps(dict_all, indent=4)
                     films.write(end)


    def houtui(self,index):
        path_json="address.json"
        if os.path.exists(path_json): 
            with open(path_json) as file:
                dict_all = json.loads(file.read())
        if self.index_address>0:
            self.index_address=self.index_address-1
            data=dict_all["address"+str(self.index_address)]
            data=str(data).decode('utf-8')
            self.address.setText(data)
            data=dict_all["address"+str(self.index_address)]
            self._list.shangji(data)

    def qianjin(self,index):
        path_json="address.json"
        lent=0
        if os.path.exists(path_json): 
            with open(path_json) as file:
                dict_all = json.loads(file.read())
            lent=len(dict_all)
        if self.index_address<lent-1:
            self.index_address=self.index_address+1
            data=dict_all["address"+str(self.index_address)]
            data=str(data).decode('utf-8')
            self.address.setText(data)
            self._list.shangji(data)
    def update(self,index):
        absolute_path = str(self.address.text())
        path=os.path.abspath(os.path.join(absolute_path, "../"))
        path=str(path).decode('utf-8')
        self.address.setText(path)
        self._list.shangji(path)
    def refresh(self,index):

        path = str(self.address.text())
        path=str(path).decode('utf-8')
        self._list.clear()
        self._list.update(path)
    def refresh_c(self,index):
        path = str(self.chazhao.text())
        file_add=str(self.address.text())
        if path.strip()!='':
            list=self.listfiels(file_add)
        else:
            QMessageBox.information(self,"Information",(u"搜索内容为空!"))


    def closeEvent(self, event):
        path_json="address.json"
        if os.path.exists(path_json):
            os.remove("address.json")
    def listfiels(self,path):
        path = path.replace("\\", "/")
        path=str(path).decode('utf-8')
        mlist = os.listdir(path)
        list=[]
        lit = str(self.chazhao.text())
        for m in mlist:
            if re.findall(lit,m):
                print m
                list.append(m)
            mpath = os.path.join(path, m)
            self._list.chazhao(list)
            if os.path.isfile(mpath):
                 pass
            else:
                  pt = os.path.abspath(mpath)
                  print pt
                  self.listfiels(pt)




if __name__ == '__main__':
    import  sys
    app=QApplication(sys.argv)
    con=MuluTree()
    con.show()
    sys.exit(app.exec_())

这里写图片描述

  • 7
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

佐倉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值