本文整理匯總了Golang中github.com/sqp/godock/widgets/cfbuild/cftype.Key.Storage方法的典型用法代碼示例。如果您正苦於以下問題:Golang Key.Storage方法的具體用法?Golang Key.Storage怎麽用?Golang Key.Storage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/sqp/godock/widgets/cfbuild/cftype.Key
的用法示例。
在下文中一共展示了Key.Storage方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: addTest
func (lf *lineFeed) addTest(key *cftype.Key) {
def, e := key.Storage().Default(key.Group, key.Name)
if e != nil {
println("default: ", e.Error())
return
}
valStatus := key.ValueState(def)
if !valStatus.IsChanged() {
return
}
lf.countChanged++
lf.valuePrint = func(key *cftype.Key, line tablist.Liner) {
for i, st := range valStatus {
curline := lf.testNewLine(line, i)
switch {
// case cftype.StateUnchanged:
// curline.Set(RowOld, st.Old)
case st.State == cftype.StateEdited && st.New != "":
curline.Set(RowOld, st.New)
case st.State == cftype.StateAdded:
curline.Colored(RowOld, color.FgYellow, st.New)
case st.State == cftype.StateEdited, st.State == cftype.StateRemoved:
curline.Colored(RowOld, color.FgMagenta, "**EMPTY**")
}
}
}
lf.Add(key)
}
示例2: ColorSelector
// ColorSelector adds a color selector widget.
//
func ColorSelector(key *cftype.Key) {
values := key.Value().ListFloat()
if len(values) == 3 {
values = append(values, 1) // no transparency.
}
gdkColor := gdk.NewRGBA(values...)
widget := newgtk.ColorButtonWithRGBA(gdkColor)
var getValue func() interface{}
switch key.Type {
case cftype.KeyColorSelectorRGB:
key.NbElements = 3
getValue = func() interface{} { return widget.GetRGBA().Floats()[:3] } // Need to trunk ?
case cftype.KeyColorSelectorRGBA:
key.NbElements = 4
getValue = func() interface{} { return widget.GetRGBA().Floats() }
}
widget.Set("use-alpha", key.IsType(cftype.KeyColorSelectorRGBA))
key.PackKeyWidget(key,
getValue,
func(uncast interface{}) { widget.SetRGBA(gdk.NewRGBA(uncast.([]float64)...)) },
widget,
)
oldval, e := key.Storage().Default(key.Group, key.Name)
if e == nil {
PackReset(key, oldval.ListFloat())
}
}
示例3: PackValuerAsInt
// PackValuerAsInt packs a valuer widget with its reset button (to given value).
// Values are get and set as int.
//
func PackValuerAsInt(key *cftype.Key, w gtk.IWidget, valuer WidgetValuer, value int) {
key.PackKeyWidget(key,
func() interface{} { return int(valuer.GetValue()) },
func(uncast interface{}) { valuer.SetValue(float64(uncast.(int))) },
w)
oldval, e := key.Storage().Default(key.Group, key.Name)
if e == nil {
PackReset(key, oldval.Int())
}
}
示例4: PackReset
// PackReset adds a reset value button.
//
func PackReset(key *cftype.Key, value interface{}) *gtk.Button {
fileDefault := key.Storage().FileDefault()
if fileDefault == "" {
return nil
}
back := newgtk.ButtonFromIconName("edit-clear", gtk.ICON_SIZE_MENU)
back.Connect("clicked", func() { key.ValueSet(value) })
key.PackSubWidget(back)
return back
}
示例5: PackComboBoxWithListField
// PackComboBoxWithListField creates a combo box filled with the getList call.
//
func PackComboBoxWithListField(key *cftype.Key, withEntry, numbered bool, getList func() []datatype.Field) *gtk.ComboBox {
var list []datatype.Field
if getList != nil {
list = getList()
}
current, _ := key.Storage().String(key.Group, key.Name)
widget, _, getValue, setValue := NewComboBox(key, withEntry, numbered, current, list)
key.PackKeyWidget(key, getValue, setValue, widget)
return widget
}
示例6: valueDefault
func (lf *lineFeed) valueDefault(key *cftype.Key, line tablist.Liner) {
flag := false
def, e := key.Storage().Default(key.Group, key.Name)
if e != nil {
println("default: ", e.Error())
}
valStatus := key.ValueState(def)
for i, st := range valStatus {
curline := lf.testNewLine(line, i)
switch st.State {
case cftype.StateBothEmpty:
line.Set(RowOld, "**EMPTY**")
case cftype.StateUnchanged:
curline.Set(RowOld, st.Old)
case cftype.StateEdited:
curline.Set(RowOld, st.Old)
if st.New == "" {
curline.Colored(RowNew, color.FgMagenta, "**EMPTY**")
} else {
curline.Colored(RowNew, color.FgGreen, st.New)
}
flag = true
case cftype.StateAdded:
curline.Set(RowOld, "**EMPTY**")
curline.Colored(RowNew, color.FgYellow, st.New)
flag = true
case cftype.StateRemoved:
curline.Set(RowOld, st.Old)
curline.Colored(RowNew, color.FgMagenta, "**EMPTY**")
flag = true
}
}
if flag {
lf.countChanged++
}
}
示例7: valueUpdated
func (lf *lineFeed) valueUpdated(key *cftype.Key, line tablist.Liner) {
flag := false
older := key.Storage().Valuer(key.Group, key.Name)
valStatus := key.ValueState(older)
for i, st := range valStatus {
curline := lf.testNewLine(line, i)
switch st.State {
case cftype.StateBothEmpty:
line.Colored(RowOld, color.FgMagenta, "**EMPTY**")
line.Colored(RowNew, color.BgRed, " == ")
case cftype.StateUnchanged:
curline.Set(RowOld, st.Old)
curline.Colored(RowNew, color.BgRed, " == ")
case cftype.StateEdited:
curline.Set(RowOld, st.Old)
st.New = ternary.String(st.New == "", "**EMPTY**", st.New)
curline.Colored(RowNew, color.FgGreen, st.New)
flag = true
case cftype.StateAdded:
curline.Set(RowOld, "**EMPTY**")
curline.Colored(RowNew, color.FgGreen, st.New)
flag = true
case cftype.StateRemoved:
curline.Set(RowOld, st.Old)
curline.Colored(RowNew, color.FgGreen, "**EMPTY**")
flag = true
}
}
if flag {
lf.countChanged++
}
}
示例8: ListDock
// ListDock adds a dock list widget.
//
func ListDock(key *cftype.Key) {
// Get current Icon name if its a Subdock.
iIconType, _ := key.Storage().Int(key.Group, "Icon Type")
SubdockName := ""
if iIconType == cftype.UserIconStack { // it's a stack-icon
SubdockName, _ = key.Storage().String(key.Group, "Name") // It's a subdock, get its name to remove the selection of a recursive position (inside itself).
}
list := key.Source().ListDocks("", SubdockName) // Get the list of available docks. Keep parent, but remove itself from the list.
list = append(list, datatype.Field{
Key: datatype.KeyNewDock,
Name: tran.Slate("New main dock")},
)
model := newModelSimple()
current := key.Value().String()
if current == "" {
current = datatype.KeyMainDock
}
model.SetSortColumnId(RowName, gtk.SORT_ASCENDING)
widget := newgtk.ComboBoxWithModel(model)
renderer := newgtk.CellRendererText()
widget.PackStart(renderer, false)
widget.AddAttribute(renderer, "text", RowName)
saved := indexiter.NewByString(widget, key.Log())
iter := fillModelWithFields(key, model, list, current, saved)
widget.SetActiveIter(iter)
key.PackKeyWidget(key,
getValueListCombo(widget, model, key.Log()),
func(uncast interface{}) { saved.SetActive(uncast.(string)) },
widget)
}
示例9: Float
// Float adds a float selector widget. SpinButton or Horizontal Scale
//
func Float(key *cftype.Key) {
if key.NbElements > 1 { // TODO: remove temp test
key.Log().Info("Float multi", key.NbElements, key.Type.String())
}
values := key.Value().ListFloat()
minValue, maxValue := minMaxValues(key)
var valuers []WidgetValuer
for k := 0; k < key.NbElements; k++ {
var value float64
if k < len(values) {
value = values[k]
}
switch key.Type {
case cftype.KeyFloatScale:
adjustment := newgtk.Adjustment(
value,
minValue,
maxValue,
(maxValue-minValue)/20,
(maxValue-minValue)/10, 0,
)
w := newgtk.Scale(gtk.ORIENTATION_HORIZONTAL, adjustment)
w.Set("digits", 3)
key.PackSubWidget(WrapKeyScale(key, w))
valuers = append(valuers, w)
case cftype.KeyFloatSpin:
w := newgtk.SpinButtonWithRange(minValue, maxValue, 1)
w.Set("digits", 3)
w.SetValue(value)
key.PackSubWidget(w)
valuers = append(valuers, w)
}
}
switch {
case key.NbElements == 1:
key.PackKeyWidget(key,
func() interface{} { return valuers[0].GetValue() },
func(uncast interface{}) { valuers[0].SetValue(uncast.(float64)) },
)
oldval, e := key.Storage().Default(key.Group, key.Name)
if e == nil {
PackReset(key, oldval.Float())
}
default:
key.PackKeyWidget(key,
func() interface{} { return listValuerGet(valuers) },
func(uncast interface{}) { listValuerSet(valuers, uncast.([]float64)) },
)
oldval, e := key.Storage().Default(key.Group, key.Name)
if e == nil {
PackReset(key, oldval.ListFloat())
}
}
}
示例10: IntegerSize
// IntegerSize adds an integer selector widget.
//
func IntegerSize(key *cftype.Key) {
if key.NbElements > 1 { // TODO: remove temp test
key.Log().Info("IntegerSize multi", key.NbElements, key.Type.String())
}
toggle := newgtk.ToggleButton()
img := newgtk.ImageFromIconName("media-playback-pause", gtk.ICON_SIZE_MENU) // get better image.
toggle.SetImage(img)
values := key.Value().ListInt()
minValue, maxValue := minMaxValues(key)
var valuers []WidgetValuer
key.NbElements *= 2 // Two widgets to add.
// Value pair data.
var firstValue int
var firstWidget *gtk.SpinButton
var cbBlock func() func()
for k := 0; k < key.NbElements; k++ {
var value int
if k < len(values) {
value = values[k]
}
w := newgtk.SpinButtonWithRange(minValue, maxValue, 1)
w.SetValue(float64(value))
key.PackSubWidget(w)
valuers = append(valuers, w)
if k&1 == 0 { // first value, separator
label := newgtk.Label("x")
key.PackSubWidget(label)
firstWidget = w
firstValue = value
} else { // second value. connect both spin values.
if firstValue == value {
toggle.SetActive(true)
}
cb0, e := firstWidget.Connect("value-changed", onValuePairChanged, &valuePair{
linked: w,
toggle: toggle})
key.Log().Err(e, "IntegerSize connect value-changed 1")
cb1, e := w.Connect("value-changed", onValuePairChanged, &valuePair{
linked: firstWidget,
toggle: toggle})
key.Log().Err(e, "IntegerSize connect value-changed 2")
cbBlock = func() func() {
firstWidget.HandlerBlock(cb0)
w.HandlerBlock(cb1)
return func() {
firstWidget.HandlerUnblock(cb0)
w.HandlerUnblock(cb1)
}
}
}
}
setValue := func(uncast interface{}) {
if cbBlock == nil {
key.Log().NewErr("no valuePair callbacks", "IntegerSize", key.Name)
} else {
defer cbBlock()() // This disables now and reenables during defer.
}
values := uncast.([]int)
if len(values) < 2 {
key.Log().NewErr("not enough values provided", "IntegerSize set value", key.Name, values)
values = []int{0, 0}
}
listValuerSet(valuers, cast.IntsToFloats(values))
toggle.SetActive(values[0] == values[1])
}
key.PackKeyWidget(key,
func() interface{} { return cast.FloatsToInts(listValuerGet(valuers)) },
setValue,
toggle,
)
oldval, e := key.Storage().Default(key.Group, key.Name)
key.Log().Err(e, "IntegerSize original value")
if e == nil {
PackReset(key, oldval.ListInt())
}
}