Python pyqt5 qss美化窗口

news2024/11/16 15:46:01

效果

在这里插入图片描述

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_())


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/692810.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Google测试之道丨如何从角色出发谈谈漫游测试?

谈到“漫游测试”&#xff0c;想必大多数人想起的都是James A.whittaker提出的全局探索性测试方法。他将软件测试比如为城市旅游&#xff0c;并划分了不同的区域&#xff08;如&#xff1a;商业区、历史区、娱乐区等等&#xff09;&#xff0c;将测试人员比喻为旅游者进行城市旅…

vue3组件通信之pinia

简述 在vue3&#xff0c;vue的状态管理也迎来了新的变更&#xff0c;在vue3使用新的组件pinia来代理原有的vuex。pinia相比vuex&#xff0c;功能收敛了不少&#xff0c;比如不直接暴露setter方式&#xff0c;外部直接修改数据 两者的概念区别 vuex:集中式管理状态容器,可以实…

java之路—— Spring IOC 的详解与基本应用

创作不易&#xff0c;给个小支持一下呗 文章目录 前言一、IOC 基本概念二、理解IOC三、基本步骤 前言 首先在了解ioc之前&#xff0c;我们要先了解Spring的基本概念。 Spring是一个开源的Java应用程序开发框架&#xff0c;它提供了一套全面的解决方案&#xff0c;用于开发企业…

从此告别网速慢,轻松掌握浏览器缓存知识点!

文章目录 I. 介绍浏览器缓存的作用提高网页加载速度减少网络带宽消耗优化用户体验 II. 浏览器缓存的原理缓存机制缓存分类1. 强缓存2. 协商缓存 III. 强缓存缓存操作流程缓存过期机制如何设置强缓存 IV. 协商缓存304 Not Modified状态码缓存操作流程如何设置协商缓存 V. 缓存失…

kubernetes核心概念 Pod

Kubernetes集群核心概念 Pod 一、工作负载(workloads) 参考链接&#xff1a;https://kubernetes.io/zh/docs/concepts/workloads/ 工作负载&#xff08;workload&#xff09;是在kubernetes集群中运行的应用程序。无论你的工作负载是单一服务还是多个一同工作的服务构成&…

第2章-Java基本语法

Java基础知识图解 1. 关键字与保留字 关键字 Java保留字&#xff1a; 现有Java版本尚未使用&#xff0c; 但以后版本可能会作为关键字使用。自己命名标识符时要避免使用这些保留字 goto 、 const 2. 标识符 Java 对各种变量、 方法和类等要素命名时使用的字符序列称为标识符…

Elasticsearch:增量快照如何工作?

作者&#xff1a;Lutf ur Rehman Elastic 提供许多由讲师指导的面对面和虚拟现场培训以及点播培训。 我们的旗舰课程是 Elasticsearch 工程师、Kibana 数据分析和 Elastic 可观测性工程师。 所有这些课程都会获得认证。如果你想更多了解这些认证方面的知识&#xff0c;请阅读文…

【CXP协议与CXP测试套件】

CXP协议 CoaXPress (简称CXP)是指一种采用同轴线缆进行互联的相机数据传输标准&#xff0c;主要用于替代之前的Camera Link协议&#xff0c;常见于科学相机、工业相机、医学图像、航空防务等场景。CXP是一个非对称的高速点对点串行传输协议&#xff0c;主要用于传输视频和静态…

GO 微信支付V3SDK回调踩坑

通过微信官网提示安装sdk外部库 SDK&#xff0c;工具 | 微信支付商户平台文档中心 下面只讲解微信支付回调部分 先成功下一单微信支付拿到支付回调的数据&#xff0c;方便后续调试 因为在go里面打印请求参数不方便我使用的php打印全部参数&#xff0c; 圈起来的部分是我们需…

centos8.x系统安装K8S,kubernetes集群v1.23.9,docker支持的最后一个版本

1. 部署环境主机&#xff08;条件说明&#xff09; 卸载podman&#xff0c;centos默认安装了podman容器&#xff08;不管有没有&#xff0c;执行下总没错&#xff09;&#xff0c;可能与docker存在冲突 #环境准备 master 192.168.186.128 CentOS Linux release 8.5 (Core) n…

软件接口测试是什么?有哪些好用的接口测试工具?

在软件开发中&#xff0c;接口是不可避免的。软件接口测试是一种验证应用程序接口是否按照设计规范进行交互和协作的测试方法。接口测试是将模块之间的接口连接在一起以进行完整系统测试的关键部分。 当软件开发过程中不同模块之间需要数据交互&#xff0c;采用接口协议来实现…

Qt之事件过滤器讲解并且实现快捷键切换鼠标焦点

目录 1、需求背景2、使用Qt键盘事件3、安装事件过滤器4、事件处理级别 1、需求背景 现在有一个类似于下方图的ui&#xff0c;用户需要在输入前一行内容后&#xff0c;需要摁下指定案件能够跳转到下一行继续进行输入。 2、使用Qt键盘事件 一种更为直接的解决方案是子类化QLi…

【SpringCloud-6】Config配置中心

集群环境下&#xff0c;服务节点很多&#xff0c;我们不可能对每个服务都维护一套自己的配置&#xff0c;有修改时把每个节点都改一遍。 所以需要一个公共的配置文件&#xff0c;并且还能实现动态刷新。 在springcloud中&#xff0c;springcloud config组件就是一个配置中心&…

8年测试老鸟整理,软件测试面试问题-初中级,全覆盖问题...

目录&#xff1a;导读 前言一、Python编程入门到精通二、接口自动化项目实战三、Web自动化项目实战四、App自动化项目实战五、一线大厂简历六、测试开发DevOps体系七、常用自动化测试工具八、JMeter性能测试九、总结&#xff08;尾部小惊喜&#xff09; 前言 一般测试面试分为…

pytorch动态调整学习率torch.optim.lr_scheduler import MultiStepLR

from torch.optim.lr_scheduler import MultiStepLR 简单来说&#xff0c;就是分阶段调整学习率&#xff0e; 用法&#xff1a; model ANet(classes5) #加载模型 optimizer optim.SGD(params model.parameters(), lr0.05) #优化方法使用SGD#在指定的epoch值&#x…

极端交换————晴问算法

文章目录 1 题目2 思路3 实现 1 题目 2 思路 以此比较最大值、最小值&#xff0c;记录最大、最小值以及其下标位置&#xff0c;结束遍历后&#xff0c;交换其位置。 3 实现 #include<iostream> using namespace std;int main(){int n;scanf("%d", &n);i…

30分钟,认识 html 本质

30分钟&#xff0c;认识 html 本质 html 是什么&#xff1f;html 起源html 发展标签分类空间占用方式布局文本修饰流媒体标签 预定义符号 Symbols弃用的部分标签学习 html html 是什么&#xff1f; HTML的英文全称是 Hyper Text Markup Language&#xff0c;即超文本标记语言。…

redismariadb + keepalived 高可用

目录 机器准备 安装后服务 redis 安装redis mariadb 安装mariadb 启动和配置 互为主从同步配置 keepalived keepalived安装 修改主从 keepalived的配置 主从配置-mariadb监控 主从配置-redis监控 查看和使用 Keepalived Mariadb redis 机器准备 两台机器&…

计算机专业套装书书单推荐

1、深度学习经典教程 深度学习动手学深度学习 “花书”与沐神大作双剑合璧&#xff0c;入门深度学习看这一套就够了&#xff0c;来自一线科学家的经验总结&#xff0c;人工智能机器学习AI算法数据科学领域的重磅作品。理论实战&#xff0c;一套书帮你get深度学习的各种知识。 …

RK3568/RK3588+LinuxCNC+Ethercat解决方案

RK3588是瑞芯微新一代旗舰级高端处理器&#xff0c;具有高算力、低功耗、超强多媒体、丰富数据接口等特点。搭载四核A76四核A55的八核CPU和ARM G610MP4 GPU&#xff0c;内置6.0TOPs算力的NPU。 有五大技术优势 1. 内置多种功能强大的嵌入式硬件引擎&#xff0c;支持8K60fps 的…