# eric6.Templates.TemplateViewer

Module implementing a template viewer and associated classes.

### Global Attributes

None

### Classes

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

### Functions

None

## TemplateEntry

Class immplementing a template entry.

### Derived from

QTreeWidgetItem

### Class Attributes

None

### Class Methods

None

### Methods

TemplateEntry | Constructor
__displayText | Private method to generate the display text.
__expandFormattedVariable | Private method to expand a template variable with special formatting.
__extractVariables | Private method to retrieve the list of variables.
getDescription | Public method to get the description of the entry.
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 entry.
getTemplateText | Public method to get the template text.
getVariables | Public method to get the list of variables.
setDescription | Public method to update the description of the entry.
setName | Public method to update the name of the entry.
setTemplateText | Public method to update the template text.

### Static Methods

None

#### TemplateEntry (Constructor)

TemplateEntry(parent, name, description, templateText)

Constructor

parent
  parent widget of the template entry (QWidget)
name
  name of the entry (string)
description
  descriptive text for the template (string)
templateText
  text of the template entry (string)

#### TemplateEntry.__displayText

__displayText()

Private method to generate the display text.

Returns:
  display text (string)

#### 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)

Returns:
  expanded and formatted variable (string)

#### TemplateEntry.__extractVariables

__extractVariables()

Private method to retrieve the list of variables.

#### TemplateEntry.getDescription

getDescription()

Public method to get the description of the entry.

Returns:
  description of the entry (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:
  a tuple of the expanded template text (string), the number of lines (integer) and the length of the last line (integer)

#### 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 entry.

Returns:
  name of the entry (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.setDescription

setDescription(description)

Public method to update the description of the entry.

description
  description of the entry (string)

#### TemplateEntry.setName

setName(name)

Public method to update the name of the entry.

name
  name of the entry (string)

#### TemplateEntry.setTemplateText

setTemplateText(templateText)

Public method to update the template text.

templateText
  text of the template entry (string)

Up

## TemplateGroup

Class implementing a template group.

### Derived from

QTreeWidgetItem

### Class Attributes

None

### Class Methods

None

### 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.
getEntryNames | Public method to get the names of all entries, who's name starts with the given string.
getLanguage | Public method to get the name of the group.
getName | Public method to get the name of the group.
hasEntry | Public method to check, if the group has an entry with the given name.
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.

### Static Methods

None

#### TemplateGroup (Constructor)

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

Constructor

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

#### TemplateGroup.addEntry

addEntry(name, description, template, quiet=False)

Public method to add a template entry to this group.

name
  name of the entry (string)
description
  description of the entry to add (string)
template
  template text of the entry (string)
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)

Returns:
  reference to the entry (TemplateEntry)

#### TemplateGroup.getEntryNames

getEntryNames(beginning)

Public method to get the names of all entries, who's name starts with the given string.

beginning
  string denoting the beginning of the template name (string)

Returns:
  list of entry names found (list of strings)

#### 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.hasEntry

hasEntry(name)

Public method to check, if the group has an entry with the given name.

name
  name of the entry to check for (string)

Returns:
  flag indicating existence (boolean)

#### 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)

#### TemplateGroup.setLanguage

setLanguage(language)

Public method to update the name of the group.

language
  programming language for the group (string)

#### TemplateGroup.setName

setName(name)

Public method to update the name of the group.

name
  name of the group (string)

Up

## TemplateViewer

Class implementing the template viewer.

### Derived from

QTreeWidget

### Class Attributes

None

### Class Methods

None

### Methods

TemplateViewer | Constructor
__addEntry | Private slot to handle the Add Entry context menu action.
__addGroup | Private slot to handle the Add Group context menu action.
__configure | Private method to open the configuration dialog.
__edit | Private slot to handle the Edit context menu action.
__export | Private slot to handle the Export context menu action.
__getPredefinedVars | Private method to return predefined variables.
__import | Private slot to handle the Import context menu action.
__reload | Private slot to reload the templates.
__remove | Private slot to handle the Remove context menu action.
__resort | Private method to resort the tree.
__showContextMenu | Private slot to show the context menu of the list.
__showHelp | Private method to show some help.
__templateItemActivated | Private slot to handle the activation of an item.
addEntry | Public method to add a template entry.
addGroup | Public method to add a group.
applyNamedTemplate | Public method to apply a template given a template name.
applyTemplate | Public method to apply the template.
changeEntry | Public method to change a template entry.
changeGroup | Public method to rename a group.
getAllGroups | Public method to get all groups.
getGroupNames | Public method to get all group names.
getTemplateNames | Public method to get the names of templates starting with the given string.
hasGroup | Public method to check, if a group with the given name exists.
hasTemplate | Public method to check, if an entry of the given name exists.
readTemplates | Public method to read in the templates file (.e4c).
removeEntry | Public method to remove a template entry.
removeGroup | Public method to remove a group.
save | Public slot to save the templates.
writeTemplates | Public method to write the templates data to an XML file (.e4c).

### Static Methods

None

#### TemplateViewer (Constructor)

TemplateViewer(parent, viewmanager)

Constructor

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

#### TemplateViewer.__addEntry

__addEntry()

Private slot to handle the Add Entry context menu action.

#### TemplateViewer.__addGroup

__addGroup()

Private slot to handle the Add Group context menu action.

#### TemplateViewer.__configure

__configure()

Private method to open the configuration dialog.

#### TemplateViewer.__edit

__edit()

Private slot to handle the Edit context menu action.

#### TemplateViewer.__export

__export()

Private slot to handle the Export context menu action.

#### TemplateViewer.__getPredefinedVars

__getPredefinedVars()

Private method to return predefined variables.

Returns:
  dictionary of predefined variables and their values

#### TemplateViewer.__import

__import()

Private slot to handle the Import context menu action.

#### TemplateViewer.__reload

__reload()

Private slot to reload the templates.

#### TemplateViewer.__remove

__remove()

Private slot to handle the Remove context menu action.

#### TemplateViewer.__resort

__resort()

Private method to resort the tree.

#### TemplateViewer.__showContextMenu

__showContextMenu(coord)

Private slot to show the context menu of the list.

coord
  the position of the mouse pointer (QPoint)

#### TemplateViewer.__showHelp

__showHelp()

Private method to show some help.

#### TemplateViewer.__templateItemActivated

__templateItemActivated(itm=None, col=0)

Private slot to handle the activation of an item.

itm
  reference to the activated item (QTreeWidgetItem)
col
  column the item was activated in (integer)

#### TemplateViewer.addEntry

addEntry(groupName, name, description, template, quiet=False)

Public method to add a template entry.

groupName
  name of the group to add to (string)
name
  name of the entry to add (string)
description
  description of the entry to add (string)
template
  template text of the entry (string)
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)
language
  programming language for the group (string)

#### TemplateViewer.applyNamedTemplate

applyNamedTemplate(templateName, groupName=None)

Public method to apply a template given a template name.

templateName
  name of the template item to apply (string)
groupName
  name of the group to get the entry from (string). None or empty means to apply the first template found with the given name.

#### TemplateViewer.applyTemplate

applyTemplate(itm)

Public method to apply the template.

itm
  reference to the template item to apply (TemplateEntry)

#### TemplateViewer.changeEntry

changeEntry(itm, name, groupName, description, template)

Public method to change a template entry.

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

#### TemplateViewer.changeGroup

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

Public method to rename a group.

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

#### 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.getTemplateNames

getTemplateNames(start, groupName=None)

Public method to get the names of templates starting with the given string.

start
  start string of the name (string)
groupName
  name of the group to get the entry from (string). None or empty means to look in all groups.

Returns:
  sorted list of matching template names (list of strings)

#### TemplateViewer.hasGroup

hasGroup(name)

Public method to check, if a group with the given name exists.

name
  name of the group to be checked for (string)

Returns:
  flag indicating an existing group (boolean)

#### TemplateViewer.hasTemplate

hasTemplate(entryName, groupName=None)

Public method to check, if an entry of the given name exists.

entryName
  name of the entry to check for (string)
groupName
  name of the group to check for the entry (string). None or empty means to check all groups.

Returns:
  flag indicating the existence (boolean)

#### TemplateViewer.readTemplates

readTemplates(filename=None)

Public method to read in the templates file (.e4c).

filename
  name of a templates file to read (string)

#### 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)

#### TemplateViewer.save

save()

Public slot to save the templates.

#### TemplateViewer.writeTemplates

writeTemplates(filename=None)

Public method to write the templates data to an XML file (.e4c).

filename
  name of a templates file to read (string)

Returns:
  flag indicating success (boolean)

Up