rbcurse 0.1.2 gem released

Posted February 22, 2009 by totalrecall
Categories: ruby

Version 0.1.2 of rbcurse (Ruby Curses Widgets) has been released. Minor enhancements:

  • search in textview, textarea with wrap-around, case insensitive and highlighting searched text
  • table can have nil data to start with
  • tabbed pane has  ok button by default, can set ok_cancel etc
  • table autosizing – required for adhoc queries
  • table horizontal scrolling – if more columns than can be shown
  • Table editing when more columns than viewable in table
  • Confirm dialog, normal mnemonics for buttons (in addition to Alt-o, Alt-c etc)

I expect to release 0.1.3 by Feb 28th, with more minor tweaks. See http://rubyforge.org/frs/?group_id=7775

Sample: SQL Client in ruby ncurses

Posted February 14, 2009 by totalrecall
Categories: ncurses, rbcurse, ruby

I am putting up a small SQL Client made in about 3 hours using rbcurse. The idea of course was to see deficiencies in the library, and yes, for adhoc queries auto_sizing of columns is required. Need to work on that.

quick dirty sql client

quick dirty sql client

The demo shows a textarea, enter a query and press Run to see the results in a table. The listbox on top-right shows the tables in the database, pressing Space on any will show its columns in the second list. Pressing Enter will display its data in the table.

The idea of the columns is to select columns and have the names be pushed to the textarea, or auto-generate SQL’s.Similar to sqlminus (sourceforge project).

I will put in some more work on this, just to find out how rbcurse can be improved more.

Image Link
Video Link.

Update on Finder app (ruby curses)

Posted February 9, 2009 by totalrecall
Categories: ruby

A very rough demo (7 mb) of the app (sorry, its hastily done with no planning) and a couple screens. The aim is really to find loopholes in the ruby curses widgets and framework. I have while making this added the ability to easily get radio buttons and checkboxes onto dialog boxes. You almost always need them in dialogs in a serious application. The Finder (file explorer) demo actually does quite a lot and i will keep enhancing it slowly.

File explorer sample app

File explorer sample app

Next application is to do a basic SQL viewer using the curses Tables. I intend making different kinds of apps with basic functionality to see that the widgets provide what is needed.

rubygem

I have also registered for a project on rubyforge, and will try creating a gem using HOE and uploading. Then I can keep releasing rbcurse as a gem.

Finder app using ruby curses widgets

Posted February 2, 2009 by totalrecall
Categories: rbcurse

After some work on a TODO app, which used editable tables and other widgets, I have started a sort of Finder app with 2 panes, like Midnight Commander. Shows how easy it is to put up something with minimal code using the Listbox widget.

This will also use the TextView for viewing files, TextArea for editing files (or your EDITOR). The aim of this application, as was the aim of the TODO, is to see how well the widgets fare when we use them for something useful.
Here’s a very rough pic, will keep updating this link as things improve.

file explorer application using rbcurses widgets

file explorer application using rbcurses widgets

(Offtopic: am recovering from a bad cold, but will take longer to recover from Roger’s loss at AO).

First real app with Ruby-Curses (rbcurse)

Posted January 18, 2009 by totalrecall
Categories: ncurses, rbcurse, ruby

I decided to start doing a small app to test out the widgets (VIDEO). More real life than the eye-candy I’ve been posting till now. Its a TODO like app which will actually manage my TODO, FIXME, DONE list that I am using for this. The base is a YAML file – not the best idea compared to a database, I know, since the list will grow with time.

So a lot of minor issues and bugs or gaps are getting taken care of. Yes, occasionally a bug creeps in too!
I am realizing that for real-life table sorting and filtering is required — without touching the table model, else I wont be able to write back to disk. I have it in mind, an intermediate view that maps to the table model.

I will be adding more options or customizations so the widgets suit real needs rather than just look cute.
Here’s the first rough screen-shot after half a day of work. I _am_ using it! This link will have an updated screenshot, updated daily once. Another.

Todo app with cursor on category combo list

Todo app with cursor on category combo list

Briefly, Category is a combo and refreshes the table with items for that category such as TODO, DONE, FIXME etc.
The :CHANGED event is bound to refresh the table.
Within the table, Module and Status are combos too. Priority is numeric, and Task is wider than displayed and will horizontally scroll. Within the table, TAB and backtab will go from cell to cell. After the last cell, they go to next row. When no more row, they go to next field. Alt-Tab and Alt-backtab immediately moved to next/previous field.

Down and UP arrow, C-n and C-p, do vertical navigation or paging. Interestingly, combos use UP and DOWN for changing the value, however, this app unbinds the combos UP and DOWN so it can be used by Table for navigation. One can still change combo values using M-Down (alt-down). One rarely modifies Module anyway. This is one example of actual usage making me change or tweak widgets.

Editing automatically happens on entering a cell. In the demo video, editing on a cell required hitting ENTER. Otherwise the cells were readonly, and navigation was fast. This is optional now. Tables that have very little editing such as a Finder/File Explorer can require user to press ENTER to make a cell editable.

Hopefully, by Jan end, I can release a V0.1.

Check todo.yml and testtodo.rb on github. VIDEO LINK.

Update: I have added an ApplicationHeader class and KeyLabels like alpine (email client) has at top and bottom. See latest screenshot. In this image, cursor moves to the Tasks Table and the keys printed below change. Table Row is updated as you scroll down the table.

Editable Multi-column tables

Posted January 13, 2009 by totalrecall
Categories: ncurses, rbcurse, ruby

Quite excited to share that I’ve just got editable tables coded and running. String, numeric, checkboxes (for boolean) and combolists. That sort of covers the minimum requirements of an editable table. Also see earlier post with a non-edit table that allowed column moving, resizing etc.

Editable table

Editable table

A quicktime file demos this 2.6 MB).  Updated on Jan 16th.

1. Keys! One needs to decide whether editing should automatically happen when you enter a field (I have used that approach in the editable lists) or upon a key.
In tables, I’ve starting editing on hitting ENTER. Save also on hitting ENTER. Esc or C-c cancels edit.

The demos shows me editing a couple of string fields, cancelling an edit, toggling a checkbox and then changing values in a combo list on 2 rows. All this is easily possible due to CellRenderers and CellEditors. Thus, one can easily add another widget onto a table, and just run some tests to ensure it’s working and displaying fine.

I guess now for some time, I will tweak and clean up – nothing new. I shall try writing some sample apps, to figure out anything missing, integrating this with some yaml files and a database. Perhaps a table row sorter could happen (I love writing new stuff!)

Edit: Updated demo. You can also see events being fired in the Events field below.

Screenshot.
Demo.

Editable lists: Fields, Checkboxes, ComboBoxes

Posted January 11, 2009 by totalrecall
Categories: rbcurse, ruby

Thanks to CellRenderers and CellEditors, we may edit existing lists with just this line added:


  cell_editing_allowed true
  

If you want row selectors to be shown:


    show_selector true
  

The selector itself may be changed, the default is a gt sign: “>”

Editable list using Field class

Editable list using Field class

Since the rows are selectable, therefore you can make a list of items, and select some as you would in a checklist, or todo list. However, now the user can edit and add to the list also. However, editing facilities means that keys for selection and navigation need to be selected so they do not clash with editing keys. Earlier, space bar selected.

Here is the result on a list of strings. When the cursor falls on the row, the default CellEditor which uses a Field is used for accepting keys. You may extend and install your own editor, as we have done for checkboxes and combos.

By default, boolean values would show as “true” and “false”, so we needed to create a CheckBoxCellRenderer, that display true and false just as a checkbox does. As far as the CellEditor is concerned, just pass a Checkbox in the constructor. It will be reused for editing each row.(link)

The 2 important lines are:


          # create and set a cell renderer

          cell_renderer RubyCurses::CheckBoxCellRenderer.new nil, {"parent" => self, "display_length"=> @width-2}

          # create and set a cell editor, passing a checkbox
          cell_editor RubyCurses::CellEditor.new(RubyCurses::CheckBox.new nil, {"focusable"=>false, "visible"=>false})

  

A listing of the box code is as follows. alist is the list of boolean values.


        alist = [true, false, true, false, true, false, true, false, true]
        cblist = RVariable.new alist
        listcb = Listbox.new @form do
          name   "cblist"
          row  1
          col  96
          width 8
          height 10
#         list mylist
          list_variable cblist
          #selection_mode :SINGLE
          title "Checklist"
          title_attrib 'reverse'
          cell_renderer RubyCurses::CheckBoxCellRenderer.new nil, {"parent" => self, "display_length"=> @width-2}
          cell_editing_allowed true
          cell_editor RubyCurses::CellEditor.new(RubyCurses::CheckBox.new nil, {"focusable"=>false, "visible"=>false})
        end
  

The above will be of more practical value when we allow editable multi-column tables, with columns containing Fields, checkboxes etc.

A list of editable checkboxes, and one of combolists

A list of editable checkboxes, and one of combolists

The next example is of a list of comboboxes. The main lines are those setting the CellRenderer (not really required, i think, since the combobox extends Field. However, the editor is created with a combobox passed in the constructor of the editor. Note that the constructor of the combobox must pass in the list or list_data_model, as before.


          cell_renderer RubyCurses::ComboBoxCellRenderer.new nil, {"parent" => self, "display_length"=> width()-2}
          cell_editing_allowed true
          cell_editor RubyCurses::CellEditor.new(RubyCurses::ComboBox.new nil, {"focusable"=>false, "visible"=>false, "list"=>colist, "display_length"=>width()-2})

  

Big internal changes amiss

Posted January 8, 2009 by totalrecall
Categories: rbcurse, ruby

Some major changes (internal)

### firing property change

1. In order not to repaint the entire form each time, we must only repaint a widget when modified. However, as can be seen, widgets are being modified by other widgets. Thus whenever a property is changed, we need a flag to be set that repainting is required.

### dsl_property

Thus, copied dsl_accessorand made dsl_property. Whenever, such props are modified, a property change is now fired, and repaint_required is set to true. I am currently changing this. What this means is that on startup, fire_prop_change will be called many times, and i need to avoid this on first time instantiation. TODO.

2. The tricky part was text_variables. When their value changes, any widget (such as label) automatically changes. NOW: When a text_variable is defined for field, internally that field, adds itself as a dependent. When its value is changed, it fires a change to the dependent field.

3. The real worrisome part was this:

When user passes in a hash in the constructor, i was directly setting variables, NOT calling methods. Tracked this down. Now i am calling methods and not setting variables. See rwidget.rb variable_set (top). Only thorough testing will tell how much this change will affect stuff. Maybe not.

4. Rewriting Listboxes: the scrolling and painting logic was crap. I did not understand modules then. I think I have had an insight into modules and classes now. Also, a ListCellRenderer is being used, as in Table.

So basically, things are going to be unstable for a week or so.

Those alternating rows everyone craves

Posted January 7, 2009 by totalrecall
Categories: ruby

Just thought i’d override the TableCellRenderer and set it, and voila, those alternating colored rows some folks want.

testtable.rb contains various column manipulations, as well as a sample of editing table cells using an external field.

alternate colors on rows

alternate colors on rows

class Table : rough release

Posted January 6, 2009 by totalrecall
Categories: rbcurse, ruby

A wip release of Table, tabular data based on the MVC architecture. Default models and listeners and created and can be manipulated for specific behaviour. CellRenderers are used for columns and headers which may be set or modified.

Besides selection of rows, and scrolling, column add/delete/move/resizing are supported. Listeners on selection and change are to be worked on. Currently, editing is not provided, but coming in future release.

The demo (1.3 mb) shows columns being widened and narrowed, column deletion, etc.
The first screenshot shows 2 selected rows, and one focussed row.

Ruby Curses Table with row selection

Ruby Curses Table with row selection

The second screenshot is after moving a row, and narrowing the first row. Demo link.

Row moving and resizing

Row moving and resizing