lqg 2 years ago
parent
commit
755bf01014
3 changed files with 219 additions and 122 deletions
  1. 118 105
      conf/main.ui
  2. 4 3
      crawl_baidu/__init__.py
  3. 97 14
      crawl_baidu/qt_ui.py

+ 118 - 105
crawl_baidu.ui → conf/main.ui

@@ -1,105 +1,118 @@
-<?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>546</width>
-    <height>215</height>
-   </rect>
-  </property>
-  <property name="windowTitle">
-   <string>MainWindow</string>
-  </property>
-  <widget class="QWidget" name="centralwidget">
-   <widget class="QLabel" name="label">
-    <property name="geometry">
-     <rect>
-      <x>40</x>
-      <y>40</y>
-      <width>54</width>
-      <height>12</height>
-     </rect>
-    </property>
-    <property name="text">
-     <string>Cookie:</string>
-    </property>
-   </widget>
-   <widget class="QLabel" name="label_2">
-    <property name="geometry">
-     <rect>
-      <x>40</x>
-      <y>70</y>
-      <width>54</width>
-      <height>12</height>
-     </rect>
-    </property>
-    <property name="text">
-     <string>Cookie:</string>
-    </property>
-   </widget>
-   <widget class="QLabel" name="label_3">
-    <property name="geometry">
-     <rect>
-      <x>40</x>
-      <y>100</y>
-      <width>54</width>
-      <height>12</height>
-     </rect>
-    </property>
-    <property name="text">
-     <string>关键词:</string>
-    </property>
-   </widget>
-   <widget class="QPushButton" name="pushButton">
-    <property name="geometry">
-     <rect>
-      <x>240</x>
-      <y>140</y>
-      <width>75</width>
-      <height>23</height>
-     </rect>
-    </property>
-    <property name="text">
-     <string>运行</string>
-    </property>
-   </widget>
-   <widget class="QWidget" name="">
-    <property name="geometry">
-     <rect>
-      <x>100</x>
-      <y>20</y>
-      <width>391</width>
-      <height>111</height>
-     </rect>
-    </property>
-    <layout class="QVBoxLayout" name="verticalLayout">
-     <item>
-      <widget class="QLineEdit" name="lineEdit"/>
-     </item>
-     <item>
-      <widget class="QLineEdit" name="lineEdit_2"/>
-     </item>
-     <item>
-      <widget class="QLineEdit" name="lineEdit_3"/>
-     </item>
-    </layout>
-   </widget>
-  </widget>
-  <widget class="QMenuBar" name="menubar">
-   <property name="geometry">
-    <rect>
-     <x>0</x>
-     <y>0</y>
-     <width>546</width>
-     <height>21</height>
-    </rect>
-   </property>
-  </widget>
-  <widget class="QStatusBar" name="statusbar"/>
- </widget>
- <resources/>
- <connections/>
-</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>546</width>
+    <height>223</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralwidget">
+   <widget class="QLabel" name="label">
+    <property name="geometry">
+     <rect>
+      <x>40</x>
+      <y>60</y>
+      <width>54</width>
+      <height>12</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Cookie:</string>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_2">
+    <property name="geometry">
+     <rect>
+      <x>40</x>
+      <y>90</y>
+      <width>54</width>
+      <height>12</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Cookie:</string>
+    </property>
+   </widget>
+   <widget class="QLabel" name="label_3">
+    <property name="geometry">
+     <rect>
+      <x>40</x>
+      <y>120</y>
+      <width>54</width>
+      <height>12</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>关键词:</string>
+    </property>
+   </widget>
+   <widget class="QPushButton" name="btnCrawlBaidu">
+    <property name="geometry">
+     <rect>
+      <x>240</x>
+      <y>160</y>
+      <width>75</width>
+      <height>23</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>运行</string>
+    </property>
+   </widget>
+   <widget class="QWidget" name="layoutWidget">
+    <property name="geometry">
+     <rect>
+      <x>100</x>
+      <y>40</y>
+      <width>391</width>
+      <height>111</height>
+     </rect>
+    </property>
+    <layout class="QVBoxLayout" name="verticalLayout">
+     <item>
+      <widget class="QLineEdit" name="lineEdit"/>
+     </item>
+     <item>
+      <widget class="QLineEdit" name="lineEdit_2"/>
+     </item>
+     <item>
+      <widget class="QLineEdit" name="lineEdit_3"/>
+     </item>
+    </layout>
+   </widget>
+   <widget class="QLabel" name="label_4">
+    <property name="geometry">
+     <rect>
+      <x>60</x>
+      <y>20</y>
+      <width>251</width>
+      <height>16</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>抓取百度指数</string>
+    </property>
+   </widget>
+  </widget>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>546</width>
+     <height>21</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QStatusBar" name="statusbar"/>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 4 - 3
crawl_baidu/__init__.py

@@ -7,11 +7,12 @@
 @Desc    :   pyqt ui
 '''
 
-from crawl_baidu.crawl_baidu import CrawlBaidu
-from PyQt5.QtWidgets import QApplication,QMainWindow,QWidget
+from PyQt5.QtWidgets import QApplication
+from crawl_baidu.qt_ui import ConfigureWindow
+
 def main():
     app=QApplication([])
-    win=MyMainWindow()
+    win=ConfigureWindow()
     app.exec()
     # crawl=CrawlBaidu()
     # crawl.get_index_data()

+ 97 - 14
crawl_baidu/qt_ui.py

@@ -7,29 +7,112 @@
 @Desc    :   main ui
 '''
 
-from PyQt5.QtWidgets import QMainWindow
+from PyQt5.QtWidgets import QApplication, QMainWindow, QGraphicsDropShadowEffect, QListWidgetItem, QListView, QWidget, \
+    QLabel, QHBoxLayout, QFileDialog
+from PyQt5.QtCore import Qt, QPropertyAnimation, QEasingCurve, QThread, pyqtSignal, QMutex, QSize, QEvent, QPoint
+from PyQt5.QtGui import QMouseEvent, QCursor, QColor
+from PyQt5.uic import loadUi
 
+class Window(QMainWindow):
+    '''主窗体'''
 
-class MyWindow(QMainWindow):
-    def setWwarninginfo(self, text):
-        """
-        param self, text:
-        return:
-        """
-        pass
+    def mousePressEvent(self, event):
+        # 重写一堆方法使其支持拖动
+        if event.button() == Qt.LeftButton:
+            self.m_drag = True
+            self.m_DragPosition = event.globalPos() - self.pos()
+            event.accept()
+
+    def mouseMoveEvent(self, QMouseEvent):
+        try:
+            if Qt.LeftButton and self.m_drag:
+                self.move(QMouseEvent.globalPos() - self.m_DragPosition)
+                QMouseEvent.accept()
+        except:
+            pass
+
+    def mouseReleaseEvent(self, QMouseEvent):
+        self.m_drag = False
+
+    def _frame(self):
+        # 边框
+        self.setWindowFlags(Qt.FramelessWindowHint)
+        self.setAttribute(Qt.WA_TranslucentBackground, True)
+        # 阴影
+        effect = QGraphicsDropShadowEffect(blurRadius=12, xOffset=0, yOffset=0)
+        effect.setColor(QColor(25, 25, 25, 170))
+        # self.mainFrame.setGraphicsEffect(effect)
+
+    def doFadeIn(self):
+        # 动画
+        self.animation = QPropertyAnimation(self, b'windowOpacity')
+        # 持续时间250ms
+        self.animation.setDuration(250)
+        try:
+            # 尝试先取消动画完成后关闭窗口的信号
+            self.animation.finished.disconnect(self.close)
+        except:
+            pass
+        self.animation.stop()
+        # 透明度范围从0逐渐增加到1
+        self.animation.setEasingCurve(QEasingCurve.InOutCubic)
+        self.animation.setStartValue(0)
+        self.animation.setEndValue(1)
+        self.animation.start()
 
     def doFadeOut(self):
-        """
-        param self:
-        return:
-        """
-        pass
+        self.animation.stop()
+        # 动画完成则关闭窗口
+        self.animation.finished.connect(self.close)
+        # 透明度范围从1逐渐减少到0s
+        self.animation.setEasingCurve(QEasingCurve.InOutCubic)
+        self.animation.setStartValue(1)
+        self.animation.setEndValue(0)
+        self.animation.start()
+
+    def setWarninginfo(self, text):
+        self.lab_info.setStyleSheet("""
+            .QLabel {
+                border:1px solid #ffccc7;
+                border-radius:3px;
+                line-height: 140px;
+                padding: 5px;
+                color: #434343;
+                background: #fff2f0;
+            }
+            """)
+        self.lab_info.setText(text)
 
+    def setSuccessinfo(self, text):
+        self.lab_info.setStyleSheet("""
+            .QLabel {
+                border:1px solid #b7eb8f;
+                border-radius:3px;
+                line-height: 140px;
+                padding: 5px;
+                color: #434343;
+                background: #f6ffed;
+            }
+            """)
+        self.lab_info.setText(text)
 
-class ConfigureWindow(MyWindow):
+class ConfigureWindow(Window):
+    '''配置弹框'''
     config = {}
     def __init__(self):
         super().__init__()
+        loadUi("./conf/main.ui", self)
+        # self._frame()
+        # self._eventfilter()
+        # self.doFadeIn()
+        self.config_exists = True
+
+        # 判断配置文件是否存在
+        # if not os.path.exists(working_dir + "/config.json"):
+        #     self.setWarninginfo("配置文件不存在!请单击“设置”创建配置文件")
+        #     self.config_exists = False
+
+        self.show()
         
     def saveConf(self):
         self.updateConfig()