Python pyqt5 qss美化窗口

效果

在这里插入图片描述

QSS

                   QWidget#widget{
    
    
                   background-color:#eef0f6;
                   border-left:0.5px solid lightgray;
                   border-right:0.5px solid lightgray;
                   border-top:0.5px solid lightgray;
                   border-bottom:0.5px solid #e5e5e5;
                   border-top-left-radius: 5px;
                   border-top-right-radius: 5px;
                   }
                   
                   QWidget#widget_2{
    
    
                   background-color:#ffffff;
                   border-left:0.5px solid lightgray;
                    border-right:0.5px solid lightgray;
                   border-bottom:0.5px solid #e5e5e5;
                   border-bottom-left-radius: 5px;
                   border-bottom-right-radius: 5px;
                   padding:5px 5px 5px 5px
                   }
                   
                   QPushButton#pushButton
                   {
    
    
                   font-family:"Webdings";
                   text-align:top;
                   background:#6DDF6D;border-radius:5px;
                   border:none;
                   font-size:13px;
                   }
                   QPushButton#pushButton:hover{
    
    background:green;}
                   
                   QPushButton#pushButton_2
                   {
    
    
                   font-family:"Webdings";
                   background:#F7D674;border-radius:5px;
                   border:none;
                   font-size:13px;
                   }
                   QPushButton#pushButton_2:hover{
    
    background:yellow;}
                   
                   QPushButton#pushButton_3
                   {
    
    
                   font-family:"Webdings";
                   background:#F76677;border-radius:5px;
                   border:none;
                   font-size:13px;
                   }
                   QPushButton#pushButton_3:hover{
    
    background:red;}

                   QPushButton#pushButton_5
                   {
    
    
                   font-family:"Webdings";
                   background:#A9B4EA;border-radius:5px;
                   border:none;
                   font-size:13px;
                   }
                   QPushButton#pushButton_5:hover{
    
    background:blue;}

                   QPushButton#pushButton_6
                   {
    
    
                   font-family:"Webdings";
                   background:#EFE9B5;border-radius:5px;
                   border:none;
                   font-size:13px;
                   }
                   QPushButton#pushButton_6:hover{
    
    background:#E5D654;}

                   QPushButton#pushButton_7
                   {
    
    
                   font-family:"Webdings";
                   background:#F8F6E4;border-radius:5px;
                   border:none;
                   font-size:13px;
                   }
                   QPushButton#pushButton_7:hover{
    
    background:#F2EAA7;}


                   QPushButton#pushButton_8
                   {
    
    
                   font-family:"Webdings";
                   background:#F8F6E4;border-radius:5px;
                   border:none;
                   font-size:13px;
                   }
                   QPushButton#pushButton_8:hover{
    
    background:#F2EAA7;}

                   QPushButton#pushButton_9
                   {
    
    
                   font-family:"Webdings";
                   background:#F98F8F;border-radius:5px;
                   border:none;
                   font-size:13px;
                   }
                   QPushButton#pushButton_9:hover{
    
    background:#F82222;}

pyqt designer设计

在这里插入图片描述

designer ui文件

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Form</class>
 <widget class="QWidget" name="Form">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>644</width>
    <height>415</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Form</string>
  </property>
  <widget class="QWidget" name="widget" native="true">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>641</width>
     <height>41</height>
    </rect>
   </property>
   <widget class="QLabel" name="icon">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>5</y>
      <width>31</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
     <string>TextLabel</string>
    </property>
   </widget>
   <widget class="QLabel" name="title">
    <property name="geometry">
     <rect>
      <x>60</x>
      <y>5</y>
      <width>131</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
     <string>TextLabel</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton">
    <property name="geometry">
     <rect>
      <x>560</x>
      <y>5</y>
      <width>31</width>
      <height>31</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <family>Webdings</family>
     </font>
    </property>
    <property name="text">
     <string>0</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_3">
    <property name="geometry">
     <rect>
      <x>600</x>
      <y>5</y>
      <width>31</width>
      <height>31</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <family>Webdings</family>
     </font>
    </property>
    <property name="text">
     <string>r</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_5">
    <property name="geometry">
     <rect>
      <x>520</x>
      <y>5</y>
      <width>31</width>
      <height>31</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <family>Webdings</family>
     </font>
    </property>
    <property name="text">
     <string>s</string>
    </property>
   </widget>
  </widget>
  <widget class="QWidget" name="widget_2" native="true">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>41</y>
     <width>641</width>
     <height>361</height>
    </rect>
   </property>
   <widget class="QGroupBox" name="groupBox">
    <property name="geometry">
     <rect>
      <x>9</x>
      <y>9</y>
      <width>301</width>
      <height>171</height>
     </rect>
    </property>
    <property name="styleSheet">
     <string notr="true">border-color: rgb(156, 156, 156);
border-width: 2px;
margin-top: 0.5ex;
border-style: solid;
border-radius:8px;
font-family:&quot;Consolas&quot;;</string>
    </property>
    <property name="title">
     <string>Load</string>
    </property>
    <property name="flat">
     <bool>false</bool>
    </property>
    <property name="checkable">
     <bool>false</bool>
    </property>
    <widget class="QTextEdit" name="textEdit">
     <property name="geometry">
      <rect>
       <x>2</x>
       <y>20</y>
       <width>251</width>
       <height>31</height>
      </rect>
     </property>
    </widget>
    <widget class="QPushButton" name="pushButton_2">
     <property name="geometry">
      <rect>
       <x>255</x>
       <y>20</y>
       <width>41</width>
       <height>31</height>
      </rect>
     </property>
     <property name="text">
      <string>OPEN</string>
     </property>
    </widget>
    <widget class="QCheckBox" name="checkBox">
     <property name="geometry">
      <rect>
       <x>10</x>
       <y>60</y>
       <width>61</width>
       <height>31</height>
      </rect>
     </property>
     <property name="styleSheet">
      <string notr="true"/>
     </property>
     <property name="text">
      <string>递归</string>
     </property>
     <property name="checked">
      <bool>true</bool>
     </property>
    </widget>
    <widget class="QCheckBox" name="checkBox_2">
     <property name="geometry">
      <rect>
       <x>80</x>
       <y>60</y>
       <width>61</width>
       <height>31</height>
      </rect>
     </property>
     <property name="styleSheet">
      <string notr="true"/>
     </property>
     <property name="text">
      <string>SVG</string>
     </property>
     <property name="checked">
      <bool>true</bool>
     </property>
     <property name="tristate">
      <bool>false</bool>
     </property>
    </widget>
    <widget class="QCheckBox" name="checkBox_3">
     <property name="geometry">
      <rect>
       <x>150</x>
       <y>60</y>
       <width>61</width>
       <height>31</height>
      </rect>
     </property>
     <property name="styleSheet">
      <string notr="true"/>
     </property>
     <property name="text">
      <string>Xml</string>
     </property>
    </widget>
    <widget class="QCheckBox" name="checkBox_4">
     <property name="geometry">
      <rect>
       <x>220</x>
       <y>60</y>
       <width>61</width>
       <height>31</height>
      </rect>
     </property>
     <property name="styleSheet">
      <string notr="true"/>
     </property>
     <property name="text">
      <string>Log</string>
     </property>
     <property name="checked">
      <bool>true</bool>
     </property>
    </widget>
    <widget class="QCheckBox" name="checkBox_5">
     <property name="geometry">
      <rect>
       <x>10</x>
       <y>100</y>
       <width>61</width>
       <height>31</height>
      </rect>
     </property>
     <property name="styleSheet">
      <string notr="true"/>
     </property>
     <property name="text">
      <string>并发</string>
     </property>
     <property name="checked">
      <bool>true</bool>
     </property>
    </widget>
    <widget class="QPushButton" name="pushButton_6">
     <property name="geometry">
      <rect>
       <x>234</x>
       <y>135</y>
       <width>61</width>
       <height>31</height>
      </rect>
     </property>
     <property name="text">
      <string>Apply</string>
     </property>
    </widget>
    <widget class="QPushButton" name="pushButton_7">
     <property name="geometry">
      <rect>
       <x>169</x>
       <y>135</y>
       <width>61</width>
       <height>31</height>
      </rect>
     </property>
     <property name="text">
      <string>Reload</string>
     </property>
    </widget>
    <widget class="QPushButton" name="pushButton_8">
     <property name="geometry">
      <rect>
       <x>114</x>
       <y>135</y>
       <width>51</width>
       <height>31</height>
      </rect>
     </property>
     <property name="text">
      <string>Recall</string>
     </property>
    </widget>
    <widget class="QPushButton" name="pushButton_9">
     <property name="geometry">
      <rect>
       <x>10</x>
       <y>135</y>
       <width>101</width>
       <height>31</height>
      </rect>
     </property>
     <property name="text">
      <string>Clean Cache</string>
     </property>
    </widget>
   </widget>
   <widget class="QGroupBox" name="groupBox_2">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>180</y>
      <width>301</width>
      <height>181</height>
     </rect>
    </property>
    <property name="styleSheet">
     <string notr="true">border-color: rgb(156, 156, 156);
border-width: 2px;
margin-top: 0.5ex;
border-style: solid;
border-radius:8px;
font-family:&quot;Consolas&quot;;</string>
    </property>
    <property name="title">
     <string>Build</string>
    </property>
    <widget class="QCheckBox" name="checkBox_6">
     <property name="geometry">
      <rect>
       <x>10</x>
       <y>20</y>
       <width>281</width>
       <height>31</height>
      </rect>
     </property>
     <property name="text">
      <string>Open Convert Svg to Xml</string>
     </property>
     <property name="checked">
      <bool>true</bool>
     </property>
    </widget>
    <widget class="QCheckBox" name="checkBox_7">
     <property name="geometry">
      <rect>
       <x>10</x>
       <y>50</y>
       <width>281</width>
       <height>31</height>
      </rect>
     </property>
     <property name="text">
      <string>Enable Image read/write permissions</string>
     </property>
     <property name="checked">
      <bool>true</bool>
     </property>
    </widget>
    <widget class="QCheckBox" name="checkBox_8">
     <property name="enabled">
      <bool>true</bool>
     </property>
     <property name="geometry">
      <rect>
       <x>10</x>
       <y>80</y>
       <width>281</width>
       <height>31</height>
      </rect>
     </property>
     <property name="text">
      <string>Set Texture Format RGBA8</string>
     </property>
     <property name="checked">
      <bool>false</bool>
     </property>
    </widget>
    <widget class="QCheckBox" name="checkBox_9">
     <property name="geometry">
      <rect>
       <x>10</x>
       <y>110</y>
       <width>281</width>
       <height>31</height>
      </rect>
     </property>
     <property name="text">
      <string>Check dependency image is missing</string>
     </property>
     <property name="checked">
      <bool>true</bool>
     </property>
    </widget>
    <widget class="QCheckBox" name="checkBox_10">
     <property name="geometry">
      <rect>
       <x>10</x>
       <y>140</y>
       <width>281</width>
       <height>31</height>
      </rect>
     </property>
     <property name="text">
      <string>Check Image pixel bound box</string>
     </property>
     <property name="checked">
      <bool>true</bool>
     </property>
    </widget>
   </widget>
   <widget class="QGroupBox" name="groupBox_3">
    <property name="geometry">
     <rect>
      <x>319</x>
      <y>9</y>
      <width>316</width>
      <height>91</height>
     </rect>
    </property>
    <property name="styleSheet">
     <string notr="true">border-color: rgb(156, 156, 156);
border-width: 2px;
margin-top: 0.5ex;
border-style: solid;
border-radius:8px;
font-family:&quot;Consolas&quot;;</string>
    </property>
    <property name="title">
     <string>SVG Verify</string>
    </property>
    <widget class="QCheckBox" name="checkBox_11">
     <property name="geometry">
      <rect>
       <x>10</x>
       <y>20</y>
       <width>71</width>
       <height>31</height>
      </rect>
     </property>
     <property name="text">
      <string>图层重叠</string>
     </property>
     <property name="checked">
      <bool>true</bool>
     </property>
    </widget>
    <widget class="QCheckBox" name="checkBox_12">
     <property name="geometry">
      <rect>
       <x>90</x>
       <y>20</y>
       <width>71</width>
       <height>31</height>
      </rect>
     </property>
     <property name="text">
      <string>命名错误</string>
     </property>
     <property name="checked">
      <bool>true</bool>
     </property>
    </widget>
    <widget class="QCheckBox" name="checkBox_13">
     <property name="geometry">
      <rect>
       <x>170</x>
       <y>20</y>
       <width>141</width>
       <height>31</height>
      </rect>
     </property>
     <property name="text">
      <string>左右图层数量不对称</string>
     </property>
     <property name="checked">
      <bool>true</bool>
     </property>
    </widget>
    <widget class="QCheckBox" name="checkBox_14">
     <property name="geometry">
      <rect>
       <x>10</x>
       <y>50</y>
       <width>71</width>
       <height>31</height>
      </rect>
     </property>
     <property name="text">
      <string>眼影特性</string>
     </property>
    </widget>
    <widget class="QCheckBox" name="checkBox_15">
     <property name="geometry">
      <rect>
       <x>90</x>
       <y>50</y>
       <width>71</width>
       <height>31</height>
      </rect>
     </property>
     <property name="text">
      <string>模型特性</string>
     </property>
    </widget>
    <widget class="QCheckBox" name="checkBox_16">
     <property name="geometry">
      <rect>
       <x>170</x>
       <y>50</y>
       <width>141</width>
       <height>31</height>
      </rect>
     </property>
     <property name="text">
      <string>图层ID重复</string>
     </property>
     <property name="checked">
      <bool>true</bool>
     </property>
    </widget>
   </widget>
   <widget class="QLineEdit" name="lineEdit">
    <property name="geometry">
     <rect>
      <x>322</x>
      <y>340</y>
      <width>261</width>
      <height>20</height>
     </rect>
    </property>
    <property name="styleSheet">
     <string notr="true">border-color: rgb(156, 156, 156);
border-width: 2px;
margin-top: 0.5ex;
border-style: solid;
border-radius:2px;
font-family:&quot;Consolas&quot;;</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton_4">
    <property name="geometry">
     <rect>
      <x>589</x>
      <y>340</y>
      <width>51</width>
      <height>20</height>
     </rect>
    </property>
    <property name="styleSheet">
     <string notr="true">border-color: rgb(156, 156, 156);
border-width: 2px;
margin-top: 0.5ex;
border-style: solid;
border-radius:2px;
font-family:&quot;Consolas&quot;;</string>
    </property>
    <property name="text">
     <string>筛选</string>
    </property>
   </widget>
   <widget class="QTextEdit" name="textEdit_2">
    <property name="geometry">
     <rect>
      <x>323</x>
      <y>110</y>
      <width>316</width>
      <height>221</height>
     </rect>
    </property>
    <property name="styleSheet">
     <string notr="true">border-color: rgb(156, 156, 156);
border-width: 2px;
margin-top: 0.5ex;
border-style: solid;
border-radius:2px;
font-family:&quot;Consolas&quot;;</string>
    </property>
    <property name="textInteractionFlags">
     <set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
    </property>
   </widget>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

源码


class MyWindow(QWidget, Ui_Form):
    def __init__(self, parent=None):
        super(MyWindow, self).__init__(parent)
        self.setupUi(self)
        self._init_main_window()  # 主窗口初始化设置

        self._initDrag()  # 设置鼠标跟踪判断扳机默认值
        self.setMouseTracking(True)  # 设置widget鼠标跟踪
        print(self.width(), self.height())
        self.my_Qss()  # 美化
        self.widget.installEventFilter(self)  # 初始化事件过滤器
        self.widget_2.installEventFilter(self)

    def _init_main_window(self):
        # 设置窗体无边框
        self.setWindowFlags(Qt.FramelessWindowHint)
        # 设置背景透明
        self.setAttribute(Qt.WA_TranslucentBackground)

        # 在测试时记得设置自己的图标地址
        # 设置图标
        w = self.icon.width()
        h = self.icon.height()
        self.pix = QPixmap(r"splash.png")  # 注意修改Windows路径问题
        self.icon.setPixmap(self.pix)
        self.icon.setScaledContents(True)

        # 设置标题
        self.title.setText('SVG Tool')
        # 设置标题字体,大小
        # font-weight:bold;
        self.title.setStyleSheet('''
                                   font-family:"High-Gear";
                                   font-size:17px;
                                   color:rgb(164,166,175,250);
                                   ''')

    def _initDrag(self):
        # 设置鼠标跟踪判断扳机默认值
        self._move_drag = False
        self._corner_drag = False
        self._bottom_drag = False
        self._right_drag = False
        # self.setAcceptDrops(True)

    @pyqtSlot()
    def on_pushButton_clicked(self):
        # 最小化
        self.showMinimized()

    @pyqtSlot()
    def on_pushButton_2_clicked(self):
        path = QFileDialog.getExistingDirectory(self, "选取指定文件夹", "C:/")
        if path != None and os.path.exists(path):
            self.textEdit.setText(path)

    @pyqtSlot()
    def on_pushButton_6_clicked(self):
        path = self.textEdit.toPlainText()
        folder = []
        svgs = []
        if None != path and path != "":
            files = path.split()

            for file in files:
                url = file.replace("file:///", "")
                if url.endswith('.svg'):
                    svgs.append(url)
                elif os.path.isdir(url):
                    folder.append(url)

        if self.checkBox.isChecked():
            print("正在递归搜索...")
            for f in folder:
                find(f, '.svg', svgs)

        if len(svgs) == 0:
            QMessageBox.warning(
                self, "IO Error", "你传入的所有 文件/文件夹 中没有找到SVG文件", QMessageBox.Yes)
        else:
            if self.checkBox_5.isChecked():
                self.dealSVGFilesConcurrenc(svgs)
            else:
                self.dealSVGFiles(svgs)

    @pyqtSlot()
    def on_pushButton_7_clicked(self):
        result = QMessageBox.warning(
            self, "危险操作", "是否强制执行重新加载", QMessageBox.Yes | QMessageBox.No)
        if result == QMessageBox.Yes:
            self.logLine("Script", "强制执行重新加载")

            self.textEdit_2.clear()
            if 'svgs' in local_data.getData().keys():
                svgs = local_data.getData()['svgs']
                if None != svgs and len(svgs) > 0:
                    if self.checkBox_5.isChecked():
                        self.dealSVGFilesConcurrenc(svgs)
                    else:
                        self.dealSVGFiles(svgs)
        else:
            self.logLine("Script", "取消强制执行重新加载")

    @pyqtSlot()
    def on_pushButton_8_clicked(self):
        result = QMessageBox.warning(
            self, "危险操作", "是否强制回滚所有操作", QMessageBox.Yes | QMessageBox.No)
        if result == QMessageBox.Yes:
            self.logLine("Script", "强制回滚所有操作")
        else:
            self.logLine("Script", "妈呀~ 手滑了...")
            return

        svgs = None
        if 'svgs' in local_data.getData().keys():
            svgs = local_data.getData()['svgs']
            local_data.getData().pop("svgs")

        if svgs == None:
            return

        self.logLine("Script", "正在删除生成的Xml文件")
        for svg in svgs:
            (path, filename) = os.path.split(svg)
            (name, _) = os.path.splitext(filename)
            newname = os.path.join(path, name+'.xml')
            if os.path.exists(newname):
                os.remove(newname)
                self.logLine("Script", f"回滚成功: {
      
      svg}")

        self.logLine("Script", "正在恢复图片的Read/Write Enabled权限")
        self.logLine("Script", "正在恢复图片的格式 设置为初代格式")
        try:
            for item in cacheDict.keys():
                img_url = item[0]
                img_info = item[1]
                e = img_info['read_write_enabled'][0]
                f = img_info['texture_format'][0]
                UnityTextureImporter.SetTextureReadWriteEnabled(img_url, e)
                UnityTextureImporter.SetTextureFormat(img_url, f)
        except:
            msg = traceback.format_exc()
            self.logLine("traceback", msg)

    @pyqtSlot()
    def on_pushButton_9_clicked(self):
        result = QMessageBox.warning(
            self, "危险操作", "是否清理缓存", QMessageBox.Yes | QMessageBox.No)
        if result == QMessageBox.Yes:
            if os.path.exists(getCacheFilePath()):
                os.remove(getCacheFilePath())
            self.logLine("Script", "清理缓存成功")
        else:
            self.logLine("Script", "啊呀,手又滑了呢~")
            return

    def logLine(self, tag, content):
        timestr = time.strftime("%H:%M:%S", time.localtime())
        lineContent = f"{
      
      timestr} [{
      
      tag}] {
      
      content}\n"
        self.textEdit_2.append(lineContent)
        print(lineContent)

    def dealSVGFilesConcurrenc(self, svgs):
        self.logLine("Script", "并发处理SVG文件")
        threads = []
        limgs = []
        b_overlap = self.checkBox_11.isChecked()
        b_name = self.checkBox_12.isChecked()
        b_layerCount = self.checkBox_13.isChecked()
        b_eye = self.checkBox_14.isChecked()
        b_model = self.checkBox_15.isChecked()
        b_id = self.checkBox_16.isChecked()
        b_imgMiss = self.checkBox_9.isChecked()
        b_enableReadWrite = self.checkBox_7.isChecked()
        b_compressedAtc = self.checkBox_8.isChecked()
        b_checkImg_pixelBoundBox = self.checkBox_10.isChecked()
        b_convet2xml = self.checkBox_6.isChecked()
        depend_img_info = []

        # svg 文件处理
        for svg in svgs:
            t1 = threading.Thread(target=loadSVG, args=(
                svg,
                self.logLine,
                limgs,
                b_overlap,
                b_name,
                b_layerCount,
                b_eye,
                b_model,
                b_id,
                b_imgMiss,
                b_enableReadWrite,
                b_compressedAtc,
                depend_img_info,
            ))
            threads.append(t1)
            t1.start()

        # 这里类似await  只有所有线程执行完成后 才能继续执行后面的代码
        for t in threads:
            t.join()

        # 处理图片矩阵
        if b_checkImg_pixelBoundBox:

            for pair in limgs:
                result = dissymmetry(getBoundingBox(
                    pair[0]), getBoundingBox(pair[1]))
                if result != 0:
                    getErrorstr = ""
                    if result == 1:
                        getErrorstr = "图片像素检测 - 左边翻转后与右边像素不完全重叠"
                    elif result == 2:
                        getErrorstr = "图片像素检测中心坐标 - 垂直坐标中心不对称"
                    elif result == 3:
                        getErrorstr = "图片像素检测包围盒 - 大小不同"

                    folder, _ = os.path.split(pair[0])
                    self.logLine("image-bound-box",
                                 f'{
      
      getErrorstr}: {
      
      folder}\n{
      
      _}')

        # 转换xml
        if b_convet2xml and len(svgs) > 0:
            self.logLine("Script", "----------转换程序正在运行----------")
            start_time = time.time()
            for svg in svgs:
                (path, filename) = os.path.split(svg)
                (name, _) = os.path.splitext(filename)
                if 'Models' in path:
                    name = 'svg'
                newname = os.path.join(path, name+'.xml')
                if os.path.exists(newname):
                    os.remove(newname)
                    self.logLine("Script", f"覆盖成功 {
      
      newname}")
                else:
                    self.logLine("Script", f"生成 {
      
      newname}")
                shutil.copyfile(svg, newname)
            self.logLine("Script", "----------转换程序结束运行----------")
            self.logLine("Script", f"运行用时: {
      
      time.time()-start_time}秒")
            local_data.getData()['svgs'] = svgs
            local_data.save()

        # 记录存储缓存数据
        if len(depend_img_info) > 0:
            global cacheDict
            for info in depend_img_info:
                if info[0] not in cacheDict.keys():
                    item = cacheDict[info[0]] = {
    
    }
                    item['read_write_enabled'] = [info[2]]
                    item['texture_format'] = [info[1]]
                else:
                    item = cacheDict[info[0]]
                    item['read_write_enabled'].append(info[2])
                    item['texture_format'].append(info[1])
            cacheData()

        # 记录日志
        local_data.getData()['log'] = self.textEdit_2.toPlainText()

    def dealSVGFiles(self, svgs):
        self.logLine("Script", "低开销模式处理SVG文件")
        limgs = []
        b_overlap = self.checkBox_11.isChecked()
        b_name = self.checkBox_12.isChecked()
        b_layerCount = self.checkBox_13.isChecked()
        b_eye = self.checkBox_14.isChecked()
        b_model = self.checkBox_15.isChecked()
        b_id = self.checkBox_16.isChecked()
        b_imgMiss = self.checkBox_9.isChecked()
        b_enableReadWrite = self.checkBox_7.isChecked()
        b_compressedAtc = self.checkBox_8.isChecked()
        b_checkImg_pixelBoundBox = self.checkBox_10.isChecked()
        b_convet2xml = self.checkBox_6.isChecked()
        depend_img_info = []

        # svg 文件处理
        for svg in svgs:
            loadSVG(
                svg,
                self.logLine,
                limgs,
                b_overlap,
                b_name,
                b_layerCount,
                b_eye,
                b_model,
                b_id,
                b_imgMiss,
                b_enableReadWrite,
                b_compressedAtc,
                depend_img_info
            )

        # 处理图片矩阵
        if b_checkImg_pixelBoundBox:

            for pair in limgs:
                result = dissymmetry(getBoundingBox(
                    pair[0]), getBoundingBox(pair[1]))
                if result != 0:
                    getErrorstr = ""
                    if result == 1:
                        getErrorstr = "图片像素检测 - 左边翻转后与右边像素不完全重叠"
                    elif result == 2:
                        getErrorstr = "图片像素检测中心坐标 - 垂直坐标中心不对称"
                    elif result == 3:
                        getErrorstr = "图片像素检测包围盒 - 大小不同"

                    folder, _ = os.path.split(pair[0])
                    self.logLine("image-bound-box",
                                 f'{
      
      getErrorstr}: {
      
      folder}\n{
      
      _}')

        # 转换xml
        if b_convet2xml and len(svgs) > 0:
            self.logLine("Script", "----------转换程序正在运行----------")
            start_time = time.time()
            for svg in svgs:
                (path, filename) = os.path.split(svg)
                (name, _) = os.path.splitext(filename)
                if 'Models' in path:
                    name = 'svg'
                newname = os.path.join(path, name+'.xml')
                if os.path.exists(newname):
                    os.remove(newname)
                    self.logLine("Script", f"覆盖成功 {
      
      newname}")
                else:
                    self.logLine("Script", f"生成 {
      
      newname}")
                shutil.copyfile(svg, newname)
            self.logLine("Script", "----------转换程序结束运行----------")
            self.logLine("Script", f"运行用时: {
      
      time.time()-start_time}秒")
            local_data.getData()['svgs'] = svgs
            local_data.save()

        # 记录存储缓存数据
        if len(depend_img_info) > 0:
            global cacheDict
            for info in depend_img_info:
                if info[0] not in cacheDict.keys():
                    item = cacheDict[info[0]] = {
    
    }
                    item['read_write_enabled'] = [info[2]]
                    item['texture_format'] = [info[1]]
                else:
                    item = cacheDict[info[0]]
                    item['read_write_enabled'].append(info[2])
                    item['texture_format'].append(info[1])
            cacheData()

        # 记录日志
        local_data.getData()['log'] = self.textEdit_2.toPlainText()

    @pyqtSlot()
    def on_pushButton_3_clicked(self):
        # 关闭程序
        self.close()

    @pyqtSlot()
    def on_pushButton_4_clicked(self):
        command = self.lineEdit.text()
        if 'log' in local_data.getData().keys():
            content = local_data.getData()['log']
            if command == "":
                self.textEdit_2.setPlainText(content)
            else:
                result_list = re.findall(f'.*{
      
      command}.*\n',content)
                self.textEdit_2.setPlainText('\n'.join(result_list))

    @pyqtSlot()
    def on_pushButton_5_clicked(self):
        print("click 5")
        popen("start tencent://message/?uin=331565861&Site=&Menu=yes")

    def eventFilter(self, obj, event):
        # 事件过滤器,用于解决鼠标进入其它控件后还原为标准鼠标样式
        if isinstance(event, QEnterEvent):
            self.setCursor(Qt.ArrowCursor)
        # 注意 ,MyWindow是所在类的名称
        return super(MyWindow, self).eventFilter(obj, event)
        # return QWidget.eventFilter(self, obj, event)  # 用这个也行,但要注意修改窗口类型

    def resizeEvent(self, QResizeEvent):
        # 自定义窗口调整大小事件
        # 改变窗口大小的三个坐标范围
        self._right_rect = [QPoint(x, y) for x in range(self.width() - 5, self.width() + 5)
                            for y in range(self.widget.height() + 20, self.height() - 5)]
        self._bottom_rect = [QPoint(x, y) for x in range(1, self.width() - 5)
                             for y in range(self.height() - 5, self.height() + 1)]
        self._corner_rect = [QPoint(x, y) for x in range(self.width() - 5, self.width() + 1)
                             for y in range(self.height() - 5, self.height() + 1)]

    def mousePressEvent(self, event):
        # 重写鼠标点击的事件
        if (event.button() == Qt.LeftButton) and (event.pos() in self._corner_rect):
            # 鼠标左键点击右下角边界区域
            self._corner_drag = True
            event.accept()
        elif (event.button() == Qt.LeftButton) and (event.pos() in self._right_rect):
            # 鼠标左键点击右侧边界区域
            self._right_drag = True
            event.accept()
        elif (event.button() == Qt.LeftButton) and (event.pos() in self._bottom_rect):
            # 鼠标左键点击下侧边界区域
            self._bottom_drag = True
            event.accept()
        elif (event.button() == Qt.LeftButton) and (event.y() < self.widget.height()):
            # 鼠标左键点击标题栏区域
            self._move_drag = True
            self.move_DragPosition = event.globalPos() - self.pos()
            event.accept()

    def mouseMoveEvent(self, QMouseEvent):
        # 判断鼠标位置切换鼠标手势
        if QMouseEvent.pos() in self._corner_rect:  # QMouseEvent.pos()获取相对位置
            self.setCursor(Qt.SizeFDiagCursor)
        elif QMouseEvent.pos() in self._bottom_rect:
            self.setCursor(Qt.SizeVerCursor)
        elif QMouseEvent.pos() in self._right_rect:
            self.setCursor(Qt.SizeHorCursor)

        # 当鼠标左键点击不放及满足点击区域的要求后,分别实现不同的窗口调整
        # 没有定义左方和上方相关的5个方向,主要是因为实现起来不难,但是效果很差,拖放的时候窗口闪烁,再研究研究是否有更好的实现
        if Qt.LeftButton and self._right_drag:
            # 右侧调整窗口宽度
            self.resize(QMouseEvent.pos().x(), self.height())
            QMouseEvent.accept()
        elif Qt.LeftButton and self._bottom_drag:
            # 下侧调整窗口高度
            self.resize(self.width(), QMouseEvent.pos().y())
            QMouseEvent.accept()
        elif Qt.LeftButton and self._corner_drag:
            #  由于我窗口设置了圆角,这个调整大小相当于没有用了
            # 右下角同时调整高度和宽度
            self.resize(QMouseEvent.pos().x(), QMouseEvent.pos().y())
            QMouseEvent.accept()
        elif Qt.LeftButton and self._move_drag:
            # 标题栏拖放窗口位置
            self.move(QMouseEvent.globalPos() - self.move_DragPosition)
            QMouseEvent.accept()

    def mouseReleaseEvent(self, QMouseEvent):
        # 鼠标释放后,各扳机复位
        self._move_drag = False
        self._corner_drag = False
        self._bottom_drag = False
        self._right_drag = False

    def my_Qss(self):
        # Qss美化
        qssStyle = '''
                    
                   QWidget#widget{
                   background-color:#eef0f6;
                   border-left:0.5px solid lightgray;
                   border-right:0.5px solid lightgray;
                   border-top:0.5px solid lightgray;
                   border-bottom:0.5px solid #e5e5e5;
                   border-top-left-radius: 5px;
                   border-top-right-radius: 5px;
                   }
                   
                   QWidget#widget_2{
                   background-color:#ffffff;
                   border-left:0.5px solid lightgray;
                    border-right:0.5px solid lightgray;
                   border-bottom:0.5px solid #e5e5e5;
                   border-bottom-left-radius: 5px;
                   border-bottom-right-radius: 5px;
                   padding:5px 5px 5px 5px
                   }
                   
                   QPushButton#pushButton
                   {
                   font-family:"Webdings";
                   text-align:top;
                   background:#6DDF6D;border-radius:5px;
                   border:none;
                   font-size:13px;
                   }
                   QPushButton#pushButton:hover{background:green;}
                   
                   QPushButton#pushButton_2
                   {
                   font-family:"Webdings";
                   background:#F7D674;border-radius:5px;
                   border:none;
                   font-size:13px;
                   }
                   QPushButton#pushButton_2:hover{background:yellow;}
                   
                   QPushButton#pushButton_3
                   {
                   font-family:"Webdings";
                   background:#F76677;border-radius:5px;
                   border:none;
                   font-size:13px;
                   }
                   QPushButton#pushButton_3:hover{background:red;}

                   QPushButton#pushButton_5
                   {
                   font-family:"Webdings";
                   background:#A9B4EA;border-radius:5px;
                   border:none;
                   font-size:13px;
                   }
                   QPushButton#pushButton_5:hover{background:blue;}

                   QPushButton#pushButton_6
                   {
                   font-family:"Webdings";
                   background:#EFE9B5;border-radius:5px;
                   border:none;
                   font-size:13px;
                   }
                   QPushButton#pushButton_6:hover{background:#E5D654;}

                   QPushButton#pushButton_7
                   {
                   font-family:"Webdings";
                   background:#F8F6E4;border-radius:5px;
                   border:none;
                   font-size:13px;
                   }
                   QPushButton#pushButton_7:hover{background:#F2EAA7;}


                   QPushButton#pushButton_8
                   {
                   font-family:"Webdings";
                   background:#F8F6E4;border-radius:5px;
                   border:none;
                   font-size:13px;
                   }
                   QPushButton#pushButton_8:hover{background:#F2EAA7;}

                   QPushButton#pushButton_9
                   {
                   font-family:"Webdings";
                   background:#F98F8F;border-radius:5px;
                   border:none;
                   font-size:13px;
                   }
                   QPushButton#pushButton_9:hover{background:#F82222;}
                   '''

        self.setStyleSheet(qssStyle)

    def closeEvent(self, e):
        cacheData()
        local_data.save()


if __name__ == "__main__":

    # 初始化App
    initApp()

    # 适配2k等高分辨率屏幕,低分辨率屏幕可以缺省
    QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
    app = QApplication(sys.argv)

    # 加载字体到内存
    QFontDatabase.addApplicationFont("bin/fontFiles/High-Gear.ttf")
    QFontDatabase.addApplicationFont("bin/fontFiles/Dreamy.otf")

    # 显示窗口
    myWin = MyWindow()
    myWin.show()
    sys.exit(app.exec_())


猜你喜欢

转载自blog.csdn.net/qq_39162566/article/details/131422951