本文整理汇总了Golang中github.com/sqp/godock/libs/cdtype.Events类的典型用法代码示例。如果您正苦于以下问题:Golang Events类的具体用法?Golang Events怎么用?Golang Events使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Events类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewApplet
// NewApplet creates a new applet instance.
//
func NewApplet(base cdtype.AppBase, events *cdtype.Events) cdtype.AppInstance {
app := &Applet{AppBase: base}
app.SetConfig(&app.conf)
// Events.
events.OnClick = app.Command().Callback(cmdLeft) // Left and middle click: launch the configured action.
events.OnMiddleClick = app.Command().Callback(cmdMiddle)
events.OnBuildMenu = func(menu cdtype.Menuer) {
if app.conf.LeftAction > 0 && app.conf.LeftCommand != "" {
menu.AddEntry("Action left click", "system-run", app.Command().Callback(cmdLeft))
}
if app.conf.MiddleAction > 0 && app.conf.MiddleCommand != "" {
menu.AddEntry("Action middle click", "system-run", app.Command().Callback(cmdMiddle))
}
}
// Memory service.
app.Poller().Add(app.GetMemActivity)
app.service.App = app
app.service.Texts = map[cdtype.InfoPosition]sysinfo.RenderOne{
cdtype.InfoNone: {},
cdtype.InfoOnIcon: {Sep: "\n", ShowPre: false},
cdtype.InfoOnLabel: {Sep: " - ", ShowPre: true},
}
return app
}
示例2: NewApplet
// NewApplet creates a new applet instance.
//
func NewApplet(base cdtype.AppBase, events *cdtype.Events) cdtype.AppInstance {
app := &Applet{AppBase: base}
app.SetConfig(&app.conf, app.actions()...)
// Events.
events.OnClick = func() { app.Action().Launch(app.Action().ID(app.conf.ActionClickLeft)) }
events.OnMiddleClick = func() { app.Action().Launch(app.Action().ID(app.conf.ActionClickMiddle)) }
events.OnBuildMenu = func(menu cdtype.Menuer) {
switch {
case !app.data.IsValid(): // No running loop = no registration. User will do as expected !
app.Action().BuildMenu(menu, menuRegister)
case app.Window().IsOpened(): // Monitored application opened.
app.Action().BuildMenu(menu, menuFull[1:]) // Drop "Open client" option, already provided as window action by the dock.
default:
app.Action().BuildMenu(menu, menuFull)
}
}
// Prepare mailbox with the display callback that will receive update info.
app.data = NewFeed(app.updateDisplay)
// The poller will check for new mails on a timer, with a small emblem during the polling.
poller := app.Poller().Add(app.data.Check)
poller.SetPreCheck(func() {
app.SetEmblem(app.FileLocation("img", "go-down.svg"), cdtype.EmblemTopLeft)
app.Log().Debug("Check mails")
})
poller.SetPostCheck(func() { app.SetEmblem("none", cdtype.EmblemTopLeft) })
return app
}
示例3: NewApplet
// NewApplet creates a new applet instance.
//
func NewApplet(base cdtype.AppBase, events *cdtype.Events) cdtype.AppInstance {
app := &Applet{AppBase: base, weather: weather.New()}
app.SetConfig(&app.conf, app.actions()...)
// Events.
events.OnClick = app.DialogWeatherCurrent
events.OnMiddleClick = app.DialogWeatherCurrent
events.OnSubClick = app.DialogWeatherForecast
events.OnBuildMenu = func(menu cdtype.Menuer) {
var items []int
if app.weather.Current() != nil || app.weather.Forecast() != nil {
if app.weather.Current() != nil {
items = append(items, ActionShowCurrent)
}
items = append(items, ActionOpenWebpage, ActionRecheckNow)
}
items = append(items, ActionSetLocation)
app.Action().BuildMenu(menu, items)
}
// Weather polling.
app.Poller().Add(app.Check)
app.Poller().SetPreCheck(func() { app.SetEmblem(app.FileLocation("img", IconWork), EmblemWork) })
app.Poller().SetPostCheck(func() { app.SetEmblem("none", EmblemWork) })
return app
}
示例4: NewApplet
// NewApplet creates a new applet instance.
//
func NewApplet(base cdtype.AppBase, events *cdtype.Events) cdtype.AppInstance {
app := &Applet{AppBase: base}
app.SetConfig(&app.conf, app.actions()...)
app.Action().SetMax(1)
// Events
events.OnClick = app.onClick
events.OnMiddleClick = app.onMiddleClick
events.OnScroll = app.onScroll
events.OnBuildMenu = app.onBuildMenu
events.OnDropData = app.GrepTarget
// Create a cairo-dock sources version checker.
app.version = versions.NewVersions(app.onGotVersions)
// The poller will check for new versions on a timer.
poller := app.Poller().Add(app.version.Check)
// Set "working" emblem during version check. It should be removed or changed by the check.
poller.SetPreCheck(func() { app.SetEmblem(app.FileLocation("img", app.conf.VersionEmblemWork), EmblemVersion) })
poller.SetPostCheck(func() {
for _, v := range app.version.Sources() {
v.Log = strhelp.EscapeGtk(v.Log) // Escape <>&
}
})
return app
}
示例5: NewApplet
// NewApplet creates a new applet instance.
//
func NewApplet(base cdtype.AppBase, events *cdtype.Events) cdtype.AppInstance {
app := &Applet{AppBase: base}
app.SetConfig(&app.conf)
// Events.
events.OnClick = app.Command().Callback(cmdLeft)
events.OnMiddleClick = app.Command().Callback(cmdMiddle)
events.OnBuildMenu = func(menu cdtype.Menuer) {
if app.conf.LeftAction > 0 && app.conf.LeftCommand != "" {
menu.AddEntry("Action left click", "system-run", app.Command().Callback(cmdLeft))
}
if app.conf.MiddleAction > 0 && app.conf.MiddleCommand != "" {
menu.AddEntry("Action middle click", "system-run", app.Command().Callback(cmdMiddle))
}
}
app.service = sysinfo.NewIOActivity(app)
app.service.Log = app.Log()
app.service.FormatIcon = formatIcon
app.service.FormatLabel = formatLabel
app.service.GetData = sysinfo.GetDiskActivity
app.Poller().Add(app.service.Check)
return app
}
示例6: NewApplet
// NewApplet create a new applet instance.
//
// It will be trigered remotely by the dock when the applet icon is created.
// Only called once for each running instance.
//
// The goal is to:
// -Create and fill the applet struct.
// -Set the config pointer, and maybe some actions.
// -Register (dock to) applet events (See cdtype.Events for the full list).
// -Declare and load permanent items required during all the applet lifetime.
// (those who do not require a config setting, unless it's in a callback).
//
func NewApplet(base cdtype.AppBase, events *cdtype.Events) cdtype.AppInstance {
app := &Applet{AppBase: base}
app.SetConfig(&app.conf)
// Events.
// Forward click events to the defined command launcher.
events.OnClick = app.Command().Callback(cmdClickLeft)
events.OnMiddleClick = app.Command().Callback(cmdClickMiddle)
// For simple callbacks event, use a closure.
events.OnDropData = func(data string) {
app.Log().Info("dropped", data)
}
events.OnBuildMenu = func(menu cdtype.Menuer) { // Another closure.
menu.AddEntry("disabled entry", "icon-name", nil)
menu.AddSeparator()
menu.AddEntry("my action", "system-run", func() {
app.Log().Info("clicked")
})
}
events.OnScroll = app.myonScroll // Or use another function with the same args.
//
// Create and set your other permanent items here...
return app
}
示例7: NewApplet
// NewApplet creates a new applet instance.
//
func NewApplet(base cdtype.AppBase, events *cdtype.Events) cdtype.AppInstance {
app := &Applet{AppBase: base}
app.SetConfig(&app.conf)
// Events.
events.OnClick = app.Command().Callback(cmdLeft)
events.OnMiddleClick = app.Command().Callback(cmdMiddle)
events.OnBuildMenu = app.buildMenu
events.End = func() { app.video.WebUnregister() }
events.OnDropData = func(data string) {
if strings.HasPrefix(data, "http://") || strings.HasPrefix(data, "https://") {
if app.conf.VideoDLEnabled {
app.DownloadVideo(data)
}
} else {
app.UpToShareUpload(data)
}
}
// Uptoshare actions
app.up = uptoshare.New()
app.up.Log = app.Log()
app.up.SetPreCheck(func() { app.SetEmblem(app.FileLocation("icon"), EmblemAction) })
app.up.SetPostCheck(func() { app.SetEmblem("none", EmblemAction) })
app.up.SetOnResult(app.onUploadDone)
// Network activity actions.
app.service = sysinfo.NewIOActivity(app)
app.service.Log = app.Log()
app.service.FormatIcon = sysinfo.FormatIcon
app.service.FormatLabel = formatLabel
app.service.GetData = sysinfo.GetNetActivity
app.Poller().Add(app.service.Check)
// Video download actions.
ActionsVideoDL := 0
hist := videodl.NewHistoryVideo(app, videodl.HistoryFile)
app.video = videodl.NewManager(app, app.Log(), hist)
app.video.SetPreCheck(func() error { return app.SetEmblem(app.FileLocation("img", "go-down.svg"), EmblemDownload) })
app.video.SetPostCheck(func() error { return app.SetEmblem("none", EmblemDownload) })
app.video.Actions(ActionsVideoDL, app.Action().Add)
app.video.WebRegister()
hist.Load()
return app
}
示例8: NewApplet
// NewApplet creates a new applet instance.
//
func NewApplet(base cdtype.AppBase, events *cdtype.Events) cdtype.AppInstance {
app := &Applet{AppBase: base, notifs: &Notifs{}}
app.SetConfig(&app.conf, app.actions()...)
// Events.
events.OnClick = app.Action().Callback(ActionShowAll)
events.OnMiddleClick = app.Action().Callback(ActionClear)
events.OnBuildMenu = app.Action().CallbackMenu(menuUser)
// Notifs.
app.notifs.SetOnCount(app.UpdateCount)
e := app.notifs.Start()
app.Log().Err(e, "notifications listener")
return app
}
示例9: NewApplet
// NewApplet creates a new applet instance.
//
func NewApplet(base cdtype.AppBase, events *cdtype.Events) cdtype.AppInstance {
app := &Applet{AppBase: base}
app.SetConfig(&app.conf)
// Events.
events.OnClick = app.onClick
events.OnMiddleClick = app.onMiddleClick
events.OnScroll = app.onScroll
events.OnBuildMenu = app.onBuildMenu
events.OnSubMiddleClick = app.onSubMiddleClick
events.OnSubScroll = app.onSubScroll
events.OnSubBuildMenu = app.onSubBuildMenu
// Pulseaudio service.
log = app.Log()
var e error
app.pulse, e = NewAppPulse(app)
if log.Err(e, "pulseaudio dbus") {
return nil
}
return app
}
示例10: NewApplet
// NewApplet creates a new applet instance.
//
func NewApplet(base cdtype.AppBase, events *cdtype.Events) cdtype.AppInstance {
app := &Applet{AppBase: base}
app.SetConfig(&app.conf, app.actions()...)
// Events.
events.OnClick = func() { // Left click: open and manage the gui window.
if app.Window().IsOpened() { // Window opened.
app.Window().ToggleVisibility()
} else {
app.createGui(true, true)
}
}
events.OnMiddleClick = func() { app.Action().Launch(app.Action().ID(app.conf.ActionClickMiddle)) }
events.OnScroll = func(scrollUp bool) {
var key int
switch app.conf.ActionMouseWheel {
case "Change volume":
key = ternary.Int(scrollUp, int(upnptype.ActionVolumeUp), int(upnptype.ActionVolumeDown))
case "Seek in track":
key = ternary.Int(scrollUp, int(upnptype.ActionSeekForward), int(upnptype.ActionSeekBackward))
}
app.Action().Launch(key)
}
events.OnBuildMenu = app.Action().CallbackMenu(dockMenu)
events.End = func() {
if app.win != nil {
glib.IdleAdd(app.win.Destroy)
}
}
// Create the UPnP device manager.
var e error
app.cp, e = gupnp.New(&logger{app.Log()})
app.Log().Err(e, "temp Dir")
// Connect local tests.
hook := app.cp.SubscribeHook("applet")
hook.OnRendererFound = app.onMediaRendererFound
hook.OnServerFound = app.onMediaServerFound
hook.OnRendererLost = app.onMediaRendererLost
hook.OnServerLost = app.onMediaServerLost
// hook.OnRendererSelected = gui.SetRenderer
// hook.OnServerSelected = gui.SetServer
// hook.OnTransportState = func(r upnptype.Renderer, state upnptype.PlaybackState) { gui.SetPlaybackState(state) }
// hook.OnCurrentTrackDuration = func(r upnptype.Renderer, dur int) { gui.SetDuration(mediacp.TimeToString(dur)) }
// hook.OnCurrentTrackMetaData = func(r upnptype.Renderer, item upnptype.Item) { gui.SetTitle(item.Title) }
// hook.OnMute = func(r upnptype.Renderer, muted bool) { gui.SetMuted(muted) }
// hook.OnVolume = func(r upnptype.Renderer, vol uint) { gui.SetVolume(int(vol)) }
// hook.OnCurrentTime = func(r upnptype.Renderer, secs int, f float64) { gui.SetCurrentTime(secs, f*100) }
// hook.OnSetVolumeDelta = func(delta int) { gui.SetVolumeDelta(delta) }
// }
// Connect an UPnP backend to the manager.
// mgr := backendsonos.NewManager(&logger{app.Log()})
// mgr.SetEvents(app.cp.DefineEvents())
// go mgr.Start(true)
cp := backendgupnp.NewControlPoint()
cp.SetEvents(app.cp.DefineEvents())
return app
}