Ejemplo n.º 1
0
class DateRequest(Request):
    def __init__(self, parent):
        Request.__init__(self, parent)
        self.setOperators()
        self.setDateTime()

    def setOperators(self):
        self.operatorCombo = OperatorCombo(self)
        self.hlayout.addWidget(self.operatorCombo)
        self.connect(self.operatorCombo, SIGNAL("currentIndexChanged ( int )"),
                     self.updateQuery)
        self.connect(self.operatorCombo,
                     SIGNAL("currentIndexChanged ( const QString &)"),
                     self.updateQuery)

    def updateQuery(self, data):
        self.emit(SIGNAL("queryUpdated"))

    def setDateTime(self):
        self.datetime = QDateTimeEdit(self)
        self.datetime.setCalendarPopup(True)
        self.hlayout.addWidget(self.datetime, 50)
        self.connect(self.datetime, SIGNAL("dateChanged ( const QDate &)"),
                     self.updateQuery)
        self.connect(self.datetime,
                     SIGNAL("dateTimeChanged ( const QDateTime &)"),
                     self.updateQuery)
        self.connect(self.datetime, SIGNAL("timeChanged ( const QTime &)"),
                     self.updateQuery)

    def request(self):
        res = "(time " + str(self.operatorCombo.currentText())
        date_time = self.datetime.dateTime()
        res += str(date_time.toString("yyyy-MM-ddThh:mm:ss")) + ")"
        return res
Ejemplo n.º 2
0
class DateDialog(QDialog):
    def __init__(self, parent=None):
        super(DateDialog, self).__init__(parent)

        layout = QVBoxLayout(self)

        # nice widget for editing the date
        self.datetime = QDateTimeEdit(self)
        self.datetime.setCalendarPopup(True)
        self.datetime.setDateTime(QDateTime.currentDateTime())
        layout.addWidget(self.datetime)

        # OK and Cancel buttons
        self.buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self)
        layout.addWidget(self.buttons)

        self.buttons.accepted.connect(self.accept)
        self.buttons.rejected.connect(self.reject)

    # get current date and time from the dialog
    def dateTime(self):
        return self.datetime.dateTime()

    # static method to create the dialog and return (date, time, accepted)
    @staticmethod
    def getDateTime(parent=None):
        dialog = DateDialog(parent)
        result = dialog.exec_()
        date = dialog.dateTime()
        return (date.date(), date.time(), result == QDialog.Accepted)
Ejemplo n.º 3
0
class DateRequest(Request):
  def __init__(self, parent):
    Request.__init__(self, parent)
    self.setOperators()
    self.setDateTime()

  def setOperators(self):
    self.operatorCombo = OperatorCombo(self)
    self.hlayout.addWidget(self.operatorCombo)

  def setDateTime(self):
    self.datetime = QDateTimeEdit(self)
    self.datetime.setCalendarPopup(True)
    self.hlayout.addWidget(self.datetime, 50)

  def request(self):
    res = "(time " +  str(self.operatorCombo.currentText())
    date_time = self.datetime.dateTime()
    res += str(date_time.toString("yyyy-MM-ddThh:mm:ss")) + ")"
    return res
Ejemplo n.º 4
0
class DateRequest(Request):
    def __init__(self, parent):
        Request.__init__(self, parent)
        self.setOperators()
        self.setDateTime()

    def setOperators(self):
        self.operatorCombo = OperatorCombo(self)
        self.hlayout.addWidget(self.operatorCombo)

    def setDateTime(self):
        self.datetime = QDateTimeEdit(self)
        self.datetime.setCalendarPopup(True)
        self.hlayout.addWidget(self.datetime, 50)

    def request(self):
        res = "(time " + str(self.operatorCombo.currentText())
        date_time = self.datetime.dateTime()
        res += str(date_time.toString("yyyy-MM-ddThh:mm:ss")) + ")"
        return res
Ejemplo n.º 5
0
class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.agreement1ID = 'AG01'
        self.agreement2ID = 'AG02'
        self.dbNameInit = 'test1'
        self.calculate1 = '+'
        self.c1 = '1'
        self.c3 = '1'
        self.threads = []
        self.onInit()

    def onInit(self):
        self.resize(450, 300)
        self.center()
        self.setMenu()
        self.setWindowTitle(u'MainWindow')
        self.setWindowIcon(QIcon('learning.ico'))

        self.agreement1 = QLabel('Contract1', self)
        self.agreement11 = QLabel('      Contract1 *', self)

        self.agreement2 = QLabel('Contract2', self)
        self.agreement22 = QLabel('Contract2 *', self)
        self.calculate = QLabel('Formula', self)
        self.startTime = QLabel('Start Time', self)
        self.endTime = QLabel('End Time', self)
        self.agreement1Edit = QLineEdit()
        self.agreement2Edit = QLineEdit()
        self.calculate1Edit = QLineEdit()
        self.calculate2Combo = QComboBox()
        self.calculate2Combo.addItem('+')
        self.calculate2Combo.addItem('-')
        self.calculate2Combo.addItem('*')
        self.calculate2Combo.addItem('/')

        self.calculate2Combo.activated[str].connect(self.onActivated)

        self.calculate2Edit = QLineEdit()
        self.calculate3Edit = QLineEdit()
        self.startTimeEdit = QDateTimeEdit(
            datetime.strptime('20150101 00:00:00', '%Y%m%d %H:%M:%S'), self)
        self.startTimeEdit.setDisplayFormat('yyyy-MM-dd')
        self.startTimeEdit.setCalendarPopup(True)
        self.endTimeEdit = QDateTimeEdit(QDateTime.currentDateTime(), self)
        self.endTimeEdit.setDisplayFormat('yyyy-MM-dd')
        self.endTimeEdit.setCalendarPopup(True)
        self.stateEdit = QTextEdit()

        self.run = QPushButton('Run', self)
        self.run.clicked.connect(self.runMain)
        #self.setAgreementBtn = QPushButton('Setting', self)
        #self.setAgreementBtn.clicked.connect(self.setAgreement)

        grid = QGridLayout()
        #grid.setSpacing(10)
        grid.addWidget(self.agreement1, 1, 0)
        grid.addWidget(self.agreement1Edit, 1, 1)
        grid.addWidget(self.agreement2, 2, 0)
        grid.addWidget(self.agreement2Edit, 2, 1)
        #grid.addWidget(self.setAgreementBtn, 2, 2)
        grid.addWidget(self.startTime, 3, 0)
        grid.addWidget(self.startTimeEdit, 3, 1)
        grid.addWidget(self.endTime, 4, 0)
        grid.addWidget(self.endTimeEdit, 4, 1)
        grid.addWidget(self.calculate, 5, 0)
        grid.addWidget(self.agreement11, 5, 1)
        grid.addWidget(self.calculate1Edit, 5, 2)
        grid.addWidget(self.calculate2Combo, 5, 3)
        grid.addWidget(self.agreement22, 5, 4)
        grid.addWidget(self.calculate3Edit, 5, 5)
        grid.addWidget(self.stateEdit, 6, 1, 1, 5)
        grid.addWidget(self.run, 7, 1)
        gridWidget = QWidget()
        gridWidget.setLayout(grid)
        self.agreement11.move(200, 100)
        self.setCentralWidget(gridWidget)
        self.show()

    def onActivated(self, text):
        self.calculate1 = text

    def setMenu(self):
        exitAction = QAction(u'Quit', self)
        exitAction.triggered.connect(qApp.quit)

        menubar = self.menuBar()
        fileMenu = menubar.addMenu(u'Menu')
        fileMenu.addAction(exitAction)

    def center(self):
        qr = self.frameGeometry()
        cp = QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())

    def done(self, ls):
        self.stateEdit.append(u'Maximum:%f' % ls[1])
        self.stateEdit.append(u'Minimum:%f' % ls[2])
        self.stateEdit.append(u'Average:%f' % ls[3])
        show(ls[0])
        self.run.setEnabled(True)
        self.stateEdit.append('End time: %s' % time.ctime())

    def runMain(self):
        self.run.setEnabled(False)
        agreementt1 = self.agreement1Edit.text()
        agreementt2 = self.agreement2Edit.text()
        if agreementt1 == '':
            self.stateEdit.append('Settings of contract1 have error!')
        elif agreementt2 == '':
            self.stateEdit.append('Settings of contract2 have error!')
        else:
            self.agreement1ID = agreementt1
            self.agreement2ID = agreementt2
        startTime = self.startTimeEdit.dateTime()
        endTime = self.endTimeEdit.dateTime()
        self.c1 = self.calculate1Edit.text()
        self.c3 = self.calculate3Edit.text()
        self.stateEdit.append('Formula: ' + self.c1 + '*' + self.agreement1ID +
                              self.calculate1 + self.c3 + '*' +
                              self.agreement2ID + ' have set')
        self.stateEdit.append('Start time: %s' % time.ctime())
        self.workThread = WorkThread(self.agreement1ID, self.agreement2ID,
                                     startTime, endTime, self.c1, self.c3,
                                     self.calculate1)
        self.workThread.finishSignal.connect(self.done)
        self.workThread.start()
Ejemplo n.º 6
0
class TplRow(QWidget):
	def __init__(self, parent = None, _id = 0):
		super(TplRow, self).__init__(parent)
		self.id = _id
		self.setLayout(QHBoxLayout())
		self.idLabel = QLabel(self)
		self.beginEdit = QDateTimeEdit(self)
		self.beginEdit.setCalendarPopup(True) 
		self.endEdit = QDateTimeEdit(self)
		self.endEdit.setCalendarPopup(True)
		self.timeDiff = ClickLabel(self)
		self.descriptionEdit = QLineEdit(self)
		self.noteEdit = QLineEdit(self)
		self.delButton = QPushButton(self)
		self.delButton.setText('X')
		
		self.layout().addWidget(self.idLabel)
		self.layout().addWidget(self.beginEdit)
		self.layout().addWidget(self.endEdit)
		self.layout().addWidget(self.timeDiff)
		self.layout().addWidget(self.descriptionEdit)
		self.layout().addWidget(self.noteEdit)
		self.layout().addWidget(self.delButton)

		self.layout().setContentsMargins(2,2,2,2)
		
		self.connect(self.descriptionEdit, SIGNAL('editingFinished ()'), self.notify)
		self.connect(self.noteEdit, SIGNAL('editingFinished ()'), self.notify)
		self.connect(self.beginEdit, SIGNAL('editingFinished ()'), self.notify)
		self.connect(self.endEdit, SIGNAL('editingFinished ()'), self.notify)
		self.connect(self.delButton, SIGNAL('clicked()'), self.delete)
		self.connect(self.timeDiff, SIGNAL('clicked()'), self.onTimeDiff)

	def set(self, tpl):
		self.idLabel.setText(str(tpl[0]))
		self.beginEdit.setDateTime(QDateTime.fromTime_t(tpl[1]))
		self.endEdit.setDateTime(QDateTime.fromTime_t(tpl[2]))
		self.timeDiff.setText( self.mkDiff( tpl[1], tpl[2] ) )
		self.descriptionEdit.setText(str(tpl[3]))
		self.noteEdit.setText(str(tpl[4]))
	
	def get(self):
		tpl = []
		tpl.append(int(self.idLabel.text()))
		tpl.append(self.beginEdit.dateTime().toTime_t())
		tpl.append(self.endEdit.dateTime().toTime_t())
		tpl.append(self.descriptionEdit.text())
		tpl.append(self.noteEdit.text())
		return tpl
	
	def clear(self):
		self.beginEdit.clear()
		self.endEdit.clear()
		self.timeDiff.clear()
		self.descriptionEdit.clear()
		self.noteEdit.clear()
		self.idLabel.clear()

	def mkDiff(self, begin, end):
		return '%4d' % ceil( float( end - begin ) / 60 )

	@pyqtSlot()
	def onTimeDiff(self):
		self.parent().parent().parent().statusBar.showMessage( '%s copied to clipboard.' % self.timeDiff.text() )
		self.parent().clipboard.setText( str(self.timeDiff.text()).strip() )

	@pyqtSlot()
	def delete(self):
		if self.idLabel.text():
			if QMessageBox.question(self, 'delete ?', 'really delete id %s ?' % self.idLabel.text(), QMessageBox.Yes|QMessageBox.No, QMessageBox.No) == QMessageBox.Yes:
				self.emit(SIGNAL('del(int)'), self.id)

	@pyqtSlot()
	def notify(self):
		if self.idLabel.text():
			self.timeDiff.setText( self.mkDiff( self.beginEdit.dateTime().toTime_t(), self.endEdit.dateTime().toTime_t() ) )
			self.emit(SIGNAL('valueChanged(int)'), self.id)
Ejemplo n.º 7
0
class RunsDialog(QtHelper.EnhancedQDialog):
    """
    Runs several dialog
    """
    RefreshRepository = pyqtSignal(str)
    def __init__(self, dialogName, parent = None, iRepo=None, lRepo=None, rRepo=None):
        """
        Constructor
        """
        QtHelper.EnhancedQDialog.__init__(self, parent)

        self.name = self.tr("Prepare a group of runs")
        self.projectReady = False
        self.iRepo = iRepo
        self.lRepo = lRepo
        self.rRepo = rRepo

        self.createDialog()
        self.createConnections()

    def createDialog(self):
        """
        Create qt dialog
        """
        self.setWindowTitle( self.name )

        mainLayout = QHBoxLayout()
        layoutTests = QHBoxLayout()
        layoutRepoTest = QVBoxLayout()

        self.prjCombo = QComboBox(self)
        self.prjCombo.setEnabled(False)

        self.repoTests = QTreeWidget(self)
        self.repoTests.setFrameShape(QFrame.NoFrame)
        if USE_PYQT5:
            self.repoTests.header().setSectionResizeMode(QHeaderView.Stretch)
        else:
            self.repoTests.header().setResizeMode(QHeaderView.Stretch)
        self.repoTests.setHeaderHidden(True)
        self.repoTests.setContextMenuPolicy(Qt.CustomContextMenu)
        self.repoTests.setIndentation(10)

        layoutRepoTest.addWidget(self.prjCombo)
        layoutRepoTest.addWidget(self.repoTests)

        self.testsList = QListWidget(self)

        layoutTests.addLayout( layoutRepoTest )
        layoutTests.addWidget( self.testsList )
        mainLayout.addLayout( layoutTests )

        buttonLayout = QVBoxLayout()

        self.okButton = QPushButton(self.tr("Execute All"), self)
        self.okButton.setEnabled(False)
        self.cancelButton = QPushButton(self.tr("Cancel"), self)
        self.upButton = QPushButton(self.tr("UP"), self)
        self.upButton.setEnabled(False)
        self.downButton = QPushButton(self.tr("DOWN"), self)
        self.downButton.setEnabled(False)
        self.clearButton = QPushButton(self.tr("Remove All"), self)
        self.delButton = QPushButton(self.tr("Remove"), self)
        self.delButton.setEnabled(False)

        self.runSimultaneous = QCheckBox(self.tr("Simultaneous Run"))
        
        self.schedImmed = QRadioButton(self.tr("Run Immediately"))
        self.schedImmed.setChecked(True)
        self.schedAt = QRadioButton(self.tr("Run At:"))
        self.schedAtDateTimeEdit = QDateTimeEdit(QDateTime.currentDateTime())
        self.schedAtDateTimeEdit.setEnabled(False)

        buttonLayout.addWidget(self.okButton)
        buttonLayout.addWidget(self.runSimultaneous)
        buttonLayout.addWidget(self.schedImmed)
        buttonLayout.addWidget(self.schedAt)
        buttonLayout.addWidget(self.schedAtDateTimeEdit)

        
        buttonLayout.addWidget( self.upButton )
        buttonLayout.addWidget( self.downButton )
        buttonLayout.addWidget( self.delButton )
        buttonLayout.addWidget( self.clearButton )

        buttonLayout.addWidget(self.cancelButton)

        mainLayout.addLayout(buttonLayout)

        self.setMinimumHeight(400)
        self.setMinimumWidth(750)
        self.setLayout(mainLayout)

    def initProjects(self, projects=[], defaultProject=1):
        """
        Initialize projects
        """
        # init date and time
        self.schedAtDateTimeEdit.setDateTime(QDateTime.currentDateTime()) 

        self.projectReady = False

        self.repoTests.clear()
        self.prjCombo.clear()
        self.testsList.clear()

        self.prjCombo.setEnabled(True)
        
        # insert data
        pname = ''
        for p in projects:
            self.prjCombo.addItem ( p['name']  )
            if defaultProject == p['project_id']:
                pname = p['name']
        
        for i in xrange(self.prjCombo.count()):
            item_text = self.prjCombo.itemText(i)
            if str(pname) == str(item_text):
                self.prjCombo.setCurrentIndex(i)

        self.projectReady = True
        self.RefreshRepository.emit(pname)

    def initializeTests(self, listing):
        """
        Initialize tests
        """
        self.repoTests.clear()
        self.testRoot = self.rRepo.Item(repo = self.iRepo.remote(), 
                                        parent = self.repoTests, txt = "Root", 
                                        type = QTreeWidgetItem.UserType+10, 
                                        isRoot = True )
        self.testRoot.setSelected(True)
        self.createRepository(listing=listing, parent=self.testRoot,fileincluded=True)
        self.repoTests.sortItems(0, Qt.AscendingOrder)

        self.hideItems(hideTsx=False, hideTpx=False, hideTcx=True, hideTdx=True, hideTxt=True, hidePy=True,
                                hideTux=False, hidePng=True, hideTgx=False, hideTax=False)

    def createRepository(self, listing, parent, fileincluded=True):
        """
        Create repository

        @param listing: 
        @type listing: list

        @param parent: 
        @type parent:

        @param fileincluded: 
        @type fileincluded: boolean
        """
        try:
            for dct in  listing:
                if dct["type"] == "folder":
                    item = self.rRepo.Item(repo = self.iRepo.remote(), parent = parent, 
                                           txt = dct["name"], propertiesFile=dct )
                    self.createRepository(  dct["content"] , item, fileincluded )
                else:
                    if fileincluded:
                        if dct["type"] == "file":
                            pname = self.iRepo.remote().getProjectName(dct["project"])
                            # {'modification': 1342259500, 'type': 'file', 'name': '__init__.py', 'size': '562 }
                            item = self.rRepo.Item(repo = self.iRepo.remote(), parent = parent, txt = dct["name"] ,
                                                   propertiesFile=dct, type = QTreeWidgetItem.UserType+0, 
                                                   projectId=dct["project"], projectName=pname )

        except Exception as e:
            self.error( "unable to create tree for runs: %s" % e )

    def onProjectChanged(self, projectItem):
        """
        Called when the project changed on the combo box
        """
        if self.projectReady:
            item_text = self.prjCombo.itemText(projectItem)
            self.RefreshRepository.emit(item_text)

    def createConnections (self):
        """
        create qt connections
         * ok
         * cancel
        """
        self.prjCombo.currentIndexChanged.connect(self.onProjectChanged)
        self.okButton.clicked.connect( self.acceptClicked )
        self.cancelButton.clicked.connect( self.reject )
        self.upButton.clicked.connect(self.upTest)
        self.downButton.clicked.connect(self.downTest)
        self.clearButton.clicked.connect(self.clearList)
        self.delButton.clicked.connect(self.delTest)

        self.testsList.itemClicked.connect(self.onItemSelected)
        self.testsList.itemSelectionChanged.connect(self.onItemSelectionChanged)

        self.schedAt.toggled.connect(self.onSchedAtActivated)

        self.repoTests.itemDoubleClicked.connect( self.onTestDoucleClicked )

    def onSchedAtActivated(self, toggled):
        """
        On sched at button activated
        """
        if toggled:
            self.schedAtDateTimeEdit.setEnabled(True)
        else:
            self.schedAtDateTimeEdit.setEnabled(False)

    def onItemSelectionChanged(self):
        """
        Called on item selection changed
        """
        self.onItemSelected(itm=None)

    def onItemSelected(self, itm):
        """
        Call on item selected
        """
        selectedItems = self.testsList.selectedItems()
        if len(selectedItems):
            self.delButton.setEnabled(True)
            self.upButton.setEnabled(True)
            self.downButton.setEnabled(True)
        else:
            self.delButton.setEnabled(False)
            self.upButton.setEnabled(False)
            self.downButton.setEnabled(False)

        if not self.testsList.count():
            self.okButton.setEnabled(False)

    def upTest(self):
        """
        Up test
        """
        currentRow = self.testsList.currentRow()
        currentItem = self.testsList.takeItem(currentRow)
        self.testsList.insertItem(currentRow - 1, currentItem)

    def downTest(self):
        """
        Down test
        """
        currentRow = self.testsList.currentRow()
        currentItem = self.testsList.takeItem(currentRow)
        self.testsList.insertItem(currentRow + 1, currentItem)


    def delTest(self):
        """
        Del test
        """
        currentRow = self.testsList.currentRow()
        currentItem = self.testsList.takeItem(currentRow)

    def clearList(self):
        """
        Clear test
        """
        self.testsList.clear()
        self.delButton.setEnabled(False)
        self.upButton.setEnabled(False)
        self.downButton.setEnabled(False)

        self.okButton.setEnabled(False)

    def iterateTree(self, item, hideTsx, hideTpx, hideTcx, hideTdx, hideTxt, 
                          hidePy, hideTux, hidePng, hideTgx, hideTax):
        """
        Iterate tree
        """
        child_count = item.childCount()
        for i in range(child_count):
            subitem = item.child(i)
            subchild_count = subitem.childCount()
            if subchild_count > 0:
                self.iterateTree(item=subitem, hideTsx=hideTsx, 
                                 hideTpx=hideTpx, hideTcx=hideTcx, 
                                 hideTdx=hideTdx, hideTxt=hideTxt,
                                 hidePy=hidePy, hideTux=hideTux, 
                                 hidePng=hidePng, hideTgx=hideTgx, hideTax=hideTax)
            else:
                if hideTux and subitem.getExtension() == self.rRepo.EXTENSION_TUX:
                    subitem.setHidden (True)
                elif hideTpx and subitem.getExtension() == self.rRepo.EXTENSION_TPX:
                    subitem.setHidden (True)
                elif hideTgx and subitem.getExtension() == self.rRepo.EXTENSION_TGX:
                    subitem.setHidden (True)
                elif hideTcx and subitem.getExtension() == self.rRepo.EXTENSION_TCX:
                    subitem.setHidden (True)
                elif hideTsx and  subitem.getExtension() == self.rRepo.EXTENSION_TSX:
                    subitem.setHidden (True)
                elif hideTdx and  subitem.getExtension() == self.rRepo.EXTENSION_TDX:
                    subitem.setHidden (True)
                elif hideTxt and  subitem.getExtension() == self.rRepo.EXTENSION_TXT:
                    subitem.setHidden (True)
                elif hidePy and  subitem.getExtension() == self.rRepo.EXTENSION_PY:
                    subitem.setHidden (True)
                elif hidePng and  subitem.getExtension() == self.rRepo.EXTENSION_PNG:
                    subitem.setHidden (True)
                elif hideTax and  subitem.getExtension() == self.rRepo.EXTENSION_TAx:
                    subitem.setHidden (True)
                else:
                    subitem.setHidden(False)

    def hideItems(self, hideTsx=False, hideTpx=False, hideTcx=False, hideTdx=False, hideTxt=False, hidePy=False, 
                        hideTux=False, hidePng=False, hideTgx=False, hideTax=False):
        """
        Hide items
        """
        root = self.repoTests.invisibleRootItem()
        self.iterateTree(item=root, hideTsx=hideTsx, hideTpx=hideTpx, hideTcx=hideTcx, 
                         hideTdx=hideTdx, hideTxt=hideTxt, hidePy=hidePy,
                         hideTux=hideTux, hidePng=hidePng, hideTgx=hideTgx, hideTax=hideTax)

    def onTestDoucleClicked(self, testItem):
        """
        On tests double clicked
        """
        if testItem.type() != QTreeWidgetItem.UserType+0:
            return

        self.okButton.setEnabled(True)

        currentProject = self.prjCombo.currentText()

        testName = "%s:%s" % (str(currentProject),testItem.getPath(withFileName = True))
        testItem = QListWidgetItem(testName )

        if testName.endswith(self.rRepo.EXTENSION_TUX):
            testItem.setIcon(QIcon(":/tux.png"))
        if testName.endswith(self.rRepo.EXTENSION_TSX):
            testItem.setIcon(QIcon(":/tsx.png"))
        if testName.endswith(self.rRepo.EXTENSION_TPX):
            testItem.setIcon(QIcon(":/tpx.png"))
        if testName.endswith(self.rRepo.EXTENSION_TGX):
            testItem.setIcon(QIcon(":/tgx.png"))
        if testName.endswith(self.rRepo.EXTENSION_TAX):
            testItem.setIcon(QIcon(":/tax.png"))
            
        self.testsList.addItem( testItem )

    def acceptClicked (self):
        """
        Called on accept button
        """
        self.accept()
    
    def getTests(self):
        """
        Returns all tests in the list
        """
        tests = []
        for i in xrange(self.testsList.count()):
            testItem = self.testsList.item(i)
            tests.append( str(testItem.text()) )

        runSimultaneous = False
        if self.runSimultaneous.isChecked(): runSimultaneous = True
        
        if self.schedImmed.isChecked():
            runAt = (0,0,0,0,0,0)
            return (tests, False, runAt, runSimultaneous)
        else:
            pydt = self.schedAtDateTimeEdit.dateTime().toPyDateTime()
            runAt = (pydt.year, pydt.month, pydt.day, pydt.hour, pydt.minute, pydt.second)
            return (tests, True, runAt, runSimultaneous)
class DlgAixmEffectiveDate(QDialog):
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)

        self.resize(290, 136)
        self.setWindowTitle("Effective Date")
        sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth())
        self.setSizePolicy(sizePolicy)
        verticalLayoutDlg = QVBoxLayout(self)
        verticalLayoutDlg.setObjectName(("verticalLayoutDlg"))

        self.groupBox = GroupBox(self)
        verticalLayoutDlg.addWidget(self.groupBox)

        self.dtpDate = QDateTimeEdit(self.groupBox)
        self.dtpDate.setObjectName(("dtpDate"))
        self.dtpDate.setDateTime(QDateTime.currentDateTime())
        self.groupBox.Add = self.dtpDate

        self.calendar = QCalendarWidget(self.groupBox)
        self.groupBox.Add = self.calendar
        self.calendar.clicked.connect(self.calendar_clicked)

        self.btnBoxOkCancel = QDialogButtonBox(self)
        self.btnBoxOkCancel.setObjectName(("btnBoxOkCancel"))
        self.btnBoxOkCancel.setStandardButtons(QDialogButtonBox.Cancel
                                               | QDialogButtonBox.Ok)
        # btnOK = self.btnBoxOkCancel.button(QDialogButtonBox.Ok)
        # btnOK.setText("Create")
        self.connect(self.btnBoxOkCancel, SIGNAL("accepted()"), self.acceptDlg)
        self.connect(self.btnBoxOkCancel, SIGNAL("rejected()"), self.reject)

        verticalLayoutDlg.addWidget(self.btnBoxOkCancel)

    def calendar_clicked(self, date):
        self.dtpDate.setDate(date)

    def get_DateTime(self):
        return self.dtpDate.dateTime()

    def set_DateTime(self, dateTime):
        if dateTime != None:
            self.dtpDate.setDateTime(dateTime)
            self.calendar.setCurrentPage(dateTime.date().year(),
                                         dateTime.date().month())

    DateTime = property(get_DateTime, set_DateTime, None, None)

    def acceptDlg(self):
        self.accept()

    @staticmethod
    def smethod_0(dateTime_0):
        flag = False
        dlgAixmEffectiveDate = DlgAixmEffectiveDate()
        dlgAixmEffectiveDate.dtpDate.setDateTime(dateTime_0)
        resultDlg = dlgAixmEffectiveDate.exec_()
        if (resultDlg != 1):
            return False, dateTime_0
        else:
            dateTime_0 = dlgAixmEffectiveDate.DateTime
            flag = True
        return flag, dateTime_0
Ejemplo n.º 9
0
class QtDatetimeSelector(QtBoundedDatetime, ProxyDatetimeSelector):
    """ A Qt implementation of an Enaml ProxyDatetimeSelector.

    """
    #: A reference to the widget created by the proxy.
    widget = Typed(QDateTimeEdit)

    #--------------------------------------------------------------------------
    # Initialization API
    #--------------------------------------------------------------------------
    def create_widget(self):
        """ Create the QDateTimeEdit widget.

        """
        self.widget = QDateTimeEdit(self.parent_widget())

    def init_widget(self):
        """ Initialize the widget.

        """
        super(QtDatetimeSelector, self).init_widget()
        d = self.declaration
        self.set_datetime_format(d.datetime_format)
        self.set_calendar_popup(d.calendar_popup)
        self.widget.dateTimeChanged.connect(self.on_datetime_changed)

    #--------------------------------------------------------------------------
    # Abstract API Implementation
    #--------------------------------------------------------------------------
    def get_datetime(self):
        """ Return the current datetime in the control.

        Returns
        -------
        result : datetime
            The current control datetime as a datetime object.

        """
        return self.widget.dateTime().toPyDateTime()

    def set_minimum(self, datetime):
        """ Set the widget's minimum datetime.

        Parameters
        ----------
        datetime : datetime
            The datetime object to use for setting the minimum datetime.

        """
        self.widget.setMinimumDateTime(datetime)

    def set_maximum(self, datetime):
        """ Set the widget's maximum datetime.

        Parameters
        ----------
        datetime : datetime
            The datetime object to use for setting the maximum datetime.

        """
        self.widget.setMaximumDateTime(datetime)

    def set_datetime(self, datetime):
        """ Set the widget's current datetime.

        Parameters
        ----------
        datetime : datetime
            The datetime object to use for setting the datetime.

        """
        self._guard |= CHANGED_GUARD
        try:
            self.widget.setDateTime(datetime)
        finally:
            self._guard &= ~CHANGED_GUARD

    def set_datetime_format(self, format):
        """ Set the widget's datetime format.

        Parameters
        ----------
        format : str
            A Python time formatting string.

        """
        # XXX make sure Python's and Qt's format strings are the
        # same, or convert between the two.
        self.widget.setDisplayFormat(format)

    def set_calendar_popup(self, popup):
        """ Set whether a calendar popup is available on the widget.

        Parameters
        ----------
        popup : bool
            Whether the calendar popup is enabled.

        """
        self.widget.setCalendarPopup(popup)
Ejemplo n.º 10
0
class EvtControlPannel(QWidget):
    def __init__(self, evt_widget, parent=None):
        QWidget.__init__(self, parent)
        self.evt_widget = evt_widget

        self.verticalLayout = QVBoxLayout(self)
        spacerItem = QSpacerItem(20, 259, QSizePolicy.Minimum,
                                 QSizePolicy.Expanding)

        tmp_widget = QWidget()
        self.verticalLayout.addWidget(tmp_widget)
        hor_layout = QHBoxLayout(tmp_widget)
        hor_layout.addWidget(QLabel("Display :"))

        self.admin_events = QPushButton(QIcon(":/green_configure.png"),
                                        "Admin. events")

        self.choose_event_type = QComboBox()
        self.choose_event_type.addItem(QIcon(":/internet_explorer"), "All", 42)
        self.choose_event_type.addItem(QIcon(":/audit_success"),
                                       "Audit success", EVENTLOG_AUDIT_SUCCESS)
        self.choose_event_type.addItem(QIcon(":/audit_failure"),
                                       "Audit failure", EVENTLOG_AUDIT_FAILURE)
        self.choose_event_type.addItem(QIcon(":/error"), "Error",
                                       EVENTLOG_ERROR_TYPE)
        self.choose_event_type.addItem(QIcon(":/warning"), "Warning",
                                       EVENTLOG_WARNING_TYPE)
        self.choose_event_type.addItem(QIcon(":/info"), "Information",
                                       EVENTLOG_INFORMATION_TYPE)
        self.choose_event_type.addItem(QIcon(":/chat.png"), "Comment", 5)

        hor_layout.addWidget(self.choose_event_type)

        tmp_widget = QWidget()
        self.verticalLayout.addWidget(tmp_widget)
        hor_layout = QHBoxLayout(tmp_widget)
        self.id = QLineEdit()
        hor_layout.addWidget(QLabel("Id :"))

        self.cb = QComboBox()
        self.cbs = QComboBox()
        self.init()

        hor_layout.addWidget(self.cb)

        tmp_widget = QWidget()
        self.verticalLayout.addWidget(tmp_widget)
        hor_layout = QHBoxLayout(tmp_widget)
        self.source = QLineEdit()
        hor_layout.addWidget(QLabel("Source :"))
        hor_layout.addWidget(self.cbs)

        self.verticalLayout.addWidget(QLabel("Start date :"))
        self.select_date_b = QDateTimeEdit()
        self.select_date_b.setDisplayFormat("MMM dd yyyy hh:mm AP")
        self.verticalLayout.addWidget(self.select_date_b)
        self.verticalLayout.addWidget(QLabel("End date:"))
        self.select_date_e = QDateTimeEdit()
        self.select_date_e.setDisplayFormat("MMM dd yyyy hh:mm AP")
        self.verticalLayout.addWidget(self.select_date_e)
        self.search_date = QPushButton("Go")
        self.verticalLayout.addWidget(self.search_date)
        self.verticalLayout.addItem(spacerItem)

        self.search_date.clicked.connect(self.filterByDate)
        self.cb.activated.connect(self.filterById)
        self.cbs.activated.connect(self.filterBySource)
        self.choose_event_type.activated.connect(self.filterByLvl)

    def filterByDate(self, checked):
        date_begin = self.select_date_b.dateTime()
        date_end = self.select_date_e.dateTime()

        date_begin_str = str(date_begin.toString('yyyy-MM-dd hh:mm:ss'))
        date_end_str = str(date_end.toString('yyyy-MM-dd hh:mm:ss'))

        if date_begin > date_end:
            message = QMessageBox()
            message.setText('Date mismatch.')
            message.exec_()
        else:
            for i in range(self.evt_widget.rowCount()):
                data = self.evt_widget.item(i, 2)
                if data.text() >= date_begin_str and data.text(
                ) <= date_end_str:
                    self.evt_widget.showRow(i)
                else:
                    self.evt_widget.hideRow(i)

    def filterById(self, index):
        lvl = self.cb.currentText()
        for i in range(self.evt_widget.rowCount()):
            item = self.evt_widget.item(i, 1)
            data = item.text()
            if data != lvl:
                self.evt_widget.hideRow(i)
            else:
                self.evt_widget.showRow(i)

    def dispAll(self):
        for i in range(self.evt_widget.rowCount()):
            self.evt_widget.showRow(i)

    def filterByLvl(self, index):
        type_e = self.choose_event_type.currentText()
        if type_e == 'All':
            self.dispAll()
        else:
            for i in range(self.evt_widget.rowCount()):
                item = self.evt_widget.item(i, 0)
                data = item.text()
                if data != type_e:
                    self.evt_widget.hideRow(i)
                else:
                    self.evt_widget.showRow(i)

    def reload(self, item):
        self.init()

    def filterBySource(self, index):
        lvl = self.cbs.currentText()
        for i in range(self.evt_widget.rowCount()):
            item = self.evt_widget.item(i, 3)
            data = item.text()
            if data != lvl:
                self.evt_widget.hideRow(i)
            else:
                self.evt_widget.showRow(i)

    def init(self):
        tmp_list = []
        tmp_list2 = []
        self.cb.clear()
        self.cbs.clear()

        for i in range(self.evt_widget.rowCount()):
            item = self.evt_widget.item(i, 1).text()
            tmp_list.append(item)
            item = self.evt_widget.item(i, 3).text()
            tmp_list2.append(item)

        tmp_list = self.unique(tmp_list)
        tmp_list2 = self.unique(tmp_list2)

        self.cb.addItems(tmp_list)
        self.cbs.addItems(tmp_list2)

    def unique(self, seq, idfun=None):
        # order preserving
        if idfun is None:

            def idfun(x):
                return x

        seen = {}
        result = []
        for item in seq:
            marker = idfun(item)
            if marker in seen: continue
            seen[marker] = 1
            if item is not None:
                result.append(item)
        return sorted(result)