From 45cd6814cb79d8091d45fa7cae6eedfd4f1f8190 Mon Sep 17 00:00:00 2001 From: qydysky Date: Fri, 23 Oct 2020 15:00:35 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8D=E8=87=B4=E5=91=BD=E9=94=99?= =?utf8?q?=E8=AF=AFSIGSEGV?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Reply/F.go | 4 +- Reply/gtk.go | 232 +++++++++++++++++++++++++++------------------ demo/config_F.json | 4 +- demo/go.mod | 2 +- demo/go.sum | 2 + 5 files changed, 146 insertions(+), 98 deletions(-) diff --git a/Reply/F.go b/Reply/F.go index 1618aee..23f5514 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -33,7 +33,7 @@ var AllF = map[string]bool{ obs https://obsproject.com/download obs-websocket https://github.com/Palakis/obs-websocket/releases */ - "Autoban":true,//自动封禁(仅提示,未完成) + "Autoban":false,//自动封禁(仅提示,未完成) "Jiezou":true,//带节奏预警,提示弹幕礼仪 "Danmuji":true,//反射型弹幕机,回应弹幕 "Danmuji_auto":false,//自动型弹幕机,定时输出 @@ -154,7 +154,7 @@ var qtd = Qtd { func Qtdf(){ if !IsOn("Qtd") {return} - go Qtdanmu() + Qtdanmu() } //Ass 弹幕转字幕 diff --git a/Reply/gtk.go b/Reply/gtk.go index 263d508..defea9c 100644 --- a/Reply/gtk.go +++ b/Reply/gtk.go @@ -13,136 +13,181 @@ import ( ) const appId = "com.github.qydysky.bili_danmu.reply" -var BTList = list.New() -var BIList = list.New() +type gtk_list struct { + text *gtk.TextView + img *gtk.Image + handle glib.SignalHandle +} + +type gtk_get struct { + src string + uid string +} +var gtkGetList = list.New() +var imgbuf = make(map[string](*gdk.Pixbuf)) var ( Gtk_on bool Gtk_Tra bool Gtk_img_path string = "face" - Gtk_danmuChan chan string = make(chan string, 100) - Gtk_danmuChan_uid chan string = make(chan string, 100) + Gtk_danmuChan chan string = make(chan string, 1000) + Gtk_danmuChan_uid chan string = make(chan string, 1000) ) func Gtk_danmu() { if Gtk_on {return} + var y func(string,string) + var win *gtk.Window + var scrolledwindow0 *gtk.ScrolledWindow + var viewport0 *gtk.Viewport + application, err := gtk.ApplicationNew(appId, glib.APPLICATION_FLAGS_NONE) - if err != nil {return} + if err != nil {log.Println(err);return} application.Connect("startup", func() { log.Println("application startup") + var grid0 *gtk.Grid; builder, err := gtk.BuilderNewFromFile("ui/1.glade") - if err != nil {return} + if err != nil {log.Println(err);return} - signals := map[string]interface{}{ - "on_main_window_destroy": onMainWindowDestroy, + { + signals := map[string]interface{}{ + "on_main_window_destroy": onMainWindowDestroy, + } + builder.ConnectSignals(signals) + } + { + obj, err := builder.GetObject("main_window") + if err != nil {log.Println(err);return} + win, err = isWindow(obj) + if err != nil {log.Println(err);return} + application.AddWindow(win) + defer win.ShowAll() } - 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 err != nil {log.Println(err);return} if tmp,ok := obj.(*gtk.ScrolledWindow); ok { scrolledwindow0 = tmp - } + }else{log.Println("cant find #scrolledwindow0 in .glade");return} } - var viewport0 *gtk.Viewport { obj, err := builder.GetObject("viewport0") - if err != nil {return} + if err != nil {log.Println(err);return} if tmp,ok := obj.(*gtk.Viewport); ok { viewport0 = tmp - } + }else{log.Println("cant find #viewport0 in .glade");return} } - var grid0 *gtk.Grid; { obj, err := builder.GetObject("grid0") - if err != nil {return} + if err != nil {log.Println(err);return} if tmp,ok := obj.(*gtk.Grid); ok { grid0 = tmp - } + }else{log.Println("cant find #grid0 in .glade");return} } - var y func(bool) - y = func(tra bool){ - Gtk_Tra = true - - s:=<-Gtk_danmuChan - t,_ := gtk.TextViewNew(); - BTList.PushBack(t) - t.SetMarginStart(5) - t.SetEditable(false) - t.SetHExpand(true) - t.SetVExpand(false) - t.SetWrapMode(gtk.WRAP_WORD_CHAR) + imgbuf["face/0default"],_ = gdk.PixbufNewFromFileAtSize("face/0default", 40, 40); + + y = func(s,img_src string){ + var tmp_list gtk_list + + tmp_list.text,_ = gtk.TextViewNew(); + { + tmp_list.text.SetMarginStart(5) + tmp_list.text.SetEditable(false) + tmp_list.text.SetHExpand(true) + tmp_list.text.SetWrapMode(gtk.WRAP_WORD_CHAR) + } + { + var e error + tmp_list.handle,e = tmp_list.text.Connect("size-allocate", func(){ + + b,e := tmp_list.text.GetBuffer() + if e != nil {log.Println(e);return} + b.SetText(s) + + { + var e error + tmp := scrolledwindow0.GetVAdjustment() + h := viewport0.GetViewWindow().WindowGetHeight() + if tmp.GetUpper() - tmp.GetValue() < float64(h) * 1.3 { + tmp.SetValue(tmp.GetUpper() - float64(h)) + } + if e != nil {log.Println(e)} + } + }) + if e != nil {log.Println(e)} + } + + tmp_list.img,_ =gtk.ImageNew(); + { + var pixbuf *gdk.Pixbuf + if v,ok := imgbuf[img_src];ok{ + pixbuf,_ = gdk.PixbufCopy(v) + } else { + pixbuf,_ = gdk.PixbufNewFromFileAtSize(img_src, 40, 40); + imgbuf[img_src],_ = gdk.PixbufCopy(pixbuf) + } + tmp_list.img.SetFromPixbuf(pixbuf) + } + { + loc := int(grid0.Container.GetChildren().Length())/2; + grid0.InsertRow(loc); + grid0.Attach(tmp_list.img, 0, loc, 1, 1) + grid0.Attach(tmp_list.text, 1, loc, 1, 1) + + for loc > 50 { + + if i,e := grid0.GetChildAt(0,0); e != nil{i.(*gtk.Widget).Destroy()} + if i,e := grid0.GetChildAt(1,0); e != nil{i.(*gtk.Widget).Destroy()} + grid0.RemoveRow(0) + loc = int(grid0.Container.GetChildren().Length())/2; + } + } - img,_ :=gtk.ImageNew(); - BIList.PushBack(img) - - var handle glib.SignalHandle - handle,_ = t.Connect("size-allocate", func(){ - Gtk_Tra = false - b,e := t.GetBuffer() - if e != nil {return} - b.SetText(s) - - img_src := load_face(<-Gtk_danmuChan_uid) - pixbuf,e := gdk.PixbufNewFromFileAtSize(img_src, 40, 40); - if e != nil {return} - img.SetFromPixbuf(pixbuf) - t.HandlerDisconnect(handle) - - if tra { - handle,_ = t.Connect("size-allocate", func(){ - tmp := scrolledwindow0.GetVAdjustment() - tmp.SetValue(tmp.GetUpper()) - t.HandlerDisconnect(handle) - }) + glib.TimeoutAdd(uint(3000), func()(o bool){ + o = true + + if gtkGetList.Len() == 0 {return} + el := gtkGetList.Front() + if el == nil {return} + if tmp_get,ok := gtkGetList.Remove(el).(gtk_get);ok{ + req := p.Req() + if e := req.Reqf(p.Rval{ + Url:tmp_get.src, + SaveToPath:Gtk_img_path + `/` + tmp_get.uid, + Timeout:3, + }); e != nil{log.Println(e);} } - if len(Gtk_danmuChan) != 0 {y(tra)} + + { + if len(imgbuf) > 100 { + for k,_ := range imgbuf {delete(imgbuf,k);break} + } + } + return }) - tmp,_ := t.Container.Widget.Cast() - loc := BTList.Len(); - grid0.InsertRow(loc); - grid0.Attach(img, 0, loc - 1, 1, 1) - grid0.Attach(tmp, 1, loc - 1, 1, 1) - for tra && BTList.Len() > 50 { - BTList.Remove(BTList.Front()).(*gtk.TextView).Destroy() - BIList.Remove(BIList.Front()).(*gtk.Image).Destroy() - grid0.RemoveRow(0) - } win.ShowAll() } - glib.TimeoutAdd(uint(100), func() bool { - if !Gtk_Tra && len(Gtk_danmuChan) != 0 { - tmp := scrolledwindow0.GetVAdjustment() - h := viewport0.GetViewWindow().WindowGetHeight() - y(tmp.GetUpper() - tmp.GetValue() < float64(h) * 1.3) - } - return true - }) - win.Show() - application.AddWindow(win) Gtk_on = true }) application.Connect("activate", func() { log.Println("application activate") + glib.TimeoutAdd(uint(300),func()(o bool){ + o = true + for len(Gtk_danmuChan) != 0 { + y(<-Gtk_danmuChan,load_face(<-Gtk_danmuChan_uid)) + } + return + }) + }) application.Connect("shutdown", func() { @@ -164,17 +209,18 @@ func onMainWindowDestroy() { log.Println("onMainWindowDestroy") } -func load_face(uid string) string { - defaultuid := "0default" - if uid != "" && p.Checkfile().IsExist(Gtk_img_path + `/` + uid) {return Gtk_img_path + `/` + uid} +func load_face(uid string) (loc string) { + loc = Gtk_img_path + `/` + "0default" + if uid != "" && p.Checkfile().IsExist(Gtk_img_path + `/` + uid) && p.Rand().MixRandom(1,100) > 5 { + loc = Gtk_img_path + `/` + uid + return + } if src := F.Get_face_src(uid);src != "" { - req := p.Req() - if e := req.Reqf(p.Rval{ - Url:src, - SaveToPath:Gtk_img_path + `/` + uid, - Timeout:3, - }); e != nil{log.Println(e);return Gtk_img_path + `/` + defaultuid} - return Gtk_img_path + `/` + uid + if gtkGetList.Len() > 1000 {return} + gtkGetList.PushBack(gtk_get{ + src:src, + uid:uid, + }) } - return Gtk_img_path + `/` + defaultuid + return } \ No newline at end of file diff --git a/demo/config_F.json b/demo/config_F.json index fdcfe72..944a7bc 100644 --- a/demo/config_F.json +++ b/demo/config_F.json @@ -1,10 +1,10 @@ { "Gtk": true, "Qtd": false, - "Saveflv": true, + "Saveflv": false, "Ass": true, "Obs": false, - "Autoban": true, + "Autoban": false, "Jiezou": true, "Danmuji": true, "Danmuji_auto": false, diff --git a/demo/go.mod b/demo/go.mod index 98c757e..6514f70 100644 --- a/demo/go.mod +++ b/demo/go.mod @@ -9,7 +9,7 @@ require ( github.com/klauspost/compress v1.11.1 // indirect github.com/mitchellh/mapstructure v1.3.3 // indirect github.com/qydysky/bili_danmu v0.0.0 - github.com/qydysky/part v0.0.7 // indirect + github.com/qydysky/part v0.0.8 // indirect github.com/shirou/gopsutil v2.20.9+incompatible // indirect github.com/therecipe/env_darwin_amd64_513 v0.0.0-20190626001412-d8e92e8db4d0 // indirect github.com/therecipe/env_linux_amd64_513 v0.0.0-20190626000307-e137a3934da6 // indirect diff --git a/demo/go.sum b/demo/go.sum index 2d828dc..5edccbc 100644 --- a/demo/go.sum +++ b/demo/go.sum @@ -86,6 +86,8 @@ github.com/qydysky/part v0.0.6 h1:DEIziO8d9PT+E1OIij3Ua0H8vO9Z5yqCJGb3m8BOGL0= github.com/qydysky/part v0.0.6/go.mod h1:+8N3UgJBVyJj8ar31eZtucwrKpLpay854Y5qq0xk3x0= github.com/qydysky/part v0.0.7 h1:nT7Y5WIMvKv/AhW+AyQJ+RccMO5zAML9SZZyCeWZs24= github.com/qydysky/part v0.0.7/go.mod h1:+8N3UgJBVyJj8ar31eZtucwrKpLpay854Y5qq0xk3x0= +github.com/qydysky/part v0.0.8 h1:W7icXUo22y1hewPev0u/H+DL+Ks0zP58HjrhVBaRgco= +github.com/qydysky/part v0.0.8/go.mod h1:+8N3UgJBVyJj8ar31eZtucwrKpLpay854Y5qq0xk3x0= github.com/shirou/gopsutil v2.20.7+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/gopsutil v2.20.8+incompatible h1:8c7Atn0FAUZJo+f4wYbN0iVpdWniCQk7IYwGtgdh1mY= github.com/shirou/gopsutil v2.20.8+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -- 2.39.2