Supporting classes for metagui
Exit with a traceback, and print a custom error message.
Ensure that the given objects are of the required type. If not, print a message and call exit_with_traceback.
Divide a list of things into several pieces, of roughly equal size.
Get a tk.PhotoImage from a given image file.
- filename
- Full path to the image file, in any format that ‘convert’ understands
- width
- Desired image width in pixels
- height
- Desired image height in pixels
- background
- An ‘#RRGGBB’ string for the desired background color. Only effective for images with transparency.
- dither
- True to dither the image. May increase graininess. Smallish images usually look better without dithering.
Width and height may be used to scale the image in different ways:
- width == 0, height == 0
- Preserve the original image’s size
- width > 0, height == 0
- Resize to the given width; height automatically adjusts to maintain aspect ratio
- width == 0, height > 0
- Resize to the given height; width automatically adjusts to maintain aspect ratio
- width > 0, height > 0
- Resize to exactly the given dimensions
A Listbox with a scrollbar.
Similar to a tk.Listbox, a ScrollList shows a list of items. tk.Variable objects may be associated with both the list of items, and the one that is currently selected.
Create a ScrollList widget.
- master
- Tkinter widget that will contain the ScrollList
- items
- ListVar or Python list of items to show in listbox
- selected
- Tk StringVar to store currently selected choice in
Keyword arguments:
- width
- Width of the listbox, in characters
- height
- Height of the listbox, in characters
Add the given values to the end of the list. Calls insert callbacks for each added item.
Add a callback function for the given action.
- action
- May be ‘insert’, ‘remove’, ‘select’, or ‘swap’
- function
- Callback function to call for the given action
All callback functions except ‘swap’ must take (index, value) parameters; the ‘swap’ callback should accept (index_a, index_b). In all cases, index is 0-based, and -1 is passed for the last item.
Delete values in a given index range (first, last), not including last itself. If last is None, delete only the item at index first. Calls remove callbacks for each removed item.
Return a list of all entries in the list.
Insert values at a given index. Calls insert callbacks for each added item.
Link to another ScrollList, so they scroll and select in unison.
Event handler when <Return> is pressed
Event handler when the list is scrolled.
Event handler when an item in the list is selected.
Select (highlight) the list item at the given index. Calls select callbacks for the selected item.
Set the list values to those given.
Set the ScrollList to use the given ListVar for its items.
Summon callbacks for the given action, passing index and item to each.
Swap the element at index_a with the one at index_b. Calls swap callbacks for the swapped items.
A scrollable listbox with drag-and-drop support.
Create a DragList widget.
Event handler when an item in the list is dragged.
Event handler when an item in the list is “dropped”.
Event handler when an item in the list is selected.
A widget for choosing an ImageMagick font name.
Set the selected font. Called by base Dialog when “OK” is pressed.
Draw widgets inside the Dialog, and return the widget that should have the initial focus. Called by the Dialog base class constructor.
Redraw the preview using the current font and size.
Return a tk.PhotoImage preview of the given font.
A popup widget with a scale for choosing a number.
Create the scale dialog with the given Number control as a parent.
Set the result to the current scale value. Called when “OK” is pressed.
Draw the popup dialog and return the widget that should have the initial focus.
Configuration settings dialog box.
Create and display a configuration window.
Apply the selected configuration settings.
Draw widgets inside the Dialog, and return the widget that should have the initial focus. Called by the Dialog base class constructor.
Return a (family, size, style) tuple for the current font.
Refresh the preview to show the current font.
A top-level window with scrollbars.
To use as a container for other widgets, do:
window = ScrolledWindow()
button = tk.Button(window.frame, text="Click me", ...)
entry = tk.Entry(window.frame, ...)
window.draw()
That is, use window.frame as the master of child widgets, instead of window itself. (TODO: Eliminate this requirement.)
Draw the scrollbars and container frame.
Generic widget style definitions.
Apply the current style to the given Tkinter root window.
Load style settings from an .ini-formatted config file.
Save the current style settings to an .ini-formatted config file.