def __init__(self, app): """ Setup GUI layout, connect event handlers. """ super(Main, self).__init__() # Make sure cache exists if not os.path.isdir(const.CACHE_PATH): os.mkdir(const.CACHE_PATH) # Ensure system requirements are met self.checkDependancies() # This is always the same self.ui = Ui_MainWindow() self.ui.setupUi(self) # Change title, position self.setWindowTitle('SemTeX') self.move(200, 200) # Connect event handlers self.ui.push_refresh.clicked.connect(self.refresh) self.ui.push_history.clicked.connect(self.saveToHistory) self.ui.push_equation.clicked.connect(self.copyToClipboard) self.ui.action_about.triggered.connect(self.showAbout) self.ui.action_add_matrix.triggered.connect(self.showMatrix) self.ui.action_add_frac.triggered.connect(self.showFrac) # Keyboard shortcuts QtGui.QShortcut(QtGui.QKeySequence("Ctrl+Q"), self, QtGui.qApp.quit) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+R"), self, self.refresh) # Display application logo self.displayPng() # Access saved equations and set last equation in the editor text box self.loadHistory() self.setFromHistory(len(self.equation_history)) # Bind application clipboard self.clipboard = app.clipboard()
class Main(QtGui.QMainWindow): """ Main window for the SemTeX Equation Editor. """ # Misc Variables equation_history = [] # Buffer for saved equation strings def __init__(self, app): """ Setup GUI layout, connect event handlers. """ super(Main, self).__init__() # Make sure cache exists if not os.path.isdir(const.CACHE_PATH): os.mkdir(const.CACHE_PATH) # Ensure system requirements are met self.checkDependancies() # This is always the same self.ui = Ui_MainWindow() self.ui.setupUi(self) # Change title, position self.setWindowTitle('SemTeX') self.move(200, 200) # Connect event handlers self.ui.push_refresh.clicked.connect(self.refresh) self.ui.push_history.clicked.connect(self.saveToHistory) self.ui.push_equation.clicked.connect(self.copyToClipboard) self.ui.action_about.triggered.connect(self.showAbout) self.ui.action_add_matrix.triggered.connect(self.showMatrix) self.ui.action_add_frac.triggered.connect(self.showFrac) # Keyboard shortcuts QtGui.QShortcut(QtGui.QKeySequence("Ctrl+Q"), self, QtGui.qApp.quit) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+R"), self, self.refresh) # Display application logo self.displayPng() # Access saved equations and set last equation in the editor text box self.loadHistory() self.setFromHistory(len(self.equation_history)) # Bind application clipboard self.clipboard = app.clipboard() def refresh(self): """ Takes the equation from the self.teInput, compiles and converts to PNG. """ try: # Clear statusbar self.status() # Read from self.teInput eq = self.getInput() # If it contains an equation... if eq is not None: # ... compile and display it... self.generateLatex(eq) self.compileLatex() self.convertPng() self.convertPng(const.PNG_TRANS, const.PNG_DISP_PATH) self.cleanUp() self.displayPng() else: # ... otherwise, display the semtex logo self.displayPng() except Exception, e: raise e