Code documentation

How it works

vkvh represents kvh-files in the form of a tree based on a widget of wxPython library wx.lib.agw.hypertreelist.HyperTreeList. Each tree has a coupled flat list with key-value pairs tree.itlist. This flat list is used as helper for searching and editing tree items.

Each tree is shown in a wx.Panel which, in turn, is a tab in the wx.aui.AuiNotebook shown in the main window.

Code files

  • vkvh.py - a file which contains the code for the interface structure. The search interface is also defined in this file. It uses the functions from the parcours.py to create trees and to realize search procedures.

  • parcours.py - a file which contains functions used for construction and manipulation of a tree.

Details of vkvh.py

The file vkvh.py contains mostly the code for GUI (graphical user interface) of the application.

class vkvh.vkvh.HistSearchCtrl(parent, id=-1, value='', pos=wx.Point(-1, -1), size=wx.Size(-1, -1), style=0, doSearch=None, name='searchCtrl')
MakeMenu()
OnMenuItem(evt)
OnTextEntered(evt)
maxSearches = 5
class vkvh.vkvh.MyForm
DoSearch(text)

called by HistSearchCtrl

OnNew(evt)

Create a new KVH file and a tab for editing its content. Must be followed by “Save” or “Save as”.

OnOpen(evt)

Called with “File > Open”. User can choose a file from his directories. It creates a new tab of the NoteBook, where a tree list control will be created

OnReload(evt)

Re-read KVH file into current tab for editing its content.

OnSave(evt)

Save current tab in its path

OnSaveAs(evt)

Save current tab in asked path

OnTabChange(evt)
OnTabClose(evt)
err_mes(mes)

Show dialog with error message

f2tab(path, tab=None)
noyes(mes)

Show Yes/No dialog with ‘No’ default. Returns True for Yes, False for No

onQuit(event)

Function to quit application

onSwitchAide(event)

Function for Help message dialog

onSwitchInfo(event)

Function for Information message dialog

vkvh.vkvh.main()

Details of parcours.py

A tree is created by a method make_tree() of a class TreeCreation. The latter creates a new panel to be added to the notebook. The main search helper is the function parcours_tree_by_label()

vkvh.parcours.AddItem(tree, content, parent)

Recursive function, without return value, which add items to the tree

param tree

Tree list control

type tree

wx.lib.gizmos.treelistctrl.TreeListCtrl

param content

Content of the kvh file in the form of the list which contains couples of keys and values

type content

list[tuple]

param parent

Initially, the root of the tree, then parents for each level recursively

type parent

wx.lib.agw.hypertreelist.TreeListItem

vkvh.parcours.PathCreation(tab)

Show the path to the selected item in the status window

Parameters

tab (Panel) – Parent element (layer) of the tree

class vkvh.parcours.TreeCreation(parent, path)

Create a panel and tree list control from path

Parameters
  • parent (wx.aui.AuiNotebook) – Parent element (notebook) of the tree.

  • path (str) – Path to a kvh file.

OnAddKey(event, after=1)
OnCollapse(evt)
OnExpand(evt)
OnItemDelete(event)
OnKeyAfter(event)
OnKeyBefore(event)
OnLabelEdit(evt)
OnLeftDClick(event)
OnRightUp(event)

create popup menu on rightclick

OnSelect(evt)
OnSize(evt)
OnSubKey(event)
make_tree(path)
vkvh.parcours.get_desc(tree, item)

Collect tuples (index, item) of the item and all its descendants in the tree

vkvh.parcours.parcours_tree_by_label(tree, search_text, dir_up, in_kv, wholeWord, matchCase)

Function for a search of the text. Returns ID of the found element, None otherwise.

param tree

Tree widget

param search_text

search text

type search_text

str

param dir_up

if True: search in backward direction

param in_kv

contains “k” and/or “v” for searching in keys/values

type in_kv

string

param wholeWord

if True: match only the whole word

param matchCase

if True: match case in the search

return

TreeId of the element of the tree widget if found

rtype

None if no corresponding elements were found

vkvh.parcours.text_in_item(search_text, item, in_kv, wholeWord, matchCase)

Returns True or False if the search_text is found or not in the item

Parameters
  • search_text (str) – search text

  • item – tree item ( root item for the first search )

  • in_kv (string) – have we search in the key, in the value or both? Takes value one of “k”, “v”, “kv”.

  • wholeWord (Bool) – True if the whole word must be found

  • matchCase (Bool) – True if a case of the element must correspond to the case of the search text

Returns

True if text was found in the item

vkvh.parcours.tree2tlist(tree, li=None)

Translate a (sub-)tree in a list of kv-tuples for storing in kvh file