grail.widgets.glistbox module

Version: 16.2

Table of Contents

Description

Contains the GListBox widget. This widget provides the user with the ability to associate a run-time variable (RTV) from the grail.rtv module with an item picked in the GListBox widget. Whenever the user modifies the GListBox, the appropriate RTV will be modified.

Because there is only a one to one relationship between the contents of the GListBox and the RTV, the GListBox is only a single selection listbox.

Finally, to make life simpler the Tkinter scrollbar logic has been automatically wrapped into this widget for easier use.

Example

The follow example illustrates working with the GListBox

from grail.widgets import *
from grail import rtv

def onselect(index):
print "selected: %s (%d)" % (lb.get(index), index)

def ondoubleclick(index):
print "double-clicked: %s (%d)" % (lb.get(index), index)

def onenabledisable():
if btn['text'] == 'disable':
btn['text'] = 'enable'
lb.disable()
else:
btn['text'] = 'disable'
lb.enable()

root = gwidgetinit()
variable = rtv.StringRTV(name="glistboxtestrtv", value="b")
lb = GListBox(root, items=["a", "b", "c"], rtv=variable)
btn = Tkinter.Button(root, text="disable", command=onenabledisable)
lb.pack(expand=1, fill='both')
btn.pack(expand=1, fill='x')
objsignal.listen(lb, const.sigON_SELECT, None, onselect)
objsignal.listen(lb, const.sigON_DOUBLE_CLICK, None, ondoubleclick)
variable.fromstring("c")
root.title("Demo - GListBox")
root.geometry("%dx%d+%d+%d" % (200, 200, 100, 100))
root.mainloop()

Notice, that for simplicity, we mixed in a Tkinter.Button into our dialog. This also illustrates that one can use both the MineSight® Grail and the Tkinter widgets side-by-side.

The example script above will generate a Tkinter window that appears as follows,

Screen shot of the GListbox widget.

Example of the GListBox widget.

GListBox Widget

The GListBox widget inherits from,
class GListBox([parent, **keywords])

Creates a single pick list box that can be associated with a run-time variable (see grail.rtv). In addition the scrollbar logic is wrapped into this widget for easier use.

This listbox incorporates variables as well as wraps the scrollbar logic directly into the same widget.

Note

A few remarks on using GListBox,

  • If you have multiple listboxes within the same frame you may see that the "selection" behavior will be only apparent in the last listbox selected. To avoid this behavior ensure you set the keyword exportselect is set to 1 (the default is 0).
  • The double-click behavior will generate both a sigON_SELECT and a sigON_DOUBLE_CLICK signal. The first signal is to indicate that the something was selected, the second is to indicate that the user double-clicked on their selection.
Arguments:
parent : Tkinter.Frame
Parent widget, widget we insert into.
keywords
Variable keyword list defined below.
Keywords:

All keywords usable with the Tkinter.ListBox [1] widget are usable with the GListBox widget. However, the selectmode is always set to Tkinter.SINGLE.

items : list
List of strings to display within the listbox.
rtv : StringRTV
A variable to associate with listbox.
disabledbackground : string
A HEX representation of the RGB color to use when the listbox is disabled.
Components:
None.
Signals:
const.sigON_SELECT
Generated when the user picks an item in the list, this also transmits the index of the picked item.
const.sigON_DOUBLE_CLICK
Generated when the user double clicks on a list item, this also transmits the index of the picked item.
delete(first[, last])
Delete elements from first to last indices. If last index is not specified it will remove only the index specified in first.
destroy()
Handles Tkinter de-allocation.
disable()
Set the listbox to ignore user events.
enable()
Set the listbox to respond to user events.
selectedindex()

Returns the index of the selected item. Since only single is allowed I thought this little convenience function may come in handy for the GListBox.

The Python None is returned if no items are selected.

selection_clear()
Clears the selected item.
selection_set(index)
Sets the selected item to the one indicated in the index.
updatevars()
Forces a synchronization with the user interface and any internal run-time variable.

[1]John W. Shipman. "The Label widget." Tkinter Reference: a GUI for Python. 2004 June 6. 2004 June 18. <http://infohost.nmt.edu/tcc/help/pubs/tkinter/ar01s11.html>