添加qt .ui转css 小工具接口

master
DESKTOP-4RNDQIC\29019 2021-05-08 00:15:04 +08:00
parent f13a1a627a
commit 80180f55f3
3 changed files with 113 additions and 14 deletions

41
main.go
View File

@ -8,6 +8,7 @@ import (
_ "background/docs"
"background/logs"
"background/model"
"encoding/xml"
"log"
"os"
"strconv"
@ -91,9 +92,47 @@ func InitElasticSearch() {
func InitLogs() {
logs.Init(config.GetLogConfig().Dir, config.GetLogConfig().File, config.GetLogConfig().Level, config.GetLogConfig().SaveFile)
}
func getAttr(name string, attr []xml.Attr) string {
for _, a := range attr {
if a.Name.Local == name {
return a.Value
}
}
return ""
}
func TestUI(){
xmlFile, err := os.Open("process.ui")
if err != nil {
log.Fatal(err)
}
defer xmlFile.Close()
decoder := xml.NewDecoder(xmlFile)
for {
token, _ := decoder.Token()
if token == nil {
break
}
switch startElement := token.(type) {
case xml.StartElement:
log.Print(startElement.Name.Local)
if(startElement.Name.Local == "widget"){
log.Print(getAttr("name",startElement.Attr))
}
break
case xml.EndElement:
log.Print(startElement.Name.Local)
break
}
}
}
func main() {
log.Print("gid is", os.Getegid())
TestUI()
InitConfig()
InitLogs()
InitRedisConfig()

51
process.ui Normal file
View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Process</class>
<widget class="QDialog" name="Process">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>324</width>
<height>88</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QProgressBar" name="progressBar">
<property name="geometry">
<rect>
<x>30</x>
<y>50</y>
<width>281</width>
<height>31</height>
</rect>
</property>
<property name="value">
<number>24</number>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>120</x>
<y>30</y>
<width>121</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>正在加载数据</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -1,6 +1,9 @@
package test
import (
"encoding/xml"
"log"
"os"
"testing"
)
@ -15,18 +18,24 @@ type Test struct {
}
func TestXml(t *testing.T) {
// x := map[string]interface{}{}
// x["map"] = 1
// x["ss"] = 2
// test := Test{A: 1, B: false, C: "hell", D: Sub{A: "aa"}}
// bytes, e := xml.Marshal(&test)
// if nil != e {
// t.Error(e.Error())
xmlFile, err := os.Open("process.ui")
if err != nil {
log.Fatal(err)
}
defer xmlFile.Close()
decoder := xml.NewDecoder(xmlFile)
for {
token, _ := decoder.Token()
if token == nil {
break
}
switch startElement := token.(type) {
case xml.StartElement:
t.Log(startElement.Name.Local)
if startElement.Name.Local == "entry" {
// do what you need to do for each entry below
}
}
}
// }
// bytes, e = xml.Marshal(&x)
// if nil != e {
// t.Error(e.Error())
// }
}