def _getCalendar(self, display_format, value = None):
     '''
     Get a combobox filled with the given values
     
     :param values: The values as key = value, value = description or text
     :type values: Dict
     
     :returns: A combobox
     :rtype: QWidget
     '''
     
     
     widget = QWidget()
     calendar = QDateTimeEdit()
     calendar.setCalendarPopup(True)
     calendar.setDisplayFormat(display_format)
     if value is not None:
         calendar.setDate(QDate.fromString(value, display_format))
     else:
         calendar.setDate(QDate.currentDate())
     layout = QHBoxLayout(widget)
     layout.addWidget(calendar, 1);
     layout.setAlignment(Qt.AlignCenter);
     layout.setContentsMargins(5,0,5,0);
     widget.setLayout(layout);
             
     return widget
Exemplo n.º 2
0
 def createEditor(self, parent, option, index):
     """QWidget * QStyledItemDelegate::createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index )"""
     editor = QDateTimeEdit(parent)
     editor.setCalendarPopup(True)
     editor.setDisplayFormat(self.edit_pattern)
     editor.dateTimeChanged.connect(self._commitAndClose)
     return editor
    def _getCalendar(self, display_format, value=None):
        '''
        Get a combobox filled with the given values
        
        :param values: The values as key = value, value = description or text
        :type values: Dict
        
        :returns: A combobox
        :rtype: QWidget
        '''

        widget = QWidget()
        calendar = QDateTimeEdit()
        calendar.setCalendarPopup(True)
        calendar.setDisplayFormat(display_format)
        if value is not None:
            calendar.setDate(QDate.fromString(value, display_format))
        else:
            calendar.setDate(QDate.currentDate())
        layout = QHBoxLayout(widget)
        layout.addWidget(calendar, 1)
        layout.setAlignment(Qt.AlignCenter)
        layout.setContentsMargins(5, 0, 5, 0)
        widget.setLayout(layout)

        return widget
Exemplo n.º 4
0
   def createEditor(self, parent, styleOption, index):
      if index.column() == 1:
         editor = QDateTimeEdit(parent)
         editor.setDisplayFormat(self.parent().currentDateFormat)
         editor.setCalendarPopup(True)
         return editor

      editor = QLineEdit(parent)
      # create a completer with the strings in the column as model
      allStrings = []
      for i in range(1, index.model().rowCount()):
         strItem = index.model().data(index.sibling(i, index.column()), Qt.EditRole)
         if strItem not in allStrings:
            allStrings.append(strItem)
      aS = [str(x.toString()) for x in allStrings]
      autoComplete = QCompleter(QStringList(",".join(aS)))
      editor.setCompleter(autoComplete)
      editor.editingFinished.connect(self.commitAndCloseEditor)
      return editor
Exemplo 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()
Exemplo n.º 6
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)
Exemplo n.º 7
0
class dlgSelectCuenta( QDialog ):

    def __init__( self, parent = None ):
        super( dlgSelectCuenta, self ).__init__( parent )
        self.padre = parent

        self.ctaBancomodel = QSqlQueryModel()
        self.ctaBancomodel.setQuery( """
        SELECT
            b.descripcion as Banco,
            cb.ctabancaria as 'No. Cuenta',
            tm.simbolo as Moneda,
            c.codigo as 'Codigo Contable',
            c.idcuenta as Id,
            c.descripcion as 'Cuenta Contable',
            IF(
                con.fecha IS NULL,
                LAST_DAY(MIN(d.fechacreacion)),
                (MAX(con.fecha) + INTERVAL 1 MONTH))
                AS conciliar

        FROM cuentasbancarias cb
        JOIN bancos b ON cb.idbanco=b.idbanco
        JOIN cuentascontables c ON c.idcuenta=cb.idcuentacontable
        JOIN tiposmoneda tm ON tm.idtipomoneda=cb.idtipomoneda
        LEFT JOIN conciliaciones con ON con.idcuentabancaria=cb.idcuentacontable
        LEFT JOIN cuentasxdocumento cd ON cd.idcuenta=c.idcuenta
        LEFT JOIN documentos d ON cd.iddocumento = d.iddocumento
        WHERE d.iddocumento IS NOT NULL
        GROUP BY c.idcuenta
         ;
        """ )
#        
#        if self.ctaBancomodel.rowCount() == 0 :
#            QMessageBox.critical(self,"Cuentas Bancarias","No existe ninguna cuenta bancaria")
#            self.destroy()


        self.setWindowTitle( u"Elija fecha y cuenta bancaria para la conciliación" )
        self.filtermodel = QSortFilterProxyModel()
        self.filtermodel.setSourceModel( self.ctaBancomodel )
        self.filtermodel.setFilterCaseSensitivity( Qt.CaseInsensitive )
        self.filtermodel.setFilterKeyColumn( -1 )

        self.tblCuenta = QTableView()
        self.tblCuenta.setSelectionMode( QAbstractItemView.SingleSelection )
        self.tblCuenta.setSelectionBehavior( QAbstractItemView.SelectRows )

        self.tblCuenta.setModel( self.filtermodel )
        buttonbox = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel )

        self.txtSearch = QLineEdit()
        formlayout = QFormLayout()

        formlayout.addRow( "&Buscar", self.txtSearch )



        self.dtPicker = QDateTimeEdit()
        self.dtPicker.setReadOnly( True )
#        self.dtPicker.setCalendarPopup(True)                                       
        self.dtPicker.setAlignment( Qt.AlignHCenter )
        self.dtPicker.setDisplayFormat( "MMMM 'd'el yyyy" )
#        self.dtPicker.setMinimumDate(QDate(2009,1,1))
        fecha = QDate.currentDate()
        self.dtPicker.setDate( QDate( fecha.year(), fecha.month(), fecha.daysInMonth() ) )

        fechalayout = QFormLayout()
        fechalayout.addRow( "&Fecha", self.dtPicker )

        layout = QVBoxLayout()


        layout.addLayout( fechalayout )
        layout.addWidget( self.tblCuenta )
        layout.addLayout( formlayout )
        layout.addWidget( buttonbox )
        self.setLayout( layout )

        self.setMinimumWidth( 400 )

        buttonbox.accepted.connect( self.aceptar )
        buttonbox.rejected.connect( self.reject )
        self.txtSearch.textChanged[unicode].connect( self.updateFilter )
        self.tblCuenta.selectionModel().currentChanged[QModelIndex, QModelIndex].connect( self.on_tblCuenta_currentChanged )

        self.setModal( True )
        self.setWindowFlags( Qt.Dialog | Qt.MSWindowsFixedSizeDialogHint | Qt.WindowTitleHint )
        self.show()
        self.tblCuenta.setFocus()
        self.tblCuenta.selectRow( 0 )
        self.tblCuenta.setColumnHidden( 4, True )
        self.tblCuenta.setColumnHidden( 5, True )
        self.tblCuenta.setColumnHidden( 6, True )
        self.tblCuenta.horizontalHeader().setStretchLastSection( True )
        self.tblCuenta.resizeColumnsToContents()

    @property
    def data( self ):
        data = {}
        fila = self.tblCuenta.selectionModel().currentIndex().row()
        fecha = self.dtPicker.date()

        data['banco'] = self.filtermodel.index( fila, 0 ).data().toString()
        data['id_cuenta_contable'] = self.filtermodel.index( fila, 4 ).data().toInt()[0]
        data['codigo_cuenta_contable'] = self.filtermodel.index( fila, 3 ).data().toString()
        data['cuenta_bancaria'] = self.filtermodel.index( fila, 5 ).data().toString()
        data['fecha'] = QDate( fecha.year(), fecha.month(), fecha.daysInMonth() )
        data['moneda'] = self.filtermodel.index( fila, 2 ).data().toString()


        if not QSqlDatabase.database().isOpen() and not QSqlDatabase.open():
            raise Exception( QSqlDatabase.lastError() )

        query = QSqlQuery()
        if not query.exec_( "CALL spSaldoCuenta( %d, %s )" % ( 
                data['id_cuenta_contable'],
                QDate( data['fecha'].year(), data['fecha'].month(), data['fecha'].daysInMonth() ).toString( "yyyyMMdd" )
            )
        ):
            raise Exception( query.lastError().text() )

        query.first()

        data['saldo_inicial_libro'] = Decimal( query.value( 0 ).toString() )



        return data

    def aceptar( self ):
        fecha = QDate.currentDate()
        fecha = QDate( fecha.year(), fecha.month(), fecha.daysInMonth() )
        if self.dtPicker.date() > fecha:
            QMessageBox.information( None, "Cuentas Bancarias", "La cuenta seleccionada ya fue conciliada" )
        else:
            return self.accept()


    def exec_( self ):
        if self.ctaBancomodel.rowCount() == 0:
            QMessageBox.critical( self.padre, "Cuentas Bancarias",
                "No existe ninguna cuenta bancaria con movimientos en este mes" )
            return self.reject()
        else:
            return QDialog.exec_( self )

    def updateFilter( self, str ):
        self.filtermodel.setFilterWildcard( str )

#    @pyqtSlot( "QModelIndex" )
#    def on_tblCuenta_clicked(self, index):
    def on_tblCuenta_currentChanged( self, _current, _previous ):
        fila = self.tblCuenta.selectionModel().currentIndex().row()
        fecha = self.filtermodel.index( fila, 6 ).data().toDate()
        if fecha.toString() != "":
            self.dtPicker.setDate( fecha )
        else:
            fecha = QDate.currentDate()
Exemplo n.º 8
0
class EvtxAdminPannel(QWidget):
    def __init__(self, parent=None, chunks=[]):
        super(EvtxAdminPannel, self).__init__(parent)
        self.verticalLayout = QVBoxLayout(self)
        spacerItem = QSpacerItem(20, 259, QSizePolicy.Minimum,
                                 QSizePolicy.Expanding)

        self.verticalLayout.setMargin(3)
        self.verticalLayout.addWidget(
            QLabel("Number of chunk(s) : " + str(len(chunks))))

        nb_rec = 0
        for i in chunks:
            nb_rec += i.nbRecord()

        self.nb_rec = nb_rec
        self.verticalLayout.addWidget(
            QLabel("Number of record(s) : " + str(nb_rec)))

        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")
        hor_layout.addWidget(self.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", 0)
        self.choose_event_type.addItem(QIcon(":/audit_failure"),
                                       "Audit failure", 1)
        self.choose_event_type.addItem(QIcon(":/error"), "Error", 2)
        self.choose_event_type.addItem(QIcon(":/warning"), "Warning", 3)
        self.choose_event_type.addItem(QIcon(":/info"), "Information", 4)
        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 = self.initId(chunks, 'id')
        self.cb.setMaxVisibleItems(15)
        hor_layout.addWidget(self.cb)
        hor_layout.addWidget(self.id)
        self.search_id = QPushButton("Go")
        hor_layout.addWidget(self.search_id)

        tmp_widget = QWidget()
        self.verticalLayout.addWidget(tmp_widget)
        hor_layout = QHBoxLayout(tmp_widget)
        self.source = QLineEdit()
        hor_layout.addWidget(QLabel("Source :"))
        self.cbs = self.initId(chunks, 'source')
        hor_layout.addWidget(self.cbs)
        hor_layout.addWidget(self.source)
        self.search_source = QPushButton("Go")
        hor_layout.addWidget(self.search_source)

        self.verticalLayout.addWidget(QLabel("Date debut :"))
        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("date fin:"))
        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)

    def initId(self, chunks, param):
        cb = QComboBox()
        tmp_list = []
        for chunk in chunks:
            events = chunk.events()
            for event in events:
                tmp_list.append(str(events[event][param]))
        tmp_list = self.unique(tmp_list)
        cb.addItems(tmp_list)
        return cb

    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)
Exemplo n.º 9
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)