Python ユーティリティ ツールの開発: Pyqt/PySide6 は、「Everything のローエンド バージョン」と呼ぶことができる、コンピューター上の「学習資料」を見つけるためのファイル検索ツールを作成します (ソース コードが添付されています)

目次

 

序文

1. pyqt/pyside6の導入とインストール

2. インターフェイスと UI インターフェイス コードを実行する

3. リソースのダウンロードと使用方法のチュートリアル

4. まとめ


序文

少し前に、コンピューターの最適化とソフトウェアの推奨事項に関する記事を公開しました (興味のある友人はこの記事を読むことができます)。その中に非常に感銘を受けたソフトウェアがあり、それがファイル検索アーティファクト: Everything です。検索速度ミリ秒レベルでメモリ占有量も少ないので、win10付属の検索エンジンと比べると格段に違います。私はたまたま最近 GUI (Graphical User Interface) を勉強しており、Python の学習者としてこのソフトウェアを真似したいと思っているので、考えるよりも行動する方が悪いです...

[おすすめコレクション] 新しいコンピューター Windows 10/11 システムの最適化、コンピューターのパフォーマンスとエクスペリエンスを向上させるための使用仕様とテクニックとソフトウェアの推奨事項_import _this's blog - CSDN ブログ 新しいコンピューター Windows 10/11 のシステムの最適化、コンピューターのパフォーマンスとエクスペリエンスを向上させるための使用仕様とテクニックとソフトウェアの推奨事項パフォーマンスと経験。役に立ったと思われる場合は、「いいね!」または「フォロー」してください。ご視聴いただきありがとうございますhttps://blog.csdn.net/python_sy/article/details/127268101


1. pyqt/pyside6の導入とインストール

pyside6 をまだインストールしていない場合は、次の記事を読んでください。

Pyqt/PySide6 の紹介とインストール方法PySide6 と PyQt5 はどちらも Qt ライブラリをベースにしています。Qt ライブラリには非常に強力なグラフィカル インターフェイス開発ライブラリがありますが、Qt ライブラリは C++ 言語で開発されており、PySide2、PySide6、および PyQt5 を使用すると、Python 言語を介して Qt を使用できますhttps://blog.csdn.net/python_sy /記事/詳細/ 127425142


2. インターフェイスと UI インターフェイス コードを実行する

実行インターフェース:

294efd205c7f493f974347046328fe16.png

検索完了インターフェース:

21fa0341459a409686aace896cf4c7f6.png

 自分で調べられる機能がたくさんあります(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>搜索(&amp;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>工具(&amp;T)</string>
    </property>
    <addaction name="actionTextViewer"/>
    <addaction name="actionPlayerViewer"/>
    <addaction name="actionImageViewer"/>
   </widget>
   <widget class="QMenu" name="helpMenu">
    <property name="title">
     <string>帮助(&amp;H)</string>
    </property>
    <addaction name="actionHelp"/>
   </widget>
   <widget class="QMenu" name="aboutMenu">
    <property name="title">
     <string>关于(&amp;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. まとめ

これで、ファイル検索アプレットがついに完成しました。
また、このコードの使用中に問題が発生した場合は、フィードバックをお送りください。

いつもご覧いただき、応援していただきありがとうございます。ここを見て気に入っていただけましたら、ぜひフォローしてください^_^。皆さんの応援が更新の一番のモチベーションです!

おすすめ

転載: blog.csdn.net/python_sy/article/details/127424641
おすすめ