configtreeview.tools Package

The tools package contains modules that work alongside the ConfigTreeView implementation. The tools package contains:

dataformatter module
A tool to convert a row of data that follows the structure defined by the ConfigTreeView implementation into the format that a GtkListStore expects( python list [] format) by mapping the index_map of the ConfigTreeView to the types list defined at ConfigTreeView runtime.

dataformatter Module

class configtreeview.tools.dataformatter.DataFormatter(index_map, types)

TreeView data coming from the server will come in list of dicts. Each dict represents a row in the treeview. Each key-path in the dict corresponds to an index as defined in the index_map of a ConfigTreeView. Example index_map( mapping a column hierachy to an index in the TreeView row):

{'address': {'markup': 6},
 'cell-bg-index': 10,
 'comments': {'markup': 7},
 'contact': {'markup': 3},
 'market': {'pixbuf': 5},
 'name': {'markup': 11},
 'payment': [{'markup': 8}, {'markup': 9}],
 'placed': {'markup': 4},
 'shipping': {'markup': 2},
 'status': [{'markup': 0}, {'markup': 1}]
}

Sample data(Key-paths will have the same hierarchy as the index_map:

{
  'market': {'pixbuf': 'images/pixbufs/my_image.png'},
  'name': {'markup': 'Wesley Hansen'},
  'cell-bg-index': 'blue',
  'address':{'markup': '2336 112th Avenue'}
}

As you can see, the data coming from the server will share the same hierarchy, as this is important to determine which column/renderer and, ultimately, the index in a row to insert the data into.

The DataFormatter will take care of this, creating a simple API to do it. It will be able to, taking in an index_map and a types list(these things are taken from a ConfigTreeView), take in data and generate formatted rows, which are ready for either appending to a liststore, or some other post-formatting function.

__init__(index_map, types)

Create a new data formatter with the given index_map and types

Parameters:
  • index_map – A dict that maps a key location to an index in the types list
  • types – A list of types that describe what data types, and the order with which, a row of data for this gtk.TreeView‘s TreeModel is expecting
get_new_row()

Returns an empty list with the correct length a gtk.TreeModel with the given index_map (from the constructor) expects.

Example: if the index_map contained 4 different values of type str, then this function would return: [None, None, None, None]

get_rows(data)

Yields formatted rows of data where data is a list of dicts, where each dict’s key-path has a valid value in index_map...if it doesn’t a warning is printed out, and that value is skipped in that row.

Parameters:data – The data, whose structure is a list of dicts, as described by the index_map.

Table Of Contents

Previous topic

configtreeview.tools Package

Next topic

Examples

This Page