From b55de44847228065a4aec98d2d310153a7ade3ed Mon Sep 17 00:00:00 2001 From: qydysky Date: Sun, 18 Oct 2020 22:00:19 +0800 Subject: [PATCH] =?utf8?q?gtk=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Reply/F.go | 8 ++- Reply/Reply.go | 56 ++++++++++----------- Reply/gtk.go | 127 +++++++++++++++++++++++++++++++++++++++++++++++ bili_danmu.go | 3 +- demo/Autoban.txt | 4 +- demo/config.json | 3 +- demo/go.mod | 1 + demo/go.sum | 2 + demo/ui/1.glade | 38 ++++++++++++++ 9 files changed, 209 insertions(+), 33 deletions(-) create mode 100644 Reply/gtk.go create mode 100644 demo/ui/1.glade diff --git a/Reply/F.go b/Reply/F.go index d2b526a..1a45348 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -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 { diff --git a/Reply/Reply.go b/Reply/Reply.go index f7c2322..0ef3123 100644 --- a/Reply/Reply.go +++ b/Reply/Reply.go @@ -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 index 0000000..4a2bde0 --- /dev/null +++ b/Reply/gtk.go @@ -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") +} diff --git a/bili_danmu.go b/bili_danmu.go index 31c4193..ba8b443 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -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() } } }() diff --git a/demo/Autoban.txt b/demo/Autoban.txt index 2541098..3e47259 100644 --- a/demo/Autoban.txt +++ b/demo/Autoban.txt @@ -6,10 +6,10 @@ 呦钕 菜 垃圾 -媳妇的妹换衣服 点我 +媳妇的妹换衣服点我 铭少籹 来签名婕光了啊免费 自拍洗造点浅 不穿内騒 -打开看黄色 +打开看黄色屎 0123456789 \ No newline at end of file diff --git a/demo/config.json b/demo/config.json index af2d0ed..fdcfe72 100644 --- a/demo/config.json +++ b/demo/config.json @@ -1,5 +1,6 @@ { - "Qtd": true, + "Gtk": true, + "Qtd": false, "Saveflv": true, "Ass": true, "Obs": false, diff --git a/demo/go.mod b/demo/go.mod index 21f70e5..98c757e 100644 --- a/demo/go.mod +++ b/demo/go.mod @@ -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 diff --git a/demo/go.sum b/demo/go.sum index fd236c8..2d828dc 100644 --- a/demo/go.sum +++ b/demo/go.sum @@ -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 index 0000000..abc1796 --- /dev/null +++ b/demo/ui/1.glade @@ -0,0 +1,38 @@ + + + + + + False + mouse + 400 + 500 + + + + + + True + True + never + + + True + False + none + + + True + False + vertical + + + + + + + + + + + -- 2.39.2