目次
2. インターフェイスと UI インターフェイス コードを実行する
序文
少し前に、コンピューターの最適化とソフトウェアの推奨事項に関する記事を公開しました (興味のある友人はこの記事を読むことができます)。その中に非常に感銘を受けたソフトウェアがあり、それがファイル検索アーティファクト: Everything です。検索速度ミリ秒レベルでメモリ占有量も少ないので、win10付属の検索エンジンと比べると格段に違います。私はたまたま最近 GUI (Graphical User Interface) を勉強しており、Python の学習者としてこのソフトウェアを真似したいと思っているので、考えるよりも行動する方が悪いです...
1. pyqt/pyside6の導入とインストール
pyside6 をまだインストールしていない場合は、次の記事を読んでください。
2. インターフェイスと 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>
3. リソースのダウンロードと使用方法のチュートリアル
使用方法のチュートリアルはソフトウェアに含まれているので、ダウンロードして見てください。
関連リソース: https://download.csdn.net/download/python_sy/86801488
4. まとめ
これで、ファイル検索アプレットがついに完成しました。
また、このコードの使用中に問題が発生した場合は、フィードバックをお送りください。
いつもご覧いただき、応援していただきありがとうございます。ここを見て気に入っていただけましたら、ぜひフォローしてください^_^。皆さんの応援が更新の一番のモチベーションです!