# eric4.Tools.TRPreviewer

Module implementing the TR Previewer main window.

### Global Attributes

noTranslationName

### Classes

TRPreviewer | Class implementing the UI Previewer main window.
Translation | Class to store the properties of a translation
TranslationsDict | Class to store all loaded translations.
WidgetView | Class to show a dynamically loaded widget (or dialog).
WidgetWorkspace | Specialized workspace to show the loaded widgets.

### Functions

_filename | Protected module function to chop off the path.

## TRPreviewer

Class implementing the UI Previewer main window.

### Derived from

KQMainWindow

### Class Attributes

None

### Class Methods

None

### Methods

TRPreviewer | Constructor
__about | Private slot to show the about information.
__aboutQt | Private slot to show info about Qt.
__initActions | Private method to define the user interface actions.
__initMenus | Private method to create the menus.
__initToolbars | Private method to create the toolbars.
__openTranslation | Private slot to handle the Open Translation action.
__openWidget | Private slot to handle the Open Dialog action.
__showWindowMenu | Private slot to handle the aboutToShow signal of the window menu.
__updateActions | Private slot to update the actions state.
__whatsThis | Private slot called in to enter Whats This mode.
closeEvent | Private event handler for the close event.
reloadTranslations | Public slot to reload all translations.
setTranslation | Public slot to activate a translation.
show | Public slot to show this dialog.

### Static Methods

None

#### TRPreviewer (Constructor)

TRPreviewer(filenames = [], parent = None, name = None)

Constructor

filenames
  filenames of form and/or translation files to load
parent
  parent widget of this window (QWidget)
name
  name of this window (string or QString)

#### TRPreviewer.__about

__about()

Private slot to show the about information.

#### TRPreviewer.__aboutQt

__aboutQt()

Private slot to show info about Qt.

#### TRPreviewer.__initActions

__initActions()

Private method to define the user interface actions.

#### TRPreviewer.__initMenus

__initMenus()

Private method to create the menus.

#### TRPreviewer.__initToolbars

__initToolbars()

Private method to create the toolbars.

#### TRPreviewer.__openTranslation

__openTranslation()

Private slot to handle the Open Translation action.

#### TRPreviewer.__openWidget

__openWidget()

Private slot to handle the Open Dialog action.

#### TRPreviewer.__showWindowMenu

__showWindowMenu()

Private slot to handle the aboutToShow signal of the window menu.

#### TRPreviewer.__updateActions

__updateActions()

Private slot to update the actions state.

#### TRPreviewer.__whatsThis

__whatsThis()

Private slot called in to enter Whats This mode.

#### TRPreviewer.closeEvent

closeEvent(event)

Private event handler for the close event.

event
  close event (QCloseEvent)

#### TRPreviewer.reloadTranslations

reloadTranslations()

Public slot to reload all translations.

#### TRPreviewer.setTranslation

setTranslation(name)

Public slot to activate a translation.

name
  name (language) of the translation (string or QString)

#### TRPreviewer.show

show()

Public slot to show this dialog.

This overloaded slot loads a UI file to be previewed after the main window has been shown. This way, previewing a dialog doesn't interfere with showing the main window.

Up

## Translation

Class to store the properties of a translation

### Derived from

object

### Class Attributes

None

### Class Methods

None

### Methods

Translation | Constructor

### Static Methods

None

#### Translation (Constructor)

Translation()

Constructor

Up

## TranslationsDict

Class to store all loaded translations.

### Signals

translationChanged()
  emit after a translator was set

### Derived from

QObject

### Class Attributes

None

### Class Methods

None

### Methods

TranslationsDict | Constructor
__del | Private method to delete a translator from the list of available translators.
__findFileName | Private method to find a translation by file name.
__findName | Private method to find a translation by name.
__haveFileName | Private method to check for the presence of a translation.
__haveName | Private method to check for the presence of a named translation.
__uniqueName | Private method to generate a unique name.
add | Public method to add a translation to the list.
hasTranslations | Public method to check for loaded translations.
loadTransFile | Public slot to load a translation file.
reload | Public method to reload all translators.
set | Public slot to set a translator by name.

### Static Methods

None

#### TranslationsDict (Constructor)

TranslationsDict(selector, parent)

Constructor

selector
  reference to the QComboBox used to show the available languages (QComboBox)
parent
  parent widget (QWidget)

#### TranslationsDict.__del

__del(name)

Private method to delete a translator from the list of available translators.

name
  name of the translator to delete (string or QString)

#### TranslationsDict.__findFileName

__findFileName(transFileName)

Private method to find a translation by file name.

transFileName
  file name of the translation file (string or QString)

Returns:
  reference to a translation object or None

#### TranslationsDict.__findName

__findName(name)

Private method to find a translation by name.

name
  name (language) of the translation (string or QString)

Returns:
  reference to a translation object or None

#### TranslationsDict.__haveFileName

__haveFileName(transFileName)

Private method to check for the presence of a translation.

transFileName
  file name of the translation file (string or QString)

Returns:
  flag indicating the presence of the translation (boolean)

#### TranslationsDict.__haveName

__haveName(name)

Private method to check for the presence of a named translation.

name
  name (language) of the translation (string or QString)

Returns:
  flag indicating the presence of the translation (boolean)

#### TranslationsDict.__uniqueName

__uniqueName(transFileName)

Private method to generate a unique name.

transFileName
  file name of the translation file (string or QString)

Returns:
  unique name (QString)

#### TranslationsDict.add

add(transFileName, setTranslation = True)

Public method to add a translation to the list.

If the translation file (*.qm) has not been loaded yet, it will be loaded automatically.

transFileName
  name of the translation file to be added (string or QString)
setTranslation
  flag indicating, if this should be set as the active translation (boolean)

#### TranslationsDict.hasTranslations

hasTranslations()

Public method to check for loaded translations.

Returns:
  flag signaling if any translation was loaded (boolean)

#### TranslationsDict.loadTransFile

loadTransFile(transFileName)

Public slot to load a translation file.

transFileName
  file name of the translation file (string or QString)

Returns:
  reference to the new translator object (QTranslator)

#### TranslationsDict.reload

reload()

Public method to reload all translators.

#### TranslationsDict.set

set(name)

Public slot to set a translator by name.

name
  name (language) of the translator to set (string or QString)

Up

## WidgetView

Class to show a dynamically loaded widget (or dialog).

### Derived from

QWidget

### Class Attributes

None

### Class Methods

None

### Methods

WidgetView | Constructor
__rebuildWidget | Private method to schedule a rebuild of the widget.
buildWidget | Public slot to load a UI file.
isValid | Public method to return the validity of this widget view.
uiFileName | Public method to retrieve the name of the UI file.

### Static Methods

None

#### WidgetView (Constructor)

WidgetView(uiFileName, parent = None, name = None)

Constructor

uiFileName
  name of the UI file to load (string or QString)
parent
  parent widget (QWidget)
name
  name of this widget (string)

#### WidgetView.__rebuildWidget

__rebuildWidget()

Private method to schedule a rebuild of the widget.

#### WidgetView.buildWidget

buildWidget()

Public slot to load a UI file.

#### WidgetView.isValid

isValid()

Public method to return the validity of this widget view.

Returns:
  flag indicating the validity (boolean)

#### WidgetView.uiFileName

uiFileName()

Public method to retrieve the name of the UI file.

Returns:
  filename of the loaded UI file (QString)

Up

## WidgetWorkspace

Specialized workspace to show the loaded widgets.

### Signals

lastWidgetClosed()
  emitted after last widget was closed

### Derived from

QWorkspace

### Class Attributes

None

### Class Methods

None

### Methods

WidgetWorkspace | Constructor
__findWidget | Private method to find a specific widget view.
__toggleWidget | Private method to toggle a workspace window.
closeAllWidgets | Public slot to close all windows.
closeWidget | Public slot to close the active window.
eventFilter | Protected method called to filter an event.
hasWidgets | Public method to check for loaded widgets.
loadWidget | Public slot to load a UI file.
showWindowMenu | Public method to set up the widgets part of the Window menu.
toggleSelectedWidget | Public method to handle the toggle of a window.

### Static Methods

None

#### WidgetWorkspace (Constructor)

WidgetWorkspace(parent = None)

Constructor

parent
  parent widget (QWidget)

#### WidgetWorkspace.__findWidget

__findWidget(uiFileName)

Private method to find a specific widget view.

uiFileName
  filename of the loaded UI file (string or QString)

Returns:
  reference to the widget (WidgetView) or None

#### WidgetWorkspace.__toggleWidget

__toggleWidget(w)

Private method to toggle a workspace window.

w
  window to be toggled

#### WidgetWorkspace.closeAllWidgets

closeAllWidgets()

Public slot to close all windows.

#### WidgetWorkspace.closeWidget

closeWidget()

Public slot to close the active window.

#### WidgetWorkspace.eventFilter

eventFilter(obj, ev)

Protected method called to filter an event.

object
  object, that generated the event (QObject)
event
  the event, that was generated by object (QEvent)

Returns:
  flag indicating if event was filtered out

#### WidgetWorkspace.hasWidgets

hasWidgets()

Public method to check for loaded widgets.

Returns:
  flag signaling if any widget was loaded (boolean)

#### WidgetWorkspace.loadWidget

loadWidget(uiFileName)

Public slot to load a UI file.

uiFileName
  name of the UI file to load (string or QString)

#### WidgetWorkspace.showWindowMenu

showWindowMenu(windowMenu)

Public method to set up the widgets part of the Window menu.

windowMenu
  reference to the window menu

#### WidgetWorkspace.toggleSelectedWidget

toggleSelectedWidget(act)

Public method to handle the toggle of a window.

act
  reference to the action that triggered (QAction)

Up

## _filename

_filename(path)

Protected module function to chop off the path.

path
  path to extract the filename from (string or QString)

Returns:
  extracted filename (QString)

Up