Module abstk

Main module to AbsTK

Info:

  • License: MIT
  • Author: Pedro Alves

abstk

set_mode (arg) Sets mode to determine whether UI will be drawn, TUI (Curses) or GUI (GTK).
new_screen (title, w, h) Constructs a Screen.
new_wizard (title[, w=600][, h=w*0.75], exit_callback) Constructs a Wizard.

Class Screen

Screen:add_label (id, label) Adds a label to screen.
Screen:add_button (id, label[, tooltip[, callback]]) Adds a button to screen.
Screen:create_button_box (id, labels[, tooltips[, callbacks]]) Creates a buttonset and adds it to screen.
Screen:create_combobox (id, title, labels[, default_value=1[, tooltip[, callback]]]) Creates a ComboBox and adds it to screen.
Screen:add_image (id, path[, dimensions[, tooltip]]) Adds an image widget to screen.
Screen:add_text_input (id[, label[, default_value[, tooltip[, callback]]]]) Adds a text input field to screen.
Screen:add_password (id[, label[, default_value[, tooltip[, callback]]]]) Adds a password input field to screen.
Screen:add_textbox (id[, title[, default_value[, tooltip]]]) Adds a TextBox field to the screen.
Screen:add_checkbox (id, label[, default_value[, tooltip[, callback]]]) Adds a single checkbox to the screen.
Screen:create_checklist (id, title, list[, default_value[, tooltip[, callback]]])

Creates a checkboxes list and adds it to the screen.

Screen:create_selector (id, title, list[, default_value[, tooltip[, callback]]])

Creates a list in which just one item can be selected at a time and adds it to the screen.

Screen:show_message_box (message[, buttons='OK']) Shows a message box.
Screen:set_enabled (id, bool[, index]) Enables or disables a widget.
Screen:delete_widget (id) Deletes a widget from screen.
Screen:set_value (id, value[, index]) Sets a value to a widget.
Screen:get_value (id[, index]) Gets the value of a widget.
Screen:run (self) Runs a single screen.

Class Wizard

Wizard:add_page (id, screen) Adds a screen to a wizard.
Wizard:run (self) Runs a wizard.


abstk

set_mode (arg)
Sets mode to determine whether UI will be drawn, TUI (Curses) or GUI (GTK).

Parameters:

  • arg the mode
new_screen (title, w, h)
Constructs a Screen.

Parameters:

  • title the title of the screen
  • w the width of the screen (only used in GUI)
  • h the height of the screen (only used in GUI)

Returns:

    a Screen.
new_wizard (title[, w=600][, h=w*0.75], exit_callback)
Constructs a Wizard.

Parameters:

  • title the title of the window
  • w the width of the window (only used in GUI) (default 600)
  • h the height of the window (only used in GUI) (default w*0.75)
  • exit_callback a callback function to override the default confirmation messagebox. Receives exit ("DONE" or "QUIT"), data and screen. Must return true or false. More info at https://github.com/PedroAlvesV/AbsTK/wiki/Callbacks#exit-callback

Returns:

    a Wizard.

Class Screen

Screen:add_label (id, label)
Adds a label to screen.

Parameters:

  • id the id of the object
  • label the text itself to be the label
Screen:add_button (id, label[, tooltip[, callback]])
Adds a button to screen.

Parameters:

  • id the id of the object
  • label the label that will be written over the button
  • tooltip a tooltip text for the button (optional)
  • callback a callback function to the button. This callback function receives two arguments: the id (string) and the label of the button (string). (optional)
Screen:create_button_box (id, labels[, tooltips[, callbacks]])
Creates a buttonset and adds it to screen.

Parameters:

  • id the id of the object
  • labels a table containing the labels that will be written over the buttons
  • tooltips a table containing the tooltips texts for the buttons (optional)
  • callbacks a table containing the callback functions to the buttons. Every function receives three arguments: the id (string), the index of the clicked button (number) and its label (string). (optional)
Screen:create_combobox (id, title, labels[, default_value=1[, tooltip[, callback]]])
Creates a ComboBox and adds it to screen. On GUI it's a dropdown menu, on TUI turns into a Selector.

Parameters:

  • id the id of the object
  • title the title of the field
  • labels a table containing the labels that will be the entries
  • default_value the index of the entry selected by default (default 1)
  • tooltip a tooltip text for the object (optional)
  • callback a callback function. This callback function receives three arguments: the id (string), the index of the clicked item (number) its label (string). (optional)

See also:

Screen:add_image (id, path[, dimensions[, tooltip]])
Adds an image widget to screen. Does nothing if running TUI.

Parameters:

  • id the id of the object
  • path the path of the image file
  • dimensions a table containing the dimensions to resize the image (optional)
  • tooltip a tooltip text for the object (optional)

Usage:

    scr:add_image('lua_img', 'images/lua.png')
    scr:add_image('batman_img', 'images/batman.png', {512, 384})
Screen:add_text_input (id[, label[, default_value[, tooltip[, callback]]]])
Adds a text input field to screen.

Parameters:

  • id the id of the object
  • label a label that precedes the field (optional)
  • default_value a placeholder (optional)
  • tooltip a tooltip text for the object (optional)
  • callback a callback function to the field. This callback function receives two arguments: the id (string) and the text that is inside the field (string). (optional)
Screen:add_password (id[, label[, default_value[, tooltip[, callback]]]])
Adds a password input field to screen. It's essentially a text input that covers the text on the UI.

Parameters:

  • id the id of the object
  • label a label that precedes the field (optional)
  • default_value a placeholder (optional)
  • tooltip a tooltip text for the object (optional)
  • callback a callback function to the field. This callback function receives two arguments: the id (string) and the text that is inside the field (string). (optional)

See also:

Screen:add_textbox (id[, title[, default_value[, tooltip]]])
Adds a TextBox field to the screen.

Parameters:

  • id the id of the object
  • title a title to the box (optional)
  • default_value the text (optional)
  • tooltip a tooltip text for the object (optional)
Screen:add_checkbox (id, label[, default_value[, tooltip[, callback]]])
Adds a single checkbox to the screen.

Parameters:

  • id the id of the object
  • label the label of the checkbox
  • default_value a boolean to determine the default state of the checkbox (optional)
  • tooltip a tooltip text for the object (optional)
  • callback a callback function to the checkbox. This callback function receives three arguments: the id (string), the state of the box (boolean) and its label (string). (optional)

See also:

Screen:create_checklist (id, title, list[, default_value[, tooltip[, callback]]])

Creates a checkboxes list and adds it to the screen. There are 4 ways to call it. The first one is by passing just an array with the labels as the list parameter. The second one is similar, but you pass, also, an array of booleans, as default\_value, representing the states of those buttons. The third one is an alternative to the second, since it's better readable: you pass an array of tables. Each table represents a box and its state. Also, there's a fourth way of doing that: default\_value can be just a single index to mark an item.

Parameters:

  • id the id of the object
  • title the title of the list
  • list an array with the labels or an array of tables holding paired info.
  • default_value a table containing the states of the boxes or the index to a single item (optional)
  • tooltip a tooltip text to the list (optional)
  • callback a callback function to the boxes. This callback function receives four arguments: the id (string), the index of the clicked checkbox (number), its index (number) and its label (string). (optional)

See also:

Usage:

    scr:create_checklist('style1', "Checklist 1:", {'a', 'b', 'c'}, nil, tooltip, chk_callback)
    
    scr:create_checklist('style2', "Checklist 2:", {'7', '8', '9'}, {true, false, true}, tooltip, chk_callback)
    
    local check_table = {
      {'z', false},
      {'x', true},
      {'c', true},
    }
    scr:create_checklist('style3', "Checklist 3:", check_table, nil, tooltip, chk_callback)
    scr:create_checklist('style4', "Checklist 4:", {'x', 'y', 'z'}, 3, tooltip, chk_callback)
Screen:create_selector (id, title, list[, default_value[, tooltip[, callback]]])

Creates a list in which just one item can be selected at a time and adds it to the screen. Its calling is very similar to checkboxes. There are 3 ways to do so. The first one is by passing just an array with the labels as the list parameter. The second one is different from it's equivalent in checkboxes, because selector items can only be active one at the time. So, the second way asks for a number — the index, more precisely —, as default\_value, to activate that button. The third one is actually equal to it's equivalent in checkboxes (list being an array of tables).

Parameters:

  • id the id of the object
  • title the title of the list
  • list an array with the labels or an array of tables holding paired info.
  • default_value a index to refer the active button (optional)
  • tooltip a tooltip text to the list (optional)
  • callback a callback function to the list. This callback function receives three arguments: the id (string), the index of the clicked item (number) and its label (string). (optional)

See also:

Usage:

    scr:create_selector('style1', "Selector 1:", {'x', 'y', 'z'}, nil, tooltip, slct_callback)
    
    scr:create_selector('style2', "Selector 2:", {'a', 's', 'd'}, 3, tooltip, slct_callback)
    
    local selector_values = {
      {'q', false},
      {'w', true},
      {'e', false},
    }
    scr:create_selector('style3', "Selector 3:", selector_values, nil, tooltip, slct_callback)
Screen:show_message_box (message[, buttons='OK'])

Shows a message box. There are a few constants to determine which buttonset is going to be used in a message box. Those are:

  • OK - an OK button
  • CLOSE - a Close button
  • YES_NO - Yes and No buttons
  • OK_CANCEL - OK and Cancel buttons

Parameters:

  • message the message that will be written over the message dialog
  • buttons an constant that determines which buttonset is going to be used (default 'OK')

Returns:

    usually, the clicked button label in uppercase. However, CLOSE button returns "CANCEL".
Screen:set_enabled (id, bool[, index])
Enables or disables a widget.

Parameters:

  • id the id of the object
  • bool the boolean value representing if it will enable or disable the widget
  • index an index to target the child button of a buttonbox (optional)
Screen:delete_widget (id)
Deletes a widget from screen.

Parameters:

  • id the id of the object

Returns:

    true if successful, false if not
Screen:set_value (id, value[, index])

Sets a value to a widget. Each widget works with a type of value:

  • Label - string (label itself)
  • Button - string (button label)
  • ButtonBox - string (single button label)
  • ComboBox - integer (item to be set active index)
  • Image - string (image path)
  • Text Input - string (text to be insert)
  • Password Input - string (text to be insert)
  • TextBox - string (text to be insert)
  • CheckBox - boolean (state of button)
  • CheckList - boolean (state of button) and integer (item index)
  • Selector - table (the new items list) and integer (default value)

Parameters:

  • id the id of the object
  • value the value that will be assigned to the widget
  • index an index to target the child of the widget. Must be passed to refer to set ButtonBoxes, ComboBoxes and CheckLists. To Selectors it becames new list's default_value and is optional. (optional)

Usage:

    scr:set_value('label', "New Label")
    scr:set_value('button', "New Button Label")
    scr:set_value('button_box', "New Button Label", 2)
    scr:set_value('combobox', 2)
    scr:set_value('image', 'imgs/image.png')
    scr:set_value('text_input', "New Text")
    scr:set_value('password_input', "New Password")
    scr:set_value('textbox', "New Text")
    scr:set_value('checkbox', true)
    scr:set_value('checklist', true, 1)
    scr:set_value('selector', {'item1', 'item2', 'item3'}, 2)
Screen:get_value (id[, index])
Gets the value of a widget.

Parameters:

  • id the id of the object
  • index an index to target the child of the widget, if it has children (optional)

Returns:

    • Label - a string (label itself)
    • Button - a string (button label)
    • Buttonbox - a string (single button label)
    • Combobox - a string (active entry)
    • Image - a string (image path)
    • Text input - a string (current text)
    • Textbox - a string (current text)
    • Checklist - a string and a boolean (label and state of button)
    • Selector - a string and a boolean (label and state of button)
Screen:run (self)
Runs a single screen. Doing so, presumes a single screen window. If it needs more than a single screen, must add them all to a wizard and run only the wizard.

Parameters:

  • self

Returns:

    a table containing all widgets data

See also:

Class Wizard

Wizard:add_page (id, screen)
Adds a screen to a wizard. The screen turns into a page with footer navigation buttons.

Parameters:

  • id the id of the object
  • screen the screen that will be added
Wizard:run (self)
Runs a wizard. Must be called in the end of the UI construction.

Parameters:

  • self

Returns:

    a table containing all widgets data

See also:

generated by LDoc 1.4.6 Last updated 2017-04-06 15:36:58