目录
前言
就在不久前,我发布了一篇关于电脑优化和软件推荐的文章(感兴趣的小伙伴可以去看一看文章),里面有一款软件让我印象非常深刻,那就是文件搜索神器:Everything,毫秒级别的搜索速度,而且软件占内存小,比较win10自带的搜索器那真是天壤之别。刚好最近我在研究GUI(图形用户界面),作为python的学习者,非常想复刻这款软件,于是,心动不如行动......
一、pyqt/pyside6简介及安装
如果还没有安装pyside6的小伙伴可以看看下面的文章:
二、运行界面和UI界面代码
运行界面:
搜索完成界面:
功能比较多可以自行探索(因为是叫低配版的Everything所以我取名为Anything嘻嘻~)
ui界面代码:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>760</width>
<height>594</height>
</rect>
</property>
<property name="windowTitle">
<string>Anything</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>icons/icon.png</normaloff>icons/icon.png</iconset>
</property>
<property name="styleSheet">
<string notr="true">QTreeView {
border:none
}
</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="font">
<font>
<stylestrategy>PreferDefault</stylestrategy>
</font>
</property>
<property name="mouseTracking">
<bool>false</bool>
</property>
<property name="tabletTracking">
<bool>false</bool>
</property>
<property name="contextMenuPolicy">
<enum>Qt::DefaultContextMenu</enum>
</property>
<property name="accessibleName">
<string/>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="title">
<string>填写内容后点击开始搜索</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="flat">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QLineEdit" name="upLineEdit">
<property name="placeholderText">
<string>请输入文件路径(默认C:/)</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="downLineEdit">
<property name="placeholderText">
<string>请输入文件类型,列如exe</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="downLabel">
<property name="font">
<font>
<family>微软雅黑</family>
<pointsize>11</pointsize>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>类型:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="upLabel">
<property name="font">
<font>
<family>微软雅黑</family>
<pointsize>11</pointsize>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>路径:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="searchButton">
<property name="text">
<string>开始搜索</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="browseButton">
<property name="text">
<string>选择文件夹</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QTreeWidget" name="outputTreeWidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum>
</property>
<property name="showDropIndicator" stdset="0">
<bool>true</bool>
</property>
<property name="indentation">
<number>20</number>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="uniformRowHeights">
<bool>false</bool>
</property>
<property name="itemsExpandable">
<bool>true</bool>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
<property name="animated">
<bool>false</bool>
</property>
<property name="allColumnsShowFocus">
<bool>false</bool>
</property>
<property name="headerHidden">
<bool>false</bool>
</property>
<property name="expandsOnDoubleClick">
<bool>true</bool>
</property>
<property name="columnCount">
<number>5</number>
</property>
<attribute name="headerVisible">
<bool>true</bool>
</attribute>
<attribute name="headerCascadingSectionResizes">
<bool>false</bool>
</attribute>
<attribute name="headerMinimumSectionSize">
<number>25</number>
</attribute>
<attribute name="headerDefaultSectionSize">
<number>100</number>
</attribute>
<attribute name="headerHighlightSections">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>名称</string>
</property>
<property name="textAlignment">
<set>AlignLeading|AlignVCenter</set>
</property>
</column>
<column>
<property name="text">
<string>类型</string>
</property>
<property name="textAlignment">
<set>AlignLeading|AlignVCenter</set>
</property>
</column>
<column>
<property name="text">
<string>大小</string>
</property>
<property name="textAlignment">
<set>AlignTrailing|AlignVCenter</set>
</property>
</column>
<column>
<property name="text">
<string>修改时间</string>
</property>
<property name="textAlignment">
<set>AlignCenter</set>
</property>
</column>
<column>
<property name="text">
<string>路径</string>
</property>
</column>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>760</width>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="searchMenu">
<property name="title">
<string>搜索(&S)</string>
</property>
<addaction name="actionSearchType"/>
<addaction name="actionSearchName"/>
<addaction name="actionSearchWeb"/>
<addaction name="actionSearchKey"/>
</widget>
<widget class="QMenu" name="toolsMenu">
<property name="title">
<string>工具(&T)</string>
</property>
<addaction name="actionTextViewer"/>
<addaction name="actionPlayerViewer"/>
<addaction name="actionImageViewer"/>
</widget>
<widget class="QMenu" name="helpMenu">
<property name="title">
<string>帮助(&H)</string>
</property>
<addaction name="actionHelp"/>
</widget>
<widget class="QMenu" name="aboutMenu">
<property name="title">
<string>关于(&A)</string>
</property>
<addaction name="actionAbout"/>
</widget>
<addaction name="searchMenu"/>
<addaction name="toolsMenu"/>
<addaction name="helpMenu"/>
<addaction name="aboutMenu"/>
</widget>
<action name="actionAbout">
<property name="text">
<string>关于作者</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+A</string>
</property>
</action>
<action name="actionHelp">
<property name="text">
<string>查看用法</string>
</property>
<property name="shortcut">
<string>Ctrl+H</string>
</property>
</action>
<action name="actionSearchType">
<property name="icon">
<iconset>
<normaloff>icons/radio-circle-marked.png</normaloff>icons/radio-circle-marked.png</iconset>
</property>
<property name="text">
<string>类型搜索</string>
</property>
</action>
<action name="actionSearchName">
<property name="icon">
<iconset>
<normaloff>icons/radio-circle.png</normaloff>icons/radio-circle.png</iconset>
</property>
<property name="text">
<string>名称搜索</string>
</property>
</action>
<action name="actionTextViewer">
<property name="text">
<string>文本查看器</string>
</property>
</action>
<action name="actionPlayerViewer">
<property name="text">
<string>音频播放器</string>
</property>
</action>
<action name="actionImageViewer">
<property name="text">
<string>图像查看器</string>
</property>
</action>
<action name="actionSearchWeb">
<property name="icon">
<iconset>
<normaloff>icons/radio-circle.png</normaloff>icons/radio-circle.png</iconset>
</property>
<property name="text">
<string>Web搜索</string>
</property>
</action>
<action name="actionSearchKey">
<property name="icon">
<iconset>
<normaloff>icons/radio-circle.png</normaloff>icons/radio-circle.png</iconset>
</property>
<property name="text">
<string>文件关键字搜索</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>
三、资源下载和使用教程
使用教程在软件里,快去下载看看吧!
相关资源:https://download.csdn.net/download/python_sy/86801488
四、总结
至此,就终于完成了文件搜索小程序了!
另外,如果在使用这个代码的过程中有遇到什么问题,也欢迎向我反馈。
感谢大家的支持和观看,看到这儿的朋友要是喜欢的话就点个关注呗^_^,你们的支持是我更新的最大动力!