Module morseCheatSheet
[hide private]
[frames] | no frames]

Source Code for Module morseCheatSheet

 1   
 2  import string 
 3   
 4  from morseCodeTranslationKey import codeKey; 
 5   
 6  from python_qt_binding import loadUi; 
 7  from python_qt_binding import QtGui; 
 8  from python_qt_binding import QtCore; 
 9  from QtGui import QDialog 
10  #from QtCore import QPoint, Qt, QTimer, QEvent, Signal, QCoreApplication, QRect;  
11   
12 -class MorseCheatSheet(QDialog):
13
14 - def __init__(self, parent=None):
15 super(MorseCheatSheet,self).__init__(parent); 16 self.parent = parent; 17 self.initTable();
18
19 - def initTable(self):
20 relPathQtCreatorFileMorseTable = "qt_files/morseTable/morsetabledialog.ui"; 21 qtCreatorXMLFilePath = self.parent.findFile(relPathQtCreatorFileMorseTable); 22 if qtCreatorXMLFilePath is None: 23 raise ValueError("Can't find Morse cheat sheet QtCreator user interface file %s" % relPathQtCreatorFileMorseTable); 24 # Make QtCreator generated UI a child if this instance: 25 loadUi(qtCreatorXMLFilePath, self); 26 self.windowTitle = "Morser Cheat Sheet"; 27 self.setWindowTitle(self.windowTitle); 28 29 # Need table letter-->morse, rather than morse-->letter, 30 # which the codeKey provides. Create that: 31 morseSheetDict = {}; 32 for keyValue in codeKey.items(): 33 morseSheetDict[keyValue[1]] = keyValue[0]; 34 35 # Get string with just the punctuation letters for which we 36 # have Morse: 37 punctuation = ''; 38 for punctLetter in string.punctuation: 39 if morseSheetDict.has_key(punctLetter): 40 punctuation += punctLetter; 41 42 # Special characters: 43 specialChars = ['BS','NL', 'HS']; 44 45 # Fill the text labels: 46 colCount = self.morseCodeGrid.columnCount(); 47 rowCount = self.morseCodeGrid.rowCount(); 48 keyIndex = 0; 49 letterLists = [string.lowercase, string.digits, punctuation, specialChars]; 50 currentList = 0; 51 for col in range(colCount): 52 for row in range(rowCount): 53 labelTxt = letterLists[currentList][keyIndex] + ": " + morseSheetDict[letterLists[currentList][keyIndex]] 54 labelObj = self.morseCodeGrid.itemAtPosition(row, col); 55 labelObj.widget().setText(labelTxt); 56 keyIndex += 1 57 if keyIndex >= len(letterLists[currentList]): 58 currentList += 1; 59 keyIndex = 0; 60 if currentList >= len(letterLists): 61 return;
62