本文整理匯總了Golang中github.com/sqp/godock/widgets/cfbuild/cftype.Key.PackKeyWidget方法的典型用法代碼示例。如果您正苦於以下問題:Golang Key.PackKeyWidget方法的具體用法?Golang Key.PackKeyWidget怎麽用?Golang Key.PackKeyWidget使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/sqp/godock/widgets/cfbuild/cftype.Key
的用法示例。
在下文中一共展示了Key.PackKeyWidget方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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())
}
}
示例2: PackComboBoxWithIndexHandbooker
// PackComboBoxWithIndexHandbooker creates a combo box filled with the getList call.
//
func PackComboBoxWithIndexHandbooker(key *cftype.Key, index map[string]datatype.Handbooker) {
model := newModelSimple()
model.SetSortColumnId(RowName, gtk.SORT_ASCENDING)
widget, getValue := NewComboBoxWithModel(model, key.Log(), false, false, false)
value := key.Value().String()
details := handbook.New(key.Log())
key.PackWidget(details, false, false, 0)
widget.Connect("changed", func() {
name := key.Value().String()
pack, ok := index[name]
if ok {
details.SetPackage(pack)
} else {
key.Log().NewErr("key missing", "ComboHandbook select preview:", name)
}
})
fields := datatype.IndexHandbooksToFields(index)
saved := indexiter.NewByString(widget, key.Log())
iter := fillModelWithFields(key, model, fields, value, saved)
widget.SetActiveIter(iter) // Set iter after connect, to update with current value.
key.PackKeyWidget(key,
getValue,
func(uncast interface{}) { saved.SetActive(uncast.(string)) },
widget,
)
}
示例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: 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
}
示例5: FontSelector
// FontSelector adds a font selector widget.
//
func FontSelector(key *cftype.Key) {
value := key.Value().String()
widget := newgtk.FontButtonWithFont(value)
widget.Set("show-style", true)
widget.Set("show-size", true)
widget.Set("use-size", true)
widget.Set("use-font", true)
key.PackKeyWidget(key,
func() interface{} { return widget.GetFontName() },
func(val interface{}) { widget.SetFontName(val.(string)) },
widget)
}
示例6: Link
// Link adds a link widget.
//
func Link(key *cftype.Key) {
var text, link string
if len(key.AuthorizedValues) > 0 {
text = key.AuthorizedValues[0]
} else {
text = tran.Slate("link")
}
if len(key.AuthorizedValues) > 1 { // Custom keys have to use this input way.
link = key.AuthorizedValues[1]
} else {
link = key.Value().String()
}
widget := newgtk.LinkButtonWithLabel(link, text)
key.PackKeyWidget(key,
func() interface{} { return widget.GetUri() },
func(val interface{}) { widget.SetUri(val.(string)) },
widget)
}
示例7: 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)
}
示例8: Handbook
// Handbook adds a handbook widget to show basic applet informations.
//
func Handbook(key *cftype.Key) {
appletName := key.Value().String()
widget := handbook.New(key.Log())
widget.ShowVersion = true
book := key.Source().Handbook(appletName)
if widget == nil || book == nil {
key.Log().NewErr("Handbook no widget")
return
}
widget.SetPackage(book)
key.BoxPage().PackStart(widget, true, true, 0)
key.PackKeyWidget(key,
func() interface{} { return appletName },
func(uncast interface{}) {
appletName = uncast.(string)
book := key.Source().Handbook(appletName)
widget.SetPackage(book)
},
)
}
示例9: TreeView
//.........這裏部分代碼省略.........
imgRm := newgtk.ImageFromIconName("list-remove", gtk.ICON_SIZE_SMALL_TOOLBAR)
buttonAdd.SetImage(imgAdd)
buttonRm.SetImage(imgRm)
vboxItems.PackStart(buttonRm, false, false, 0)
grid.Attach(newgtk.Separator(gtk.ORIENTATION_HORIZONTAL), 0, 1, 2, 1)
grid.Attach(buttonAdd, 0, 2, 1, 1)
grid.Attach(entry, 1, 2, 1, 1)
data.entry = entry
buttonAdd.Connect("clicked", onTreeviewAddText, data) // Add new iter to model with the value of the entry widget. Clear entry widget.
buttonRm.Connect("clicked", onTreeviewRemoveText, data) // Remove selected iter from model. Set its value to the entry widget.
}
}
setValues := func(newvalues []string) {
for i, val := range newvalues {
iter := model.Append()
model.SetValue(iter, RowKey, val)
model.SetValue(iter, RowName, val)
model.SetValue(iter, 4, true) // active
model.SetValue(iter, 5, i) // order
}
}
// Fill model with values.
switch key.Type {
case cftype.KeyTreeViewSortModify, // add saved values.
cftype.KeyTreeViewSortSimple: // TODO: TEMP to improve and maybe regroup this case as was with multichoice and not modify.
setValues(values)
key.PackKeyWidget(key,
getValue,
func(uncast interface{}) { model.Clear(); setValues(uncast.([]string)) },
grid)
case cftype.KeyTreeViewMultiChoice:
if len(key.AuthorizedValues) > 0 {
// var NbMax, order int
}
// else if (pAuthorizedValuesList != NULL) // on liste les choix possibles dans l'ordre choisi. Pour CAIRO_DOCK_WidgetTreeViewMultiChoice, on complete avec ceux n'ayant pas ete selectionnes.
// {
// gint iNbPossibleValues = 0, iOrder = 0;
// while (pAuthorizedValuesList[iNbPossibleValues] != NULL)
// iNbPossibleValues ++;
// guint l;
// for (l = 0; l < length; l ++)
// {
// cValue = cValueList[l];
// if (! g_ascii_isdigit (*cValue)) // ancien format.
// {
// cd_debug ("old format\n");
// int k;
// for (k = 0; k < iNbPossibleValues; k ++) // on cherche la correspondance.
// {
// if (strcmp (cValue, pAuthorizedValuesList[k]) == 0)
// {
// cd_debug (" correspondance %s <-> %d", cValue, k);
// g_free (cValueList[l]);
// cValueList[l] = g_strdup_printf ("%d", k);
// cValue = cValueList[l];
// break ;
// }
示例10: Lists
//.........這裏部分代碼省略.........
key.SetNbControlled(0)
}
// gchar *cResult = (listIsNumbered ? g_new0 (gchar , 10) : NULL);
for k := 0; k < len(key.AuthorizedValues); k += step { // on ajoute toutes les chaines possibles a la combo.
if !listIsNumbered && iSelectedItem == -1 && value == key.AuthorizedValues[k] {
current = value
iSelectedItem = k / step
}
// if (cResult != NULL)
// snprintf (cResult, 9, "%d", k/dk); // dk becomes step
// iExcept = 0;
// if key.IsType(cftype.KeyListNbCtrlSelect) {
// iOrder1 = atoi (key.AuthorizedValues[k+1]);
// gchar *str = strchr (key.AuthorizedValues[k+2], ',');
// if (str) // Note: this mechanism is an addition to the original {first widget, number of widgets}; it's not very generic nor beautiful, but until we need more, it's well enough (currently, only the Dock background needs it).
// {
// *str = '\0';
// iExcept = atoi (str+1);
// }
// iOrder2 = atoi (key.AuthorizedValues[k+2]);
// NbControlled = MAX (NbControlled, iOrder1 + iOrder2 - 1);
// //g_print ("iSelectedItem:%d ; k/dk:%d\n", iSelectedItem , k/dk);
// if (iSelectedItem == (int)k/dk)
// {
// iFirstSensitiveWidget = iOrder1;
// iNbSensitiveWidgets = iOrder2;
// iNonSensitiveWidget = iExcept;
// if (iNonSensitiveWidget != 0)
// NbControlled ++;
// }
// } else {
// iOrder1 = iOrder2 = k;
// }
//
name := ""
if key.IsType(cftype.KeyListEntry) {
name = key.AuthorizedValues[k]
} else {
name = key.Translate(key.AuthorizedValues[k])
}
list = append(list, datatype.Field{
Key: key.AuthorizedValues[k],
Name: name,
})
// CAIRO_DOCK_MODEL_ORDER, iOrder1,
// CAIRO_DOCK_MODEL_ORDER2, iOrder2,
// CAIRO_DOCK_MODEL_STATE, iExcept, -1);
}
}
// Current choice wasn't in the list. Select first.
if current == "" && len(list) > 0 {
current = list[0].Key
iSelectedItem = 0
}
// Build the combo widget.
widget, _, getValue, setValue := NewComboBox(key, key.IsType(cftype.KeyListEntry), listIsNumbered, current, list)
// gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (modele), GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
// int iNonSensitiveWidget = 0;
if len(key.AuthorizedValues) > 0 {
if key.IsType(cftype.KeyListNbCtrlSimple, cftype.KeyListNbCtrlSelect) {
// _allocate_new_buffer;
// data[0] = pKeyBox;
// data[1] = (pFrameVBox != NULL ? pFrameVBox : pGroupBox);
if key.IsType(cftype.KeyListNbCtrlSimple) {
// NbControlled = k;
// data[2] = GINT_TO_POINTER (NbControlled);
// g_signal_connect (G_OBJECT (pOneWidget), "changed", G_CALLBACK (_cairo_dock_select_one_item_in_control_combo), data);
// iFirstSensitiveWidget = iSelectedItem+1; // on decroit jusqu'a 0.
// iNbSensitiveWidgets = 1;
// //g_print ("CONTROL : %d,%d,%d\n", NbControlled, iFirstSensitiveWidget, iNbSensitiveWidgets);
} else {
// data[2] = GINT_TO_POINTER (NbControlled);
// g_signal_connect (G_OBJECT (pOneWidget), "changed", G_CALLBACK (_cairo_dock_select_one_item_in_control_combo_selective), data);
// //g_print ("CONTROL : %d,%d,%d\n", NbControlled, iFirstSensitiveWidget, iNbSensitiveWidgets);
}
// g_object_set_data (G_OBJECT (pKeyBox), "nb-ctrl-widgets", GINT_TO_POINTER (NbControlled));
// g_object_set_data (G_OBJECT (pKeyBox), "one-widget", pOneWidget);
// CDControlWidget *cw = g_new0 (CDControlWidget, 1);
// pControlWidgets = g_list_prepend (pControlWidgets, cw);
// cw->pControlContainer = (pFrameVBox != NULL ? pFrameVBox : pGroupBox);
// cw->NbControlled = NbControlled;
// cw->iFirstSensitiveWidget = iFirstSensitiveWidget;
// cw->iNbSensitiveWidgets = iNbSensitiveWidgets;
// cw->iNonSensitiveWidget = iNonSensitiveWidget;
// //g_print (" pControlContainer:%x\n", pControlContainer);
}
}
key.PackKeyWidget(key, getValue, setValue, widget)
}
示例11: ListIconsMainDock
//.........這裏部分代碼省略.........
// gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (pOneWidget), rend, "text", CAIRO_DOCK_MODEL_NAME, NULL);
// _pack_subwidget (pOneWidget);
// // get the dock
// CairoDock *pDock = NULL;
// if (pAuthorizedValuesList != NULL && pAuthorizedValuesList[0] != NULL)
// pDock = gldi_dock_get (pAuthorizedValuesList[0]);
// if (!pDock)
// pDock = g_pMainDock;
// // insert each icon
// cValue = g_key_file_get_string (pKeyFile, cGroupName, cKeyName, NULL);
// gint iDesiredIconSize = cairo_dock_search_icon_size (GTK_ICON_SIZE_LARGE_TOOLBAR); // 24 by default
// GtkTreeIter iter;
// Icon *pIcon;
// gchar *cImagePath, *cID;
// const gchar *cName;
// GdkPixbuf *pixbuf;
// GList *ic;
// for (ic = pDock->icons; ic != NULL; ic = ic->next)
// {
// pIcon = ic->data;
// if (pIcon->cDesktopFileName != NULL
// || pIcon->pModuleInstance != NULL)
// {
// pixbuf = NULL;
// cImagePath = NULL;
// cName = NULL;
// // get the ID
// if (pIcon->cDesktopFileName != NULL)
// cID = pIcon->cDesktopFileName;
// else
// cID = pIcon->pModuleInstance->cConfFilePath;
// // get the image
// if (pIcon->cFileName != NULL)
// {
// cImagePath = cairo_dock_search_icon_s_path (pIcon->cFileName, iDesiredIconSize);
// }
// if (cImagePath == NULL || ! g_file_test (cImagePath, G_FILE_TEST_EXISTS))
// {
// g_free (cImagePath);
// if (GLDI_OBJECT_IS_SEPARATOR_ICON (pIcon))
// {
// if (myIconsParam.cSeparatorImage)
// cImagePath = cairo_dock_search_image_s_path (myIconsParam.cSeparatorImage);
// }
// else if (CAIRO_DOCK_IS_APPLET (pIcon))
// {
// cImagePath = g_strdup (pIcon->pModuleInstance->pModule->pVisitCard->cIconFilePath);
// }
// else
// {
// cImagePath = cairo_dock_search_image_s_path (CAIRO_DOCK_DEFAULT_ICON_NAME);
// if (cImagePath == NULL || ! g_file_test (cImagePath, G_FILE_TEST_EXISTS))
// {
// g_free (cImagePath);
// cImagePath = g_strdup (GLDI_SHARE_DATA_DIR"/icons/"CAIRO_DOCK_DEFAULT_ICON_NAME);
// }
// }
// }
// //g_print (" + %s\n", cImagePath);
// if (cImagePath != NULL)
// {
// pixbuf = gdk_pixbuf_new_from_file_at_size (cImagePath, iDesiredIconSize, iDesiredIconSize, NULL);
// }
// //g_print (" -> %p\n", pixbuf);
// // get the name
// if (CAIRO_DOCK_IS_USER_SEPARATOR (pIcon)) // separator
// cName = "---------";
// else if (CAIRO_DOCK_IS_APPLET (pIcon)) // applet
// cName = pIcon->pModuleInstance->pModule->pVisitCard->cTitle;
// else // launcher
// cName = (pIcon->cInitialName ? pIcon->cInitialName : pIcon->cName);
// // store the icon
// memset (&iter, 0, sizeof (GtkTreeIter));
// gtk_list_store_append (GTK_LIST_STORE (modele), &iter);
// gtk_list_store_set (GTK_LIST_STORE (modele), &iter,
// CAIRO_DOCK_MODEL_NAME, cName,
// CAIRO_DOCK_MODEL_RESULT, cID,
// CAIRO_DOCK_MODEL_ICON, pixbuf, -1);
// g_free (cImagePath);
// if (pixbuf)
// g_object_unref (pixbuf);
// if (cValue && strcmp (cValue, cID) == 0)
// gtk_combo_box_set_active_iter (GTK_COMBO_BOX (pOneWidget), &iter);
// }
// }
// g_free (cValue);
// }
key.PackKeyWidget(key,
getValueListCombo(widget, model, key.Log()),
func(uncast interface{}) { saved.SetActive(uncast.(string)) },
widget)
}
示例12: CheckButton
// CheckButton adds a check button widget.
//
func CheckButton(key *cftype.Key) {
if key.NbElements > 1 { // TODO: remove temp test
key.Log().Info("CheckButton multi", key.NbElements, key.Type.String())
}
values := key.Value().ListBool()
var activers []widgetActiver
for k := 0; k < key.NbElements; k++ {
var value bool
if k < len(values) {
value = values[k]
}
w := newgtk.Switch()
w.SetActive(value)
key.PackSubWidget(w)
activers = append(activers, w)
if key.IsType(cftype.KeyBoolCtrl) {
// _allocate_new_buffer;
// data[0] = pKeyBox;
// data[1] = (pFrameVBox != NULL ? pFrameVBox : pGroupBox);
// if (pAuthorizedValuesList != NULL && pAuthorizedValuesList[0] != NULL)
// NbControlled = g_ascii_strtod (pAuthorizedValuesList[0], NULL);
// else
// NbControlled = 1;
// data[2] = GINT_TO_POINTER (NbControlled);
// if (NbControlled < 0) // a negative value means that the behavior is inverted.
// {
// bValue = !bValue;
// NbControlled = -NbControlled;
// }
// g_signal_connect (G_OBJECT (pOneWidget), "toggled", G_CALLBACK(_cairo_dock_toggle_control_button), data);
// g_object_set_data (G_OBJECT (pKeyBox), "nb-ctrl-widgets", GINT_TO_POINTER (NbControlled));
// g_object_set_data (G_OBJECT (pKeyBox), "one-widget", pOneWidget);
// if (! bValue) // les widgets suivants seront inactifs.
// {
// CDControlWidget *cw = g_new0 (CDControlWidget, 1);
// pControlWidgets = g_list_prepend (pControlWidgets, cw);
// cw->iNbSensitiveWidgets = 0;
// cw->NbControlled = NbControlled;
// cw->iFirstSensitiveWidget = 1;
// cw->pControlContainer = (pFrameVBox != NULL ? pFrameVBox : pGroupBox);
// } // sinon le widget suivant est sensitif, donc rien a faire.
}
}
if key.NbElements == 1 {
key.PackKeyWidget(key,
func() interface{} { return activers[0].GetActive() },
func(uncast interface{}) { activers[0].SetActive(uncast.(bool)) },
)
} else {
key.PackKeyWidget(key,
func() interface{} { return listActiverGet(activers) },
func(uncast interface{}) { listActiverSet(activers, uncast.([]bool)) },
)
}
}
示例13: 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())
}
}
}
示例14: 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())
}
}
示例15: Strings
// Strings adds a string widget. Many options included.
// TODO: need password cypher, G_USER_DIRECTORY_PICTURES, play sound.
//
func Strings(key *cftype.Key) {
value := key.Value().String()
widget := newgtk.Entry()
widget.SetText(value)
if key.IsType(cftype.KeyPasswordEntry) { // Hide text and decrypt value.
widget.SetVisibility(false)
value = key.Source().DecryptString(value)
}
// Pack the widget before any other (in full size if needed).
// So we do it now and fill the callbacks later
key.PackKeyWidget(key, nil, nil, widget)
var setValue func(interface{})
// Add special buttons to fill the entry box.
switch key.Type {
case cftype.KeyFileSelector, cftype.KeyFolderSelector,
cftype.KeySoundSelector, cftype.KeyImageSelector: // Add a file selector.
fileChooser := newgtk.Button()
img := newgtk.ImageFromIconName("document-open", gtk.ICON_SIZE_SMALL_TOOLBAR)
fileChooser.SetImage(img)
fileChooser.Connect("clicked", onFileChooserOpen, fileChooserData{widget, key})
key.PackSubWidget(fileChooser)
if key.IsType(cftype.KeySoundSelector) { //Sound Play Button
play := newgtk.Button()
imgPlay := newgtk.ImageFromIconName("media-playback-start", gtk.ICON_SIZE_SMALL_TOOLBAR)
play.SetImage(imgPlay)
// play.Connect("clicked", C._cairo_dock_play_a_sound, data)
key.PackSubWidget(play)
}
case cftype.KeyShortkeySelector, cftype.KeyClassSelector: // Add a key/class grabber.
grab := newgtk.ButtonWithLabel("Grab")
key.PackSubWidget(grab)
// gtk_widget_add_events(pMainWindow, GDK_KEY_PRESS_MASK);
switch key.Type {
case cftype.KeyClassSelector:
grab.Connect("clicked", func() {
widget.SetSensitive(false) // Block widgets.
grab.SetSensitive(false)
go func() {
class, e := key.Source().GrabWindowClass() // Wait user selection in a routine.
glib.IdleAdd(func() { // And resync with the GTK loop to display results.
widget.SetSensitive(true) // Reactivate widgets.
grab.SetSensitive(true)
if !key.Log().Err(e, "ClassSelector", key.Group, key.Name) {
setValue(class) // On success.
key.Log().Debug("KeyClassSelector window selected", class)
}
})
}()
})
case cftype.KeyShortkeySelector:
grab.Connect("clicked", onKeyGrabClicked, &textGrabData{entry: widget, win: key.Source().GetWindow()})
}
// for _, sk := range key.Source().ListShortkeys() {
// if sk.GetConfFilePath() == key.Storage().FilePath() {
// println("found file shortkey")
// }
// }
}
// Display a default value when empty.
if len(key.AuthorizedValues) > 0 && key.AuthorizedValues[0] != "" {
defaultText := key.Translate(key.AuthorizedValues[0])
cbChanged, _ := widget.Connect("changed", onTextDefaultChanged, key)
data := textDefaultData{key: key, text: defaultText, cbID: cbChanged}
widget.Connect("focus-in-event", onTextDefaultFocusIn, data)
widget.Connect("focus-out-event", onTextDefaultFocusOut, data)
// TODO: check other use of those fields.
// g_object_set_data (G_OBJECT (pEntry), "ignore-value", GINT_TO_POINTER (TRUE));
// g_object_set_data (G_OBJECT (pOneWidget), "default-text", cDefaultText);
context, _ := widget.GetStyleContext()
context.AddProvider(MainCSS(), gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
setValue = func(uncast interface{}) {
// if !key.IsDefault { // not sure why this was here.
widget.SetText(uncast.(string))
onTextDefaultFocusOut(widget, nil, data)
}
//.........這裏部分代碼省略.........