Package tipy :: Module gui :: Class MainWindow
[hide private]
[frames] | no frames]

Class MainWindow

source code

      object --+                    
               |                    
??.simplewrapper --+                
                   |                
          ??.wrapper --+            
                       |            
    PyQt5.QtCore.QObject --+        
                           |        
          object --+       |        
                   |       |        
    ??.simplewrapper --+   |        
                       |   |        
PyQt5.QtGui.QPaintDevice --+        
                           |        
     PyQt5.QtWidgets.QWidget --+    
                               |    
     PyQt5.QtWidgets.QMainWindow --+
                                   |
                                  MainWindow

The main window of the graphical user interface.

Class Hierarchy for MainWindow
Class Hierarchy for MainWindow

Nested Classes [hide private]

Inherited from PyQt5.QtWidgets.QMainWindow: DockOption, DockOptions

Inherited from PyQt5.QtWidgets.QWidget: RenderFlag, RenderFlags

Inherited from PyQt5.QtGui.QPaintDevice: PaintDeviceMetric

Instance Methods [hide private]
 
__init__(self, driver)
MainWindow creator.
source code
 
setupUi(self, MainWindow)
Create and set the main window widgets and layouts.
source code
 
on_paste_btn_triggered(self, checked=False)
Paste what's inside the clipboard.
source code
 
on_copy_btn_triggered(self, checked=False)
Copy the selection.
source code
 
on_cut_btn_triggered(self, checked=False)
Cut the selection.
source code
 
on_show_probabilities_triggered(self, checked=False)
Show the suggested words probabilities.
source code
 
on_pref_triggered(self, checked=False)
Open the settings dialog.
source code
 
write_config(self)
Write the current configuration in the configuration file.
source code
list
predictors_using_db(self)
Create a list of every predictors name which use a given database.
source code
 
on_miner_selected(self, miner)
Callback called when the user select a miner in the combo box.
source code
 
set_miner_widgets_values(self)
Update the widgets (labels and list) displaying infos on the miner.
source code
 
progress_callback(self, perc=0, text=None)
Update the label showing the mining operation and the progress bar.
source code
 
on_rm_db_btn_released(self)
Callback called when the user press the "Delete database" button.
source code
 
on_mine_btn_released(self)
Callback called when the user press the "MINE!" button.
source code
 
on_input_text_change(self)
Update the input buffers and compute the suggestion.
source code
 
make_suggestions(self)
Compute and show suggestions.
source code
 
on_input_text_cursor_position_change(self)
Callback called when the input text cursor position change.
source code
 
on_suggestion_double_clicked(self, item)
Complete the input with the selected suggestion.
source code

Inherited from PyQt5.QtWidgets.QMainWindow: addDockWidget, addToolBar, addToolBarBreak, centralWidget, contextMenuEvent, corner, createPopupMenu, dockOptions, dockWidgetArea, documentMode, event, iconSize, iconSizeChanged, insertToolBar, insertToolBarBreak, isAnimated, isDockNestingEnabled, isSeparator, menuBar, menuWidget, removeDockWidget, removeToolBar, removeToolBarBreak, restoreDockWidget, restoreState, saveState, setAnimated, setCentralWidget, setCorner, setDockNestingEnabled, setDockOptions, setDocumentMode, setIconSize, setMenuBar, setMenuWidget, setStatusBar, setTabPosition, setTabShape, setToolButtonStyle, setUnifiedTitleAndToolBarOnMac, splitDockWidget, statusBar, tabPosition, tabShape, tabifiedDockWidgets, tabifyDockWidget, takeCentralWidget, toolBarArea, toolBarBreak, toolButtonStyle, toolButtonStyleChanged, unifiedTitleAndToolBarOnMac

Inherited from PyQt5.QtWidgets.QWidget: acceptDrops, accessibleDescription, accessibleName, actionEvent, actions, activateWindow, addAction, addActions, adjustSize, autoFillBackground, backgroundRole, baseSize, changeEvent, childAt, childrenRect, childrenRegion, clearFocus, clearMask, close, closeEvent, contentsMargins, contentsRect, contextMenuPolicy, create, createWindowContainer, cursor, customContextMenuRequested, destroy, devType, dragEnterEvent, dragLeaveEvent, dragMoveEvent, dropEvent, effectiveWinId, ensurePolished, enterEvent, find, focusInEvent, focusNextChild, focusNextPrevChild, focusOutEvent, focusPolicy, focusPreviousChild, focusProxy, focusWidget, font, fontInfo, fontMetrics, foregroundRole, frameGeometry, frameSize, geometry, getContentsMargins, grab, grabGesture, grabKeyboard, grabMouse, grabShortcut, graphicsEffect, graphicsProxyWidget, hasFocus, hasHeightForWidth, hasMouseTracking, height, heightForWidth, hide, hideEvent, initPainter, inputMethodEvent, inputMethodHints, inputMethodQuery, insertAction, insertActions, isActiveWindow, isAncestorOf, isEnabled, isEnabledTo, isFullScreen, isHidden, isLeftToRight, isMaximized, isMinimized, isModal, isRightToLeft, isVisible, isVisibleTo, isWindow, isWindowModified, keyPressEvent, keyReleaseEvent, keyboardGrabber, layout, layoutDirection, leaveEvent, locale, lower, mapFrom, mapFromGlobal, mapFromParent, mapTo, mapToGlobal, mapToParent, mask, maximumHeight, maximumSize, maximumWidth, metric, minimumHeight, minimumSize, minimumSizeHint, minimumWidth, mouseDoubleClickEvent, mouseGrabber, mouseMoveEvent, mousePressEvent, mouseReleaseEvent, move, moveEvent, nativeEvent, nativeParentWidget, nextInFocusChain, normalGeometry, overrideWindowFlags, overrideWindowState, paintEngine, paintEvent, palette, parentWidget, pos, previousInFocusChain, raise_, rect, releaseKeyboard, releaseMouse, releaseShortcut, removeAction, render, repaint, resize, resizeEvent, restoreGeometry, saveGeometry, scroll, setAcceptDrops, setAccessibleDescription, setAccessibleName, setAttribute, setAutoFillBackground, setBackgroundRole, setBaseSize, setContentsMargins, setContextMenuPolicy, setCursor, setDisabled, setEnabled, setFixedHeight, setFixedSize, setFixedWidth, setFocus, setFocusPolicy, setFocusProxy, setFont, setForegroundRole, setGeometry, setGraphicsEffect, setHidden, setInputMethodHints, setLayout, setLayoutDirection, setLocale, setMask, setMaximumHeight, setMaximumSize, setMaximumWidth, setMinimumHeight, setMinimumSize, setMinimumWidth, setMouseTracking, setPalette, setParent, setShortcutAutoRepeat, setShortcutEnabled, setSizeIncrement, setSizePolicy, setStatusTip, setStyle, setStyleSheet, setTabOrder, setToolTip, setToolTipDuration, setUpdatesEnabled, setVisible, setWhatsThis, setWindowFilePath, setWindowFlags, setWindowIcon, setWindowIconText, setWindowModality, setWindowModified, setWindowOpacity, setWindowRole, setWindowState, setWindowTitle, sharedPainter, show, showEvent, showFullScreen, showMaximized, showMinimized, showNormal, size, sizeHint, sizeIncrement, sizePolicy, stackUnder, statusTip, style, styleSheet, tabletEvent, testAttribute, toolTip, toolTipDuration, underMouse, ungrabGesture, unsetCursor, unsetLayoutDirection, unsetLocale, update, updateGeometry, updateMicroFocus, updatesEnabled, visibleRegion, whatsThis, wheelEvent, width, winId, window, windowFilePath, windowFlags, windowHandle, windowIcon, windowIconChanged, windowIconText, windowIconTextChanged, windowModality, windowOpacity, windowRole, windowState, windowTitle, windowTitleChanged, windowType, x, y

Inherited from PyQt5.QtCore.QObject: __getattr__, blockSignals, childEvent, children, connectNotify, customEvent, deleteLater, destroyed, disconnect, disconnectNotify, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, eventFilter, findChild, findChildren, inherits, installEventFilter, isSignalConnected, isWidgetType, isWindowType, killTimer, metaObject, moveToThread, objectName, objectNameChanged, parent, property, pyqtConfigure, receivers, removeEventFilter, sender, senderSignalIndex, setObjectName, setProperty, signalsBlocked, startTimer, thread, timerEvent, tr

Inherited from PyQt5.QtGui.QPaintDevice: colorCount, depth, devicePixelRatio, heightMM, logicalDpiX, logicalDpiY, paintingActive, physicalDpiX, physicalDpiY, widthMM

Inherited from unreachable.simplewrapper: __new__

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  CORPUS_NGRAM_PREDICTOR = 0
  USER_SMOOTH_NGRAM_PREDICTOR = 1
  FB_SMOOTH_NGRAM_PREDICTOR = 2
  LAST_OCCUR_PREDICTOR = 3
  MEMORIZE_PREDICTOR = 4
  DICTIONARY_PREDICTOR = 5
  TEXT_FILE_MINER = 0
  DICTIONARY_MINER = 1
  FACEBOOK_MINER = 2
  TWITTER_MINER = 3

Inherited from PyQt5.QtWidgets.QMainWindow: AllowNestedDocks, AllowTabbedDocks, AnimatedDocks, ForceTabbedDocks, VerticalTabs

Inherited from PyQt5.QtWidgets.QWidget: DrawChildren, DrawWindowBackground, IgnoreMask

Inherited from PyQt5.QtCore.QObject: staticMetaObject

Inherited from PyQt5.QtGui.QPaintDevice: PdmDepth, PdmDevicePixelRatio, PdmDpiX, PdmDpiY, PdmHeight, PdmHeightMM, PdmNumColors, PdmPhysicalDpiX, PdmPhysicalDpiY, PdmWidth, PdmWidthMM

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, driver)
(Constructor)

source code 

MainWindow creator.

It allow the user to:

  • Type text and get predictive suggestions.
  • Directly complete input words or insert predicted words in the input.
  • See the miners informations.
  • Execute mining operations using the defined miners.
  • Delete miners database.
  • Modify almost every options of the configuration file using the settings window.
Parameters:
  • driver (Driver) - The Driver instance wich contains everything needed for word prediction.
Overrides: object.__init__

predictors_using_db(self)

source code 

Create a list of every predictors name which use a given database.

Returns: list
The list of the predictors using the database file 'self.dbPath'.

on_miner_selected(self, miner)

source code 

Callback called when the user select a miner in the combo box.

When a miner is selected in the miner selection combo box some settings of the miner have to be retrieved from the configuration in order to display them to the user using the set_miner_widgets_values() method. As every miners store their results (n-grams) in a database the database path and the n-gram size are retrieved from the configuration and stored into the "dbPath" and "nGramSize" instance variables.

Parameters:
  • miner (int) - The index of the miner in the combo box.

set_miner_widgets_values(self)

source code 

Update the widgets (labels and list) displaying infos on the miner.

When a miner is selected in the miner selection combo box, its config settings are retrieve from the configuration and the instance variables "dbPath", "nGramSize" and "predsUsingDb" are set. This method modify the value of the widgets displaying the informations about the miner with the above-mentioned variables.

progress_callback(self, perc=0, text=None)

source code 

Update the label showing the mining operation and the progress bar.

This method is a callback which is called from the miners. It update the text of the label displaying the minig operation and the value of the progress bar displaying the operation progression.

Parameters:
  • perc (float or int) - Computed by the miners calling the callback, it indicate the operation progression and is usually a float but it must be converted to int as the progress bar only show integers.
  • text (str) - The text to display in the mining operation label.

on_rm_db_btn_released(self)

source code 

Callback called when the user press the "Delete database" button.

The method first identify the current miner selected in the combo box using its index then create an instance of this miner and called its rm_db() method to effectively carry out the database suppression operation. Some miners modify the configuration so the config file needs to be rewrite after the operation. Here is a short description of the miners database suppression operation, please refer to their rm_db() method docstring for more informations:

  • CorpusMiner: Remove the database file.
  • FbMiner: Remove the database file and set the "last_update" config option to the minimum value so the config have to be writen afterward.

on_mine_btn_released(self)

source code 

Callback called when the user press the "MINE!" button.

The method first identify the current miner selected in the combo box using its index then create an instance of this miner and called its mine() method to effectively carry out the mining operation. Some miners modify the configuration so the config file needs to be rewrite after the operation. Here is a short description of the miners mining operation, please refer to their mine() method docstring for more informations:

  • CorpusMiner: Mine a text corpus (i.e. a set of text files) by extracting n-grams from the files and inserting them into a database.
  • FbMiner: Mine a facebook user wall (only text messages from posts) by extracting n-grams from the posts and inserting them into a database. This miner modifies the "last_update" option of its config section so the config have to be writen afterward.
  • TwiterMiner: Not implemented yet but it will be very similar to FbMiner.

on_input_text_change(self)

source code 

Update the input buffers and compute the suggestion.

This method is called whenever one or more character(s) is/are added to or removed from the input text. It update the input left and right buffers according to the text change and then generate the suggestions for the new input context. There is three king of input text change:

  • Characters have been appened: -> Characters are added to the left input buffer (via callback.update()).
  • Part of the characters have been removed: -> Characters are removed to the left input buffer (via callback.update()). It simulates a backspace input.
  • Every characters have been removed (while new ones have been added): -> Every characters of the left input buffer are removed (via callback.update()). New characters, if any, are added to the left input buffer (via callback.update()).

Note: It correspond to a Ctrl+A then <some printable characters> or <backspace>.

make_suggestions(self)

source code 

Compute and show suggestions.

Request the PredictorActivator to compute the suggestions and show them in the suggestion list.

on_input_text_cursor_position_change(self)

source code 

Callback called when the input text cursor position change.

There's three possible moves types:

  • The cursor moved because one or more character(s) have been added to or removed from the input text: -> The cursor position and the input text length are saved and the suggestions are updated according to the current input.
  • The cursor moved because the user pressed the left arrow key or clicked somewhere in the text, on the left of the previous cursor position: -> In this case the input text has not change we call the Driver callback to modify the input left and right buffer so that the left buffer now contains what's on the left of the cursor and the right buffer now contains what's on the right of the cursor. The suggestions are then updated according to the current cursor position.
  • The cursor moved because the user pressed the right arrow key or clicked somewhere in the text, on the right of the previous cursor position: -> In this case the input text has not change we call the Driver callback to modify the input left and right buffer so that the left buffer now contains what's on the left of the cursor and the right buffer now contains what's on the right of the cursor. The suggestions are then updated according to the current cursor position.

Note: The on_input_text_change() method used to be connected to the textChanged signal of the input text widget but it is redundant because if the text change, the cursor position automatically change too. It save some operations.

Bug: When selecting characters in the input field (self.inputTextEdit) the cursor position is modified and induce erroneous context changes and word predictions.

on_suggestion_double_clicked(self, item)

source code 

Complete the input with the selected suggestion.

When the user double click on a word of the list the word is used to complete the input text. There is two kind of completion depending on the input cursor position:

  • The cursor is at the end of the text: -> The completion for the last token is computed and append to the input text. A space is then added allowing the user to save a key and the program to immediatly suggest the next word prediction.
  • The cursor is not at the end of the text: -> The completion for the token in which the cursor is is computed and the end of the token is replaced by the completion.

During this method the input text widget signals are disconnected which means that no suggestions will be compute during the completion process. This is important because this method will modify the input text but, of course, there is no need to generate any suggestions as the user isn't typing anything during the process.

Parameters:
  • item (QtWidgets.QListWidgetItem) - The selected item (word) in the suggestion list.

Note: A token can be a word or a separator. If it is a word then the completion represents the end of the word. If it is a separator then the completion represents the next word.