# eric3.UI.TemplateViewer

Module implementing a template viewer and associated classes.

### Classes

TemplateEntry | Class immplementing a template entry.
TemplateGroup | Class implementing a template group.
TemplateToolTip | Class implementing a specialized tooltip.
TemplateViewer | Class implementing the template viewer.

### Functions

None

## TemplateEntry

Class immplementing a template entry.

### Derived from

QListViewItem

### Methods

TemplateEntry | Constructor
__extractVariables | Private method to retrieve the list of variables.
expandFormattedVariable | Private method to expand a template variable with special formatting.
getExpandedText | Public method to get the template text with all variables expanded.
getGroupName | Public method to get the name of the group this entry belongs to.
getName | Public method to get the name of the group.
getTemplateText | Public method to get the template text.
getVariables | Public method to get the list of variables.
setName | Public method to update the name of the group.
setTemplateText | Public method to update the template text.

### TemplateEntry (Constructor)

TemplateEntry(parent, name, templateText)

Constructor

parent
  parent widget of the template group (QWidget)
name
  name of the group (string or QString)
templateText
  text of the template entry (string or QString)

### TemplateEntry.__extractVariables

__extractVariables()

Private method to retrieve the list of variables.

### TemplateEntry.expandFormattedVariable

expandFormattedVariable(var, val, txt)

Private method to expand a template variable with special formatting.

var
  template variable name (string)
val
  value of the template variable (string)
txt
  template text (string)

### TemplateEntry.getExpandedText

getExpandedText(varDict, indent)

Public method to get the template text with all variables expanded.

varDict
  dictionary containing the texts of each variable with the variable name as key.
indent
  indentation of the line receiving he expanded template text (string)

Returns:
  the expanded template text (string)

### TemplateEntry.getGroupName

getGroupName()

Public method to get the name of the group this entry belongs to.

Returns:
  name of the group containing this entry (string)

### TemplateEntry.getName

getName()

Public method to get the name of the group.

Returns:
  name of the group (string)

### TemplateEntry.getTemplateText

getTemplateText()

Public method to get the template text.

Returns:
  the template text (string)

### TemplateEntry.getVariables

getVariables()

Public method to get the list of variables.

Returns:
  list of variables (list of strings)

### TemplateEntry.setName

setName(name)

Public method to update the name of the group.

name
  name of the group (string or QString)

### TemplateEntry.setTemplateText

setTemplateText(templateText)

Public method to update the template text.

templateText
  text of the template entry (string or QString)

Up

## TemplateGroup

Class implementing a template group.

### Derived from

QListViewItem

### Methods

TemplateGroup | Constructor
addEntry | Public method to add a template entry to this group.
getAllEntries | Public method to retrieve all entries.
getEntry | Public method to get an entry.
getLanguage | Public method to get the name of the group.
getName | Public method to get the name of the group.
removeAllEntries | Public method to remove all template entries of this group.
removeEntry | Public method to remove a template entry from this group.
setLanguage | Public method to update the name of the group.
setName | Public method to update the name of the group.

### TemplateGroup (Constructor)

TemplateGroup(parent, name, language="All")

Constructor

parent
  parent widget of the template group (QWidget)
name
  name of the group (string or QString)
language
  programming language for the group (string or QString)

### TemplateGroup.addEntry

addEntry(name, template, quiet=0)

Public method to add a template entry to this group.

name
  name of the entry (string or QString)
template
  template text of the entry (string or QString)
quiet
  flag indicating quiet operation (boolean)

### TemplateGroup.getAllEntries

getAllEntries()

Public method to retrieve all entries.

Returns:
  list of all entries (list of TemplateEntry)

### TemplateGroup.getEntry

getEntry(name)

Public method to get an entry.

name
  name of the entry to retrieve (string or QString)

Returns:
  reference to the entry (TemplateEntry)

### TemplateGroup.getLanguage

getLanguage()

Public method to get the name of the group.

Returns:
  language of the group (string)

### TemplateGroup.getName

getName()

Public method to get the name of the group.

Returns:
  name of the group (string)

### TemplateGroup.removeAllEntries

removeAllEntries()

Public method to remove all template entries of this group.

### TemplateGroup.removeEntry

removeEntry(name)

Public method to remove a template entry from this group.

name
  name of the entry to be removed (string or QString)

### TemplateGroup.setLanguage

setLanguage(language)

Public method to update the name of the group.

language
  programming language for the group (string or QString)

### TemplateGroup.setName

setName(name)

Public method to update the name of the group.

name
  name of the group (string or QString)

Up

## TemplateToolTip

Class implementing a specialized tooltip.

### Derived from

QToolTip

### Methods

TemplateToolTip | Constructor
maybeTip | Overridden protected slot to show the tooltip.

### TemplateToolTip (Constructor)

TemplateToolTip(parent)

Constructor

parent
  parent widget of the tooltip

### TemplateToolTip.maybeTip

maybeTip(p)

Overridden protected slot to show the tooltip.

p
  position of the mouse cursor (QPoint)

Up

## TemplateViewer

Class implementing the template viewer.

### Derived from

QListView

### Methods

TemplateViewer | Constructor
addEntry | Public method to add a template entry.
addGroup | Public method to add a group.
applyTemplate |
changeEntry | Public method to change a template entry.
changeGroup | Public method to rename a group.
contentsMouseDoubleClickEvent | Protected method of QListView.
getAllGroups | Public method to get all groups.
getGroupNames | Public method to get all group names.
handleAddEntry | Private slot to handle the Add Entry context menu action.
handleAddGroup | Private slot to handle the Add Group context menu action.
handleContextMenu | Private slot to show the context menu of the listview.
handleEdit | Private slot to handle the Edit context menu action.
handleExport | Private slot to handle the Export context menu action.
handleHelp | Private method to show some help.
handleImport | Private slot to handle the Import context menu action.
handleRemove | Private slot to handle the Remove context menu action.
handleSave | Private slot to handle the Save context menu action.
removeEntry | Public method to remove a template entry.
removeGroup | Public method to remove a group.

### TemplateViewer (Constructor)

TemplateViewer(parent, viewmanager)

Constructor

parent
  the parent (QWidget)
viewmanager
  reference to the viewmanager object

### TemplateViewer.addEntry

addEntry(groupName, name, template, quiet=0)

Public method to add a template entry.

groupName
  name of the group to add to (string or QString)
name
  name of the entry to add (string or QString)
template
  template text of the entry (string or QString)
quiet
  flag indicating quiet operation (boolean)

### TemplateViewer.addGroup

addGroup(name, language="All")

Public method to add a group.

name
  name of the group to be added (string or QString)
language
  programming language for the group (string or QString)

### TemplateViewer.applyTemplate

applyTemplate(itm)

### TemplateViewer.changeEntry

changeEntry(itm, name, groupName, template)

Public method to change a template entry.

itm
  template entry to be changed (TemplateEntry)
name
  new name for the entry (string or QString)
groupName
  name of the group the entry should belong to (string or QString)
template
  template text of the entry (string or QString)

### TemplateViewer.changeGroup

changeGroup(oldname, newname, language="All")

Public method to rename a group.

oldname
  old name of the group (string or QString)
newname
  new name of the group (string or QString)
language
  programming language for the group (string or QString)

### TemplateViewer.contentsMouseDoubleClickEvent

contentsMouseDoubleClickEvent(mouseEvent=None)

Protected method of QListView.

Reimplemented to disable expanding/collapsing of items when double-clicking. Instead the selected template text is expanded and inserted at the cursor position of the active document.

mouseEvent
  the mouse event (QMouseEvent)

### TemplateViewer.getAllGroups

getAllGroups()

Public method to get all groups.

Returns:
  list of all groups (list of TemplateGroup)

### TemplateViewer.getGroupNames

getGroupNames()

Public method to get all group names.

Returns:
  list of all group names (list of strings)

### TemplateViewer.handleAddEntry

handleAddEntry()

Private slot to handle the Add Entry context menu action.

### TemplateViewer.handleAddGroup

handleAddGroup()

Private slot to handle the Add Group context menu action.

### TemplateViewer.handleContextMenu

handleContextMenu(itm, coord, col)

Private slot to show the context menu of the listview.

itm
  the selected listview item (QListViewItem)
coord
  the position of the mouse pointer (QPoint)
col
  the column of the mouse pointer (int)

### TemplateViewer.handleEdit

handleEdit()

Private slot to handle the Edit context menu action.

### TemplateViewer.handleExport

handleExport()

Private slot to handle the Export context menu action.

### TemplateViewer.handleHelp

handleHelp()

Private method to show some help.

### TemplateViewer.handleImport

handleImport()

Private slot to handle the Import context menu action.

### TemplateViewer.handleRemove

handleRemove()

Private slot to handle the Remove context menu action.

### TemplateViewer.handleSave

handleSave()

Private slot to handle the Save context menu action.

### TemplateViewer.removeEntry

removeEntry(itm)

Public method to remove a template entry.

itm
  template entry to be removed (TemplateEntry)

### TemplateViewer.removeGroup

removeGroup(itm)

Public method to remove a group.

itm
  template group to be removed (TemplateGroup)

Up