]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
gtk界面
authorqydysky <qydysky@foxmail.com>
Sun, 18 Oct 2020 14:00:19 +0000 (22:00 +0800)
committerqydysky <qydysky@foxmail.com>
Sun, 18 Oct 2020 14:00:19 +0000 (22:00 +0800)
Reply/F.go
Reply/Reply.go
Reply/gtk.go [new file with mode: 0644]
bili_danmu.go
demo/Autoban.txt
demo/config.json
demo/go.mod
demo/go.sum
demo/ui/1.glade [new file with mode: 0644]

index d2b526a3f000d10080f5b5031861b0bf6718f9ca..1a45348da869fbc233f7abdf502ec3e76717157e 100644 (file)
@@ -24,6 +24,7 @@ import (
 //功能开关
 var AllF = map[string]bool{
        "Qtd":false,//Qt弹幕窗口
+       "Gtk":false,//Gtk弹幕窗口
        "Saveflv":true,//保存直播流(默认高清,有cookie默认蓝光)
        "Ass":true,//Ass弹幕生成,由于时间对应关系,仅开启流保存时生效
        "Obs":false,//obs组件(仅录播)
@@ -115,6 +116,11 @@ func selfcross2(a []string) (float32, string) {
 }
 
 //功能区
+//Gtk 弹幕Gtk窗口
+func Gtkf(){
+       if!IsOn("Gtk") {return}
+       Gtk_danmu()
+}
 
 //Qtd 弹幕Qt窗口
 type Qtd struct {
@@ -527,7 +533,7 @@ type Autoskip struct {
 }
 
 var autoskip = Autoskip{
-       bufbreak:make(chan bool, 10),
+       bufbreak:make(chan bool, 100),
 }
 
 func Autoskipf(s string, maxNum,muteSecond int) int {
index f7c232286d576f9742ca9c217dcdb757e1e45196..0ef31234d72e2292d9f077b13ff16bdf13dc4762 100644 (file)
@@ -70,7 +70,7 @@ func (replyF) anchor_lot_start(s string){
                Assf(fmt.Sprintln("天选之人", award_name, "开始"))
        }
        fmt.Println(sh...)
-       Qtshow(Itos(sh))
+       Gui_show(Itos(sh))
 
        msglog.Base(1, "房").Fileonly(true).I(sh...).Fileonly(false)
 }
@@ -99,7 +99,7 @@ func (replyF) anchor_lot_award(s string){
                Assf(fmt.Sprintln("天选之人", award_name, "结束"))
        }
        fmt.Println(sh...)
-       Qtshow(Itos(sh))
+       Gui_show(Itos(sh))
 
        msglog.Base(1, "房").Fileonly(true).I(sh...).Fileonly(false)
 }
@@ -151,9 +151,9 @@ func (replyF) user_toast_msg(s string){
        fmt.Println(sh...)
        fmt.Print("====\n\n")
 
-       Qtshow("\n====")
-       Qtshow(Itos(sh))
-       Qtshow("====\n")
+       Gui_show("\n====")
+       Gui_show(Itos(sh))
+       Gui_show("====\n")
 
        msglog.Base(1, "礼").Fileonly(true).I(sh...).Fileonly(false)
 }
@@ -198,9 +198,9 @@ func (replyF) special_gift(s string){
        fmt.Println(sh...)
        fmt.Print("====\n\n")
 
-       Qtshow("\n====")
-       Qtshow(Itos(sh))
-       Qtshow("====\n")
+       Gui_show("\n====")
+       Gui_show(Itos(sh))
+       Gui_show("====\n")
 
        msglog.Base(1, "礼").I(sh...)
 
@@ -247,7 +247,7 @@ func (replyF) room_change(s string){
        if area_name != nil {
                sh = append(sh, area_name)
        }
-       Qtshow(Itos(sh))
+       Gui_show(Itos(sh))
 
        msglog.Base(1, "房").I(sh...)
 }
@@ -274,7 +274,7 @@ func (replyF) welcome_guard(s string){
 
        fmt.Print(">>> ")
        fmt.Println(sh...)
-       Qtshow(Itos(append([]interface{}{">>> "}, sh...)))
+       Gui_show(Itos(append([]interface{}{">>> "}, sh...)))
 
        msglog.Base(1, "房").Fileonly(true).I(sh...).Fileonly(false)
 }
@@ -321,9 +321,9 @@ func (replyF) send_gift(s string){
        fmt.Println(sh...)
        fmt.Print("====\n\n")
 
-       Qtshow("\n====")
-       Qtshow(Itos(sh))
-       Qtshow("====\n")
+       Gui_show("\n====")
+       Gui_show(Itos(sh))
+       Gui_show("====\n")
        
        msglog.Base(1, "礼").Fileonly(true).I(sh...).Fileonly(false)
 }
@@ -337,7 +337,7 @@ func (replyF) room_block_msg(s string) {
                msglog.E("uname", uname)
                return
        } else {
-               Qtshow(Itos([]interface{}{"用户", uname, "已被封禁"}))
+               Gui_show(Itos([]interface{}{"用户", uname, "已被封禁"}))
                fmt.Println("用户", uname, "已被封禁")
                msglog.Base(1, "封").I("用户", uname, "已被封禁")
        }
@@ -357,11 +357,11 @@ func (replyF) preparing(s string) {
                        Saveflv_wait()
                }
                if p.Sys().Type(roomid) == "float64" {
-                       Qtshow(Itos([]interface{}{"房间", roomid, "下播了"}))
+                       Gui_show(Itos([]interface{}{"房间", roomid, "下播了"}))
                        msglog.I("房间", int(roomid.(float64)), "下播了")
                        return
                }
-               Qtshow(Itos([]interface{}{"房间", roomid, "下播了"}))
+               Gui_show(Itos([]interface{}{"房间", roomid, "下播了"}))
                msglog.I("房间", roomid, "下播了")
        }
 }
@@ -380,11 +380,11 @@ func (replyF) live(s string) {
                        go Saveflvf()
                }
                if p.Sys().Type(roomid) == "float64" {
-                       Qtshow(Itos([]interface{}{"房间", roomid, "开播了"}))
+                       Gui_show(Itos([]interface{}{"房间", roomid, "开播了"}))
                        msglog.I("房间", int(roomid.(float64)), "开播了")
                        return
                }
-               Qtshow(Itos([]interface{}{"房间", roomid, "开播了"}))
+               Gui_show(Itos([]interface{}{"房间", roomid, "开播了"}))
                msglog.I("房间", roomid, "开播了")
        }
 }
@@ -406,23 +406,23 @@ func (replyF) super_chat_message(s string){
        }
        fmt.Println("\n====")
        fmt.Println(sh...)
-       Qtshow("\n====")
-       Qtshow(Itos(sh))
+       Gui_show("\n====")
+       Gui_show(Itos(sh))
        if message != nil && message.(string) != ""{
                fmt.Println(message)
-               Qtshow(message.(string))
+               Gui_show(message.(string))
                sh = append(sh, message)
        }
        if message_jpn != nil && message.(string) != message_jpn.(string) && message_jpn.(string) != "" {
                fmt.Println(message_jpn)
-               Qtshow(message_jpn.(string))
+               Gui_show(message_jpn.(string))
                sh = append(sh, message_jpn)
        }
        fmt.Print("====\n\n")
        
        {//额外
                Assf(fmt.Sprintln(sh...))
-               Qtshow("====\n")
+               Gui_show("====\n")
        }
        msglog.Base(1, "礼").Fileonly(true).I(sh...).Fileonly(false)
 }
@@ -502,7 +502,7 @@ func (replyF) danmu(s string) {
                {//附加功能 弹幕机 封禁 弹幕合并
                        Danmujif(msg)
                        if Autobanf(msg) {
-                               Qtshow(Itos([]interface{}{"风险", auth, ":", msg}))
+                               Gui_show(Itos([]interface{}{"风险", auth, ":", msg}))
                                fmt.Println("风险", auth, ":", msg)
                                msglog.Base(1, "风险").I(auth, ":", msg)
                                return
@@ -537,16 +537,16 @@ func Msg_showdanmu(auth interface{}, msg string) {
                        return
                } else {msg = _msg}
                Assf(msg)//ass
-               Qtshow(msg)
+               Gui_show(msg)
        }
        
        fmt.Println(msg)
        if auth != nil {msglog.I(auth, ":", msg)}
 }
 
-func Qtshow(m string){
-       if !QtOn {return}
-       QtDanmuChan <- m
+func Gui_show(m string){
+       if QtOn {QtDanmuChan <- m}
+       if Gtk_on {Gtk_danmuChan <- m}
 }
 
 func Itos(i []interface{}) string {
diff --git a/Reply/gtk.go b/Reply/gtk.go
new file mode 100644 (file)
index 0000000..4a2bde0
--- /dev/null
@@ -0,0 +1,127 @@
+package reply
+
+import (
+       "container/list"
+       "errors"
+       "log"
+       "os"
+
+       "github.com/gotk3/gotk3/glib"
+       "github.com/gotk3/gotk3/gtk"
+)
+
+const appId = "com.github.qydysky.bili_danmu.reply"
+var BList = list.New()
+
+var (
+       Gtk_on bool
+       Gtk_danmuChan chan string = make(chan string, 10)
+)
+
+func Gtk_danmu() {
+       if Gtk_on {return}
+
+       application, err := gtk.ApplicationNew(appId, glib.APPLICATION_FLAGS_NONE)
+       if err != nil {return}
+
+       application.Connect("startup", func() {
+               log.Println("application startup")      
+
+               builder, err := gtk.BuilderNewFromFile("ui/1.glade")
+               if err != nil {return}
+
+               signals := map[string]interface{}{
+                       "on_main_window_destroy": onMainWindowDestroy,
+               }
+               builder.ConnectSignals(signals)
+
+               obj, err := builder.GetObject("main_window")
+               if err != nil {return}
+
+
+
+               win, err := isWindow(obj)
+               if err != nil {return}
+
+               var scrolledwindow0 *gtk.ScrolledWindow
+               {
+                       obj, err := builder.GetObject("scrolledwindow0")
+                       if err != nil {return}
+                       if tmp,ok := obj.(*gtk.ScrolledWindow); ok {
+                               scrolledwindow0 = tmp
+                       }
+               }
+
+               var grid0 *gtk.Grid;
+               {
+                       obj, err := builder.GetObject("grid0")
+                       if err != nil {return}
+                       if tmp,ok := obj.(*gtk.Grid); ok {
+                               grid0 = tmp
+                       }
+               }
+
+               var y func()
+               y = func(){
+                       s:=<-Gtk_danmuChan
+                       t,_ := gtk.TextViewNew();
+                       t.SetEditable(false)
+                       t.SetHExpand(true)
+                       t.SetVExpand(false)
+                       t.SetWrapMode(gtk.WRAP_WORD_CHAR)
+                       var handle glib.SignalHandle
+                       handle,_ = t.Connect("size-allocate", func(){
+                               b,e := t.GetBuffer()
+                               if e != nil {return}
+                               b.SetText(s)
+                               t.HandlerDisconnect(handle)
+
+                               tmp := scrolledwindow0.GetVAdjustment()
+                               tmp.SetValue(tmp.GetUpper())
+                               if len(Gtk_danmuChan) != 0 {y()}
+                       })
+                       
+                       tmp,_ := t.Container.Widget.Cast()
+                       loc := int(grid0.Container.GetChildren().Length());
+                       grid0.InsertRow(loc);
+                       grid0.Attach(tmp, 0, loc, 1, 1)
+                       if loc > 50 {
+                               l,_ := grid0.GetChildAt(0, 0)
+                               l.ToWidget().Destroy()
+                               grid0.RemoveRow(0)
+                       }
+                       win.ShowAll()
+               }
+
+               glib.TimeoutAdd(uint(100), func() bool {
+                       if len(Gtk_danmuChan) != 0 {y()}
+                       
+                       return true
+               })
+               win.Show()
+               application.AddWindow(win)
+               Gtk_on = true
+       })
+
+       application.Connect("activate", func() {
+               log.Println("application activate")
+       })
+
+       application.Connect("shutdown", func() {
+               log.Println("application shutdown")     
+               Gtk_on = false
+       })
+
+       os.Exit(application.Run(nil))
+}
+
+func isWindow(obj glib.IObject) (*gtk.Window, error) {
+       if win, ok := obj.(*gtk.Window); ok {
+               return win, nil
+       }
+       return nil, errors.New("not a *gtk.Window")
+}
+
+func onMainWindowDestroy() {
+       log.Println("onMainWindowDestroy")
+}
index 31c41934113716c97406bb6c3e9666c9dc1a6c63..ba8b44341b0d8a2cf9f3b1d16ee62a7a33f134dc 100644 (file)
@@ -88,10 +88,11 @@ func Demo(roomid ...int) {
                                                        c.Roomid = api.Roomid
                                                        c.Live = api.Live
                                                        c.Cookie = f
-                                                       {//附加功能 弹幕机 直播流保存 Qt窗口
+                                                       {//附加功能 弹幕机 直播流保存 Qt窗口 Gtk窗口
                                                                reply.Danmuji_auto(1)
                                                                go reply.Saveflvf()
                                                                go reply.Qtdf()
+                                                               go reply.Gtkf()
                                                        }
                                                }
                                        }()
index 2541098a9ddab18f026a89f4f52a37a83f0e7204..3e472596140391dafb32a9b3a9f519f15b1acb53 100644 (file)
@@ -6,10 +6,10 @@
 呦钕
 菜
 垃圾
-媳妇的妹换衣服 点我
+媳妇的妹换衣服点我
 铭少籹
 来签名婕光了啊免费
 自拍洗造点浅
 不穿内騒
-打开看黄色
+打开看黄色
 0123456789
\ No newline at end of file
index af2d0ed55119a519a81d0c417795c3445795790a..fdcfe72a4b45dce2d7f0352f239d0bef47038052 100644 (file)
@@ -1,5 +1,6 @@
 {
-    "Qtd": true,
+    "Gtk": true,
+    "Qtd": false,
     "Saveflv": true,
     "Ass": true,
     "Obs": false,
index 21f70e555041950d71b588460338376579e9b90b..98c757e04cafaf02d337342ae33c04628ab89a9e 100644 (file)
@@ -5,6 +5,7 @@ go 1.14
 require (
        github.com/christopher-dG/go-obs-websocket v0.0.0-20200720193653-c4fed10356a5 // indirect
        github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
+       github.com/gotk3/gotk3 v0.5.0 // indirect
        github.com/klauspost/compress v1.11.1 // indirect
        github.com/mitchellh/mapstructure v1.3.3 // indirect
        github.com/qydysky/bili_danmu v0.0.0
index fd236c82a7dfea37471105d37251cab736148ad9..2d828dcaef1f80847c72ef46c7d637b27b9e28d1 100644 (file)
@@ -13,6 +13,8 @@ github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORR
 github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
 github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
 github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
+github.com/gotk3/gotk3 v0.5.0 h1:GOkq4cFgAfeK6YAukLi64bz8zPayZKeCSSRr4mcFReQ=
+github.com/gotk3/gotk3 v0.5.0/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q=
 github.com/klauspost/compress v1.10.10/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
 github.com/klauspost/compress v1.11.0 h1:wJbzvpYMVGG9iTI9VxpnNZfd4DzMPoCWze3GgSqz8yg=
 github.com/klauspost/compress v1.11.0/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
diff --git a/demo/ui/1.glade b/demo/ui/1.glade
new file mode 100644 (file)
index 0000000..abc1796
--- /dev/null
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
+<interface>
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkWindow" id="main_window">
+    <property name="can_focus">False</property>
+    <property name="window_position">mouse</property>
+    <property name="default_width">400</property>
+    <property name="default_height">500</property>
+    <child>
+      <placeholder/>
+    </child>
+    <child>
+      <object class="GtkScrolledWindow" id="scrolledwindow0">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="hscrollbar_policy">never</property>
+        <child>
+          <object class="GtkViewport">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="shadow_type">none</property>
+            <child>
+              <object class="GtkGrid" id="grid0">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="orientation">vertical</property>
+                <child>
+                  <placeholder/>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>