class dlgAbstractUserLogin( QDialog ): """ Clase base para todos los dialogos que requieren autenticar a un usuario """ def __init__( self, parent = None, maxAttempts = 3 ): super( dlgAbstractUserLogin, self ).__init__() self.setupUi() self.parent = parent self.user = None self.maxAttempts = maxAttempts self.attempts = 0 #self.txtUser.setText('root') #self.txtBd.setText('Esquipulasdb') self.buttonbox.accepted.connect( self.accept ) self.buttonbox.rejected.connect( self.reject ) def accept( self ): self.user = User( self.txtUser.text(), self.txtPassword.text() ) if self.user.valid or self.attempts == self.maxAttempts - 1: super( dlgAbstractUserLogin, self ).accept() else: self.txtPassword.setText( "" ) self.lblError.setText( u"Hay un error en su usuario o su" + u" contraseña" ) self.lblError.setVisible( True ) self.attempts += 1 QTimer.singleShot( 3000, functools.partial( self.lblError.setVisible, False ) ) def setupUi( self ): self.txtPassword = QLineEdit() self.txtPassword.setEchoMode( QLineEdit.Password ) self.txtUser = QLineEdit() self.buttonbox = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel ) self.lblError = QLabel() self.lblError.setProperty( "error", True ) self.lblError.setText( u"El usuario o la contraseña son incorrectos" ) self.lblError.setVisible( False ) self.formLayout = QFormLayout() self.formLayout.addRow( u"&Usuario", self.txtUser ) self.formLayout.addRow( u"&Contraseña", self.txtPassword ) self.txtUser.setWhatsThis( "Escriba aca su usuario" ) self.txtPassword.setWhatsThis( u"Escriba aca su contraseña, "\ + "tenga en cuenta que el sistema hace "\ + "diferencia entre minusculas y"\ + " mayusculas" ) self.txtApplication = QLabel()
class WorkingDirectoryWidget(RWidget): def __init__(self, parent=None, base="."): RWidget.__init__(self, parent) # initialise standard settings self.base = base self.currentEdit = QLineEdit(self) self.currentEdit.setToolTip("Current working directory") self.currentEdit.setWhatsThis("Current working directory") self.currentEdit.setText(self.base) self.currentEdit.setMinimumHeight(QFontMetrics(self.font()).height()*1.5) self.setwdButton = QToolButton(self) self.setwdButton.setToolTip("Set working directory") self.setwdButton.setWhatsThis("Set working directory") self.setwdButton.setIcon(QIcon(":folder-home")) self.setwdButton.setText("setwd") self.setwdButton.setAutoRaise(True) horiz = QHBoxLayout(self) horiz.addWidget(self.currentEdit) horiz.addWidget(self.setwdButton) self.connect(self.setwdButton, SIGNAL("clicked()"), self.browseToFolder) def getWorkingDir(self): command = unicode("getwd()") directory = robjects.r(command)[0] self.currentEdit.setText(directory) #self.emitCommands(command) def browseToFolder(self): directory = QFileDialog.getExistingDirectory( self, "Choose working directory",self.currentEdit.text(), (QFileDialog.ShowDirsOnly|QFileDialog.DontResolveSymlinks)) if not directory.isEmpty(): self.setWorkingDir(directory) self.currentEdit.setText(directory) def setWorkingDir(self, directory): command = unicode("setwd('%s')" % (directory)) robjects.r(command)
class GraphicsWidget(RWidget): def __init__(self, parent): RWidget.__init__(self, parent) self.parent = parent self._hist = History(items=[]) self._currentPlot = QVariant(QString()) self.callLineEdit = QLineEdit() self.callLineEdit.setReadOnly(True) self.callLineEdit.setToolTip("Commands to reproduce plot") self.callLineEdit.setWhatsThis("Commands to reproduce plot") actions = [] # playAction = QAction("Replay", self) # playAction.setStatusTip("Replay selected plot") # playAction.setToolTip("Replay selected plot") # playAction.setIcon(QIcon(":edit-copy")) # actions.append(playAction) firstAction = QAction("End", self) firstAction.setStatusTip("Move to end of history") firstAction.setToolTip("Move to end of history") firstAction.setIcon(QIcon(":go-first")) actions.append(firstAction) previousAction = QAction("Previous", self) previousAction.setStatusTip("Move to previous plot") previousAction.setToolTip("Move to previous plot") previousAction.setIcon(QIcon(":go-previous")) actions.append(previousAction) infoAction = QAction("Info", self) infoAction.setStatusTip("Show plot info") infoAction.setToolTip("Show plot info") infoAction.setIcon(QIcon(":gtk-info")) actions.append(infoAction) nextAction = QAction("Next", self) nextAction.setStatusTip("Move to next plot") nextAction.setToolTip("Move to next plot") nextAction.setIcon(QIcon(":go-next")) actions.append(nextAction) lastAction = QAction("Start", self) lastAction.setStatusTip("Move to latest plot") lastAction.setToolTip("Move to latest plot") lastAction.setIcon(QIcon(":go-last")) actions.append(lastAction) actions.append(None) clearAction = QAction("Clear", self) clearAction.setStatusTip("Clear plot history") clearAction.setToolTip("Clear plot history") clearAction.setIcon(QIcon(":edit-clear")) actions.append(clearAction) hbox = QHBoxLayout() for action in actions: if not action is None: button = QToolButton() button.setDefaultAction(action) button.setAutoRaise(True) hbox.addWidget(button) else: hbox.addWidget(self.callLineEdit) self.setLayout(hbox) self.connect(firstAction, SIGNAL("triggered()"), self.first) self.connect(previousAction, SIGNAL("triggered()"), self.previous) self.connect(infoAction, SIGNAL("triggered()"), self.info) self.connect(nextAction, SIGNAL("triggered()"), self.next) self.connect(lastAction, SIGNAL("triggered()"), self.last) self.connect(clearAction, SIGNAL("triggered()"), self.clear) def setHistory(self, history): self._hist = history def history(self): return self._hist def previous(self): return self.navigateHistory(True) def next(self): return self.navigateHistory(False) def navigateHistory(self, up=True): if up: self._currentPlot = self.history().previous() else: self._currentPlot = self.history().next() tmp = self._currentPlot.toPyObject() if not tmp == QString(): self.callLineEdit.setText(tmp[2]) return self._currentPlot def first(self): temp = self.previous() item = self._currentPlot while not isinstance(temp,QVariant): item = temp temp = self.previous() self._currentPlot = item def last(self): temp = self.next() item = self._currentPlot while not isinstance(temp,QVariant): item = temp temp = self.next() self._currentPlot = item def info(self): plot = self._currentPlot.toPyObject() if isinstance(plot,QString): return plot = self._currentPlot.toPyObject() msgBox = QMessageBox() msgBox.setText("Plot information:") msgBox.setInformativeText("Original device: %s" % str(plot[0]) +"\nHistory position: %s" % str(self.history().currentIndex()+1) +"\nSize: %s bytes" % str(plot[1]) +"\n\nWould you like to replay the plot now?") msgBox.setDetailedText("Original call:\n%s" % plot[2]) msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Close) msgBox.setDefaultButton(QMessageBox.Ok) if msgBox.exec_() == QMessageBox.Ok: print plot[3] def clear(self): self.setHistory(History(items=[])) self.callLineEdit.setText(QString()) def updateHistory(self, item): self.history().update([item]) self.previous()