diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-02-06 06:32:52 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-02-06 06:32:52 (GMT) |
commit | a21503b001d5f6ee0616b143b417a9c8e22340a8 (patch) | |
tree | be79501e9534fda570559639c17ceb12a9c5f737 | |
parent | bd46682ce6c6cdee8a1aad61c0acb5ae4303bc9b (diff) |
refactoring
-rw-r--r-- | src/rhlibrary/app_window.go | 11 | ||||
-rw-r--r-- | src/rhlibrary/player_widget.go | 12 | ||||
-rw-r--r-- | src/rhlibrary/selector_widget.go | 22 | ||||
-rw-r--r-- | src/rhlibrary/show_selector_widget.go | 47 | ||||
-rw-r--r-- | src/rhlibrary/vumeter_widget.go | 22 | ||||
-rw-r--r-- | src/rhlibrary/widget_common.go | 45 |
6 files changed, 55 insertions, 104 deletions
diff --git a/src/rhlibrary/app_window.go b/src/rhlibrary/app_window.go index 2ed4c6a..d6a428d 100644 --- a/src/rhlibrary/app_window.go +++ b/src/rhlibrary/app_window.go @@ -98,18 +98,9 @@ func NewAppWindow(db *rddb.DBChan, player *player.PlayerChan, width, height int) if frame, err = gtk.FrameNew(""); err != nil { return nil, err } - var cp *gtk.CssProvider - if cp, err = gtk.CssProviderNew(); err != nil { + if err = setCssStyle(&frame.Widget, ".frame { border: 0; padding: 15px; }"); err != nil { return nil, err } - if err = cp.LoadFromData(".frame { border: 0px; padding: 15px; }"); err != nil { - return nil, err - } - var sc *gtk.StyleContext - if sc, err = frame.GetStyleContext(); err != nil { - return nil, err - } - sc.AddProvider(cp, 600) // TOOD: hardcoded value frame.Add(grid) aw.win.Add(frame) diff --git a/src/rhlibrary/player_widget.go b/src/rhlibrary/player_widget.go index 3f674f0..8289861 100644 --- a/src/rhlibrary/player_widget.go +++ b/src/rhlibrary/player_widget.go @@ -173,19 +173,9 @@ func addPlayTime(grid *gtk.Grid, p *player.PlayerChan) (err error) { countdown = !countdown btn.SetLabel(getPlayTimeString(duration, pos, countdown)) }) - - var cp *gtk.CssProvider - if cp, err = gtk.CssProviderNew(); err != nil { - return - } - if err = cp.LoadFromData(".button { border: 1px solid; border-color: #a1a1a1; font-weight: bold; font-size: 1.3em; }"); err != nil { - return - } - var sc *gtk.StyleContext - if sc, err = btn.GetStyleContext(); err != nil { + if err = setCssStyle(&btn.Widget, ".button { border: 1px solid; border-color: #a1a1a1; font-weight: bold; font-size: 1.3em; }"); err != nil { return } - sc.AddProvider(cp, 600) // TOOD: hardcoded value grid.Attach(btn, 3, 1, 1, 1) return diff --git a/src/rhlibrary/selector_widget.go b/src/rhlibrary/selector_widget.go index 4d040b5..685b61a 100644 --- a/src/rhlibrary/selector_widget.go +++ b/src/rhlibrary/selector_widget.go @@ -102,18 +102,9 @@ func addSelectorPage(nb *gtk.Notebook, title string, getWidget getSelectorFunc, } label.SetSizeRequest(250, 0) // workaround until expanding tabs works... - var cp *gtk.CssProvider - if cp, err = gtk.CssProviderNew(); err != nil { + if err = setCssStyle(&label.Widget, ".label { font-weight: bold; font-size: 1.1em; padding: 3px; }"); err != nil { return } - if err = cp.LoadFromData(".label { font-weight: bold; font-size: 1.1em; padding: 3px; }"); err != nil { - return - } - var sc *gtk.StyleContext - if sc, err = label.GetStyleContext(); err != nil { - return - } - sc.AddProvider(cp, 600) // TOOD: hardcoded value nb.AppendPage(page, label) return @@ -156,18 +147,9 @@ func getSelectorWidget(db *rddb.DBChan, p *player.PlayerChan) (gtk.IWidget, erro } }) - var cp *gtk.CssProvider - if cp, err = gtk.CssProviderNew(); err != nil { - return nil, err - } - if err = cp.LoadFromData(".notebook.header { background-color: unset; }"); err != nil { - return nil, err - } - var sc *gtk.StyleContext - if sc, err = nb.GetStyleContext(); err != nil { + if err = setCssStyle(&nb.Widget, ".notebook.header { background-color: unset; }"); err != nil { return nil, err } - sc.AddProvider(cp, 600) // TOOD: hardcoded value nb.SetProperty("show-border", false) nb.SetHExpand(true) diff --git a/src/rhlibrary/show_selector_widget.go b/src/rhlibrary/show_selector_widget.go index 7e2a58a..0c4a212 100644 --- a/src/rhlibrary/show_selector_widget.go +++ b/src/rhlibrary/show_selector_widget.go @@ -139,19 +139,9 @@ func getShowCartListLabel(caption, css string) (label *gtk.Label, err error) { if label, err = gtk.LabelNew(caption); err != nil { return } - - var cp *gtk.CssProvider - if cp, err = gtk.CssProviderNew(); err != nil { - return - } - if err = cp.LoadFromData(css); err != nil { - return - } - var sc *gtk.StyleContext - if sc, err = label.GetStyleContext(); err != nil { + if err = setCssStyle(&label.Widget, css); err != nil { return } - sc.AddProvider(cp, 600) // TOOD: hardcoded value return } @@ -185,22 +175,13 @@ func getShowCartListEntryPlayButton(cart rddb.CartListEntry, p *player.PlayerCha return nil, err } - var cp *gtk.CssProvider - if cp, err = gtk.CssProviderNew(); err != nil { - return nil, err - } css := ".frame { border: 0; padding: 4px 15px; }" if (idx & 1) == 1 { css = ".frame { border: 0; background-color: #D2D2D2; padding: 4px 15px; }" } - if err = cp.LoadFromData(css); err != nil { + if err = setCssStyle(&frame.Widget, css); err != nil { return nil, err } - var sc *gtk.StyleContext - if sc, err = frame.GetStyleContext(); err != nil { - return nil, err - } - sc.AddProvider(cp, 600) // TOOD: hardcoded value frame.Add(btn) if len(cart.Cuts) < 1 { @@ -369,19 +350,9 @@ func addShowCartList(grid *gtk.Grid, db *rddb.DBChan, p *player.PlayerChan) (err return } showsCartListBin = &frame.Bin - var cp *gtk.CssProvider - - if cp, err = gtk.CssProviderNew(); err != nil { + if err = setCssStyle(&frame.Widget, ".frame { border: 0; }"); err != nil { return } - if err = cp.LoadFromData(".frame { border: 0; }"); err != nil { - return - } - var sc *gtk.StyleContext - if sc, err = frame.GetStyleContext(); err != nil { - return - } - sc.AddProvider(cp, 600) // TOOD: hardcoded value var sw *gtk.ScrolledWindow if sw, err = gtk.ScrolledWindowNew(nil, nil); err != nil { @@ -415,19 +386,9 @@ func getShowsSelectorWidget(db *rddb.DBChan, p *player.PlayerChan) (gtk.IWidget, if frame, err = gtk.FrameNew(""); err != nil { return nil, err } - - var cp *gtk.CssProvider - if cp, err = gtk.CssProviderNew(); err != nil { - return nil, err - } - if err = cp.LoadFromData(".frame { border: 0; padding: 25px 42px; }"); err != nil { - return nil, err - } - var sc *gtk.StyleContext - if sc, err = frame.GetStyleContext(); err != nil { + if err = setCssStyle(&frame.Widget, ".frame { border: 0; padding: 25px 42px; }"); err != nil { return nil, err } - sc.AddProvider(cp, 600) // TOOD: hardcoded value frame.Add(grid) diff --git a/src/rhlibrary/vumeter_widget.go b/src/rhlibrary/vumeter_widget.go index 233a660..1886653 100644 --- a/src/rhlibrary/vumeter_widget.go +++ b/src/rhlibrary/vumeter_widget.go @@ -150,18 +150,9 @@ func newVUMeter(ch string) (meter *vuMeter, err error) { if meter.label, err = gtk.LabelNew(ch); err != nil { return } - var cp *gtk.CssProvider - if cp, err = gtk.CssProviderNew(); err != nil { - return nil, err - } - if err = cp.LoadFromData(".label { color: #a2a2a2; padding: 0px 2px 0px 0px; font-size: 4.5px; font-variant: small-caps; font-weight: bold; }"); err != nil { + if err = setCssStyle(&meter.label.Widget, ".label { color: #a2a2a2; padding: 0px 2px 0px 0px; font-size: 4.5px; font-variant: small-caps; font-weight: bold; }"); err != nil { return nil, err } - var sc *gtk.StyleContext - if sc, err = meter.label.GetStyleContext(); err != nil { - return nil, err - } - sc.AddProvider(cp, 600) // TOOD: hardcoded value if meter.green, err = createMeterBar(meterSegmentsGreen); err != nil { return @@ -243,18 +234,9 @@ func getVUMeterWidget(p *player.PlayerChan) (gtk.IWidget, error) { return nil, err } - var cp *gtk.CssProvider - if cp, err = gtk.CssProviderNew(); err != nil { - return nil, err - } - if err = cp.LoadFromData(".frame { background-color: #2a2a2a; border: 1px solid; border-color: #a1a1a1; border-radius: 5px; padding: 11px; }"); err != nil { + if err = setCssStyle(&frame.Widget, ".frame { background-color: #2a2a2a; border: 1px solid; border-color: #a1a1a1; border-radius: 5px; padding: 11px; }"); err != nil { return nil, err } - var sc *gtk.StyleContext - if sc, err = frame.GetStyleContext(); err != nil { - return nil, err - } - sc.AddProvider(cp, 600) // TOOD: hardcoded value if err = addVUMeterGrid(frame, p); err != nil { return nil, err diff --git a/src/rhlibrary/widget_common.go b/src/rhlibrary/widget_common.go new file mode 100644 index 0000000..33be7ae --- /dev/null +++ b/src/rhlibrary/widget_common.go @@ -0,0 +1,45 @@ +// +// rhlibrary +// +// The Radio Helsinki Rivendell Library +// +// +// Copyright (C) 2016 Christian Pointner <equinox@helsinki.at> +// +// This file is part of rhlibrary. +// +// rhlibrary is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// rhlibrary is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with rhlibrary. If not, see <http://www.gnu.org/licenses/>. +// + +package main + +import ( + "github.com/gotk3/gotk3/gtk" +) + +func setCssStyle(widget *gtk.Widget, css string) (err error) { + var cp *gtk.CssProvider + if cp, err = gtk.CssProviderNew(); err != nil { + return + } + if err = cp.LoadFromData(css); err != nil { + return + } + var sc *gtk.StyleContext + if sc, err = widget.GetStyleContext(); err != nil { + return + } + sc.AddProvider(cp, 600) // TOOD: hardcoded value + return +} |