timed

package module
v0.0.0-...-567dd5d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2019 License: MIT Imports: 17 Imported by: 0

README

Timed

WORK IN PROGRESS

This is a package for dealing with the GNOME Timed Wallpaper XML and Simple Timed Wallpaper (STW) files.

The Simple Timed Wallpaper Format

STW is a format for a configuration file that specifies in which time ranges wallpapers should change from one to another, and with which transition.

It's a similar to the GNOME timed wallpaper XML format, but much simpler and less verbose.

Go module

GoDoc

The timed Go module can be used for parsing the file format and for running an event loop for setting the wallpaper, given a function with this signature:

func(string) error

Where the given string is the image filename to be set.

General info

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommonPrefix

func CommonPrefix(sl []string) string

CommonPrefix will find the longest common prefix in a slice of strings

func CommonSuffix

func CommonSuffix(sl []string) string

CommonPrefix will find the longest common suffix in a slice of strings

func GnomeFileToSimpleString

func GnomeFileToSimpleString(filename string) (string, error)

GnomeFileToSimpleString reads and parses an XML file, then returns a string representing the contents of a Simple Timed Wallpaper file.

func GnomeToSimpleString

func GnomeToSimpleString(gtw *FatWallpaper) (string, error)

GnomeToSimpleString converts a Gnome Timed Wallpaper to a string representing a Simple Timed Wallpaper. The Path field in the given struct is not included in the output string.

func Meat

func Meat(s, prefix, suffix string) string

Meat returns the meat of the string: the part that is after the prefix and before the suffix. Will return the given string if it is too short to contain the prefix and suffix.

Types

type FatWallpaper

type FatWallpaper struct {
	GNOME       bool
	Version     string
	Name        string
	Format      string
	Path        string // not part of the file data, but handy when parsing
	Statics     []*Static
	Transitions []*Transition
	LoopWait    time.Duration // how long the main event loop should sleep
	Config      *GBackground  // set to nil when not a GNOME timed wallpaper
}

FatWallpaper contains all data for either a Simple Timed Wallpaper or a GNOME Timed Wallpaper

func DataToSimple

func DataToSimple(path string, data []byte) (*FatWallpaper, error)

DataToSimple converts from the contents of a Simple Timed Wallpaper file to a Wallpaper structs. The given path is used in the error messages and for setting stw.Path.

func GnomeToSimple

func GnomeToSimple(gtw *FatWallpaper) (*FatWallpaper, error)

GnomeToSimple converts a Gnome Timed Wallpaper to a Simple Timed Wallpaper

func NewGnome

func NewGnome(name, path string, config *GBackground) *FatWallpaper

NewGnome creates a new Gnome Timed Wallpaper struct

func NewSimple

func NewSimple(version, name, format string) *FatWallpaper

NewSimple creates a new Simple Timed Wallpaper struct

func ParseSTW

func ParseSTW(filename string) (*FatWallpaper, error)
Example
stw, err := ParseSTW("testdata/adwaita-timed2.stw")
if err != nil {
	panic(err)
}
fmt.Println(stw.Name)

stw, err = ParseSTW("testdata/comments.stw")
if err != nil {
	panic(err)
}
fmt.Println(stw.Name)
Output:

adwaita-timed
comments

func ParseXML

func ParseXML(filename string) (*FatWallpaper, error)

Parse a Gnome XML file to a Wallpaper struct

Example
gtw, err := ParseXML("testdata/example1.xml")
if err != nil {
	panic(err)
}
fmt.Println(gtw.Config.StartTime.Year)
fmt.Println(gtw.Config.Transitions[0].ToFilename)

gtw, err = ParseXML("testdata/example2.xml")
if err != nil {
	panic(err)
}
fmt.Println(gtw.Config.StartTime.Year)

gtw, err = ParseXML("testdata/adwaita-timed.xml")
if err != nil {
	panic(err)
}
fmt.Println(gtw.Config.StartTime.Year)

gtw, err = ParseXML("testdata/generated.xml")
if err != nil {
	panic(err)
}
fmt.Println(gtw.Config.StartTime.Year)
Output:

2009
/usr/share/backgrounds/cosmos/comet.jpg
0
2011
2018

func (*FatWallpaper) AddStatic

func (fw *FatWallpaper) AddStatic(at time.Time, filename string)

func (*FatWallpaper) AddTransition

func (fw *FatWallpaper) AddTransition(from, upto time.Time, fromFilename, toFilename, transitionType string)

func (*FatWallpaper) EventLoop

func (fw *FatWallpaper) EventLoop(verbose bool, setWallpaperFunc func(string) error, tempImageFilename string) error

EventLoop will start the event loop for this Simple Timed Wallpaper

func (*FatWallpaper) Images

func (fw *FatWallpaper) Images() []string

func (*FatWallpaper) NextEvent

func (fw *FatWallpaper) NextEvent(now time.Time) (interface{}, error)

NextEvent finds the next event, given a timestamp. Returns an interface{} that is either a static or transition event.

func (*FatWallpaper) PrevEvent

func (fw *FatWallpaper) PrevEvent(now time.Time) (interface{}, error)

PrevEvent finds the previous event, given a timestamp. Returns an interface{} that is either a static or transition event.

func (*FatWallpaper) SetInitialWallpaper

func (fw *FatWallpaper) SetInitialWallpaper(verbose bool, setWallpaperFunc func(string) error, tempImageFilename string) error

SetInitialWallpaper will set the first wallpaper, before starting the event loop

func (*FatWallpaper) StartTime

func (fw *FatWallpaper) StartTime() time.Time

StartTime returns the timed wallpaper start time, as a time.Time

func (*FatWallpaper) String

func (fw *FatWallpaper) String() string

String builds a string with various information about this GNOME timed wallpaper

func (*FatWallpaper) UntilNext

func (fw *FatWallpaper) UntilNext(et time.Time) time.Duration

UntilNext finds the duration until the next event starts

type GBackground

type GBackground struct {
	XMLName     xml.Name      `xml:"background"`
	StartTime   GStartTime    `xml:"starttime"`
	Statics     []GStatic     `xml:"static"`
	Transitions []GTransition `xml:"transition"`
	// contains filtered or unexported fields
}

func (*GBackground) Get

func (gb *GBackground) Get(i int) (interface{}, error)

Get either a GStatic or a GTransition, given a total position. Will return nil and an error if nothing is found.

func (*GBackground) StaticOrder

func (gb *GBackground) StaticOrder(i int) (int, error)

StaticOrder finds the total position of a given GStatic position

func (*GBackground) String

func (gb *GBackground) String() string

func (*GBackground) TransitionOrder

func (gb *GBackground) TransitionOrder(i int) (int, error)

TransitionOrder finds the total position of a given GTransition position

type GStartTime

type GStartTime struct {
	XMLName xml.Name `xml:"starttime"`
	Year    int      `xml:"year"`
	Month   int      `xml:"month"`
	Day     int      `xml:"day"`
	Hour    int      `xml:"hour"`
	Minute  int      `xml:"minute"`
	Second  int      `xml:"second"`
}

type GStatic

type GStatic struct {
	XMLName  xml.Name `xml:"static"`
	Seconds  float64  `xml:"duration"`
	Filename string   `xml:"file"`
}

func (*GStatic) Duration

func (s *GStatic) Duration() time.Duration

Duration returns how long a static wallpaper should last

type GTransition

type GTransition struct {
	XMLName      xml.Name `xml:"transition"`
	Type         string   `xml:"type,attr,omitempty"`
	Seconds      float64  `xml:"duration"`
	FromFilename string   `xml:"from"`
	ToFilename   string   `xml:"to"`
}

func (*GTransition) Duration

func (t *GTransition) Duration() time.Duration

Duration returns how long a transition should last

type Static

type Static struct {
	At       time.Time
	Filename string
}

func (*Static) String

func (s *Static) String(format string) string

type StaticMap

type StaticMap map[int]int

type Transition

type Transition struct {
	From         time.Time
	UpTo         time.Time
	FromFilename string
	ToFilename   string
	Type         string
}

func (*Transition) Duration

func (t *Transition) Duration() time.Duration

func (*Transition) String

func (t *Transition) String(format string) string

type TransitionMap

type TransitionMap map[int]int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL