class Window(QWidget):

    def __init__(self):
        super().__init__()

        # Make widgets #################

        self.edit1 = QDateEdit()
        self.edit2 = QDateEdit()
        self.edit3 = QDateEdit()

        self.edit1.setMinimumDate(datetime.date(year=2017, month=9, day=1))
        self.edit2.setMinimumDate(datetime.date(year=2017, month=9, day=1))
        self.edit3.setMinimumDate(datetime.date(year=2017, month=9, day=1))

        self.edit1.setMaximumDate(datetime.date(year=2020, month=9, day=1))
        self.edit2.setMaximumDate(datetime.date(year=2020, month=9, day=1))
        self.edit3.setMaximumDate(datetime.date(year=2020, month=9, day=1))

        self.edit1.setDate(datetime.datetime.now().date())
        self.edit2.setDate(datetime.datetime.now().date())
        self.edit3.setDate(datetime.datetime.now().date())

        self.edit1.setCalendarPopup(True)
        self.edit2.setCalendarPopup(True)
        self.edit3.setCalendarPopup(True)

        # Format: see http://doc.qt.io/qt-5/qdatetime.html#toString-2
        self.edit1.setDisplayFormat("yyyy-MM-dd")
        self.edit2.setDisplayFormat("dd/MM/yyyy")
        self.edit3.setDisplayFormat("dddd d MMMM yyyy")

        self.btn = QPushButton("Print")

        # Set button slot ##############

        self.btn.clicked.connect(self.printText)

        # Set the layout ###############

        vbox = QVBoxLayout()

        vbox.addWidget(self.edit1)
        vbox.addWidget(self.edit2)
        vbox.addWidget(self.edit3)

        vbox.addWidget(self.btn)

        self.setLayout(vbox)

    def printText(self):
        print(self.edit1.text())
        print(self.edit2.text())
        print(self.edit3.text())
class EditWindow(QWidget):
    """Käyttöliittymäluokka edit-ikkunalle. Perii QWidget-luokan.
    
    Attributes:
        id: elokuvan id
        title: elokuvan nimi
    """
    def __init__(self, movie_id, movie_title, movie_release):
        """Luokan konstruktori.

        Args:
            movie_id: elokuvan tietokanta-id
            movie_title: elokuvan nimi
            movie_release: elokuvan julkaisupäivä
        """

        super().__init__()
        self.id = movie_id
        self.title = movie_title
        self.release = movie_release
        self.setup_ui()

    def setup_ui(self):
        """Alustaa ikkunan käyttöliittymäkomponentit.
        """

        minimum_date = QDate.fromString(self.release, "yyyy-MM-dd")
        maximum_date = QDate.currentDate()
        self.title_label = QLabel(self.title)
        self.review_label = QLabel("Review:")
        self.watch_date_label = QLabel("Watch date:")
        self.review_entry = QComboBox()
        self.watch_date_entry = QDateEdit(QDate.currentDate())
        self.watch_date_entry.setDisplayFormat("yyyy-MM-dd")
        self.watch_date_entry.setMinimumDate(minimum_date)
        self.watch_date_entry.setMaximumDate(maximum_date)
        self.update_button = QPushButton("Update")
        self.review_entry.addItems(
            ["", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"])
        self.setup_layout()

    def setup_layout(self):
        """Alustaa ikkunan käyttöliittymäasettelun
        """

        layout = QVBoxLayout()
        review_layout = QHBoxLayout()
        watch_date_layout = QHBoxLayout()
        review_layout.addWidget(self.review_label)
        review_layout.addWidget(self.review_entry)
        watch_date_layout.addWidget(self.watch_date_label)
        watch_date_layout.addWidget(self.watch_date_entry)
        layout.addWidget(self.title_label)
        layout.addLayout(review_layout)
        layout.addLayout(watch_date_layout)
        layout.addWidget(self.update_button)

        self.setLayout(layout)
Example #3
0
    def initWidget(self):
        layout = QGridLayout(self)
        layout.setSpacing(0)

        # lbl = QLabel()
        # lbl.setText(self.inputName)
        # lbl.setContentsMargins(-10,10,10,10)

        dateDiff = math.floor(
            (self.maxValue.year() - self.minValue.year()) / 2
        )  # difference between the first date and last date, used to handle min and max values for the sliders

        minScroller = QSlider(Qt.Horizontal, self)
        minScroller.setMinimum(self.minValue.year())
        minScroller.setMaximum(self.maxValue.year())
        minScroller.setTickInterval(1)
        minScroller.setSingleStep(1)
        minScroller.setSliderPosition(self.minValue.year())

        maxScroller = QSlider(Qt.Horizontal, self)
        maxScroller.setMinimum(self.minValue.year())
        maxScroller.setMaximum(self.maxValue.year())
        maxScroller.setTickInterval(1)
        maxScroller.setSingleStep(1)
        maxScroller.setSliderPosition(self.maxValue.year())

        minEdit = QDateEdit()
        minEdit.setDate(self.minValue)
        minEdit.setDisplayFormat("yyyy")
        minEdit.setMinimumDate(self.minValue)
        minEdit.setMaximumDate(self.maxValue)

        maxEdit = QDateEdit()
        maxEdit.setDate(self.maxValue)
        maxEdit.setDisplayFormat("yyyy")
        maxEdit.setMaximumDate(self.maxValue)
        maxEdit.setMinimumDate(self.minValue)

        minScroller.valueChanged.connect(self._updateMinEdit)
        minEdit.dateChanged.connect(self._updateMinSlider)
        maxScroller.valueChanged.connect(self._updateMaxEdit)
        maxEdit.dateChanged.connect(self._updateMaxSlider)

        # layout.addWidget(lbl,0,0,0,1,QtCore.Qt.AlignCenter)

        layout.addWidget(minScroller, 1, 2)
        layout.addWidget(minEdit, 1, 3)

        layout.addWidget(maxScroller, 2, 2)
        layout.addWidget(maxEdit, 2, 3)

        self.setLayout(layout)
        self.minScroller = minScroller
        self.minEdit = minEdit
        self.maxEdit = maxEdit
        self.maxScroller = maxScroller
Example #4
0
    def createEditor(self):
        editor = QDateEdit()
        editor.setMinimumDate(self.minimumDate)
        # editor.setSpecialValueText(self.placeholderText)
        editor.setCalendarPopup(True)
        style = self.style()
        editor.setStyleSheet(style)
        # setup connections
        editor.dateChanged[QDate].connect(self.onActivated)

        return editor
    def createEditor(self, parent, option, index):
        editor = QDateEdit(parent=parent)

        editor.setMinimumDate(datetime.datetime(year=2017, month=9, day=1))
        editor.setMaximumDate(datetime.datetime(year=2020, month=9, day=1))
        editor.setDisplayFormat("yyyy-MM-dd")
        editor.setCalendarPopup(True)

        # setFrame(): tell whether the line edit draws itself with a frame.
        # If enabled (the default) the line edit draws itself inside a frame, otherwise the line edit draws itself without any frame.
        editor.setFrame(False)

        return editor
    def createEditor(self, parent, option, index):
        editor = QDateEdit(parent=parent)

        editor.setMinimumDate(datetime.datetime(year=2017, month=9, day=1))
        editor.setMaximumDate(datetime.datetime(year=2020, month=9, day=1))
        editor.setDisplayFormat("yyyy-MM-dd")
        editor.setCalendarPopup(True)

        # setFrame(): tell whether the line edit draws itself with a frame.
        # If enabled (the default) the line edit draws itself inside a frame, otherwise the line edit draws itself without any frame.
        editor.setFrame(False)

        return editor
Example #7
0
    def initUI(self):
        lbl = QLabel('QDateEdit')

        dateedit = QDateEdit(self)
        dateedit.setDate(QDate.currentDate())
        dateedit.setMinimumDate(QDate(1900, 1, 1))
        dateedit.setMaximumDate(QDate(2100, 12, 31))
        # dateedit.setDateRange(QDate(1900, 1, 1), QDate(2100, 12, 31))

        vbox = QVBoxLayout()
        vbox.addWidget(lbl)
        vbox.addWidget(dateedit)
        vbox.addStretch()

        self.setLayout(vbox)

        self.show_basic()
    def initUI(self):
        label = QLabel('QDateEdit')

        date_edit = QDateEdit(self)
        date_edit.setDate(QDate.currentDate())
        date_edit.setMinimumDate(QDate(1900, 1, 1))
        date_edit.setMaximumDate(QDate(2100, 12, 31))
        # date_edit.setDateRange(QDate(1900, 1, 1), QDate(2100, 12, 31))

        vbox = QVBoxLayout()
        vbox.addWidget(label)
        vbox.addWidget(date_edit)
        vbox.addStretch()

        self.setLayout(vbox)

        self.setWindowTitle('QDateEdit')
        self.setGeometry(300, 300, 300, 200)
        self.show()
class MyApp(QWidget):

    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        lbl = QLabel('QDateEdit')

        self.dateEditWidget = QDateEdit()
        # theDate = QDate()
        # self.dateEditWidget.setDate(theDate.currentDate())    # 현재 날짜
        # theDate.setDate()
        # self.dateEditWidget.setDate(QDate.currentDate())    # 현재 날짜
        self.dateEditWidget.setMinimumDate(QDate(2000, 1, 1))
        self.dateEditWidget.setMaximumDate(QDate(2100, 12, 31))
        self.dateEditWidget.setDisplayFormat('yyyy.MM.dd')
        self.dateEditWidget.setCalendarPopup(True)
        self.dateEditWidget.setDate(QDate(2020, 5, 1))    # 지정한 날짜

        # self.dateEditWidget.setDate(QDate.currentDate())

        self.dateEditWidget.dateChanged.connect(self.__dateChanged)

        vbox = QVBoxLayout()
        vbox.addWidget(lbl)
        vbox.addWidget(self.dateEditWidget)
        vbox.addStretch()

        self.setLayout(vbox)

        self.setWindowTitle('QDateEdit')
        self.setGeometry(300, 300, 300, 200)

    def __dateChanged(self):
        varQDate = self.dateEditWidget.date()   # QDate
        print(varQDate)
        print(varQDate.toString('yyyy-MM-dd'))
        print(f'Year:{varQDate.year()} Month:{varQDate.month()} Day:{varQDate.day()}')
        print('5 Years later:\t', varQDate.addYears(5).toString('yyyy-MM-dd'))
        print('5 Months later:\t', varQDate.addMonths(5).toString('yyyy-MM-dd'))
        print('5 Days later:\t', varQDate.addDays(5).toString('yyyy-MM-dd'))
Example #10
0
class TableWidget(QWidget):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.resize(700, 72)
        self.setMinimumWidth(700)

        # Widgets
        self.lesson = QLineEdit(self)
        self.lesson.setReadOnly(True)
        self.lesson.setToolTip('Описание предмета')
        self.deadline = QDateEdit(self)
        self.deadline.setToolTip('Дата окончания')
        self.deadline.setReadOnly(True)
        self.deadline.setDate(date.today())
        self.deadline.setMinimumDate(date(2017, 9, 1))
        self.save_button = QPushButton('Сохранить', self)
        self.delete_button = QPushButton('Удалить', self)
        self.result = QDoubleSpinBox(self)
        self.result.setSingleStep(0.01)
        self.result.setToolTip('Результат')
        self.done = QCheckBox(self)
        self.done.setToolTip('Задача выполнена')

        # Layouts
        grid_layout = QGridLayout(self)
        grid_layout.addWidget(self.lesson, 0, 1)
        grid_layout.addWidget(self.deadline, 0, 3)
        buttons_layout = QVBoxLayout()
        buttons_layout.addWidget(self.save_button)
        buttons_layout.addWidget(self.delete_button)
        grid_layout.addLayout(buttons_layout, 0, 5)
        grid_layout.addWidget(self.result, 0, 4)
        grid_layout.addWidget(self.done, 0, 0)

        # Tab order
        self.setTabOrder(self.done, self.lesson)
        self.setTabOrder(self.lesson, self.deadline)
        self.setTabOrder(self.deadline, self.result)
        self.setTabOrder(self.result, self.save_button)
        self.setTabOrder(self.save_button, self.delete_button)
Example #11
0
    def initUI(self):
        lbl = QLabel('QDateEdit')

        dateedit = QDateEdit(self)
        dateedit.setDate(QDate.currentDate())
        dateedit.setMinimumDate(QDate(1900, 1, 1))
        dateedit.setMaximumDate(QDate(2100, 12, 31))
        # QDateEdit 클래스를 이용해서 날짜 편집 위젯을 하나 만들어줍니다.
        #
        # setDate 메서드에 QDate.currentDate()를 입력해서 프로그램이 실행될 때
        # 현재 날짜로 표시되도록 합니다.
        #
        # setMinimumDate와 setMaximumDate를 이용하면 사용자가
        # 선택할 수 있는 날짜의 범위를 제한할 수 있습니다.
        #
        # 최소 날짜는 디폴트로 1752년 9월 14일로 설정되어 있고,
        # 최대 날짜는 9999년 12월 31일로 설정되어 있습니다.
        #
        # 최소 날짜는 최소 100년 1월 1일 이상이어야합니다.

        # dateedit.setDateRange(QDate(1900, 1, 1), QDate(2100, 12, 31))
        # setDateRange 메서드는 setMinimumDate와 setMaximumDate를
        # 동시에 사용하는 것과 같습니다.

        vbox = QVBoxLayout()
        vbox.addWidget(lbl)
        vbox.addWidget(dateedit)
        vbox.addStretch()
        # 수직 박스 레이아웃을 이용해서 라벨과 날짜 편집 위젯을 수직으로 배치하고,
        # 전체 위젯의 레이아웃으로 설정합니다.

        self.setLayout(vbox)

        self.setWindowTitle('QDateEdit')
        self.setGeometry(300, 300, 300, 200)
        self.show()
Example #12
0
class Window(QWidget):
    def __init__(self):
        super().__init__()

        # Make widgets #################

        self.edit1 = QDateEdit()
        self.edit2 = QDateEdit()
        self.edit3 = QDateEdit()

        self.edit1.setMinimumDate(datetime.date(year=2017, month=9, day=1))
        self.edit2.setMinimumDate(datetime.date(year=2017, month=9, day=1))
        self.edit3.setMinimumDate(datetime.date(year=2017, month=9, day=1))

        self.edit1.setMaximumDate(datetime.date(year=2020, month=9, day=1))
        self.edit2.setMaximumDate(datetime.date(year=2020, month=9, day=1))
        self.edit3.setMaximumDate(datetime.date(year=2020, month=9, day=1))

        self.edit1.setDate(datetime.datetime.now().date())
        self.edit2.setDate(datetime.datetime.now().date())
        self.edit3.setDate(datetime.datetime.now().date())

        self.edit1.setCalendarPopup(True)
        self.edit2.setCalendarPopup(True)
        self.edit3.setCalendarPopup(True)

        # Format: see http://doc.qt.io/qt-5/qdatetime.html#toString-2
        self.edit1.setDisplayFormat("yyyy-MM-dd")
        self.edit2.setDisplayFormat("dd/MM/yyyy")
        self.edit3.setDisplayFormat("dddd d MMMM yyyy")

        self.btn = QPushButton("Print")

        # Set button slot ##############

        self.btn.clicked.connect(self.printText)

        # Set the layout ###############

        vbox = QVBoxLayout()

        vbox.addWidget(self.edit1)
        vbox.addWidget(self.edit2)
        vbox.addWidget(self.edit3)

        vbox.addWidget(self.btn)

        self.setLayout(vbox)

    def printText(self):
        print(self.edit1.text())
        print(self.edit2.text())
        print(self.edit3.text())
Example #13
0
class App(QMainWindow):
    popupSignal = pyqtSignal()

    def __init__(self):
        super().__init__()

        self.title = 'Bacardi'
        self.left = 0
        self.top = 0
        self.width = 500
        self.height = 500
        self.setWindowTitle(self.title)
        self.listwidget = QListWidget()
        self.setGeometry(self.left, self.top, self.width, self.height)
        centerPoint = QDesktopWidget().availableGeometry().center()
        qtRectangle = self.frameGeometry()
        qtRectangle.moveCenter(centerPoint)
        self.move(qtRectangle.topLeft())

        self.createFormGroupBox()
        self.Connection()
        # self.getMedicineName()
        # mainLayout = QVBoxLayout()
        self.tabs = QTabWidget()
        self.tab1 = QWidget()
        self.tab2 = QWidget()
        self.medicine_names = ["2", "3", "4"]
        self.tabs.addTab(self.tab1, "Add Product")
        self.tabs.addTab(self.tab2, "Generate Bill")

        self.tab1.layout = QVBoxLayout(self)
        # self.tab1.layout.addWidget(self.formGroupBox)

        self.tab1.setLayout(self.ProductGriding())
        # self.table_widget = MyTableWidget(self)

        self.tab2.layout = QVBoxLayout(self)
        # self.tab2.layout.addWidget(self.createGrid())
        self.tab2.setLayout(self.BillGriding())
        # self.tab2.layout.addWidget(self.BillForm())

        # self.gridlayout = QGridLayout()
        # self.gridlayout.addWidget(self.tabs)
        # self.gridlayout.addWidget(self.createExampleGroup(), 0, 0)

        self.setCentralWidget(self.tabs)
        # self.setLayout(self.gridlayout)
        self.submit_btn.clicked.connect(self.SubmtEntry)
        self.show()

    def Connection(self):
        self.mysqlconnection = mysql.connector.connect(host="localhost",
                                                       user="******",
                                                       passwd="root",
                                                       database="bacardi")
        self.mysqlcursor = self.mysqlconnection.cursor()

    def increment(self):
        self.medicine_names.append("898")
        self.tabs.update()
        # self.BillForm.medicine_name.setEnabled(False)

        completer = QCompleter(self.medicine_names)
        self.medicine_name.setCompleter(completer)

        # self.price.setEnabled(False)
        print(self.medicine_names)

    def Refreshing(self):
        self.formGroup.update()
        print("tabs refreshed")

    def SubmtEntry(self):
        itemName = self.itemName.text()
        qty = self.qty.text()
        # exp_date = self.expiry_date.text()
        price = self.price.text()
        purchase_from = self.purchase_from.text()
        GST = self.GST.text()
        exp_date = QDate(self.expiry_date.date())

        type_of_packing = self.type_of_packing.currentText()
        # exp_date = exp_date.year()+"/"+exp_date.month()+"/"+exp_date.day()

        exp_date = "{}/{}/{}".format(exp_date.year(), exp_date.month(),
                                     exp_date.day())

        query = "insert into product_master values(DEFAULT,'{}',{},'{}',{},'{}','{}','{}')".format(
            itemName, qty, exp_date, price, purchase_from, GST,
            type_of_packing)
        print(query)

        # print(itemName+qty+exp_date+price+purchase_from+GST)
        self.mysqlcursor.execute(query)
        self.mysqlconnection.commit()
        # self.getMedicineName()
        self.Refreshing()
        # self.formGroup.update()
        # self.BillForm.update()
        # print("clicked")

    def ProductGriding(self):
        grid = QGridLayout()
        grid.addWidget(self.formGroupBox, 0, 0)
        return grid

    def BillGriding(self):
        grid = QGridLayout()
        # grid.addWidget(self.createGrid(), 0, 0)
        # grid.addWidget(self.createGrid(), 1, 0)
        # grid.addWidget(self.createGrid(), 0, 1)
        # grid.addWidget(self.createGrid(), 1, 1)

        grid.addWidget(self.BillForm(), 0, 0)
        return grid

    # def createGrid(self):
    #     groupBox = QGroupBox("Best Food")
    #     radio1 = QRadioButton("&Radio pizza")
    #     radio2 = QRadioButton("R&adio taco")
    #     radio3 = QRadioButton("Ra&dio burrito")

    #     radio1.setChecked(True)

    #     vbox = QVBoxLayout()
    #     vbox.addWidget(radio1)
    #     vbox.addWidget(radio2)
    #     vbox.addWidget(radio3)
    #     vbox.addStretch(1)
    #     groupBox.setLayout(vbox)
    #     return groupBox

    # def ListOfMedicine(self):

    def getMedicineName(self):
        query = "select item_name,qty from product_master"
        self.mysqlcursor.execute(query)
        d = self.mysqlcursor.fetchall()
        # print(d)
        # print(d)

        # self.listwidget.clear()
        # self.listwidget.addItems(i[0] for i in d)
        # l = (i[0] for i in d)
        self.medicine_names = []
        for i in d:
            self.medicine_names.append(i[0])
        # print(l)
        return self.medicine_names

    def BillForm(self):
        self.formGroup = QGroupBox("Generate Bill")
        layout = QFormLayout()
        print("clicked")
        submit = QPushButton("Generate")

        submit.clicked.connect(self.increment)

        userName = QLineEdit()
        userName.setValidator(QtGui.QRegExpValidator(QRegExp("[a-z-A-Z_]+")))
        age = QLineEdit()
        age.setValidator(QtGui.QIntValidator(0, 100))

        # sex = QLineEdit()
        # sex.setValidator(QtGui.QRegExpValidator())

        sex = QComboBox()
        sex.addItem("Male")
        sex.addItem("Female")
        regNo = QLineEdit()
        GST = QLineEdit()
        self.medicine_name = QLineEdit()

        completer = QCompleter(self.medicine_names)
        # print(self.getMedicineName())
        self.medicine_name.setCompleter(completer)
        # medicine_name.textChanged.connect()

        qty = QLineEdit()
        qty.setValidator(QtGui.QIntValidator(0, 100))

        expiry_date = QDateEdit()
        expiry_date.setCalendarPopup(True)
        expiry_date.setMinimumDate(QDate.currentDate())

        price = QLineEdit()
        price.setValidator(QtGui.QDoubleValidator())

        bill_pay_by = QLineEdit()

        date = QDateEdit()
        date.setCalendarPopup(True)
        date.setDate(QDate.currentDate())
        discount = QLineEdit()
        discount.setValidator(QtGui.QDoubleValidator())

        layout.addRow(QLabel("Patient Name"), userName)
        layout.addRow(QLabel("Age"), age)
        layout.addRow(QLabel("Sex"), sex)
        layout.addRow(QLabel("Registration Number"), regNo)
        layout.addRow(QLabel("GST No."), GST)
        layout.addRow(QLabel("Medicine Name"), self.medicine_name)

        # layout.addRow(None,self.listwidget)

        layout.addRow(QLabel("Quantity"), qty)
        layout.addRow(QLabel("Expiry Date"), expiry_date)
        layout.addRow(QLabel("Price"), price)
        layout.addRow(QLabel("Bill Pay By"), bill_pay_by)
        layout.addRow(QLabel("Date"), date)
        layout.addRow(QLabel("Discount"), discount)
        layout.addWidget(submit)

        self.formGroup.setLayout(layout)
        return self.formGroup

    def createFormGroupBox(self):
        self.formGroupBox = QGroupBox("Add Product")
        layout = QFormLayout()

        self.submit_btn = QPushButton("Submit")
        self.itemName = QLineEdit()
        self.qty = QLineEdit()

        self.expiry_date = QDateEdit()
        self.expiry_date.setCalendarPopup(True)
        self.expiry_date.setMinimumDate(QDate.currentDate())

        # yr = datetime.datetime.today().year
        # dt = QDate()
        # dt.getDate()

        self.price = QLineEdit()
        self.purchase_from = QLineEdit()
        self.GST = QLineEdit()
        layout.addRow(QLabel("Item Name:"), self.itemName)
        layout.addRow(QLabel("Quantity:"), self.qty)

        self.type_of_packing = QComboBox()
        self.type_of_packing.addItem("Packets")
        self.type_of_packing.addItem("Tablets")
        self.type_of_packing.addItem("Carton")
        layout.addRow(QLabel("Type"), self.type_of_packing)

        layout.addRow(QLabel("Expiry Date:"), self.expiry_date)
        layout.addRow(QLabel("Price:"), self.price)
        layout.addRow(QLabel("Purchase from:"), self.purchase_from)
        layout.addRow(QLabel("GST:"), self.GST)
        layout.addWidget(self.submit_btn)
        self.formGroupBox.setLayout(layout)
Example #14
0
class WeatherDataGapfiller(QMainWindow):

    ConsoleSignal = QSignal(str)

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

        self._corrcoeff_update_inprogress = False
        self._pending_corrcoeff_update = None
        self._loading_data_inprogress = False

        self.__initUI__()

        # Setup the DataGapfillManager.
        self.gapfill_manager = DataGapfillManager()
        self.gapfill_manager.sig_task_progress.connect(
            self.progressbar.setValue)
        self.gapfill_manager.sig_status_message.connect(
            self.set_statusbar_text)

    def __initUI__(self):
        self.setWindowIcon(get_icon('master'))

        # Setup the toolbar at the bottom.
        self.btn_fill = QPushButton('Gapfill Data')
        self.btn_fill.setIcon(get_icon('fill_data'))
        self.btn_fill.setIconSize(get_iconsize('small'))
        self.btn_fill.setToolTip(
            "Fill the gaps in the daily weather data of the selected "
            "weather station.")
        self.btn_fill.clicked.connect(self._handle_gapfill_btn_clicked)

        widget_toolbar = QFrame()
        grid_toolbar = QGridLayout(widget_toolbar)
        grid_toolbar.addWidget(self.btn_fill, 0, 0)
        grid_toolbar.setContentsMargins(0, 0, 0, 0)
        grid_toolbar.setColumnStretch(0, 100)

        # ---- Target Station groupbox
        self.target_station = QComboBox()
        self.target_station.currentIndexChanged.connect(
            self._handle_target_station_changed)

        self.target_station_info = QTextEdit()
        self.target_station_info.setReadOnly(True)
        self.target_station_info.setMaximumHeight(110)

        self.btn_refresh_staList = QToolButton()
        self.btn_refresh_staList.setIcon(get_icon('refresh'))
        self.btn_refresh_staList.setToolTip(
            'Force the reloading of the weather data files')
        self.btn_refresh_staList.setIconSize(get_iconsize('small'))
        self.btn_refresh_staList.setAutoRaise(True)
        self.btn_refresh_staList.clicked.connect(
            lambda: self.load_data_dir_content(force_reload=True))

        self.btn_delete_data = QToolButton()
        self.btn_delete_data.setIcon(get_icon('delete_data'))
        self.btn_delete_data.setEnabled(False)
        self.btn_delete_data.setAutoRaise(True)
        self.btn_delete_data.setToolTip(
            'Remove the currently selected dataset and delete the input '
            'datafile. However, raw datafiles will be kept.')
        self.btn_delete_data.clicked.connect(self.delete_current_dataset)

        # Generate the layout for the target station group widget.
        self.target_widget = QWidget()
        target_station_layout = QGridLayout(self.target_widget)
        target_station_layout.setHorizontalSpacing(1)
        target_station_layout.setColumnStretch(0, 1)
        target_station_layout.setContentsMargins(0, 0, 0, 0)

        widgets = [self.target_station, self.btn_refresh_staList,
                   self.btn_delete_data]
        target_station_layout.addWidget(self.target_station, 1, 0)
        for col, widget in enumerate(widgets):
            target_station_layout.addWidget(widget, 1, col)

        # Setup the gapfill dates.
        label_From = QLabel('From :  ')
        self.date_start_widget = QDateEdit()
        self.date_start_widget.setDisplayFormat('dd / MM / yyyy')
        self.date_start_widget.setEnabled(False)
        self.date_start_widget.dateChanged.connect(
            self._update_corrcoeff_table)

        label_To = QLabel('To :  ')
        self.date_end_widget = QDateEdit()
        self.date_end_widget.setEnabled(False)
        self.date_end_widget.setDisplayFormat('dd / MM / yyyy')
        self.date_end_widget.dateChanged.connect(
            self._update_corrcoeff_table)

        self.fillDates_widg = QWidget()
        gapfilldates_layout = QGridLayout(self.fillDates_widg)
        gapfilldates_layout.addWidget(label_From, 0, 0)
        gapfilldates_layout.addWidget(self.date_start_widget, 0, 1)
        gapfilldates_layout.addWidget(label_To, 1, 0)
        gapfilldates_layout.addWidget(self.date_end_widget, 1, 1)
        gapfilldates_layout.setColumnStretch(2, 1)
        gapfilldates_layout.setContentsMargins(0, 0, 0, 0)

        # Create the gapfill target station groupbox.
        target_groupbox = QGroupBox("Fill data for weather station")
        target_layout = QGridLayout(target_groupbox)
        target_layout.addWidget(self.target_widget, 0, 0)
        target_layout.addWidget(self.target_station_info, 1, 0)
        target_layout.addWidget(self.fillDates_widg, 2, 0)

        # Setup the left panel.
        self._regression_model_groupbox = (
            self._create_regression_model_settings())
        self._station_selection_groupbox = (
            self._create_station_selection_criteria())

        self.left_panel = QFrame()
        left_panel_layout = QGridLayout(self.left_panel)
        left_panel_layout.addWidget(target_groupbox, 0, 0)
        left_panel_layout.addWidget(self._station_selection_groupbox, 3, 0)
        left_panel_layout.addWidget(self._regression_model_groupbox, 4, 0)
        left_panel_layout.addWidget(widget_toolbar, 5, 0)
        left_panel_layout.setRowStretch(6, 1)
        left_panel_layout.setContentsMargins(0, 0, 0, 0)

        # Setup the right panel.
        self.corrcoeff_textedit = QTextEdit()
        self.corrcoeff_textedit.setReadOnly(True)
        self.corrcoeff_textedit.setMinimumWidth(700)
        self.corrcoeff_textedit.setFrameStyle(0)
        self.corrcoeff_textedit.document().setDocumentMargin(10)

        self.sta_display_summary = QTextEdit()
        self.sta_display_summary.setReadOnly(True)
        self.sta_display_summary.setFrameStyle(0)
        self.sta_display_summary.document().setDocumentMargin(10)

        self.right_panel = QTabWidget()
        self.right_panel.addTab(
            self.corrcoeff_textedit, 'Correlation Coefficients')
        self.right_panel.addTab(
            self.sta_display_summary, 'Data Overview')

        # Setup the progressbar.
        self.progressbar = QProgressBar()
        self.progressbar.setValue(0)
        self.progressbar.hide()

        self.statustext = QLabel()
        self.statustext.setStyleSheet(
            "QLabel {background-color: transparent; padding: 0 0 0 3px;}")
        self.statustext.setMinimumHeight(self.progressbar.minimumHeight())

        # Setup the main widget.
        main_widget = QWidget()
        main_grid = QGridLayout(main_widget)
        main_grid.addWidget(self.left_panel, 0, 0)
        main_grid.addWidget(self.right_panel, 0, 1)
        main_grid.addWidget(self.progressbar, 1, 0, 1, 2)
        main_grid.addWidget(self.statustext, 1, 0, 1, 2)
        main_grid.setColumnStretch(1, 500)
        main_grid.setRowStretch(0, 500)
        self.setCentralWidget(main_widget)

    def _create_station_selection_criteria(self):
        Nmax_label = QLabel('Nbr. of stations :')
        self.Nmax = QSpinBox()
        self.Nmax.setRange(0, 99)
        self.Nmax.setMinimum(1)
        self.Nmax.setValue(CONF.get('gapfill_data', 'nbr_of_station', 4))
        self.Nmax.setAlignment(Qt.AlignCenter)

        ttip = ('<p>Distance limit beyond which neighboring stations'
                ' are excluded from the gapfilling procedure.</p>'
                '<p>This condition is ignored if set to -1.</p>')
        distlimit_label = QLabel('Max. Distance :')
        distlimit_label.setToolTip(ttip)
        self.distlimit = QSpinBox()
        self.distlimit.setRange(-1, 9999)
        self.distlimit.setSingleStep(1)
        self.distlimit.setValue(
            CONF.get('gapfill_data', 'max_horiz_dist', 100))
        self.distlimit.setToolTip(ttip)
        self.distlimit.setSuffix(' km')
        self.distlimit.setAlignment(Qt.AlignCenter)
        self.distlimit.valueChanged.connect(self._update_corrcoeff_table)

        ttip = ('<p>Altitude difference limit over which neighboring '
                ' stations are excluded from the gapfilling procedure.</p>'
                '<p>This condition is ignored if set to -1.</p>')
        altlimit_label = QLabel('Max. Elevation Diff. :')
        altlimit_label.setToolTip(ttip)
        self.altlimit = QSpinBox()
        self.altlimit.setRange(-1, 9999)
        self.altlimit.setSingleStep(1)
        self.altlimit.setValue(
            CONF.get('gapfill_data', 'max_vert_dist', 350))
        self.altlimit.setToolTip(ttip)
        self.altlimit.setSuffix(' m')
        self.altlimit.setAlignment(Qt.AlignCenter)
        self.altlimit.valueChanged.connect(self._update_corrcoeff_table)

        # Setup the main widget.
        widget = QGroupBox('Stations Selection Criteria')
        layout = QGridLayout(widget)

        layout.addWidget(Nmax_label, 0, 0)
        layout.addWidget(self.Nmax, 0, 1)
        layout.addWidget(distlimit_label, 1, 0)
        layout.addWidget(self.distlimit, 1, 1)
        layout.addWidget(altlimit_label, 2, 0)
        layout.addWidget(self.altlimit, 2, 1)
        layout.setColumnStretch(0, 1)

        return widget

    def _create_advanced_settings(self):
        self.full_error_analysis = QCheckBox('Full Error Analysis.')
        self.full_error_analysis.setChecked(True)

        fig_opt_layout = QGridLayout()
        fig_opt_layout.addWidget(QLabel("Figure output format : "), 0, 0)
        fig_opt_layout.addWidget(self.fig_format, 0, 2)
        fig_opt_layout.addWidget(QLabel("Figure labels language : "), 1, 0)
        fig_opt_layout.addWidget(self.fig_language, 1, 2)

        fig_opt_layout.setContentsMargins(0, 0, 0, 0)
        fig_opt_layout.setColumnStretch(1, 100)

        # Setup the main layout.
        widget = QFrame()
        layout = QGridLayout(widget)
        layout.addWidget(self.full_error_analysis, 0, 0)
        layout.addLayout(fig_opt_layout, 2, 0)
        layout.setRowStretch(layout.rowCount(), 100)
        layout.setContentsMargins(10, 0, 10, 0)

        return widget

    def _create_regression_model_settings(self):
        self.RMSE_regression = QRadioButton('Ordinary Least Squares')
        self.RMSE_regression.setChecked(
            CONF.get('gapfill_data', 'regression_model', 'OLS') == 'OLS')

        self.ABS_regression = QRadioButton('Least Absolute Deviations')
        self.ABS_regression.setChecked(
            CONF.get('gapfill_data', 'regression_model', 'OLS') == 'LAD')

        widget = QGroupBox('Regression Model')
        layout = QGridLayout(widget)
        layout.addWidget(self.RMSE_regression, 0, 0)
        layout.addWidget(self.ABS_regression, 1, 0)

        return widget

    def set_statusbar_text(self, text):
        self.statustext.setText(text)

    @property
    def workdir(self):
        return self._workdir

    def set_workdir(self, dirname):
        """
        Set the working directory to dirname.
        """
        self._workdir = dirname
        self.gapfill_manager.set_workdir(dirname)
        self.load_data_dir_content()

    def delete_current_dataset(self):
        """
        Delete the current dataset source file and force a reload of the input
        daily weather datafiles.
        """
        current_index = self.target_station.currentIndex()
        if current_index != -1:
            basename = self.gapfill_manager.worker().wxdatasets.fnames[
                current_index]
            filename = os.path.join(self.workdir, basename)
            delete_file(filename)
            self.load_data_dir_content()

    def _handle_target_station_changed(self):
        """Handle when the target station is changed by the user."""
        self.btn_delete_data.setEnabled(
            self.target_station.currentIndex() != -1)
        self.update_corrcoeff()

    def get_dataset_names(self):
        """
        Return a list of the names of the dataset that are loaded in
        memory and listed in the target station dropdown menu.
        """
        return [self.target_station.itemText(i) for i in
                range(self.target_station.count())]

    # ---- Correlation coefficients
    def update_corrcoeff(self):
        """
        Calculate the correlation coefficients and display the results
        in the GUI.
        """
        if self.target_station.currentIndex() != -1:
            station_id = self.target_station.currentData()
            if self._corrcoeff_update_inprogress is True:
                self._pending_corrcoeff_update = station_id
            else:
                self._corrcoeff_update_inprogress = True
                self.corrcoeff_textedit.setText('')
                self.gapfill_manager.set_target_station(
                    station_id, callback=self._handle_corrcoeff_updated)

    def _handle_corrcoeff_updated(self):
        self._corrcoeff_update_inprogress = False
        if self._pending_corrcoeff_update is None:
            self._update_corrcoeff_table()
        else:
            self._pending_corrcoeff_update = None
            self.update_corrcoeff()

    def _update_corrcoeff_table(self):
        """
        This method plot the correlation coefficient table in the display area.

        It is separated from the method "update_corrcoeff" because red
        numbers and statistics regarding missing data for the selected
        time period can be updated in the table when the user changes the
        values without having to recalculate the correlation coefficient
        each time.
        """
        if self.target_station.currentIndex() != -1:
            table, target_info = (
                self.gapfill_manager.worker().generate_correlation_html_table(
                    self.get_gapfill_parameters()))
            self.corrcoeff_textedit.setText(table)
            self.target_station_info.setText(target_info)

    # ---- Load Data
    def load_data_dir_content(self, force_reload=False):
        """
        Load weater data from valid files contained in the working directory.
        """
        self._pending_corrcoeff_update = None
        self._loading_data_inprogress = True
        self.left_panel.setEnabled(False)
        self.right_panel.setEnabled(False)

        self.corrcoeff_textedit.setText('')
        self.target_station_info.setText('')
        self.target_station.clear()

        self.gapfill_manager.load_data(
            force_reload=force_reload,
            callback=self._handle_data_dir_content_loaded)

    def _handle_data_dir_content_loaded(self):
        """
        Handle when data finished loaded from valid files contained in
        the working directory.
        """
        self.left_panel.setEnabled(True)
        self.right_panel.setEnabled(True)

        self.target_station.blockSignals(True)
        station_names = self.gapfill_manager.get_station_names()
        station_ids = self.gapfill_manager.get_station_ids()
        for station_name, station_id in zip(station_names, station_ids):
            self.target_station.addItem(
                '{} ({})'.format(station_name, station_id),
                userData=station_id)
        self.target_station.blockSignals(False)

        self.sta_display_summary.setHtml(
            self.gapfill_manager.worker().generate_html_summary_table())

        if len(station_names) > 0:
            self._setup_fill_and_save_dates()
            self.target_station.blockSignals(True)
            self.target_station.setCurrentIndex(0)
            self.target_station.blockSignals(False)
        self._handle_target_station_changed()
        self._loading_data_inprogress = False

    def _setup_fill_and_save_dates(self):
        """
        Set first and last dates of the 'Fill data for weather station'.
        """
        if self.gapfill_manager.count():
            self.date_start_widget.setEnabled(True)
            self.date_end_widget.setEnabled(True)

            mindate = (
                self.gapfill_manager.worker()
                .wxdatasets.metadata['first_date'].min())
            maxdate = (
                self.gapfill_manager.worker()
                .wxdatasets.metadata['last_date'].max())

            qdatemin = QDate(mindate.year, mindate.month, mindate.day)
            qdatemax = QDate(maxdate.year, maxdate.month, maxdate.day)

            self.date_start_widget.blockSignals(True)
            self.date_start_widget.setDate(qdatemin)
            self.date_start_widget.setMinimumDate(qdatemin)
            self.date_start_widget.setMaximumDate(qdatemax)
            self.date_start_widget.blockSignals(False)

            self.date_end_widget.blockSignals(True)
            self.date_end_widget.setDate(qdatemax)
            self.date_end_widget.setMinimumDate(qdatemin)
            self.date_end_widget.setMaximumDate(qdatemax)
            self.date_end_widget.blockSignals(False)

    # ---- Gapfill Data
    def get_gapfill_parameters(self):
        """
        Return a dictionary containing the parameters that are set in the GUI
        for gapfilling weather data.
        """
        return {
            'limitDist': self.distlimit.value(),
            'limitAlt': self.altlimit.value(),
            'date_start': self.date_start_widget.date().toString('dd/MM/yyyy'),
            'date_end': self.date_end_widget.date().toString('dd/MM/yyyy')
            }

    def _handle_gapfill_btn_clicked(self):
        """
        Handle when the user clicked on the gapfill button.
        """
        if self.gapfill_manager.count() == 0:
            QMessageBox.warning(
                self, 'Warning', "There is no data to fill.", QMessageBox.Ok)
            return

        # Check for dates errors.
        datetime_start = datetime_from_qdatedit(self.date_start_widget)
        datetime_end = datetime_from_qdatedit(self.date_end_widget)
        if datetime_start > datetime_end:
            QMessageBox.warning(
                self, 'Warning',
                ("<i>From</i> date is set to a later time than "
                 "the <i>To</i> date."),
                QMessageBox.Ok)
            return
        if self.target_station.currentIndex() == -1:
            QMessageBox.warning(
                self, 'Warning',
                "No weather station is currently selected",
                QMessageBox.Ok)
            return

        self.start_gapfill_target()

    def _handle_gapfill_target_finished(self):
        """
        Method initiated from an automatic return from the gapfilling
        process in batch mode. Iterate over the station list and continue
        process normally.
        """
        self.btn_fill.setIcon(get_icon('fill_data'))
        self.btn_fill.setEnabled(True)

        self.target_widget.setEnabled(True)
        self.fillDates_widg.setEnabled(True)
        self._regression_model_groupbox.setEnabled(True)
        self._station_selection_groupbox.setEnabled(True)
        self.progressbar.setValue(0)
        QApplication.processEvents()
        self.progressbar.hide()

    def start_gapfill_target(self):
        # Update the gui.
        self.btn_fill.setEnabled(False)
        self.fillDates_widg.setEnabled(False)
        self.target_widget.setEnabled(False)
        self._regression_model_groupbox.setEnabled(False)
        self._station_selection_groupbox.setEnabled(False)
        self.progressbar.show()

        # Start the gapfill thread.
        self.gapfill_manager.gapfill_data(
            time_start=datetime_from_qdatedit(self.date_start_widget),
            time_end=datetime_from_qdatedit(self.date_end_widget),
            max_neighbors=self.Nmax.value(),
            hdist_limit=self.distlimit.value(),
            vdist_limit=self.altlimit.value(),
            regression_mode=self.RMSE_regression.isChecked(),
            callback=self._handle_gapfill_target_finished
            )

    def close(self):
        CONF.set('gapfill_data', 'nbr_of_station', self.Nmax.value())
        CONF.set('gapfill_data', 'max_horiz_dist', self.distlimit.value())
        CONF.set('gapfill_data', 'max_vert_dist', self.altlimit.value())
        CONF.set('gapfill_data', 'regression_model',
                 'OLS' if self.RMSE_regression.isChecked() else 'LAD')
        super().close()
Example #15
0
class AddBookingDetails(QMainWindow):

    closing = pyqtSignal(int)

    def __init__(self, parent, update, id=None):
        super().__init__(parent)

        self.db = DB()

        self.initUI(update, id)

    def initUI(self, update, id):

        self.setWindowModality(Qt.ApplicationModal)

        frame = QFrame()
        # frame.setStyleSheet("background-color: rgb(30, 45, 66);")
        frame.setFrameShape(QFrame.StyledPanel)
        frame.setFrameShadow(QFrame.Raised)
        # frame.setMinimumWidth(430)
        # frame.setFixedHeight(395)
        # frame.setStyleSheet("border: none")

        add_booking_button = QLabel(frame)
        add_booking_button.setAlignment(Qt.AlignCenter)
        add_booking_button.setGeometry(QRect(110, 30, 210, 41))
        add_booking_button.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n"
                                         "background-color: rgb(30, 45, 66);\n"
                                         "color: rgb(255, 255, 255);")
        add_booking_button.setText("Add Reservation Details")

        # tablelabel = QLabel(frame)
        # tablelabel.setText("Table")
        # tablelabel.setGeometry(QRect(50, 120, 81, 20))
        #
        # tabletextbox = QComboBox(frame)
        # tabletextbox.setGeometry(QRect(170, 110, 181, 31))
        # tabletextbox.setFixedWidth(180)
        # tabletextbox.addItems(["Table 1", "Table 2"])

        customernamelabel = QLabel(frame)
        customernamelabel.setText("Customer Name")
        customernamelabel.setGeometry(QRect(50, 120, 100, 20))

        self.customernametextbox = QLineEdit(frame)
        self.customernametextbox.setGeometry(QRect(170, 110, 181, 31))
        self.customernametextbox.setFixedWidth(180)

        customercontactlabel = QLabel(frame)
        customercontactlabel.setText("Customer Contact")
        customercontactlabel.setGeometry(QRect(50, 160, 145, 19))

        self.customercontacttextbox = QLineEdit(frame)
        self.customercontacttextbox.setGeometry(QRect(170, 150, 181, 31))
        self.customercontacttextbox.setFixedWidth(180)

        datelabel = QLabel(frame)
        datelabel.setText("Date")
        datelabel.setGeometry(QRect(50, 200, 145, 19))

        self.datetextbox = QDateEdit(frame)
        self.datetextbox.setGeometry(QRect(170, 190, 181, 31))
        self.datetextbox.setFixedWidth(180)
        self.datetextbox.setDate(QDate.currentDate())
        self.datetextbox.setMinimumDate(QDate.currentDate())
        self.datetextbox.setDisplayFormat("dd-MM-yyyy")

        starttimelabel = QLabel(frame)
        starttimelabel.setText("Start Time")
        starttimelabel.setGeometry(QRect(50, 240, 121, 16))

        self.starttimetextbox = QTimeEdit(frame)
        self.starttimetextbox.setGeometry(QRect(170, 230, 181, 31))
        self.starttimetextbox.setFixedWidth(180)
        # self.starttimetextbox.setTime(QDate.currentDate())
        # self.starttimetextbox.setMinimumDate(QDate.currentDate())

        self.addbutton = QPushButton(frame)
        self.addbutton.setText("Add Booking")
        self.addbutton.setGeometry(QRect(160, 300, 151, 31))
        self.addbutton.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n"
                                     "background-color: rgb(30, 45, 66);\n"
                                     "color: rgb(255, 255, 255);")
        # self.addbutton.clicked.connect(lambda: self.add_button_click("reservations"))

        if update == 'add':
            print("Add")
            print(id)
            self.addbutton.setText("Add Reservation")
            self.addbutton.clicked.connect(
                lambda: self.add_button_click("reservations"))
        else:
            print("Update")
            print(id)
            self.addbutton.setText("Update Reservation")
            self.addbutton.clicked.connect(
                lambda: self.update_button_click("reservations", id))

        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(frame)

        centralWidget = QWidget()
        centralWidget.setLayout(layout)

        self.setCentralWidget(centralWidget)

        # self.setLayout(layout)

        self.setWindowTitle("Add Reservation Details")
        self.resize(430, 395)
        self.show()

        self.center()

    def center(self):
        '''centers the window on the screen'''
        screen = QDesktopWidget().screenGeometry()
        size = self.geometry()
        self.move((screen.width() - size.width()) / 2,
                  (screen.height() - size.height()) / 2)

    def update_button_click(self, where, id):
        if where == "reservations":
            print("Tables Finally here")

            customer_name = self.customernametextbox.text()
            customer_contact = self.customercontacttextbox.text()
            start_time = self.starttimetextbox.text()

            try:
                date = datetime.datetime.strptime(self.datetextbox.text(),
                                                  "%d-%m-%Y")
                booking_date = datetime.datetime.strftime(date, "%Y-%m-%d")
            except Exception as e:
                ''' Make sure to add an error message. '''
                print(e)
                return

            if customer_name != "" and customer_contact != "":

                query = "update customerBooking set `customer_name`=%s, " \
                        "`phone_number`=%s, `booking_date`=concat(%s, ' ', %s)" \
                        "where id=%s;"
                values = (customer_name, customer_contact, booking_date,
                          start_time, id)

                result = self.db.execute(query, values)

                self.closeEvent = self.message()

    def add_button_click(self, where):
        if where == "reservations":
            print("Finally here")

            customer_name = self.customernametextbox.text()
            customer_contact = self.customercontacttextbox.text()
            start_time = self.starttimetextbox.text()

            try:
                date = datetime.datetime.strptime(self.datetextbox.text(),
                                                  "%d-%m-%Y")
                booking_date = datetime.datetime.strftime(date, "%Y-%m-%d")
            except Exception as e:
                ''' Make sure to add an error message. '''
                print(e)
                return

            if customer_name != "" and customer_contact != "":

                print("Got Here")

                query = "insert into customerBooking (`customer_name`, `phone_number`, `booking_date`)" \
                        "values (%s, %s, concat(%s, ' ', %s));"
                values = (customer_name, customer_contact, booking_date,
                          start_time)

                result = self.db.execute(query, values)

                self.closeEvent = self.message()

    def message(self):
        self.closing.emit(1)
        self.close()
Example #16
0
class IPStationBrowser(QWidget):

    __inv = None

    def __init__(self, service=None, network=None):
        super().__init__()

        # these are for managing the event info in form elements
        # self.eventInfoPopulated = False
        # self.currentEvent = None

        self.__buildUI__(service, network)
        self.show()

    def __buildUI__(self, service, network):
        vertLayout = QVBoxLayout()
        self.setLayout(vertLayout)

        gridLayout = QGridLayout()

        # First lets populate the client drop down with all available services
        self.service_cb = QComboBox()
        # self.service_cb.addItem("choose...")
        fdsn_dictionary = URL_MAPPINGS
        fdsn_dictionary.update(
            {'RaspShake': 'https://fdsnws.rasberryshakedata.com'})

        for key in sorted(fdsn_dictionary.keys()):
            self.service_cb.addItem(key)
            self.service_cb.setCurrentText('IRIS')
        if service is not None:
            self.service_cb.setCurrentText(service)

        validator = Validator(self)

        # Network selector
        self.network_edit = QLineEdit(network)
        self.network_edit.setToolTip(
            'Wildcards OK \nCan be SEED network codes or data center defined codes. \nMultiple codes are comma-separated (e.g. "IU,TA").'
        )
        self.network_edit.setValidator(validator)
        if network is not None:
            self.network_edit.setText(network)

        # Station selector
        self.station_edit = QLineEdit()
        self.station_edit.setToolTip(
            'Wildcards OK \nOne or more SEED station codes. \nMultiple codes are comma-separated (e.g. "ANMO,PFO")'
        )
        self.station_edit.setValidator(validator)

        # Location selector
        self.location_edit = QLineEdit()
        self.location_edit.setToolTip(
            'One or more SEED location identifiers. \nMultiple identifiers are comma-separated (e.g. "00,01"). \nAs a special case “--“ (two dashes) will be translated to a string of two space characters to match blank location IDs.'
        )
        self.location_edit.setText('')

        # Channel selector
        self.channel_edit = QLineEdit()
        self.channel_edit.setToolTip(
            'Wildcards OK \nOne or more SEED channel codes. \nMultiple codes are comma-separated (e.g. "BHZ,HHZ")'
        )
        self.channel_edit.setValidator(validator)

        # Date time editors
        minimumDate = QDate(1900, 1, 1)
        self.startDate_edit = QDateEdit()
        self.startDate_edit.setDisplayFormat('yyyy-MM-dd')
        self.startDate_edit.setMinimumDate(minimumDate)
        self.startDate_edit.setDate(self.startDate_edit.minimumDate())

        self.endDate_edit = QDateEdit()
        self.endDate_edit.setDisplayFormat('yyyy-MM-dd')
        self.endDate_edit.setMinimumDate(minimumDate)
        self.endDate_edit.setDate(self.endDate_edit.minimumDate())

        self.lat_edit = QDoubleSpinBox()
        self.lat_edit.setRange(-90.1,
                               90.0)  # the -90.1 is used as the "unset" value
        self.lat_edit.setDecimals(8)
        self.lat_edit.setSpecialValueText('--')
        self.lat_edit.setSingleStep(0.1)
        self.lat_edit.setValue(self.lat_edit.minimum())

        self.lon_edit = QDoubleSpinBox()
        self.lon_edit.setRange(-180.1, 180.0)
        self.lon_edit.setDecimals(8)
        self.lon_edit.setSpecialValueText('--')
        self.lon_edit.setSingleStep(0.1)
        self.lon_edit.setValue(self.lon_edit.minimum())

        # self.evt_import_button = QPushButton('Populate with Event Info')

        self.minLat_edit = QDoubleSpinBox()
        self.minLat_edit.setRange(-90.1, 90.0)
        self.minLat_edit.setDecimals(8)
        self.minLat_edit.setSpecialValueText('--')
        self.minLat_edit.setSingleStep(0.1)
        self.minLat_edit.setValue(self.minLat_edit.minimum())

        self.maxLat_edit = QDoubleSpinBox()
        self.maxLat_edit.setRange(-90.1, 90.0)
        self.maxLat_edit.setDecimals(8)
        self.maxLat_edit.setSpecialValueText('--')
        self.maxLat_edit.setSingleStep(0.1)
        self.maxLat_edit.setValue(self.maxLat_edit.minimum())

        self.minLon_edit = QDoubleSpinBox()
        self.minLon_edit.setRange(-180.1, 180.0)
        self.minLon_edit.setDecimals(8)
        self.minLon_edit.setSpecialValueText('--')
        self.minLon_edit.setSingleStep(0.1)
        self.minLon_edit.setValue(self.minLon_edit.minimum())

        self.maxLon_edit = QDoubleSpinBox()
        self.maxLon_edit.setRange(-180.1, 180.0)
        self.maxLon_edit.setDecimals(8)
        self.maxLon_edit.setSpecialValueText('--')
        self.maxLon_edit.setSingleStep(0.1)
        self.maxLon_edit.setValue(self.maxLon_edit.minimum())

        self.minRadius_edit = QDoubleSpinBox()
        self.minRadius_edit.setMinimum(0.0)
        self.minRadius_edit.setMaximum(180.0)
        self.minRadius_edit.setSpecialValueText('--')
        self.minRadius_edit.setSuffix(' deg')
        self.minRadius_edit.setValue(self.minRadius_edit.minimum())
        self.minRadius_edit.setEnabled(
            False)  # Need lat and lon before this means anything

        self.maxRadius_edit = QDoubleSpinBox()
        self.maxRadius_edit.setMinimum(0.0)
        self.maxRadius_edit.setMaximum(180.0)
        self.maxRadius_edit.setSpecialValueText('--')
        self.maxRadius_edit.setSuffix(' deg')
        self.maxRadius_edit.setValue(self.maxRadius_edit.minimum())
        self.maxRadius_edit.setEnabled(
            False)  # Need lat and lon before this means anything

        # Set up the search button here
        self.searchButton = QPushButton('Search')

        # Reset Button
        self.resetButton = QPushButton('Reset Inputs')

        # assemble the grid layout
        gridLayout.addWidget(QLabel(self.tr('Service: ')),
                             0,
                             0,
                             alignment=Qt.AlignRight)
        gridLayout.addWidget(self.service_cb, 0, 1)

        gridLayout.addWidget(QLabel(self.tr('Network(s): ')),
                             1,
                             0,
                             alignment=Qt.AlignRight)
        gridLayout.addWidget(self.network_edit, 1, 1)
        gridLayout.addWidget(QLabel(self.tr('Station(s): ')),
                             1,
                             2,
                             alignment=Qt.AlignRight)
        gridLayout.addWidget(self.station_edit, 1, 3)

        gridLayout.addWidget(QLabel(self.tr('Location(s): ')),
                             2,
                             0,
                             alignment=Qt.AlignRight)
        gridLayout.addWidget(self.location_edit, 2, 1)
        gridLayout.addWidget(QLabel(self.tr('Channel(s): ')),
                             2,
                             2,
                             alignment=Qt.AlignRight)
        gridLayout.addWidget(self.channel_edit, 2, 3)

        gridLayout.addWidget(self.HLine(), 3, 0, 1,
                             4)  # This is a horizontal line

        gridLayout.addWidget(QLabel(self.tr('Start Date (UTC)')),
                             4,
                             0,
                             alignment=Qt.AlignRight)
        gridLayout.addWidget(self.startDate_edit, 4, 1)

        gridLayout.addWidget(QLabel(self.tr('End Date (UTC)')),
                             4,
                             2,
                             alignment=Qt.AlignRight)
        gridLayout.addWidget(self.endDate_edit, 4, 3)

        gridLayout.addWidget(QLabel(self.tr('Latitude: ')),
                             5,
                             0,
                             alignment=Qt.AlignRight)
        gridLayout.addWidget(self.lat_edit, 5, 1)
        gridLayout.addWidget(QLabel(self.tr('Longitude: ')),
                             5,
                             2,
                             alignment=Qt.AlignRight)
        gridLayout.addWidget(self.lon_edit, 5, 3)

        # gridLayout.addWidget(self.evt_import_button, 6, 1, 1, 2)

        gridLayout.addWidget(self.HLine(), 7, 0, 1,
                             4)  # This is a horizontal line

        gridLayout.addWidget(QLabel(self.tr('Minimum Latitude: ')),
                             8,
                             0,
                             alignment=Qt.AlignRight)
        gridLayout.addWidget(self.minLat_edit, 8, 1)
        gridLayout.addWidget(QLabel(self.tr('Maximum Latitude: ')),
                             8,
                             2,
                             alignment=Qt.AlignRight)
        gridLayout.addWidget(self.maxLat_edit, 8, 3)

        gridLayout.addWidget(QLabel(self.tr('Minimum Longitude: ')),
                             9,
                             0,
                             alignment=Qt.AlignRight)
        gridLayout.addWidget(self.minLon_edit, 9, 1)
        gridLayout.addWidget(QLabel(self.tr('Maximum Longitude: ')),
                             9,
                             2,
                             alignment=Qt.AlignRight)
        gridLayout.addWidget(self.maxLon_edit, 9, 3)

        gridLayout.addWidget(self.HLine(), 10, 0, 1,
                             4)  # This is a horizontal line

        gridLayout.addWidget(QLabel(self.tr('Minimum Radius: ')),
                             11,
                             0,
                             alignment=Qt.AlignRight)
        gridLayout.addWidget(self.minRadius_edit, 11, 1)
        gridLayout.addWidget(QLabel(self.tr('Maximum Radius: ')),
                             11,
                             2,
                             alignment=Qt.AlignRight)
        gridLayout.addWidget(self.maxRadius_edit, 11, 3)

        gridLayout.addWidget(self.HLine(), 12, 0, 1,
                             4)  # This is a horizontal line

        gridLayout.addWidget(self.resetButton, 13, 0)
        gridLayout.addWidget(self.searchButton, 13, 2, 1, 2)

        # Center the form in the widget
        centeringLayout = QHBoxLayout()
        centeringLayout.addStretch()
        centeringLayout.addLayout(gridLayout)
        centeringLayout.addStretch()

        self.stationListWidget = QListWidget()
        # self.stationListWidget.setSelectionMode(QAbstractItemView.SingleSelection)
        # for multiple selection, uncomment out the next line, and comment out the above line
        self.stationListWidget.setSelectionMode(
            QAbstractItemView.ExtendedSelection)

        # create a tab widget to hold the stationList and the station map
        stationTabs = QTabWidget()
        stationTabs.addTab(self.stationListWidget, "Station List")

        # Placeholder for map widget, whenever I get around to making one
        self.mapWidget = QWidget()
        stationTabs.addTab(self.mapWidget, 'Map')

        vertLayout.addLayout(centeringLayout)

        vertLayout.addWidget(stationTabs)

        self.connectSignalsAndSlots()

    def connectSignalsAndSlots(self):

        self.searchButton.clicked.connect(self.onActivated_search)
        self.resetButton.clicked.connect(self.onActivated_reset)
        # self.evt_import_button.clicked.connect(self.populateEventInfo)

        self.stationListWidget.itemClicked.connect(self.getSelected)

        self.service_cb.currentIndexChanged[str].connect(self.serviceClicked)

        self.lat_edit.valueChanged.connect(self.updateWidget)
        self.lon_edit.valueChanged.connect(self.updateWidget)

        self.startDate_edit.dateChanged.connect(self.adjust_end_date)

    @QtCore.pyqtSlot(QDate)
    def adjust_end_date(self, start_date):
        if self.endDate_edit.date() == self.endDate_edit.minimumDate():
            self.endDate_edit.setDate(start_date)
        elif self.endDate_edit.date() < start_date:
            self.endDate_edit.setDate(start_date)

    def populateStationInfo(self):

        service = self.service_cb.currentText()

        if self.network_edit.text() == '':
            network = None
        else:
            network = self.network_edit.text()

        if self.station_edit.text() == '':
            station = None
        else:
            station = self.station_edit.text()

        if self.location_edit.text() == '':
            location = None
        else:
            location = self.location_edit.text()

        if self.channel_edit.text() == '':
            channel = None
        else:
            channel = self.channel_edit.text()

        if self.lat_edit.value() == self.lat_edit.minimum():
            lat = None
        else:
            lat = self.lat_edit.value()

        if self.lon_edit.value() == self.lon_edit.minimum():
            lon = None
        else:
            lon = self.lon_edit.value()

        if self.minLat_edit.value() == self.minLat_edit.minimum():
            minLat = None
        else:
            minLat = self.minLat_edit.value()

        if self.maxLat_edit.value() == self.maxLat_edit.minimum():
            maxLat = None
        else:
            maxLat = self.maxLat_edit.value()

        if self.minLon_edit.value() == self.minLon_edit.minimum():
            minLon = None
        else:
            minLon = self.minLon_edit.value()

        if self.maxLon_edit.value() == self.maxLon_edit.minimum():
            maxLon = None
        else:
            maxLon = self.maxLon_edit.value()

        if self.lat_edit.value() != self.lat_edit.minimum(
        ) and self.lon_edit.value() != self.lon_edit.minimum():

            if self.minRadius_edit.value() == self.minRadius_edit.minimum():
                minRad = None
            else:
                minRad = self.minRadius_edit.value()

            if self.maxRadius_edit.value() == self.maxRadius_edit.minimum():
                maxRad = None
            else:
                maxRad = self.maxRadius_edit.value()
        else:
            minRad = None
            maxRad = None

        if service != '':
            try:
                client = Client(service)
            except obspy.clients.fdsn.header.FDSNException as e:
                self.errorPopup(str(e))
                return

            startDate = self.startDate_edit.date().toString("yyyy-MM-dd")
            endDate = self.endDate_edit.date().toString("yyyy-MM-dd")

            try:
                self.__inv = client.get_stations(network=network,
                                                 station=station,
                                                 location=location,
                                                 channel=channel,
                                                 starttime=startDate,
                                                 endtime=endDate,
                                                 latitude=lat,
                                                 longitude=lon,
                                                 minlongitude=minLon,
                                                 maxlongitude=maxLon,
                                                 minlatitude=minLat,
                                                 maxlatitude=maxLon,
                                                 minradius=minRad,
                                                 maxradius=maxRad,
                                                 format='xml')
            except:
                emptyMessage = ["...No Data Found..."]
                self.stationListWidget.clear()
                self.stationListWidget.addItems(emptyMessage)
                return

            self.stationListWidget.clear()

            inv_contents = self.__inv.get_contents()

            stationList = []

            # fill up the stationList with stations
            for item in inv_contents['stations']:
                stationList.append(item.strip())
            self.stationListWidget.clear()
            self.stationListWidget.addItems(stationList)

    def errorPopup(self, message):
        msgBox = QMessageBox()
        msgBox.setIcon(QMessageBox.Information)
        msgBox.setText(message)
        msgBox.setWindowTitle("Oops...")
        msgBox.exec_()

    def onActivated_search(self):
        self.stationListWidget.clear()
        QtGui.QGuiApplication.processEvents()
        QApplication.processEvents()
        msg = ['...Searching...']
        self.stationListWidget.addItems(msg)
        QApplication.processEvents()
        QtGui.QGuiApplication.processEvents()
        self.populateStationInfo()
        return

    def onActivated_reset(self):
        self.__inv = None
        self.network_edit.setText('')
        self.station_edit.setText('')
        self.location_edit.setText('')
        self.channel_edit.setText('')
        self.startDate_edit.setDate(self.startDate_edit.minimumDate())
        self.endDate_edit.setDate(self.endDate_edit.minimumDate())
        self.lat_edit.setValue(self.lat_edit.minimum())
        self.lon_edit.setValue(self.lon_edit.minimum())
        self.minLat_edit.setValue(self.minLat_edit.minimum())
        self.minLon_edit.setValue(self.minLon_edit.minimum())
        self.maxLat_edit.setValue(self.maxLat_edit.minimum())
        self.maxLon_edit.setValue(self.maxLon_edit.minimum())
        self.minRadius_edit.setValue(self.minRadius_edit.minimum())
        self.maxRadius_edit.setValue(self.maxRadius_edit.minimum())
        self.stationListWidget.clear()
        # self.eventInfoPopulated = False

    # def populateEventInfo(self):
    #     if self.currentEvent is not None:
    #         date = self.currentEvent['UTC Date']
    #         lat = self.currentEvent['Latitude']
    #         lon = self.currentEvent['Longitude']

    #         self.lat_edit.setValue(lat)
    #         self.lon_edit.setValue(lon)
    #         qdate = QDate.fromString(date, 'yyyy-MM-dd')
    #         self.startDate_edit.setDate(qdate)
    #         self.endDate_edit.setDate(qdate.addDays(1))

    #         self.eventInfoPopulated = True
    #     else:
    #         msg = QMessageBox()
    #         msg.setIcon(QMessageBox.Warning)
    #         msg.setText('There is not a valid event in the Event Tab')
    #         msg.setWindowTitle('oops...')
    #         msg.setStandardButtons(QMessageBox.Ok)
    #         msg.exec_()

    # def setEvent(self, event):
    #     self.currentEvent = event

    #     # Update the event info if it has been imported
    #     if self.eventInfoPopulated:
    #         self.populateEventInfo()

    def updateWidget(self):
        # We need lat and lon values if we are going to use the radius inputs
        enableRadius = self.lat_edit.value() != self.lat_edit.minimum(
        ) and self.lon_edit.value() != self.lon_edit.minimum()
        self.maxRadius_edit.setEnabled(enableRadius)
        self.minRadius_edit.setEnabled(enableRadius)

    def getSelected(self):
        selectedText = self.stationListWidget.currentItem().text()

        # first split the string at the first space, this will return just the
        # network and the station
        name = selectedText.split(" ")
        fullID = name[0]
        # next split that at the period, to seperate the network and station
        networkID = fullID.split(".")[0]
        stationID = fullID.split(".")[1]

        result = {"networkID": networkID, "stationID": stationID}

        return result

    def get_current_center(self):
        # this method will calculate the center of the current inventory and will return a [lat,lon]

        # TODO: This is not really setup right now to handle the (very rare) case where an array straddles the
        # international date line

        lat, lon, cnt = 0, 0, 0

        for network in self.__inv:
            for station in network:
                lat += station.latitude
                lon += station.longitude
                cnt += 1

        return [lat / cnt, lon / cnt]

    def getInventory(self):
        return self.__inv

    def getSelectedInventory(self):
        reducedInv = []
        for item in self.__inv:
            if item.isSelected():
                reducedInv.append(item)
        return reducedInv

    def serviceClicked(self):
        self.stationListWidget.clear()
        self.network_edit.clear()

    def HLine(self):
        hl = QFrame()
        hl.setFrameShape(QFrame.HLine)
        hl.setFrameShadow(QFrame.Sunken)
        return hl
Example #17
0
 def createEditor(self, parent: QWidget, option,
                  index: QModelIndex) -> QWidget:
     editor = QDateEdit(parent)
     editor.setFrame(False)
     editor.setMinimumDate(date(year=2021, month=1, day=1))
     return editor
Example #18
0
class TaskAddEditor(QDialog):

    #initialize everything
    def __init__(self, dialog_name, button_name, identifier=None):
        super(TaskAddEditor, self).__init__()
        self.dialog_name = dialog_name
        self.button_name = button_name
        self.identifier = identifier

        self.setGeometry(50, 50, 300, 250)

        self.tabs = QTabWidget()
        self.tabs.tab_1 = QWidget()
        self.tabs.tab_2 = QWidget()

        self.tabs.addTab(self.tabs.tab_1, "Basic Info")
        self.tabs.addTab(self.tabs.tab_2, "Notifications")

        self.tab_1()
        self.tab_2()

        main_layout = QVBoxLayout()
        main_layout.addWidget(self.tabs)

        buttons = QHBoxLayout()

        button_ok = QPushButton(self.button_name)
        button_close = QPushButton("Cancel")
        button_ok.clicked.connect(self.dialog_button_click)
        button_close.clicked.connect(self.dialog_cancel_click)
        buttons.addWidget(button_ok)
        buttons.addWidget(button_close)

        main_layout.addLayout(buttons)

        self.setLayout(main_layout)

        self.setWindowTitle(dialog_name)
        self.exec_()

    def tab_1(self):
        # main layout
        layout = QVBoxLayout()

        task_name = QLabel('Task Name')
        due_date = QLabel('Due Date')
        due_time = QLabel('Due Time')

        if (self.button_name == "Add"):
            self.task_name_input = QLineEdit()
            self.due_date_input = QDateEdit()
            self.due_date_input.setMinimumDate(QDate.currentDate())
            self.due_time_input = QTimeEdit()

        else:

            task_info = user_tasks.get_task(self.identifier)

            self.task_name_input = QLineEdit(task_info[1])
            self.due_date_input = QDateEdit(task_info[2].date())
            self.due_date_input.setMinimumDate(QDate.currentDate())
            self.due_time_input = QTimeEdit(task_info[2].time())

        layout.addWidget(task_name)
        layout.addWidget(self.task_name_input)
        layout.addWidget(due_date)
        layout.addWidget(self.due_date_input)
        layout.addWidget(due_time)
        layout.addWidget(self.due_time_input)
        layout.addSpacing(20)

        self.tabs.tab_1.setLayout(layout)

    def tab_2(self):
        layout = QVBoxLayout()

        page_name = QLabel('Notification Settings')
        layout.addWidget(page_name)

        add_notification_area = QHBoxLayout()

        description = QLabel('Remind Me Everyday At: ')
        self.time_input = QTimeEdit()
        add_notification = QPushButton('+')
        add_notification.setFixedSize(30, 30)
        add_notification.clicked.connect(self.add_notification)

        add_notification_area.addWidget(description)
        add_notification_area.addWidget(self.time_input)
        add_notification_area.addWidget(add_notification)

        layout.addLayout(add_notification_area)

        your_notifications = QLabel('Your Notifications:')

        layout.addWidget(your_notifications)

        #create a scroll area to hold notifications
        notifications_area = QScrollArea(self)
        notifications_area.setWidgetResizable(True)
        widget = QWidget()
        notifications_area.setWidget(widget)
        self.notifications_layout = QVBoxLayout(widget)
        notifications_area.setAlignment(Qt.AlignTop)
        self.notifications_layout.setAlignment(Qt.AlignTop)

        layout.addWidget(notifications_area)

        if self.identifier is not None:

            #get a list of datetime objects
            notifications = user_tasks.get_notifications(self.identifier)

            #add notifications to the tab
            for notification_date in notifications:
                self.notifications_layout.addWidget(
                    Notification(notification_date))

        self.tabs.tab_2.setLayout(layout)

    def add_notification(self):
        # adds a notification to the layout of notifications
        for index in range(self.notifications_layout.count()):
            if ((self.notifications_layout.itemAt(
                    index).widget().notification_time) >
                (self.time_input.time().toPyTime())):
                self.notifications_layout.insertWidget(
                    index, Notification(self.time_input.time().toPyTime()))
                return
            elif (self.notifications_layout.itemAt(index).widget().
                  notification_time) == self.time_input.time().toPyTime():
                error = QMessageBox()
                error.setText("Time Already Set")
                error.exec_()
                return

        self.notifications_layout.addWidget(
            Notification(self.time_input.time().toPyTime()))

    def dialog_button_click(self):
        # when add is pressed
        if (input_error_box(self.due_time_input, self.due_date_input,
                            self.task_name_input)):

            notification_dates = []
            for notification in range(self.notifications_layout.count()):
                notification_dates.append(
                    self.notifications_layout.itemAt(
                        notification).widget().notification_time)

            if (self.button_name == 'Add'):
                print(notification_dates)
                user_tasks.add_task(
                    self.task_name_input.text(),
                    datetime.combine(self.due_date_input.date().toPyDate(),
                                     self.due_time_input.time().toPyTime()),
                    datetime.today(), str(uuid.uuid4()), notification_dates)
            else:
                print(notification_dates)
                user_tasks.edit_task(
                    self.identifier, self.task_name_input.text(),
                    datetime.combine(self.due_date_input.date().toPyDate(),
                                     self.due_time_input.time().toPyTime()),
                    notification_dates)

            self.reject()
            gui_window.refresh_tasks()

    def dialog_cancel_click(self):
        #used in the input window and closes it
        self.reject()
Example #19
0
class IPFDSNWidget(QWidget):

    sigTracesReplaced = pyqtSignal(obspy.core.stream.Stream,
                                   obspy.core.inventory.inventory.Inventory)
    sigTracesAppended = pyqtSignal(obspy.core.stream.Stream,
                                   obspy.core.inventory.inventory.Inventory)

    stream = None
    inventory = None

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

        # this is for managing the event populated form elements
        # self.eventInfoPopulated = False
        # self.currentEvent = None

        self.__buildUI__()
        self.show()

    def __buildUI__(self):

        # Put together the options container
        gridLayout = QGridLayout()
        optionsContainer = QWidget()
        optionsContainer.setLayout(gridLayout)

        # First lets populate the client drop down
        self.cb = QComboBox()
        label_service_name = QLabel(self.tr('Service:'))

        fdsn_dictionary = URL_MAPPINGS
        fdsn_dictionary.update(
            {'RaspShake': 'https://fdsnws.rasberryshakedata.com'})

        for key in sorted(URL_MAPPINGS.keys()):
            self.cb.addItem(key)
        self.cb.setCurrentText('IRIS')
        self.cb.currentIndexChanged[str].connect(self.onActivated_cb)

        validator = IPValidator(self)
        label_network_name = QLabel(self.tr('Network: '))
        self.networkNameBox = QLineEdit()
        self.networkNameBox.setToolTip(
            'Wildcards OK \nCan be SEED network codes or data center defined codes. \nMultiple codes are comma-separated (e.g. "IU,TA").'
        )
        self.networkNameBox.setValidator(validator)

        label_station_name = QLabel(self.tr('Station: '))
        self.stationNameBox = QLineEdit()
        self.stationNameBox.setToolTip(
            'Wildcards OK \nOne or more SEED station codes. \nMultiple codes are comma-separated (e.g. "ANMO,PFO")'
        )
        self.stationNameBox.setValidator(validator)

        label_location_str = QLabel(self.tr('Location:'))
        self.location_Box = QLineEdit('*')
        self.location_Box.setToolTip(
            'Wildcards OK \nOne or more SEED location identifiers. \nMultiple identifiers are comma-separated (e.g. "00,01"). \nAs a special case “--“ (two dashes) will be translated to a string of two space characters to match blank location IDs.'
        )
        self.location_Box.setValidator(validator)

        label_channel_str = QLabel(self.tr('Channel:'))
        self.channel_Box = QLineEdit('*')
        self.channel_Box.setToolTip(
            'Wildcards OK \nOne or more SEED channel codes. \nMultiple codes are comma-separated (e.g. "BHZ,HHZ")'
        )
        self.channel_Box.setValidator(validator)

        label_startDate = QLabel(self.tr('Start Date (UTC):'))
        self.startDate_edit = QDateEdit()
        self.startDate_edit.setMinimumDate(QDate(1900, 1, 1))
        self.startDate_edit.setDisplayFormat('yyyy-MM-dd')
        self.startDate_edit.setDate(self.startDate_edit.minimumDate())

        label_startTime = QLabel(self.tr('Start Time (UTC):'))
        self.startTime_edit = QTimeEdit()
        self.startTime_edit.setDisplayFormat('HH:mm:ss.zzz')

        label_traceLength = QLabel(self.tr('Trace Length (s)'))
        self.traceLength_t = QSpinBox()
        self.traceLength_t.setMinimum(1)
        self.traceLength_t.setMaximum(999999999)
        self.traceLength_t.setValue(3600)

        replaceWaveButton = QPushButton('Replace')
        replaceWaveButton.clicked.connect(self.onClicked_replace)
        appendWaveButton = QPushButton('Append')
        appendWaveButton.clicked.connect(self.onClicked_append)

        self.stationListWidget = QListWidget()
        self.stationListWidget.setSelectionMode(
            QAbstractItemView.ExtendedSelection)
        self.stationListWidget.itemSelectionChanged.connect(
            self.populateStationInfoFromStationList)

        self.browserButton = QPushButton('Station Browser')
        self.browserButton.clicked.connect(self.onClicked_browserButton)

        gridLayout.addWidget(label_service_name, 0, 0)
        gridLayout.addWidget(self.cb, 0, 1)
        gridLayout.addWidget(label_network_name, 1, 0)
        gridLayout.addWidget(self.networkNameBox, 1, 1)
        gridLayout.addWidget(label_station_name, 2, 0)
        gridLayout.addWidget(self.stationNameBox, 2, 1)
        gridLayout.addWidget(label_location_str, 3, 0)
        gridLayout.addWidget(self.location_Box, 3, 1)
        gridLayout.addWidget(label_channel_str, 4, 0)
        gridLayout.addWidget(self.channel_Box, 4, 1)
        gridLayout.addWidget(label_startDate, 5, 0)
        gridLayout.addWidget(self.startDate_edit, 5, 1)
        gridLayout.addWidget(label_startTime, 6, 0)
        gridLayout.addWidget(self.startTime_edit, 6, 1)
        gridLayout.addWidget(label_traceLength, 7, 0)
        gridLayout.addWidget(self.traceLength_t, 7, 1)
        # gridLayout.addWidget(importEventButton, 8, 1, 1, 2)

        horzLayout = QHBoxLayout(self)
        horzLayout.addWidget(replaceWaveButton)
        horzLayout.addWidget(appendWaveButton)
        addGroupBox = QGroupBox("Get Waveform(s)")
        addGroupBox.setLayout(horzLayout)

        vertlayout = QVBoxLayout(self)
        vertlayout.addWidget(optionsContainer)
        vertlayout.addWidget(addGroupBox)
        vertlayout.addWidget(self.stationListWidget)
        vertlayout.addWidget(self.browserButton)

        self.setLayout(vertlayout)

        # create stationdialog here so that you only create it once, from here on you just run exec_() to make it pop up
        self.stationDialog = IPStationBrowser.IPStationDialog()

    def onClicked_browserButton(self):

        if self.stationDialog.exec_(self.startDate_edit.date(),
                                    network=self.networkNameBox.text(),
                                    station=self.stationNameBox.text(),
                                    location=self.location_Box.text(),
                                    channel=self.channel_Box.text()):
            self.inventory = self.stationDialog.getInventory()

            inv_contents = self.inventory.get_contents()
            stationList = []

            # fill up the stationList with stations
            for item in inv_contents['stations']:
                stationList.append(item.strip())
            self.stationListWidget.clear()
            self.stationListWidget.addItems(stationList)

            if self.stationDialog.getStartDate() is not None:
                self.startDate_edit.setDate(self.stationDialog.getStartDate())

    # def populateWithEventInfo(self):
    #     if self.parent.eventWidget.hasValidEvent():
    #         self.currentEvent = self.parent.eventWidget.Dict()
    #     else:
    #         msgBox = QMessageBox()
    #         msgBox.setIcon(QMessageBox.Warning)
    #         msgBox.setText('There is not a valid event in the Event Tab')
    #         msgBox.setWindowTitle("Oops...")
    #         msgBox.exec_()
    #         return

    #     if self.currentEvent is not None:
    #         date = self.currentEvent['UTC Date']
    #         time = self.currentEvent['UTC Time'][0:5]

    #     qdate = QDate.fromString(date, 'yyyy-MM-dd')
    #     qtime = QTime.fromString(time, 'HH:mm')
    #     qtime.addSecs(-5*60)  # start about 5 minutes before event

    #     self.startDate_edit.setDate(qdate)
    #     self.startTime_edit.setTime(qtime)

    #     self.eventInfoPopulated = True

    # # if someone edits the event info, reflect the changes here
    # @QtCore.pyqtSlot(dict)
    # def updateEventInfo(self, event):
    #     if not self.eventInfoPopulated:
    #         return

    #     if self.parent.eventWidget.hasValidEvent():
    #         self.currentEvent = event

    #     if self.currentEvent is not None:
    #         date = event['UTC Date']
    #         time = event['UTC Time'][0:5]

    #     qdate = QDate.fromString(date, 'yyyy-MM-dd')
    #     qtime = QTime.fromString(time, 'HH:mm')
    #     qtime.addSecs(-5*60)  # start about 5 minutes before event

    #     self.startDate_edit.setDate(qdate)
    #     self.startTime_edit.setTime(qtime)

    def populateStationInfoFromStationList(self):
        items = self.stationListWidget.selectedItems()
        if len(items) < 1:
            return  # nothing to do

        netList = []
        staList = []

        for item in items:
            text = item.text()
            text = text.split(' ')[0]
            netSta = text.split('.')

            netList.append(netSta[0])
            staList.append(netSta[1])

            netList = list(set(netList))
            staList = list(set(staList))

            netString = ''
            for net in netList:
                netString = netString + net + ', '
            staString = ''
            for sta in staList:
                staString = staString + sta + ', '

        self.networkNameBox.setText(netString[:-2])
        self.stationNameBox.setText(staString[:-2])

    def onActivated_cb(self, key):
        if (key != 'choose...'):
            url = URL_MAPPINGS[key]

    def onClicked_replace(self):
        self.downloadWaveforms()
        if self.stream is not None and self.inventory is not None:
            self.sigTracesReplaced.emit(self.stream, self.inventory)

    def onClicked_append(self):
        self.downloadWaveforms()
        if self.stream is not None and self.inventory is not None:
            self.sigTracesAppended.emit(self.stream, self.inventory)

    # get waveform button was clicked
    def downloadWaveforms(self):
        # first check to make sure the boxes are filled...addWidget
        # TODO!!!

        # get the inputs...inputs
        service = self.cb.currentText()
        if (service == 'choose...'):
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Warning)
            msg.setText('Please select a service to search')
            msg.setWindowTitle('oops...')
            msg.setStandardButtons(QMessageBox.Ok)
            msg.exec_()
            return

        # Clear old streams because we don't need them anymore
        self.clearWaveforms()

        network = self.networkNameBox.text().upper().replace(' ', '')
        self.networkNameBox.setText(network)
        station = self.stationNameBox.text().upper().replace(' ', '')
        self.stationNameBox.setText(station)
        location = self.location_Box.text().upper().replace(' ', '')
        self.location_Box.setText(location)
        channel = self.channel_Box.text().upper().replace(' ', '')
        self.channel_Box.setText(channel)
        date = self.startDate_edit.date().toPyDate()
        time = self.startTime_edit.time().toPyTime()
        traceLength = self.traceLength_t.value()
        utcString = str(date) + 'T' + str(time)
        startTime = UTCDateTime(utcString)
        endTime = startTime + traceLength

        # Check for unfilled boxes
        if (network == '' or station == '' or channel == ''):
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Warning)
            msg.setText('You are missing some important info...')
            msg.setWindowTitle('oops...')
            msg.setDetailedText(
                "Network, Station, Location, and Channel are all required data."
            )
            msg.setStandardButtons(QMessageBox.Ok)
            msg.exec_()
            return

        # Download the waveforms
        # self.parent.setStatus('connecting to '+service)
        client = Client(service)

        # self.parent.setStatus('downloading Waveforms...')
        try:
            self.stream = client.get_waveforms(network, station, location,
                                               channel, startTime, endTime)

        except Exception:
            # self.parent.setStatus('')
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Warning)
            msg.setText('Failure loading waveform')
            msg.setWindowTitle('oops...')
            msg.setDetailedText(
                "Double check that the values you entered are valid and the time and date are appropriate."
            )
            msg.setStandardButtons(QMessageBox.Ok)
            msg.exec_()
            return

        for trace in self.stream:
            trace.data = trace.data - np.mean(trace.data)
        self.stream.merge(fill_value=0)

        # self.parent.setStatus('downloading Inventory...')
        # self.parent.consoleBox.append( 'Downloaded waveforms from '+service )

        # Now get the corresponding stations
        try:
            self.inventory = client.get_stations(network=network,
                                                 station=station)
        except:
            # self.parent.setStatus('')
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Warning)
            msg.setText('Failure loading Inventory')
            msg.setWindowTitle('oops...')
            msg.setDetailedText(
                "Double check that the values you entered are valid and the time and date are appropriate."
            )
            msg.setStandardButtons(QMessageBox.Ok)
            msg.exec_()

            return
        # self.parent.consoleBox.append( 'Downloaded stations from '+service)
        # self.parent.setStatus('Finished...', 3000)

    def getStreams(self):
        return self.stream

    def getInventory(self):
        return self.inventory

    def getService(self):
        return self.cb.currentText()

    def clearWaveforms(self):
        self.stream = None
        self.inventory = None

    def clear(self):

        self.clearWaveforms()

        self.stationListWidget.clear()
        self.cb.setCurrentText(
            'IRIS')  # default to IRIS because why the hell not?
        self.networkNameBox.clear()
        self.stationNameBox.clear()
        self.location_Box.setText('*')
        self.channel_Box.setText('*')
        self.startDate_edit.setDate(self.startDate_edit.minimumDate())
        self.startTime_edit.setTime(self.startTime_edit.minimumTime())
        self.traceLength_t.setValue(3600)
Example #20
0
class Widget(QWidget):
    def __init__(self, parent=None):
        super(Widget, self).__init__(parent)
        self._initUI()
        self.controller = _Controller(self)
        self.requireDepartments.emit()

    _requireDepartments = pyqtSignal(name='requireDepartments')
    _requireRooms = pyqtSignal(str, name='requireRooms')

    def refresh(self):
        self.requireDepartments.emit()
        self.idEdit.setFocus()

    def setDepartments(self, array):
        self.departmentCmb.clear()
        self.departmentCmb.addItems(array)
        self.requireRooms.emit(self.department)

    def setRooms(self, array):
        self.roomsCmb.clear()
        self.roomsCmb.addItems(array)

    def _initUI(self):
        self.idLabel = QLabel('Id')
        self.nameLabel = QLabel('Name')
        self.modelLabel = QLabel('Model')
        self.costLabel = QLabel('Cost')
        self.purchaseDateLabel = QLabel('Purchase date')
        self.departmentLabel = QLabel('Department')
        self.roomLabel = QLabel('Room')

        self.idEdit = QLineEdit()
        self.idEdit.setPlaceholderText('Use for editing/removing operations')
        self.nameEdit = QLineEdit()
        self.modelEdit = QLineEdit()
        self.costEdit = QLineEdit()
        self.purchaseDateEdit = QDateEdit()
        self.purchaseDateEdit.setDisplayFormat('dd.MM.yyyy')
        self.purchaseDateEdit.setCalendarPopup(True)
        self.purchaseDateEdit.setDate(QDate.currentDate())
        self.purchaseDateEdit.setMinimumDate(QDate(1900, 1, 1))
        self.purchaseDateEdit.setMaximumDate(QDate(2099, 31, 12))
        self.departmentCmb = QComboBox()
        self.roomsCmb = QComboBox()

        self.submitButton = QPushButton('Submit')
        self.editButton = QPushButton('Edit')
        self.removeButton = QPushButton('Remove')

        layout = QVBoxLayout()
        layout.addWidget(self.idLabel)
        layout.addWidget(self.idEdit)
        layout.addSpacing(20)
        layout.addWidget(self.nameLabel)
        layout.addWidget(self.nameEdit)
        layout.addSpacing(10)
        layout.addWidget(self.modelLabel)
        layout.addWidget(self.modelEdit)
        layout.addSpacing(10)
        layout.addWidget(self.costLabel)
        layout.addWidget(self.costEdit)
        layout.addSpacing(10)
        layout.addWidget(self.purchaseDateLabel)
        layout.addWidget(self.purchaseDateEdit)
        layout.addSpacing(10)
        layout.addWidget(self.departmentLabel)
        layout.addWidget(self.departmentCmb)
        layout.addSpacing(10)
        layout.addWidget(self.roomLabel)
        layout.addWidget(self.roomsCmb)
        layout.addStretch(2)
        layout.addWidget(self.submitButton)
        layout.addWidget(self.editButton)
        layout.addWidget(self.removeButton)

        hlayout = QHBoxLayout()
        hlayout.addStretch()
        hlayout.addLayout(layout)
        hlayout.addStretch()

        self.setLayout(hlayout)

    @property
    def id(self):
        return self.idEdit.text()

    @id.setter
    def id(self, value):
        self.idEdit.setText(value)

    @property
    def name(self):
        return self.nameEdit.text()

    @name.setter
    def name(self, value):
        self.nameEdit.setText(value)

    @property
    def model(self):
        return self.modelEdit.text()

    @model.setter
    def model(self, value):
        self.modelEdit.setText(value)

    @property
    def cost(self):
        return self.costEdit.text()

    @cost.setter
    def cost(self, value):
        self.costEdit.setText(value)

    @property
    def purchaseDate(self):
        return self.purchaseDateEdit.date().toPyDate()

    @property
    def department(self):
        return self.departmentCmb.currentText()

    @property
    def room(self):
        return self.roomsCmb.currentText()
Example #21
0
class ImportWindow(QDialog):
    def __init__(self, parent: QWidget = None):
        super().__init__(parent)

        self._size: int = os.cpu_count()
        if self._size is None:
            self._size = 2

        self._processes_pool = []
        self._manager = ImportManager(self._size)
        self._max_progress: int = 0
        self._timer: QTimer = QTimer()
        self._confuser = ConfuseWindow(self)
        self._date_start_cache = None
        self._tesseract_path_cache = None
        self._poppler_path_cache = None

        # window settings
        self.setWindowFlag(Qt.WindowContextHelpButtonHint, False)
        self.setWindowTitle(self.tr("Import window"))

        # list widget with files
        self.list_widget = QListWidget()
        self.list_widget.setSortingEnabled(True)

        self.layout_open_folder = QHBoxLayout()
        self.label_find = QLabel(self.tr("Schedules: ") + "0")
        self.layout_open_folder.addWidget(self.label_find)

        self.layout_open_folder.addStretch(1)

        self.push_button_open_folder = QToolButton()
        self.layout_open_folder.addWidget(self.push_button_open_folder)

        self.push_button_open_folder.setText(self.tr("Open folder"))
        self.push_button_open_folder.setPopupMode(QToolButton.MenuButtonPopup)

        self.action_open_files = QAction(self.tr("Open files"))
        self.push_button_open_folder.addAction(self.action_open_files)

        # main progress
        self.group_box_main_progress = QGroupBox(self.tr("Main progress"))
        self.layout_main_progress = QVBoxLayout(self.group_box_main_progress)

        self.process_bar_main = QProgressBar()
        self.layout_main_progress.addWidget(self.process_bar_main)

        self.layout_start_process = QHBoxLayout()
        self.layout_start_process.addStretch(1)

        self.push_button_import = QPushButton(self.tr("Import"))
        self.layout_start_process.addWidget(self.push_button_import)

        self.push_button_stop = QPushButton(self.tr("Stop"))
        self.layout_start_process.addWidget(self.push_button_stop)

        self.push_button_stop.setEnabled(False)

        self.layout_main_progress.addLayout(self.layout_start_process)

        # threads process
        self.group_box_threads = QGroupBox(self.tr("Threads"))
        self.grid_layout_threads = QGridLayout(self.group_box_threads)

        self._progresses_bars = []
        rows = self._size // 2
        columns = 2
        for i in range(rows):
            for j in range(columns):
                progress_bar = QProgressBar()
                progress_bar.setTextVisible(True)
                self._progresses_bars.append(progress_bar)
                self.grid_layout_threads.addWidget(progress_bar, i, j)

        # options
        self.group_box_options = QGroupBox(self.tr("Options"))
        self.form_layout_options = QFormLayout(self.group_box_options)

        self.check_box_weekly = QCheckBox(self.tr("Create weekly schedule"))
        self.form_layout_options.addRow(self.check_box_weekly)

        self.check_box_full = QCheckBox(self.tr("Create full schedule"))
        self.form_layout_options.addRow(self.check_box_full)

        self.check_box_debug_img = QCheckBox(self.tr("Create debug image"))
        self.form_layout_options.addRow(self.check_box_debug_img)

        self.spin_box_dpi = QSpinBox()
        self.form_layout_options.addRow(self.tr("DPI"), self.spin_box_dpi)

        self.combo_box_tesseract_path = QComboBox()
        self.form_layout_options.addRow(self.tr("Tesseract path"),
                                        self.combo_box_tesseract_path)

        self.combo_box_poppler_path = QComboBox()
        self.form_layout_options.addRow(self.tr("Poppler path"),
                                        self.combo_box_poppler_path)

        self.check_box_debug_img.setChecked(True)
        self.check_box_debug_img.setEnabled(False)

        self.spin_box_dpi.setRange(200, 800)
        self.spin_box_dpi.setValue(500)

        self.combo_box_tesseract_path.addItem(
            self.tr("<select tesseract path>"))
        self.combo_box_tesseract_path.addItem("Default", "tesseract")
        self.combo_box_tesseract_path.setCurrentIndex(1)
        self._tesseract_path_cache = self.combo_box_tesseract_path.currentText(
        )

        self.combo_box_poppler_path.addItem(self.tr("<select poppler path>"))
        self.combo_box_poppler_path.addItem("Default", None)
        self.combo_box_poppler_path.setCurrentIndex(1)
        self._poppler_path_cache = self.combo_box_poppler_path.currentText()

        # font edit
        self.group_box_font = QGroupBox(self.tr("Font settings"))
        self.form_layout_font = QFormLayout(self.group_box_font)

        self.label_font = QLabel(self.tr("Font"))
        self.form_layout_font.setWidget(0, QFormLayout.LabelRole,
                                        self.label_font)
        self.combo_box_font = QComboBox()
        self.form_layout_font.setWidget(0, QFormLayout.FieldRole,
                                        self.combo_box_font)

        self.label_encoding = QLabel(self.tr("Encoding"))
        self.form_layout_font.setWidget(1, QFormLayout.LabelRole,
                                        self.label_encoding)
        self.combo_box_encoding = QComboBox()
        self.form_layout_font.setWidget(1, QFormLayout.FieldRole,
                                        self.combo_box_encoding)

        for font_name, font_path in util.get_fonts():
            self.combo_box_font.addItem(font_name, font_path)

        self.combo_box_font.setCurrentText(qApp.font().family())
        self.combo_box_font.setEditable(True)

        self.combo_box_encoding.addItem("UTF-8")
        self.combo_box_encoding.addItem("Latin-1")
        self.combo_box_encoding.addItem("Windows-1252")

        # date edit
        self.group_box_date = QGroupBox(self.tr("Date settings"))
        self.form_layout_date = QFormLayout(self.group_box_date)

        self.label_date_start = QLabel(self.tr("Start"))
        self.form_layout_date.setWidget(0, QFormLayout.LabelRole,
                                        self.label_date_start)
        self.date_edit_start = QDateEdit()
        self.form_layout_date.setWidget(0, QFormLayout.FieldRole,
                                        self.date_edit_start)

        self.label_date_end = QLabel(self.tr("End"))
        self.form_layout_date.setWidget(1, QFormLayout.LabelRole,
                                        self.label_date_end)
        self.date_edit_end = QDateEdit()
        self.form_layout_date.setWidget(1, QFormLayout.FieldRole,
                                        self.date_edit_end)

        self.date_edit_start.setCalendarPopup(True)
        self.date_edit_end.setCalendarPopup(True)

        if QDate.currentDate().day() < QDate.currentDate().dayOfYear() / 2:
            date = QDate(QDate.currentDate().year(), 2, 1)
        else:
            date = QDate(QDate.currentDate().year(), 9, 1)

        self._date_start_cache = date.addDays(8 - date.dayOfWeek())
        self.date_edit_start.setDate(self._date_start_cache)
        self.date_edit_end.setMinimumDate(self._date_start_cache.addDays(7))
        self.date_edit_end.setDate(self._date_start_cache.addDays(16 * 7))

        # subgroup edit
        self.group_box_subgroup = QGroupBox(self.tr("Subgroup settings"))
        self.form_layout_subgroup = QFormLayout(self.group_box_subgroup)

        self.label_color_a = QLabel(self.tr("Color A"))
        self.form_layout_subgroup.setWidget(0, QFormLayout.LabelRole,
                                            self.label_color_a)
        self.combo_box_color_a = QComboBox()
        self.form_layout_subgroup.setWidget(0, QFormLayout.FieldRole,
                                            self.combo_box_color_a)

        self.label_color_b = QLabel(self.tr("Color B"))
        self.form_layout_subgroup.setWidget(1, QFormLayout.LabelRole,
                                            self.label_color_b)
        self.combo_box_color_b = QComboBox()
        self.form_layout_subgroup.setWidget(1, QFormLayout.FieldRole,
                                            self.combo_box_color_b)

        self.label_pattern_a_b = QLabel(self.tr("Pattern A and B"))
        self.form_layout_subgroup.setWidget(2, QFormLayout.LabelRole,
                                            self.label_pattern_a_b)
        self.combo_box_pattern_a_b = QComboBox()
        self.form_layout_subgroup.setWidget(2, QFormLayout.FieldRole,
                                            self.combo_box_pattern_a_b)

        self.add_standard_colors(self.combo_box_color_a)
        self.add_standard_colors(self.combo_box_color_b)
        self.combo_box_color_a.setCurrentIndex(9)  # lime
        self.combo_box_color_b.setCurrentIndex(15)  # yellow

        self.combo_box_pattern_a_b.addItem(self.tr("Chess order"))
        self.combo_box_pattern_a_b.setEnabled(False)

        # navigate
        self.layout_navigate = QHBoxLayout()

        self.layout_navigate.addStretch(1)

        self.push_button_ok = QPushButton(self.tr("OK"))
        self.layout_navigate.addWidget(self.push_button_ok)

        self.push_button_cancel = QPushButton(self.tr("Cancel"))
        self.layout_navigate.addWidget(self.push_button_cancel)

        # layout setup
        self.layout_left = QVBoxLayout()
        self.layout_left.addWidget(self.list_widget)
        self.layout_left.addLayout(self.layout_open_folder)

        self.layout_right = QVBoxLayout()
        self.layout_right.addWidget(self.group_box_main_progress)
        self.layout_right.addWidget(self.group_box_threads)

        self.layout_down = QGridLayout()
        self.layout_down.addWidget(self.group_box_options, 0, 0)
        self.layout_down.addWidget(self.group_box_font, 1, 0)
        self.layout_down.addWidget(self.group_box_date, 0, 1)
        self.layout_down.addWidget(self.group_box_subgroup, 1, 1)

        self.layout_right.addLayout(self.layout_down)
        self.layout_right.addStretch(1)
        self.layout_right.addLayout(self.layout_navigate)

        self.layout_main = QHBoxLayout()
        self.layout_main.addLayout(self.layout_left, 1)
        self.layout_main.addLayout(self.layout_right, 2)

        self.setLayout(self.layout_main)

        # connections
        self._timer.timeout.connect(self.check_processes)

        self.push_button_open_folder.clicked.connect(self.open_folder_clicked)
        self.action_open_files.triggered.connect(self.open_files_clicked)

        self.push_button_import.clicked.connect(
            self.push_button_import_clicked)
        self.push_button_stop.clicked.connect(self.push_button_stop_clicked)

        self.check_box_weekly.clicked.connect(self.check_box_weekly_clicked)
        self.combo_box_tesseract_path.activated.connect(
            self.combo_box_tesseract_path_clicked)
        self.combo_box_poppler_path.activated.connect(
            self.combo_box_poppler_path_clicked)

        self.date_edit_start.dateChanged.connect(self.date_edit_start_changed)
        self.combo_box_color_a.activated.connect(
            self.combo_box_color_a_clicked)
        self.combo_box_color_b.activated.connect(
            self.combo_box_color_b_clicked)

        self.push_button_ok.clicked.connect(self.close)
        self.push_button_cancel.clicked.connect(self.close)

    def check_processes(self):
        work_processes = 0
        for index in range(self._size):
            if self._processes_pool[index].is_alive():
                work_processes += 1

            text = self._manager.progress_text_list[index]
            if text is not None and text != "":
                self._progresses_bars[index].setFormat(text)
                self._progresses_bars[index].setValue(
                    self._manager.progress_value_list[index])

            if self._manager.confuse_answer_list[
                    index] == ConfuseWindow.NeededSolution:
                if self._confuser.status == ConfuseWindow.Solved:
                    answer_index = self._confuser.index
                    self._manager.confuse_list[
                        answer_index] = self._confuser.answer
                    self._manager.confuse_answer_list[
                        answer_index] = ConfuseWindow.Solved
                    self._confuser.status = ConfuseWindow.Nothing
                elif self._confuser.status == ConfuseWindow.Nothing:
                    self._confuser.status = ConfuseWindow.Work
                    self._confuser.index = index
                    self._confuser.text_edit_confuse.setText(
                        self._manager.confuse_info[index])
                    self._confuser.text_edit_answer.setText(
                        self._manager.confuse_list[index])
                    self._confuser.set_image(
                        self._manager.confuse_file_path[index])
                    self._confuser.show()

        progress = self._max_progress - self._manager.queue.qsize(
        ) - work_processes
        self.process_bar_main.setValue(progress)

        if work_processes == 0:
            self.push_button_stop_clicked()
            return

        if not self._manager.flags["stop"]:
            self._timer.start(1000)

    def open_folder_clicked(self):
        path = QFileDialog.getExistingDirectory(self, self.tr("Select folder"))

        provider = QFileIconProvider()
        self.list_widget.clear()

        for dir_path, dir_names, file_names in os.walk(path):
            for file_name in file_names:
                if file_name.endswith(".pdf"):
                    item = QListWidgetItem()
                    item.setText(file_name[0:-4])
                    item.setData(Qt.UserRole, dir_path + os.sep + file_name)
                    item.setIcon(
                        provider.icon(QFileInfo(dir_path + os.sep +
                                                file_name)))

                    self.list_widget.addItem(item)

        self.label_find.setText(
            self.tr("Schedules: ") + str(self.list_widget.count()))

    def open_files_clicked(self):
        files = QFileDialog.getOpenFileNames(
            self, self.tr("Select files"), "",
            "PDF file (*.pdf) ;; All files (*.*)")[0]
        provider = QFileIconProvider()
        self.list_widget.clear()

        for file_path in files:
            file = QFileInfo(file_path)
            item = QListWidgetItem()
            item.setText(file.baseName())
            item.setData(Qt.UserRole, file_path)
            item.setIcon(provider.icon(file))
            self.list_widget.addItem(item)

        self.label_find.setText(
            self.tr("Schedules: ") + str(self.list_widget.count()))

    def push_button_import_clicked(self):
        self.group_box_options.setEnabled(False)
        self.group_box_font.setEnabled(False)
        self.group_box_date.setEnabled(False)
        self.group_box_subgroup.setEnabled(False)
        self.push_button_import.setEnabled(False)
        self.push_button_stop.setEnabled(True)
        self.push_button_ok.setEnabled(False)
        self.push_button_cancel.setEnabled(False)
        self.push_button_open_folder.setEnabled(False)

        for number in range(self.list_widget.count()):
            path = self.list_widget.item(number).data(Qt.UserRole)
            self._manager.queue.put(path)

        self._max_progress = self.list_widget.count()
        self.process_bar_main.setRange(0, self._max_progress)
        self.process_bar_main.setValue(0)

        self._manager.weekly = self.check_box_weekly.isChecked()
        self._manager.full = self.check_box_full.isChecked()
        self._manager.debug_image = self.check_box_debug_img.isChecked()

        self._manager.dpi = self.spin_box_dpi.value()
        self._manager.tesseract_path = self.combo_box_tesseract_path.currentData(
            Qt.UserRole)
        self._manager.poppler_path = self.combo_box_poppler_path.currentData(
            Qt.UserRole)

        self._manager.font_name = self.combo_box_font.currentText()
        self._manager.font_path = self.combo_box_font.currentData(Qt.UserRole)
        self._manager.encoding = self.combo_box_encoding.currentText()

        self._manager.start = self.date_edit_start.date().toPyDate()
        self._manager.end = self.date_edit_end.date().toPyDate()

        self._manager.color_a = self.combo_box_color_a.currentData(Qt.UserRole)
        self._manager.color_b = self.combo_box_color_b.currentData(Qt.UserRole)

        self._manager.flags["stop"] = False

        self._processes_pool.clear()
        for index in range(self._size):
            process = Process(target=import_from_pdf,
                              args=(index, self._manager),
                              daemon=True)
            process.start()
            self._processes_pool.append(process)

        self._timer.start(500)

    def push_button_stop_clicked(self):
        self.push_button_stop.setEnabled(False)

        self._manager.flags["stop"] = True

        self.group_box_options.setEnabled(True)
        self.group_box_font.setEnabled(True)
        self.group_box_date.setEnabled(True)
        self.group_box_subgroup.setEnabled(True)
        self.push_button_import.setEnabled(True)
        self.push_button_ok.setEnabled(True)
        self.push_button_cancel.setEnabled(True)
        self.push_button_open_folder.setEnabled(True)

    def check_box_weekly_clicked(self):
        if self.check_box_weekly.isChecked():
            self.group_box_date.setEnabled(True)
            self.group_box_subgroup.setEnabled(True)
        else:
            self.group_box_date.setEnabled(False)
            self.group_box_subgroup.setEnabled(False)

    def combo_box_tesseract_path_clicked(self, index):
        if index == 0:
            path = QFileDialog.getOpenFileName(self,
                                               self.tr("Select Tesseract"))[0]

            if path == "":
                self.combo_box_tesseract_path.setCurrentText(
                    self._tesseract_path_cache)
                return

            self.combo_box_tesseract_path.addItem(path, path)
            self.combo_box_tesseract_path.setCurrentText(path)
            self._tesseract_path_cache = path

    def combo_box_poppler_path_clicked(self, index):
        if index == 0:
            path = QFileDialog.getOpenFileName(self,
                                               self.tr("Select Poppler"))[0]

            if path == "":
                self.combo_box_poppler_path.setCurrentText(
                    self._poppler_path_cache)
                return

            self.combo_box_poppler_path.addItem(path, path)
            self.combo_box_poppler_path.setCurrentText(path)
            self._poppler_path_cache = path

    def add_standard_colors(self, combo_box: QComboBox) -> None:
        """
        Adds colors to the color selection menu.

        :param combo_box: Color selection menu
        """
        color_items = [(self.tr("Custom color"), QColor()),
                       (self.tr("Aqua"), QColor(0, 255, 255)),
                       (self.tr("Grey"), QColor(128, 128, 128)),
                       (self.tr("Navy"), QColor(0, 0, 192)),
                       (self.tr("Silver"), QColor(192, 192, 192)),
                       (self.tr("Black"), QColor(0, 0, 0)),
                       (self.tr("Green"), QColor(0, 128, 0)),
                       (self.tr("Olive"), QColor(192, 192, 0)),
                       (self.tr("Blue"), QColor(0, 0, 255)),
                       (self.tr("Lime"), QColor(0, 255, 0)),
                       (self.tr("Purple"), QColor(128, 0, 128)),
                       (self.tr("White"), QColor(255, 255, 255)),
                       (self.tr("Fuchsia"), QColor(255, 0, 255)),
                       (self.tr("Maroon"), QColor(128, 0, 0)),
                       (self.tr("Red"), QColor(255, 0, 0)),
                       (self.tr("Yellow"), QColor(255, 255, 0))]

        for name, data in color_items:
            combo_box.addItem(util.create_color_icon(data), name, data)

    def combo_box_color_a_clicked(self) -> None:
        """
        Slot for color selection of A subgroup.
        """
        if self.combo_box_color_a.currentIndex() == 0:
            self.custom_color_selected(self.combo_box_color_a)

    def combo_box_color_b_clicked(self) -> None:
        """
        Slot for color selection of B subgroup.
        """
        if self.combo_box_color_b.currentIndex() == 0:
            self.custom_color_selected(self.combo_box_color_b)

    def custom_color_selected(self, combo_box: QComboBox) -> None:
        """
        Slot to select the color for the desired menu.

        :param combo_box: Menu
        """
        color = QColorDialog.getColor(combo_box.currentData(), self)
        if color.isValid():
            combo_box.setItemIcon(0, util.create_color_icon(color))
            combo_box.setItemData(0, color)

    def date_edit_start_changed(self, date: QDate):
        """
        Slot for changing the end of a range of dates.

        :param date: Start of the date range
        """
        end_date = self.date_edit_end.date().addDays(
            self._date_start_cache.daysTo(date))
        self.date_edit_end.setMinimumDate(date.addDays(7))
        self.date_edit_end.setDate(end_date)
        self._date_start_cache = QDate(date)

    def closeEvent(self, event: QCloseEvent) -> None:
        for process in self._processes_pool:
            process.terminate()

        print("Processes terminate")
class ExportWindow(QDialog):
    """
    Class describing a dialog for exports of schedules.
    """
    def __init__(self, schedule: Schedule, parent: QWidget = None):
        super().__init__(parent)
        self._schedule_ref = schedule
        self._date_start_cache = None

        # window settings
        self.setWindowFlag(Qt.WindowContextHelpButtonHint, False)
        self.setWindowTitle(self.tr("Export window"))
        self.setMinimumWidth(800)

        # title, add_date, work mode
        self.layout_title_date_mode = QHBoxLayout()

        self.label_title = QLabel(self.tr("Title"))
        self.layout_title_date_mode.addWidget(self.label_title)

        self.line_edit_title = QLineEdit()
        self.layout_title_date_mode.addWidget(self.line_edit_title)

        self.check_box_add_date = QCheckBox(self.tr("Add date"))
        self.layout_title_date_mode.addWidget(self.check_box_add_date)

        self.combo_box_work_mode = QComboBox()
        self.layout_title_date_mode.addWidget(self.combo_box_work_mode)

        self.line_edit_title.setPlaceholderText(
            self.tr("My Group. A subgroup - green color, "
                    "B subgroup - yellow color. "))
        self.check_box_add_date.setChecked(True)

        self.combo_box_work_mode.addItem(self.tr("Weekly"))
        self.combo_box_work_mode.addItem(self.tr("Full"))

        # list widget with files
        self.layout_list_widget = QVBoxLayout()

        self.check_box_use_current = QCheckBox(self.tr("Use current schedule"))
        self.layout_list_widget.addWidget(self.check_box_use_current)
        self.check_box_use_current.setChecked(True)

        self.list_widget = QListWidget()
        self.layout_list_widget.addWidget(self.list_widget)
        self.list_widget.setSortingEnabled(True)
        self.list_widget.setEnabled(False)

        self.layout_open_folder = QHBoxLayout()
        self.layout_list_widget.addLayout(self.layout_open_folder)

        self.label_find = QLabel(self.tr("Schedules: ") + "0")
        self.layout_open_folder.addWidget(self.label_find)

        self.layout_open_folder.addStretch(1)

        self.push_button_open_folder = QToolButton()
        self.layout_open_folder.addWidget(self.push_button_open_folder)
        self.push_button_open_folder.setEnabled(False)

        self.push_button_open_folder.setText(self.tr("Open folder"))
        self.push_button_open_folder.setPopupMode(QToolButton.MenuButtonPopup)

        self.action_open_files = QAction(self.tr("Open files"))
        self.push_button_open_folder.addAction(self.action_open_files)

        # font edit
        self.group_box_font = QGroupBox(self.tr("Font settings"))
        self.form_layout_font = QFormLayout(self.group_box_font)

        self.label_font = QLabel(self.tr("Font"))
        self.form_layout_font.setWidget(0, QFormLayout.LabelRole,
                                        self.label_font)
        self.combo_box_font = QComboBox()
        self.form_layout_font.setWidget(0, QFormLayout.FieldRole,
                                        self.combo_box_font)

        self.label_encoding = QLabel(self.tr("Encoding"))
        self.form_layout_font.setWidget(1, QFormLayout.LabelRole,
                                        self.label_encoding)
        self.combo_box_encoding = QComboBox()
        self.form_layout_font.setWidget(1, QFormLayout.FieldRole,
                                        self.combo_box_encoding)

        for font_name, font_path in util.get_fonts():
            self.combo_box_font.addItem(font_name, font_path)

        self.combo_box_font.setCurrentText(qApp.font().family())
        self.combo_box_font.setEditable(True)

        self.combo_box_encoding.addItem("UTF-8")
        self.combo_box_encoding.addItem("Latin-1")
        self.combo_box_encoding.addItem("Windows-1252")

        # date edit
        self.group_box_date = QGroupBox(self.tr("Date settings"))
        self.form_layout_date = QFormLayout(self.group_box_date)

        self.label_date_start = QLabel(self.tr("Start"))
        self.form_layout_date.setWidget(0, QFormLayout.LabelRole,
                                        self.label_date_start)
        self.date_edit_start = QDateEdit()
        self.form_layout_date.setWidget(0, QFormLayout.FieldRole,
                                        self.date_edit_start)

        self.label_date_end = QLabel(self.tr("End"))
        self.form_layout_date.setWidget(1, QFormLayout.LabelRole,
                                        self.label_date_end)
        self.date_edit_end = QDateEdit()
        self.form_layout_date.setWidget(1, QFormLayout.FieldRole,
                                        self.date_edit_end)

        self.date_edit_start.setCalendarPopup(True)
        self.date_edit_end.setCalendarPopup(True)

        if QDate.currentDate().day() < (QDate.currentDate().dayOfYear() / 2):
            date = QDate(QDate.currentDate().year(), 2, 1)
        else:
            date = QDate(QDate.currentDate().year(), 9, 1)

        self._date_start_cache = date.addDays(8 - date.dayOfWeek())
        self.date_edit_start.setDate(self._date_start_cache)
        self.date_edit_end.setMinimumDate(self._date_start_cache.addDays(7))
        self.date_edit_end.setDate(self._date_start_cache.addDays(16 * 7))

        # subgroup edit
        self.group_box_subgroup = QGroupBox(self.tr("Subgroup settings"))
        self.form_layout_subgroup = QFormLayout(self.group_box_subgroup)

        self.label_color_a = QLabel(self.tr("Color A"))
        self.form_layout_subgroup.setWidget(0, QFormLayout.LabelRole,
                                            self.label_color_a)
        self.combo_box_color_a = QComboBox()
        self.form_layout_subgroup.setWidget(0, QFormLayout.FieldRole,
                                            self.combo_box_color_a)

        self.label_color_b = QLabel(self.tr("Color B"))
        self.form_layout_subgroup.setWidget(1, QFormLayout.LabelRole,
                                            self.label_color_b)
        self.combo_box_color_b = QComboBox()
        self.form_layout_subgroup.setWidget(1, QFormLayout.FieldRole,
                                            self.combo_box_color_b)

        self.label_pattern_a_b = QLabel(self.tr("Pattern A and B"))
        self.form_layout_subgroup.setWidget(2, QFormLayout.LabelRole,
                                            self.label_pattern_a_b)
        self.combo_box_pattern_a_b = QComboBox()
        self.form_layout_subgroup.setWidget(2, QFormLayout.FieldRole,
                                            self.combo_box_pattern_a_b)

        self.add_standard_colors(self.combo_box_color_a)
        self.add_standard_colors(self.combo_box_color_b)
        self.combo_box_color_a.setCurrentIndex(9)  # lime
        self.combo_box_color_b.setCurrentIndex(15)  # yellow

        self.combo_box_pattern_a_b.addItem(self.tr("Chess order"))
        self.combo_box_pattern_a_b.setEnabled(False)

        # navigate buttons
        self.layout_navigate = QHBoxLayout()

        self.layout_navigate.addStretch(1)

        self.push_button_export = QPushButton(self.tr("Export"))
        self.layout_navigate.addWidget(self.push_button_export)

        self.push_button_cancel = QPushButton(self.tr("Cancel"))
        self.layout_navigate.addWidget(self.push_button_cancel)

        # layout setup
        self.layout_right_setting = QVBoxLayout()
        self.layout_right_setting.addWidget(self.group_box_font)
        self.layout_right_setting.addWidget(self.group_box_date)
        self.layout_right_setting.addWidget(self.group_box_subgroup)
        self.layout_right_setting.addStretch(1)

        self.layout_center = QHBoxLayout()
        self.layout_center.addLayout(self.layout_list_widget)
        self.layout_center.addLayout(self.layout_right_setting)

        self.layout_main = QVBoxLayout()
        self.layout_main.addLayout(self.layout_title_date_mode)
        self.layout_main.addLayout(self.layout_center)
        self.layout_main.addLayout(self.layout_navigate)

        self.setLayout(self.layout_main)

        # connection
        self.check_box_use_current.clicked.connect(
            self.check_box_use_current_clicked)
        self.push_button_open_folder.clicked.connect(self.open_folder_clicked)
        self.action_open_files.triggered.connect(self.open_files_clicked)

        self.date_edit_start.dateChanged.connect(self.date_edit_start_changed)
        self.combo_box_color_a.activated.connect(
            self.combo_box_color_a_clicked)
        self.combo_box_color_b.activated.connect(
            self.combo_box_color_b_clicked)
        self.push_button_export.clicked.connect(self.export_to_pdf)
        self.push_button_cancel.clicked.connect(self.close)

    def add_standard_colors(self, combo_box: QComboBox) -> None:
        """
        Adds colors to the color selection menu.

        :param combo_box: Color selection menu
        """
        color_items = [(self.tr("Custom color"), QColor()),
                       (self.tr("Aqua"), QColor(0, 255, 255)),
                       (self.tr("Grey"), QColor(128, 128, 128)),
                       (self.tr("Navy"), QColor(0, 0, 192)),
                       (self.tr("Silver"), QColor(192, 192, 192)),
                       (self.tr("Black"), QColor(0, 0, 0)),
                       (self.tr("Green"), QColor(0, 128, 0)),
                       (self.tr("Olive"), QColor(192, 192, 0)),
                       (self.tr("Blue"), QColor(0, 0, 255)),
                       (self.tr("Lime"), QColor(0, 255, 0)),
                       (self.tr("Purple"), QColor(128, 0, 128)),
                       (self.tr("White"), QColor(255, 255, 255)),
                       (self.tr("Fuchsia"), QColor(255, 0, 255)),
                       (self.tr("Maroon"), QColor(128, 0, 0)),
                       (self.tr("Red"), QColor(255, 0, 0)),
                       (self.tr("Yellow"), QColor(255, 255, 0))]

        for name, data in color_items:
            combo_box.addItem(util.create_color_icon(data), name, data)

    def export_to_pdf(self) -> None:
        # select path

        paths = []

        if self.check_box_use_current.isChecked():
            path = QFileDialog.getSaveFileName(self, self.tr("Export to pdf"),
                                               ".", "PDF file (*.pdf)")[0]
            if path == "":
                return

            if not path.endswith(".pdf"):
                path += ".pdf"

            paths.append(path)
        else:
            for index in range(self.list_widget.count()):
                path = self.list_widget.item(index).data(Qt.UserRole)
                paths.append(path)

        # progress dialog
        progress = QProgressDialog(self.tr("Export to pdf"),
                                   self.tr("Abort exports"), 0, 100, self)
        progress.setWindowModality(Qt.WindowModal)
        progress.setMinimumDuration(2000)

        try:
            for index, path in enumerate(paths):

                if self.check_box_use_current.isChecked():
                    title_text = self.line_edit_title.text()
                    schedule = self._schedule_ref
                else:
                    title_text = QFileInfo(path).baseName()
                    schedule = Schedule()
                    schedule.load(path)
                    path = path[0:-5] + ".pdf"

                print(path)
                mode = self.combo_box_work_mode.currentIndex()
                if mode == 0:
                    export_weeks_to_pdf(
                        schedule, title_text,
                        self.check_box_add_date.isChecked(), path,
                        self.combo_box_font.currentText(),
                        self.combo_box_font.currentData(Qt.UserRole),
                        self.combo_box_encoding.currentText(),
                        self.date_edit_start.date().toPyDate(),
                        self.date_edit_end.date().toPyDate(),
                        self.combo_box_color_a.currentData(Qt.UserRole),
                        self.combo_box_color_b.currentData(Qt.UserRole),
                        progress
                        if self.check_box_use_current.isChecked() else None)
                else:
                    export_full_to_pdf(
                        schedule, title_text, path,
                        self.combo_box_font.currentText(),
                        self.combo_box_font.currentData(Qt.UserRole),
                        self.combo_box_encoding.currentText(), progress
                        if self.check_box_use_current.isChecked() else None)

                progress.setValue(int(index * 100 / len(paths)))

            # finish dialog
            progress.setValue(100)
            finish_msg_box = QMessageBox(QMessageBox.Information,
                                         self.tr("Export to pdf"),
                                         self.tr("Gone!"))
            open_folder_button = finish_msg_box.addButton(
                self.tr("Open folder"), QMessageBox.ActionRole)
            finish_msg_box.addButton(QMessageBox.Ok)
            finish_msg_box.exec_()

            if finish_msg_box.clickedButton() == open_folder_button:
                QDesktopServices.openUrl(
                    QUrl(
                        QFileInfo(paths[0] if len(paths) != 0 else ".").
                        absolutePath()))

        except UnicodeEncodeError as ex:
            QMessageBox.critical(self, self.tr("Encoding error"), str(ex))
        except Exception as ex:
            QMessageBox.critical(self, self.tr("Unknown error"), str(ex))
        progress.setValue(100)

    def check_box_use_current_clicked(self, checked: bool):
        if checked:
            self.list_widget.setEnabled(False)
            self.push_button_open_folder.setEnabled(False)
            self.line_edit_title.setEnabled(False)
        else:
            self.list_widget.setEnabled(True)
            self.push_button_open_folder.setEnabled(True)
            self.line_edit_title.setEnabled(True)

    def open_folder_clicked(self):
        path = QFileDialog.getExistingDirectory(self, self.tr("Select folder"))

        provider = QFileIconProvider()
        self.list_widget.clear()

        for dir_path, dir_names, file_names in os.walk(path):
            for file_name in file_names:
                if file_name.endswith(".json"):
                    item = QListWidgetItem()
                    item.setText(file_name[0:-5])
                    item.setData(Qt.UserRole, dir_path + os.sep + file_name)
                    item.setIcon(
                        provider.icon(QFileInfo(dir_path + os.sep +
                                                file_name)))

                    self.list_widget.addItem(item)

        self.label_find.setText(
            self.tr("Schedules: ") + str(self.list_widget.count()))

    def open_files_clicked(self):
        files = QFileDialog.getOpenFileNames(
            self, self.tr("Select files"), "",
            "JSON file (*.json) ;; All files (*.*)")[0]
        provider = QFileIconProvider()
        self.list_widget.clear()

        for file_path in files:
            file = QFileInfo(file_path)
            item = QListWidgetItem()
            item.setText(file.baseName())
            item.setData(Qt.UserRole, file_path)
            item.setIcon(provider.icon(file))
            self.list_widget.addItem(item)

        self.label_find.setText(
            self.tr("Schedules: ") + str(self.list_widget.count()))

    def combo_box_color_a_clicked(self) -> None:
        """
        Slot for color selection of A subgroup.
        """
        if self.combo_box_color_a.currentIndex() == 0:
            self.custom_color_selected(self.combo_box_color_a)

    def combo_box_color_b_clicked(self) -> None:
        """
        Slot for color selection of B subgroup.
        """
        if self.combo_box_color_b.currentIndex() == 0:
            self.custom_color_selected(self.combo_box_color_b)

    def custom_color_selected(self, combo_box: QComboBox) -> None:
        """
        Slot to select the color for the desired menu.

        :param combo_box: Menu
        """
        color = QColorDialog.getColor(combo_box.currentData(), self)
        if color.isValid():
            combo_box.setItemIcon(0, util.create_color_icon(color))
            combo_box.setItemData(0, color)

    def date_edit_start_changed(self, date: QDate):
        """
        Slot for changing the end of a range of dates.

        :param date: Start of the date range
        """
        end_date = self.date_edit_end.date().addDays(
            self._date_start_cache.daysTo(date))
        self.date_edit_end.setMinimumDate(date.addDays(7))
        self.date_edit_end.setDate(end_date)
        self._date_start_cache = QDate(date)
class AddEmployeeDetails(QMainWindow):

    closing = pyqtSignal(int)

    def __init__(self, parent, update, id=None):
        super().__init__(parent)

        self.parent = parent

        self.db = DB()

        self.initUI(update, id)

    def initUI(self, update, id):

        self.setWindowModality(Qt.ApplicationModal)

        frame = QFrame()
        # frame.setStyleSheet("background-color: rgb(30, 45, 66);")
        frame.setFrameShape(QFrame.StyledPanel)
        frame.setFrameShadow(QFrame.Raised)
        # frame.setMinimumWidth(430)
        # frame.setFixedHeight(395)
        frame.setStyleSheet("border: none")

        add_employee_button = QLabel(frame)
        add_employee_button.setAlignment(Qt.AlignCenter)
        add_employee_button.setGeometry(QRect(110, 30, 210, 41))
        add_employee_button.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n"
                                 "background-color: rgb(30, 45, 66);\n"
                                 "color: rgb(255, 255, 255);")
        add_employee_button.setText("Add Employee Details")

        # name = QHBoxLayout()
        # jobtitle = QHBoxLayout()
        # salary = QHBoxLayout()
        # bonus = QHBoxLayout()
        # joindate = QHBoxLayout()

        namelabel = QLabel(frame)
        namelabel.setText("Name")
        namelabel.setGeometry(QRect(80, 100, 47, 13))

        self.nametextbox = QLineEdit(frame)
        self.nametextbox.setGeometry(QRect(160, 90, 181, 31))
        self.nametextbox.setFixedWidth(180)

        jobtitlelabel = QLabel(frame)
        jobtitlelabel.setText("Job Title")
        jobtitlelabel.setGeometry(QRect(80, 140, 61, 16))

        self.jobtitletextbox = QComboBox(frame)
        self.jobtitletextbox.setGeometry(QRect(160, 130, 181, 31))
        self.jobtitletextbox.setFixedWidth(180)
        self.jobtitletextbox.addItems(["Manager", "Waiter", "Chef", "Security"])

        salarylabel = QLabel(frame)
        salarylabel.setText("Salary")
        salarylabel.setGeometry(QRect(80, 180, 47, 13))

        self.salarytextbox = QLineEdit(frame)
        self.salarytextbox.setGeometry(QRect(160, 170, 181, 31))
        self.salarytextbox.setFixedWidth(180)
        self.salarytextbox.setValidator(QIntValidator())

        # bonuslabel = QLabel(frame)
        # bonuslabel.setText("Bonus")
        # bonuslabel.setGeometry(QRect(80, 220, 47, 13))

        # bonustextbox = QLineEdit(frame)
        # bonustextbox.setGeometry(QRect(160, 210, 181, 31))
        # bonustextbox.setFixedWidth(180)

        joindatelabel = QLabel(frame)
        joindatelabel.setText("Start Date")
        joindatelabel.setGeometry(QRect(80, 260, 71, 16))

        self.joindatetextbox = QDateEdit(frame)
        self.joindatetextbox.setGeometry(QRect(160, 250, 181, 31))
        self.joindatetextbox.setFixedWidth(180)
        self.joindatetextbox.setDate(QDate.currentDate())
        self.joindatetextbox.setMinimumDate(QDate.currentDate())
        self.joindatetextbox.setDisplayFormat("dd-MM-yyyy")

        self.addbutton = QPushButton(frame)
        self.addbutton.setGeometry(QRect(160, 300, 111, 31))
        self.addbutton.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n"
                                   "background-color: rgb(30, 45, 66);\n"
                                   "color: rgb(255, 255, 255);")
        if update == 'add':
            print("Add")
            print(id)
            self.addbutton.setText("Add Employee")
            self.addbutton.clicked.connect(lambda: self.add_button_click("employee"))
        else:
            print("Update")
            print(id)
            self.addbutton.setText("Update Employee")
            self.addbutton.clicked.connect(lambda: self.update_button_click("employee", id))

        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(frame)

        centralWidget = QWidget()
        centralWidget.setLayout(layout)

        self.setCentralWidget(centralWidget)

        # self.setLayout(layout)

        self.setWindowTitle("Add Employee Details")
        self.resize(430, 395)
        self.show()

        self.center()

    def center(self):
        '''centers the window on the screen'''
        screen = QDesktopWidget().screenGeometry()
        size = self.geometry()
        self.move((screen.width() - size.width()) / 2,
                  (screen.height() - size.height()) / 2)

    def update_button_click(self, where, id):
        if where == "employee":
            print("Employees Finally here")

            print(self.nametextbox.text())
            print(self.jobtitletextbox.currentText())
            print(self.salarytextbox.text())
            print(self.joindatetextbox.text())

            employee_name = self.nametextbox.text()
            job_title = self.jobtitletextbox.currentText()
            salary = self.salarytextbox.text()

            try:
                date = datetime.datetime.strptime(self.joindatetextbox.text(), "%d-%m-%Y")
                joining_date = datetime.datetime.strftime(date, "%Y-%m-%d")
            except:
                ''' Make sure to add an error message. '''
                return

            if employee_name != "" and salary != "":
                query = "update employee set `employee_name`=%s, `job_title`=%s, `salary`=%s, " \
                        "`joining_date`=%s where id=%s"
                values = (employee_name, job_title, salary, joining_date, id)

                result = self.db.execute(query, values)

                self.closeEvent = self.message()

    def add_button_click(self, where):
        if where == "employee":
            print("Employees Finally here")

            print(self.nametextbox.text())
            print(self.jobtitletextbox.currentText())
            print(self.salarytextbox.text())
            print(self.joindatetextbox.text())

            employee_name = self.nametextbox.text()
            job_title = self.jobtitletextbox.currentText()
            salary = self.salarytextbox.text()

            try:
                date = datetime.datetime.strptime(self.joindatetextbox.text(), "%d-%m-%Y")
                joining_date = datetime.datetime.strftime(date, "%Y-%m-%d")
            except:
                ''' Make sure to add an error message. '''
                return

            if employee_name != "" and salary != "":
                query = "insert into employee (`employee_name`, `job_title`,`salary`, `joining_date`)" \
                        "values (%s, %s, %s, %s);"
                values = (employee_name, job_title, salary, joining_date)

                result = self.db.execute(query, values)

                self.closeEvent = self.message()

    def message(self):
        self.closing.emit(1)
        self.close()

    # def closeEvent(self, event):
    #     print("Closed")
    #     self.closing.emit()
    #     # self.parent.update()
Example #24
0
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.textSuffix = QTextEdit(self.centralwidget)
        self.textSuffix.setGeometry(QRect(20, 230, 261, 31))
        self.textSuffix.setObjectName("textSuffix")
        self.textRiskf = QTextEdit(self.centralwidget)
        self.textRiskf.setGeometry(QRect(20, 360, 261, 31))
        self.textRiskf.setObjectName("textRiskf")
        self.label = QLabel(self.centralwidget)
        self.label.setGeometry(QRect(20, 330, 261, 20))
        self.label.setObjectName("label")
        self.label_2 = QLabel(self.centralwidget)
        self.label_2.setGeometry(QRect(20, 270, 281, 21))
        self.label_2.setObjectName("label_2")
        self.label_3 = QLabel(self.centralwidget)
        self.label_3.setGeometry(QRect(20, 200, 261, 16))
        self.label_3.setObjectName("label_3")
        self.label_4 = QLabel(self.centralwidget)
        self.label_4.setGeometry(QRect(20, 130, 261, 21))
        self.label_4.setObjectName("label_4")
        self.label_5 = QLabel(self.centralwidget)
        self.label_5.setGeometry(QRect(20, 60, 261, 21))
        self.label_5.setObjectName("label_5")
        self.startButton = QPushButton(self.centralwidget)
        self.startButton.setGeometry(QRect(20, 510, 111, 31))
        self.startButton.setObjectName("startButton")
        self.label_6 = QLabel(self.centralwidget)
        self.label_6.setGeometry(QRect(20, 10, 261, 41))
        font = QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(12)
        font.setBold(True)
        font.setUnderline(True)
        font.setWeight(75)
        self.label_6.setFont(font)
        self.label_6.setObjectName("label_6")
        self.resultBrowser = QTextBrowser(self.centralwidget)
        self.resultBrowser.setGeometry(QRect(310, 30, 461, 501))
        self.resultBrowser.setObjectName("resultBrowser")
        self.DateStart = QDateEdit(self.centralwidget)
        self.DateStart.setGeometry(QRect(20, 90, 121, 31))
        self.DateStart.setMaximumDate(QDate(2050, 12, 31))
        self.DateStart.setMinimumDate(QDate(1990, 12, 31))
        self.DateStart.setDate(QDate(2018, 1, 1))
        self.DateStart.setObjectName("DateStart")
        self.DateEnd = QDateEdit(self.centralwidget)
        self.DateEnd.setGeometry(QRect(19, 163, 121, 31))
        self.DateEnd.setDateTime(QDateTime(QDate(2018, 1, 1), QTime(0, 0, 0)))
        self.DateEnd.setMaximumDateTime(QDateTime(QDate(2050, 12, 31), QTime(23, 59, 59)))
        self.DateEnd.setMinimumDate(QDate(1990, 12, 31))
        self.DateEnd.setObjectName("DateEnd")
        self.spinBoxMode = QSpinBox(self.centralwidget)
        self.spinBoxMode.setGeometry(QRect(20, 290, 71, 31))
        self.spinBoxMode.setMinimum(1)
        self.spinBoxMode.setMaximum(3)
        self.spinBoxMode.setObjectName("spinBoxMode")
        self.label_7 = QLabel(self.centralwidget)
        self.label_7.setGeometry(QRect(170, 300, 101, 21))
        self.label_7.setObjectName("label_7")
        self.endButton = QPushButton(self.centralwidget)
        self.endButton.setGeometry(QRect(160, 510, 121, 31))
        self.endButton.setObjectName("endButton")
        self.fileButton = QPushButton(self.centralwidget)
        self.fileButton.setGeometry(QRect(20, 410, 261, 31))
        self.fileButton.setObjectName("fileButton")
        self.pathBrowser = QTextBrowser(self.centralwidget)
        self.pathBrowser.setGeometry(QRect(20, 450, 261, 41))
        self.pathBrowser.setObjectName("pathBrowser")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QMenuBar(MainWindow)
        self.menubar.setGeometry(QRect(0, 0, 800, 23))
        self.menubar.setObjectName("menubar")
        self.menuAnalysis = QMenu(self.menubar)
        self.menuAnalysis.setObjectName("menuAnalysis")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.menubar.addAction(self.menuAnalysis.menuAction())

        self.retranslateUi(MainWindow)
        QMetaObject.connectSlotsByName(MainWindow)
        ####################################################

        self.mythread = MyThread()
        self.mainthread = MyMainThread()

        self.fileButton.clicked.connect(lambda : self.file_path())
        self.mythread.trigger.connect(self.update_text)
        self.mainthread.result.connect(self.update_result)

        self.startButton.clicked.connect(lambda : self.input_Parameters())
        self.startButton.clicked.connect(lambda : self.mainthread.start())
        self.startButton.clicked.connect(lambda : self.mythread.start())
        self.endButton.clicked.connect(lambda : self.end_calculation())

        
    def input_Parameters(self):
        self.aa = str(self.DateStart.date().toString("yyyyMMdd"))
        self.bb = str(self.DateEnd.date().toString("yyyyMMdd"))
        self.cc = str(self.textSuffix.toPlainText())
        self.dd = int(self.spinBoxMode.value())
        self.ee = float(self.textRiskf.toPlainText())

        if self.dd==1:
            self.dx='p1f1'
        elif self.dd==2:
            self.dx='p0f1'
        elif self.dd==3:
            self.dx='p1f0'
        else:
            raise Exception('Running Mode is wrong')

        self.mainthread.parameters_in = [self.aa ,self.bb, self.cc, self.dx, self.ee, self.directory1]


    def file_path(self):  
        self.directory1 = QFileDialog.getExistingDirectory(self.centralwidget,"Please choose folder","/")+'/'
        self.pathBrowser.append(str(self.directory1))

    def update_text(self, message):
        self.resultBrowser.append(str(message))
    
    def update_result(self,message):
        self.mythread.stop_()
        sleep(1)
        self.resultBrowser.append(str(message))
        print(self.mainthread.str_result)
        for i in self.mainthread.str_result:
            print(i)
            self.resultBrowser.append(i)

    def end_calculation(self):
        self.mythread.stop_()
        self.mainthread.stop_()
        sleep(1)
        self.resultBrowser.append('\nCalculation terminated by user...')


    def retranslateUi(self, MainWindow):
        _translate = QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.label.setText(_translate("MainWindow", "Please input risk free rate(0.035)"))
        self.label_2.setText(_translate("MainWindow", "Choose a running mode(e.g (1)p1f1/(2)p0f1"))
        self.label_3.setText(_translate("MainWindow", "Please input the suffix for result file"))
        self.label_4.setText(_translate("MainWindow", "Please input earliest date(e.g 2018-01-01)"))
        self.label_5.setText(_translate("MainWindow", "Please input latest date(e.g 2018-12-30)"))
        self.startButton.setText(_translate("MainWindow", "Start Analysis"))
        self.label_6.setText(_translate("MainWindow", "Barra Contribution Analysis(v_test)"))
        self.label_7.setText(_translate("MainWindow", " (3)p1f0"))
        self.endButton.setText(_translate("MainWindow", "End Process"))
        self.fileButton.setText(_translate("MainWindow", "Choose a folder"))
        self.menuAnalysis.setTitle(_translate("MainWindow", "Analysis"))
Example #25
0
class FilterView(FixedWidthLabel):
    def __init__(self, controller, model):
        self.controller = controller
        self.model = model
        self.width = self.model.static_data.width
        super().__init__(self.width)

        self._init_UI()

    def _init_UI(self) -> None:
        data = self.model.static_data
        self.layout = QVBoxLayout()
        self.layout.setSpacing(4)
        self.layout.setContentsMargins(8, 2, 8, 2)
        self.layout.setAlignment(Qt.AlignTop)
        self.setLayout(self.layout)

        self.title = FixedSizeLabel(self.width - 6, 40, 'Problem Filter')
        self.title.setAlignment(Qt.AlignCenter | Qt.AlignVCenter)
        self.title.set_colours(data.bg_colour, data.text_colour)

        self.dateedit_start = QDateEdit()
        self.dateedit_start.setCalendarPopup(True)
        self.dateedit_start.userDateChanged.connect(
            self._on_start_date_changed)
        self.dateedit_end = QDateEdit()
        self.dateedit_end.setCalendarPopup(True)
        self.dateedit_end.userDateChanged.connect(self._on_end_date_changed)

        self.layout_date = QFormLayout()
        self.layout_date.setFormAlignment(Qt.AlignTop)
        self.layout_date.setLabelAlignment(Qt.AlignRight)
        self.layout_date.setContentsMargins(2, 2, 2, 2)
        self.layout_date.setSpacing(4)

        self.layout_date.addRow('Start Date:', self.dateedit_start)
        self.layout_date.addRow('End Date :', self.dateedit_end)

        self.layout_RIC = QHBoxLayout()
        self.layout_RIC.setSpacing(4)
        self.layout_RIC.setContentsMargins(0, 0, 0, 0)
        self.layout_RIC.setAlignment(Qt.AlignTop)

        self.layout_other = QGridLayout()
        self.layout_other.setSpacing(4)
        self.layout_other.setContentsMargins(0, 0, 0, 0)
        self.layout_other.setAlignment(Qt.AlignTop)

        self.button_reset = QPushButton('Reset')
        self.button_reset.clicked.connect(self._reset_filters)

        self.layout.addWidget(self.title)
        self.layout.addLayout(self.layout_date)
        self.layout.addLayout(self.layout_RIC)
        self.layout.addLayout(self.layout_other)
        self.layout.addWidget(self.button_reset)
        self._add_all_widgets()

    def set_data(self, arg: bool) -> None:
        self._remove_all_widgets()
        self._add_all_widgets()

    def _add_all_widgets(self) -> None:
        self._add_RIC_widgets()
        self._add_other_widgets()

    def _add_RIC_widgets(self) -> None:
        if len(self.model.views) >= 3:
            for widget in self.model.views[0:3]:
                self.layout_RIC.addWidget(widget, alignment=Qt.AlignTop)

    def _add_other_widgets(self) -> None:
        if len(self.model.views) >= 3:
            for index, widget in enumerate(self.model.views[3:]):
                self.layout_other.addWidget(widget,
                                            index // 2,
                                            index % 2,
                                            alignment=Qt.AlignTop)

    def _remove_all_widgets(self) -> None:
        self._remove_widgets_from(self.layout_RIC)
        self._remove_widgets_from(self.layout_other)

    def _remove_widgets_from(self, layout: QLayout) -> None:
        for index in reversed(range(layout.count())):
            widget = layout.itemAt(index).widget()
            layout.removeWidget(widget)
            widget.setParent(None)

    def _on_start_date_changed(self, date) -> None:
        self.controller.on_start_date_changed(date)

    def _on_end_date_changed(self, date) -> None:
        self.controller.on_end_date_changed(date)

    def set_min_date(self, date) -> None:
        self.dateedit_start.setMinimumDate(date)
        self.dateedit_end.setMinimumDate(date)
        self.dateedit_start.setDate(date)

    def set_max_date(self, date) -> None:
        self.dateedit_start.setMaximumDate(date)
        self.dateedit_end.setMaximumDate(date)
        self.dateedit_end.setDate(date)

    def _reset_filters(self) -> None:
        min_date = self.dateedit_start.minimumDate()
        self.dateedit_start.setDate(min_date)
        max_date = self.dateedit_end.maximumDate()
        self.dateedit_end.setDate(max_date)
        self._unselect_all_widgets_in(self.layout_RIC)
        self._unselect_all_widgets_in(self.layout_other)
        self.controller.reset()

    def _unselect_all_widgets_in(self, layout: QLayout) -> None:
        for index in reversed(range(layout.count())):
            widget = layout.itemAt(index).widget()
            widget.clear_selection()
class Tabless_Widget(QTableWidget):
    """
     subclass of QTableWidget. 
     Purpose to have signal-slot connection with Tree custom class
    """
    sig2 = pyqtSignal(int)
    sig2t = pyqtSignal(int, str, str, str, str)

    def __init__(self):
        super(Tabless_Widget, self).__init__()
        self.init_ui()

    def init_ui(self):
        self.sitetable1 = QTableWidget()
        self.status = QLabel()
        self.sitetable1.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        self.summary = QTextEdit()
        self.summary.setSizeAdjustPolicy(
            QtWidgets.QAbstractScrollArea.AdjustToContents)
        self.summary.setReadOnly(True)
        self.summary.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.summary.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.summary.setSizePolicy(
            QSizePolicy.Expanding,
            QSizePolicy.Expanding)  # horizontal, vertical
        self.summary.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.sitetable1.setEditTriggers(QtWidgets.QTableWidget.NoEditTriggers)
        self.sitetable1.setShowGrid(False)
        self.sitetable1.setStyleSheet(
            'QTableView::item {background-color: white;}')

    def show_table_rows(self):
        for jj in range(self.sitetable1.rowCount()):
            self.sitetable1.showRow(jj)

    def make_connection_2_tree(self, tree_object):
        print("Make connection")
        tree_object.getExperiment.connect(self.get_tree)
        tree_object.getTreatment.connect(self.get_treatment)
        tree_object.getNewOperation.connect(self.get_operation)
        tree_object.getOperation.connect(self.get_existingoperation)
        tree_object.informUser.connect(self.informuser)
        #return cstatus

    @pyqtSlot(int, str, str)
    def get_tree(self, intval, str_experimentname, str_cropname):
        #print("debug: tablewithsignalslot:get_tree: val,cropname=",intval, str_cropname)
        if intval == 1:
            ### works only for avoiding silent crash on multiple clicks on ADD NEW Experiment
            if self.sitetable1.isVisible() == False:
                self.showNewExperimentDialog('New', str_cropname)
            self.sitetable1.setVisible(True)
        elif intval == 0:
            self.sitetable1.clear()
            self.sitetable1.reset()
            self.sitetable1.clearContents()
            self.sitetable1.setRowCount(0)
            self.sitetable1.setVisible(False)
        elif intval == 5:
            self.showDeleteExperimentDialog('Delete', str_experimentname,
                                            str_cropname)
            self.sitetable1.setVisible(True)

    @pyqtSlot(int, str, str, str)
    def get_treatment(self, intval, str_experimentname, str_cropname,
                      str_treatmentname):
        print("get_treatment works. val=", intval)
        if intval == 2:
            self.showNewTreatmentDialog(
                'New', str_experimentname,
                str_cropname)  #  experimentname,cropname
            self.sitetable1.setVisible(True)
        elif intval == 0:
            self.sitetable1.setVisible(False)
        elif intval == 6:
            if self.sitetable1.isHidden() == False:
                self.sitetable1.clear()
                self.sitetable1.reset()
                self.sitetable1.hide()
            #  experimentname,cropname
            self.showDeleteTreatmentDialog('Delete', str_experimentname,
                                           str_cropname, str_treatmentname)
            self.sitetable1.setVisible(True)

    @pyqtSlot(int, str)
    def informuser(self, intval, tree_str):
        print("informuser val & tree_str=", intval, tree_str)
        if intval == 0:
            self.showUserInformationDialog(
                'New Treatment Node addded',
                tree_str)  #  experimentname,cropname
        elif intval == 1:
            self.sitetable1.setVisible(False)

    @pyqtSlot(int, str, str, str)
    def get_operation(self, intval, strval1, strval2, strval3):
        print("get_operation works. val=", intval)
        if intval == 3:
            self.showNewOperationDialog(
                'New', strval1, strval2,
                strval3)  # treatmentname, experimentname,cropname
            self.sitetable1.setVisible(True)
        elif intval == 0:
            self.sitetable1.setVisible(False)

    @pyqtSlot(int, str, str, str, str, QModelIndex)
    def get_existingoperation(self, intval, strval1, strval2, strval3, strval4,
                              index):
        #print("Debug: tableWithSignalSlot.get_existingoperation() val=",intval)
        if intval == 4:
            # treatmentname, experimentname,cropname,operationname
            self.showExistingOperationDialog('New', strval1, strval2, strval3,
                                             strval4)
            self.sitetable1.setVisible(True)
        elif intval == 0:
            self.sitetable1.setVisible(False)

    def showUserInformationDialog(self, value, tree_str):
        """
        QTable object. This will inform the USER what to do after adding "Add new Experiment/Treatment/Operation"
        """
        self.savebutton1 = QPushButton("Ok")
        tmp_str2 = tree_str + "Treatment node added in the left panel. All operations are added. Please \
check their operations dates and correct them if needed."

        self.summary.setText(tmp_str2)
        self.sitetable1.clearContents()
        self.sitetable1.setRowCount(
            0)  # necessary. It will clean the table internally
        self.sitetable1.clear()
        self.sitetable1.reset()
        self.sitetable1.setRowCount(6)
        self.sitetable1.setColumnCount(2)
        self.show_table_rows()

        header = self.sitetable1.horizontalHeader()
        header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
        header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)

        self.sitetable1.horizontalHeader().hide()
        self.sitetable1.verticalHeader().hide()
        self.sitetable1.setSpan(0, 0, 3, 2)
        self.sitetable1.setCellWidget(0, 0, self.summary)
        self.sitetable1.setCellWidget(4, 1, self.savebutton1)
        self.sitetable1.setVisible(True)
        self.sitetable1.resizeColumnsToContents()
        self.sitetable1.resizeRowsToContents()
        self.savebutton1.clicked.connect(self.on_okbutton_informuser_clicked)

    def showNewExperimentDialog(self, value, str_cropname):
        """
         QTable object. Ask user to enter the name of new experiment.
         Need to verify the USEr input is SAFE for database. After verification, insert this entry to 
         table: Experiment
        """
        self.strval = str_cropname
        self.cropname = str_cropname
        self.experimentname = QLineEdit()
        self.udialog = QLabel()
        regexp_alphanum = QtCore.QRegExp('\w+')
        validator_alphanum = QtGui.QRegExpValidator(regexp_alphanum)
        test1state = self.experimentname.setValidator(validator_alphanum)
        self.savebutton1 = QPushButton("Save")

        # creating local summary1 object as C++ class and python wrapper for it were not synching well
        # with operation of (delete/ create)
        # important; to have preserve a reference this way and proper cleaning of cell widget inside a
        # qtablewidget
        self.summary1 = QTextEdit(
            "EXPERIMENT Name represents broader hierarchical dataset name, for \
example `Summer 2018`. Underneath it, one can define specific TREATMENT. Provide a unique experiment \
name, click SAVE. Once it is registered in left panel, you add new treatment(s)"
        )
        self.summary1.setSizeAdjustPolicy(
            QtWidgets.QAbstractScrollArea.AdjustToContents)
        self.summary1.setReadOnly(True)
        self.summary1.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.summary1.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.summary1.setSizePolicy(
            QSizePolicy.Expanding,
            QSizePolicy.Expanding)  # horizontal, vertical
        self.summary1.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.sitetable1.clear()
        self.sitetable1.reset()
        self.sitetable1.clearContents()
        self.sitetable1.setRowCount(
            0)  # necessary. It will clean the table internally
        self.sitetable1.setRowCount(6)
        self.sitetable1.setColumnCount(2)
        self.show_table_rows()

        header = self.sitetable1.horizontalHeader()
        header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
        header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)

        self.sitetable1.horizontalHeader().hide()
        self.sitetable1.verticalHeader().hide()
        self.sitetable1.setSpan(0, 0, 3, 2)
        self.sitetable1.setCellWidget(0, 0, self.summary1)
        self.sitetable1.setItem(3, 0,
                                QTableWidgetItem("Enter New Experiment Name"))
        self.sitetable1.setCellWidget(3, 1, self.experimentname)
        self.sitetable1.setCellWidget(4, 1, self.savebutton1)
        self.sitetable1.setCellWidget(5, 0, self.udialog)
        self.sitetable1.setVisible(True)
        self.sitetable1.resizeColumnsToContents()
        self.sitetable1.resizeRowsToContents()
        ##self.savebutton1.disconnect()
        self.savebutton1.clicked.connect(self.on_savebutton_experiment_clicked)

############## delete experiment

    def showDeleteExperimentDialog(self, value, str_experimentname,
                                   str_cropname):
        """
         Delete the experiment
         QTable object. 
        """
        self.cropname = str_cropname
        self.experimentname = QLineEdit(str_experimentname)
        self.experimentname.setReadOnly(True)
        self.udialog = QLabel()
        self.yesbutton = QPushButton("Yes")
        self.nobutton = QPushButton("No")
        self.sitetable1.clear()
        self.sitetable1.reset()
        self.sitetable1.clearContents()
        self.sitetable1.setRowCount(
            0)  # necessary. It will clean the table internally
        self.sitetable1.setRowCount(3)
        self.sitetable1.setColumnCount(2)
        self.show_table_rows()
        self.sitetable1.horizontalHeader().hide()
        self.sitetable1.verticalHeader().hide()
        self.sitetable1.setItem(
            0, 0, QTableWidgetItem("Do you want to delete the experiment:"))
        self.sitetable1.setCellWidget(0, 1, self.experimentname)
        self.sitetable1.setCellWidget(1, 0, self.yesbutton)
        self.sitetable1.setCellWidget(1, 1, self.nobutton)
        self.sitetable1.setCellWidget(2, 0, self.udialog)
        self.sitetable1.setVisible(True)
        self.sitetable1.resizeColumnsToContents()
        self.sitetable1.resizeRowsToContents()
        self.yesbutton.clicked.connect(self.on_yesbutton_experiment_clicked)
        self.nobutton.clicked.connect(self.on_nobutton_experiment_clicked)

    def on_okbutton_informuser_clicked(self):
        if self.sitetable1.isHidden() == False:
            self.sitetable1.clear()
            self.sitetable1.reset()
        #return true

    def on_savebutton_experiment_clicked(self, value):
        if len(self.experimentname.text()) == 0:
            self.udialog.setText(
                "Empty string. Please, provide valid EXPERIMENT name. Hint: Alphanumeric "
            )
        else:
            self.udialog.setText("")
            #call database insert command
            status = check_and_update_experimentDB(self.experimentname.text(),
                                                   self.cropname)
            if status:
                self.udialog.setText(
                    self.experimentname.text() +
                    " added in left panel and Add New Treatment to it.")
                if self.sitetable1.isHidden() == False:
                    self.sitetable1.hide()
                # goes to update3, insert data inot datatree instead of re-loading the datatree (causing crash, due
                # to improper handling)
                self.sig2t.emit(4, self.experimentname.text(), self.cropname,
                                "blank_treament", "blank_operation")
            else:
                self.udialog.setText(
                    "Experiment name exist. Use different name !!")

    def on_yesbutton_experiment_clicked(self, value):
        self.udialog.setText("")
        #call database delete command
        status = check_and_delete_experimentDB(self.experimentname.text(),
                                               self.cropname)
        print("status=", status)
        if status:
            print("status=", status)
            self.udialog.setText("Success " + self.experimentname.text())
            self.sitetable1.clear()
            self.sitetable1.hide()
            # this way no need to re-load the data after deletion. Delete from database and delete from tree
            self.sig2.emit(3)

    def on_nobutton_experiment_clicked(self, value):
        self.udialog.setText("ok, no action taken")
        self.sig2t.emit(2, self.experimentname.text(), self.strval)

    def on_yesbutton_treatment_clicked(self, value):
        self.udialog.setText("")
        #call database delete command
        status = 1
        status = check_and_delete_treatmentDB(self.treatmentname.text(),
                                              self.ename, self.cname)
        if status:
            self.udialog.setText("Success " + self.treatmentname.text())
            self.sitetable1.clear()
            self.sitetable1.reset()
            self.sitetable1.clearContents()
            self.sitetable1.setRowCount(
                0)  # necessary. It will clean the table internally
            self.sitetable1.hide()
            self.sig2.emit(6)

    def on_nobutton_treatment_clicked(self, value):
        self.sitetable1.clear()
        self.sitetable1.reset()
        self.sitetable1.clearContents()
        self.sitetable1.setRowCount(
            0)  # necessary. It will clean the table internally
        self.sitetable1.hide()

    def on_savebutton_treatment_clicked(self, value):
        if len(self.treatmentname.text()) == 0:
            self.udialog.setText(
                "Empty string. Please, provide valid TREATMENT name. Hint: Alphanumeric "
            )
        else:
            self.udialog.setText("")
            #call database insert command
            status = check_and_update_treatmentDB(self.treatmentname.text(),
                                                  self.strval1, self.strval2)
            if status:
                #self.udialog.setText("Success")
                if self.sitetable1.isHidden() == False:
                    self.sitetable1.hide()
                # faultline check self.informuser(0,'hello')
                # will send it update(), deletes the current tree and re-load the datatree from database
                self.sig2.emit(66)
            else:
                self.udialog.setText(
                    "Treatment name exist. Use different name !!")

    def showNewTreatmentDialog(self, value, strval1, strval2):
        """
         QTable object. Ask user to enter the name of new experiment.
         Need to verify the USEr input is SAFE for database. After verification, insert this entry to 
         table: Experiment
        """
        self.strval1 = strval1
        self.strval2 = strval2
        self.treatmentname = QLineEdit()
        self.udialog = QLabel()
        regexp_alphanum = QtCore.QRegExp('\w+')
        validator_alphanum = QtGui.QRegExpValidator(regexp_alphanum)
        test1state = self.treatmentname.setValidator(validator_alphanum)
        self.savebutton1 = QPushButton("Save")
        self.sitetable1.clear()
        self.sitetable1.reset()
        self.sitetable1.clearContents()
        self.sitetable1.setRowCount(
            0)  # necessary. It will clean the table internally

        self.sitetable1.setRowCount(3)
        self.sitetable1.setColumnCount(2)
        self.show_table_rows()

        self.sitetable1.horizontalHeader().hide()
        self.sitetable1.verticalHeader().hide()
        self.sitetable1.setItem(0, 0, QTableWidgetItem("Enter New Treatment"))
        self.sitetable1.setCellWidget(0, 1, self.treatmentname)
        self.sitetable1.setCellWidget(1, 1, self.savebutton1)
        self.sitetable1.setCellWidget(2, 0, self.udialog)
        self.sitetable1.resizeColumnsToContents()
        self.sitetable1.resizeRowsToContents()
        self.savebutton1.clicked.connect(self.on_savebutton_treatment_clicked)

    def getTreatmentSummary(ename, cname, tname):
        conn = sqlite3.connect(dbDir + '\\crop.db')
        c = conn.cursor()
        if not c:
            print("database not open")
            return False

        #Get treatment id
        search_tuple = (tname, ename, cname)
        c1 = c.execute(
            "SELECT tid FROM treatment where name = ? and t_exid = (select exid from experiment where name =? and crop = ?)",
            search_tuple)
        tid = c1.fetchone()
        operationSummary = "<b>Treatment Summary</b><br>"
        if tid != None:
            # Get all operations associated with this treatment
            op = c.execute(
                "SELECT name, odate, quantity, pop, yseed, eomult, rowSpacing, cultivar, fDepth, autoirrigation, \
                            DATE(year||'-'||month||'-'||day) as dt_frmtd FROM (SELECT *, CASE WHEN LENGTH(substr(odate, 1, \
                            instr(odate,'/')-1)) = 2 THEN substr(odate, 1, instr(odate,'/')-1) ELSE '0'|| substr(odate, 1, instr(odate,'/')-1) \
                            END as month, CASE WHEN LENGTH(substr(substr(odate, instr(odate,'/')+1), 1, instr(substr(odate, instr(odate,'/')+1),\
                            '/')-1)) = 2 THEN substr(substr(odate, instr(odate,'/')+1), 1, instr(substr(odate, instr(odate,'/')+1),'/')-1) ELSE \
                            '0'|| substr(substr(odate, instr(odate,'/')+1), 1, instr(substr(odate, instr(odate,'/')+1),'/')-1) END AS day, CASE \
                            WHEN LENGTH(substr(substr(odate, instr(odate,'/')+1), instr(substr(odate, instr(odate,'/')+1),'/')+1)) = 4 THEN \
                            substr(substr(odate, instr(odate,'/')+1), instr(substr(odate, instr(odate,'/')+1),'/')+1) END AS year FROM operations) \
                            where o_t_exid=? order by dt_frmtd", tid)
            op_rows = op.fetchall()
            for op_row in op_rows:
                if (op_row[0] == "Initial Field Values"):
                    loc = "Middle"
                    if (op_row[5] == 0.5):
                        loc = "Left"
                    if (op_row[9] == 1):
                        irrigFlag = "Yes"
                    else:
                        irrigFlag = "No"
                    operationSummary += "Cultivar: " + op_row[7] + "<br>Plant Density (number of plants/m2): " + str(op_row[3]) + "<br>" + \
                                        "Seed Depth (cm): " + str(op_row[4]) + "<br>Row Spacing (cm): " + str(op_row[6]) + "<br>" + \
                                        "Auto Irrigation : " + irrigFlag + "<br>Location of Planting Grid: " + loc + "<br>"
                else:
                    operationSummary += op_row[0] + " Date: " + op_row[
                        1] + "<br>"

                if (op_row[0] == "Fertilizer-N"):
                    operationSummary += "Quantity (kg/ha): " + str(
                        op_row[2]) + "<br>Fertilizer Depth (cm): " + str(
                            op_row[8]) + "<br>"

        conn.close()
        return operationSummary

##### delete treatment #str_experimentname,str_cropname,str_treatmentname

    def showDeleteTreatmentDialog(self, value, strval1, strval2, strval3):
        """
         Deletes the treatment. Recursive to operation
        """
        self.ename = strval1
        self.cname = strval2
        self.tname = strval3
        self.treatmentname = QLineEdit(self.tname)
        self.treatmentname.setReadOnly(True)
        self.udialog = QLabel()
        self.yesbutton = QPushButton("Yes")
        self.nobutton = QPushButton("No")
        self.treatmentSummary = Tabless_Widget.getTreatmentSummary(
            self.ename, self.cname, self.tname)
        self.udialog.setText(self.treatmentSummary)

        self.sitetable1.clearContents()
        self.sitetable1.setRowCount(0)
        self.sitetable1.clear()
        self.sitetable1.reset()
        self.sitetable1.setRowCount(3)
        self.sitetable1.setColumnCount(2)
        self.show_table_rows()
        self.sitetable1.horizontalHeader().hide()
        self.sitetable1.verticalHeader().hide()
        self.sitetable1.setItem(
            0, 0, QTableWidgetItem("Do you want to delete the treatment"))
        self.sitetable1.setCellWidget(0, 1, self.treatmentname)
        self.sitetable1.setCellWidget(1, 0, self.yesbutton)
        self.sitetable1.setCellWidget(1, 1, self.nobutton)
        self.sitetable1.setCellWidget(2, 0, self.udialog)
        self.sitetable1.setVisible(True)
        self.sitetable1.resizeColumnsToContents()
        self.sitetable1.resizeRowsToContents()
        self.yesbutton.clicked.connect(self.on_yesbutton_treatment_clicked)
        self.nobutton.clicked.connect(self.on_nobutton_treatment_clicked)

    def showNewOperationDialog(self, value, strval1, strval2, strval3):
        """
         QTable object. Asks user to SELECT operation from the given set of operation.
         Need to verify the USEr input is SAFE for database. After verification, insert this 
         entry to table: Operation
        """
        self.udialog = QLabel()
        self.treatmentname = strval1
        self.experimentname = strval2
        self.cropname = strval3
        self.calendar = QDateEdit()

        lastoperation_date = getme_date_of_last_operationDB(
            self.treatmentname, self.experimentname, self.cropname)
        # first find out if this the new operation or there is a operation defined for this treatment.
        # So we use the calendar date logic
        if len(lastoperation_date) > 0:
            lastoperation_date_parts = lastoperation_date[0].split(
                "/")  # 10/20/2006
            self.calendar.setMinimumDate(
                QDate(int(lastoperation_date_parts[2]),
                      int(lastoperation_date_parts[0]),
                      int(lastoperation_date_parts[1])))
            print("debug:tabless_widget: last operation date=",
                  lastoperation_date, " ", lastoperation_date_parts[2], " ",
                  lastoperation_date_parts[1])
        else:
            self.calendar.setMinimumDate(QDate(1900, 1, 1))

        self.calendar.setMaximumDate(QDate(2200, 1, 1))
        self.calendar.setDisplayFormat("MM/dd/yyyy")
        self.calendar.setCalendarPopup(True)
        self.savebutton1 = QPushButton("Save")
        self.combo1 = QComboBox()
        self.combocropvariety = QComboBox()
        self.comboeomult = QComboBox()
        self.yseedlabel = QLabel("Seed Depth (cm)")
        self.quantitylabel = QLabel("Quantity (kg/ha)")
        self.fDepthlabel = QLabel("Fertilizer Depth (cm)")
        self.seedMasslabel = QLabel("Seedpiece Mass (g)")
        self.datelabel = QLabel("Date")
        self.cropvarietylabel = QLabel("Cultivars")
        self.poplabel = QLabel("Plant Density (number of plants/m2)")
        self.rowspacinglabel = QLabel("Row Spacing (cm)")
        self.autoirrigationlabel = QLabel("Auto Irrigation")
        self.eomultlabel = QLabel("Location of Planting Grid")

        self.blanklabeledit = QLineEdit("")
        self.quantitylabeledit = QLineEdit("")
        self.poplabeledit = QLineEdit("6.5")
        self.yseedlabeledit = QLineEdit("5")
        self.rowspacinglabeledit = QLineEdit("75")
        self.autoirrigationlabeledit = QLineEdit("0")
        self.fDepthlabeledit = QLineEdit("")
        self.seedMasslabeledit = QLineEdit("0")
        # Create and populate autoIrrigation combo
        self.comboAutoIrrig = QComboBox()
        self.comboAutoIrrig.addItem("Yes")  # val = 1
        self.comboAutoIrrig.addItem("No")  # val = 0

        #checking USER input for NUMERIC values
        regexp_num = QtCore.QRegExp('^\d*[.]?\d*$')
        validator_num = QtGui.QRegExpValidator(regexp_num)
        test1state = self.quantitylabeledit.setValidator(validator_num)
        test1state = self.poplabeledit.setValidator(validator_num)
        test1state = self.yseedlabeledit.setValidator(validator_num)
        test1state = self.rowspacinglabeledit.setValidator(validator_num)
        test1state = self.fDepthlabeledit.setValidator(validator_num)
        test1state = self.seedMasslabeledit.setValidator(validator_num)

        #The operation will only show if quantity_flag=1 on defaultoperations table.
        self.readlist = read_defaultOperationsDB()
        self.combo1.clear()
        self.combo1.addItem("Select Operation")
        for record in sorted(self.readlist):
            if record[3] == 1:
                self.combo1.addItem(record[1])

        self.sitetable1.clearContents()
        self.sitetable1.setRowCount(
            0)  # necessary. It will clean the table internally
        self.sitetable1.clear()
        self.sitetable1.reset()

        self.sitetable1.setRowCount(16)
        self.sitetable1.setColumnCount(3)
        self.show_table_rows()
        self.sitetable1.horizontalHeader().hide()
        self.sitetable1.verticalHeader().hide()
        self.sitetable1.setCellWidget(0, 1, self.combo1)

        self.sitetable1.setCellWidget(1, 0, self.datelabel)
        self.sitetable1.setCellWidget(2, 0, self.quantitylabel)
        self.sitetable1.setCellWidget(3, 0, self.cropvarietylabel)
        # Plant density
        self.sitetable1.setCellWidget(4, 0, self.poplabel)
        # Seed depth
        self.sitetable1.setCellWidget(5, 0, self.yseedlabel)
        self.sitetable1.setCellWidget(6, 0, self.rowspacinglabel)
        self.sitetable1.setCellWidget(7, 0, self.eomultlabel)
        self.sitetable1.setCellWidget(8, 0, self.fDepthlabel)
        self.sitetable1.setCellWidget(9, 0, self.seedMasslabel)
        self.sitetable1.setCellWidget(10, 0, self.autoirrigationlabel)

        self.sitetable1.setCellWidget(1, 1, self.calendar)
        self.sitetable1.setCellWidget(2, 1, self.quantitylabeledit)
        self.sitetable1.setCellWidget(3, 1, self.combocropvariety)
        self.sitetable1.setCellWidget(4, 1, self.poplabeledit)
        self.sitetable1.setCellWidget(5, 1, self.yseedlabeledit)
        self.sitetable1.setCellWidget(6, 1, self.rowspacinglabeledit)
        self.sitetable1.setCellWidget(7, 1, self.comboeomult)
        self.sitetable1.setCellWidget(8, 1, self.fDepthlabeledit)
        self.sitetable1.setCellWidget(9, 1, self.seedMasslabeledit)
        self.sitetable1.setCellWidget(10, 1, self.comboAutoIrrig)
        self.sitetable1.setCellWidget(11, 1, self.savebutton1)

        self.sitetable1.resizeColumnsToContents()
        self.sitetable1.resizeRowsToContents()
        self.sitetable1.setShowGrid(False)

        self.sitetable1.hideRow(1)
        self.sitetable1.hideRow(2)
        self.sitetable1.hideRow(3)
        self.sitetable1.hideRow(4)
        self.sitetable1.hideRow(5)
        self.sitetable1.hideRow(6)
        self.sitetable1.hideRow(7)
        self.sitetable1.hideRow(8)
        self.sitetable1.hideRow(9)
        self.sitetable1.hideRow(10)
        self.sitetable1.hideRow(11)
        self.sitetable1.hideRow(12)
        self.combo1.currentIndexChanged.connect(self.oncomboactivated)

    def showExistingOperationDialog(self, value, strval1, strval2, strval3,
                                    strval4):
        """
         str_treatmentname,str_experimentname,str_cropname,str_operationname
         QTable object. 
         Will show the existing operation. Will allow  to modify its values.
         Create the field table. Query the OPERATION table and get the flag values
        """
        self.udialog = QLabel()
        self.treatmentname = strval1
        self.experimentname = strval2
        self.cropname = strval3
        # strval4 contains operation_id and operation_name concatenated with '_' character
        self.operationname = strval4.split('_')[1]
        self.op_id = strval4.split('_')[0]
        #print("treat = ", self.treatmentname, " expir = ", self.experimentname, " crop nm = ", self.cropname, " op name = ", self.operationname, " op_id = ",self.op_id)
        self.record = list(read_operation_valuesDB2(self.op_id))
        #print("debug: record=",self.record)
        self.calendar = QDateEdit()
        self.calendar.setMinimumDate(QDate(1900, 1, 1))
        self.calendar.setMaximumDate(QDate(2200, 1, 1))
        self.calendar.setDisplayFormat("MM/dd/yyyy")
        self.calendar.setCalendarPopup(True)
        fformat = QtGui.QTextCharFormat()
        fformat.setForeground(QtGui.QColor(151, 180, 152))

        self.savebutton1 = QPushButton("Update")
        self.deletebutton = QPushButton("Delete")

        self.combo1 = QComboBox()
        self.combocropvariety = QComboBox()
        self.comboeomult = QComboBox()
        self.comboAutoIrrig = QComboBox()
        self.yseedlabel = QLabel("Seed Depth (cm)")
        self.quantitylabel = QLabel("Quantity (kg/ha)")
        self.datelabel = QLabel("Date")
        self.cropvarietylabel = QLabel("Cultivars")
        self.poplabel = QLabel("Plant Density (number of plants/m2)")
        self.rowspacinglabel = QLabel("Row Spacing (cm)")
        self.fDepthlabel = QLabel("Fertilizer Depth (cm)")
        self.seedMasslabel = QLabel("Seedpiece Mass (g)")
        self.autoirrigationlabel = QLabel("Auto Irrigation")
        self.eomultlabel = QLabel("Location of Planting Grid")

        self.blanklabeledit = QLineEdit("")
        self.quantitylabeledit = QLineEdit("")
        self.poplabeledit = QLineEdit("")
        self.yseedlabeledit = QLineEdit("")
        self.rowspacinglabeledit = QLineEdit("")
        self.fDepthlabeledit = QLineEdit("")
        self.seedMasslabeledit = QLineEdit("")

        #checking USER input for NUMERIC values
        regexp_num = QtCore.QRegExp('\.d+')
        validator_num = QtGui.QRegExpValidator(regexp_num)
        test1state = self.quantitylabeledit.setValidator(validator_num)
        test1state = self.poplabeledit.setValidator(validator_num)
        test1state = self.yseedlabeledit.setValidator(validator_num)
        test1state = self.rowspacinglabeledit.setValidator(validator_num)
        test1state = self.fDepthlabeledit.setValidator(validator_num)
        test1state = self.seedMasslabeledit.setValidator(validator_num)

        self.sitetable1.clearContents()
        self.sitetable1.setRowCount(
            0)  # necessary. It will clean the table internally
        self.sitetable1.clear()
        self.sitetable1.reset()

        self.sitetable1.setRowCount(16)
        self.sitetable1.setColumnCount(3)
        self.show_table_rows()
        self.sitetable1.horizontalHeader().hide()
        self.sitetable1.verticalHeader().hide()

        self.sitetable1.setCellWidget(1, 0, self.datelabel)
        self.sitetable1.setCellWidget(2, 0, self.quantitylabel)
        self.sitetable1.setCellWidget(3, 0, self.cropvarietylabel)
        self.sitetable1.setCellWidget(4, 0, self.poplabel)
        self.sitetable1.setCellWidget(5, 0, self.yseedlabel)
        self.sitetable1.setCellWidget(6, 0, self.rowspacinglabel)
        self.sitetable1.setCellWidget(7, 0, self.eomultlabel)
        self.sitetable1.setCellWidget(8, 0, self.fDepthlabel)
        self.sitetable1.setCellWidget(9, 0, self.seedMasslabel)
        self.sitetable1.setCellWidget(10, 0, self.autoirrigationlabel)
        if (self.operationname == "Fertilizer-N"):
            self.sitetable1.setCellWidget(11, 0, self.deletebutton)

        self.sitetable1.setCellWidget(1, 1, self.calendar)
        self.sitetable1.setCellWidget(2, 1, self.quantitylabeledit)
        self.sitetable1.setCellWidget(3, 1, self.combocropvariety)
        self.sitetable1.setCellWidget(4, 1, self.poplabeledit)
        self.sitetable1.setCellWidget(5, 1, self.yseedlabeledit)
        self.sitetable1.setCellWidget(6, 1, self.rowspacinglabeledit)
        self.sitetable1.setCellWidget(7, 1, self.comboeomult)
        self.sitetable1.setCellWidget(8, 1, self.fDepthlabeledit)
        self.sitetable1.setCellWidget(9, 1, self.seedMasslabeledit)
        self.sitetable1.setCellWidget(10, 1, self.comboAutoIrrig)
        self.sitetable1.setCellWidget(11, 1, self.savebutton1)

        header = self.sitetable1.horizontalHeader()
        header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
        header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
        self.sitetable1.verticalHeader().setSectionResizeMode(
            QtWidgets.QHeaderView.ResizeToContents)
        self.sitetable1.verticalHeader().setSectionResizeMode(
            0, QtWidgets.QHeaderView.Stretch)

        self.sitetable1.resizeColumnsToContents()
        self.sitetable1.resizeRowsToContents()
        self.sitetable1.setShowGrid(False)

        if (self.operationname == "Initial Field Values"):
            self.readcropvarietylist = read_cultivar_DB(self.cropname)
            for record2 in sorted(self.readcropvarietylist):
                self.combocropvariety.addItem(record2)
            matchedindex = self.combocropvariety.findText(str(self.record[18]))
            if matchedindex >= 0:
                self.combocropvariety.setCurrentIndex(matchedindex)

            # Build eomult picklist
            self.comboeomult.addItem("Left")  # val = 0.5
            self.comboeomult.addItem("Middle")  # val = 1.0
            if (self.record[16] == 0.5):
                matchedindex = self.comboeomult.findText("Left")
            else:
                matchedindex = self.comboeomult.findText("Middle")
            self.comboeomult.setCurrentIndex(matchedindex)

            # Create and populate autoIrrigation combo
            self.comboAutoIrrig.addItem("Yes")  # val = 1
            self.comboAutoIrrig.addItem("No")  # val = 0
            if (self.record[11] == 1):
                matchedindex = self.comboAutoIrrig.findText("Yes")
            else:
                matchedindex = self.comboAutoIrrig.findText("No")
            self.comboAutoIrrig.setCurrentIndex(matchedindex)

            self.poplabeledit.setText(str(self.record[10]))
            self.yseedlabeledit.setText(str(self.record[14]))
            self.rowspacinglabeledit.setText(str(self.record[17]))
            self.seedMasslabeledit.setText(str(self.record[20]))

            self.sitetable1.hideRow(1)
            self.sitetable1.showRow(3)
            self.sitetable1.showRow(4)
            self.sitetable1.showRow(5)
            self.sitetable1.showRow(6)
            self.sitetable1.showRow(7)
            self.sitetable1.showRow(10)
            if (re.search("potato", self.cropname)):
                self.sitetable1.showRow(9)
            else:
                self.sitetable1.hideRow(9)
        else:
            # Calendar
            self.sitetable1.showRow(1)
            # recover the mm,dd,yyyy and set the calendar
            record_parts = self.record[7].split("/")

            currentYear = record_parts[2]
            self.calendar.setDate(
                QDate(int(currentYear), int(record_parts[0]),
                      int(record_parts[1])))

            self.sitetable1.hideRow(3)
            self.sitetable1.hideRow(4)
            self.sitetable1.hideRow(5)
            self.sitetable1.hideRow(6)
            self.sitetable1.hideRow(7)
            self.sitetable1.hideRow(9)
            self.sitetable1.hideRow(10)

        # Quantity
        if (self.operationname == "Fertilizer-N"):
            self.sitetable1.showRow(2)
            self.sitetable1.showRow(8)
            self.quantitylabeledit.setText(str(self.record[6]))
            self.fDepthlabeledit.setText(str(self.record[19]))
        else:
            self.sitetable1.hideRow(2)
            self.sitetable1.hideRow(8)

        self.sitetable1.showRow(11)
        self.sitetable1.resizeColumnsToContents()
        self.sitetable1.resizeRowsToContents()
        self.sitetable1.setShowGrid(False)
        self.savebutton1.clicked.connect(self.on_savebutton_operation_clicked)
        self.deletebutton.clicked.connect(
            self.on_deletebutton_operation_clicked)

    def oncomboactivated(self, listindex):
        print("text=", listindex)
        self.record = [
            element for element in self.readlist
            if element[1] == self.combo1.currentText()
        ][0]
        op = self.record[1]

        if (op == "Initial Field Values"):
            self.readcropvarietylist = read_cultivar_DB(self.cropname)
            for record2 in sorted(self.readcropvarietylist):
                self.combocropvariety.addItem(record2)
            matchedindex = self.combocropvariety.findText(str(self.record[17]))

            # Build eomult picklist
            self.comboeomult.addItem("Left")  # value 0.5
            self.comboeomult.addItem("Middle")  # value 1.0

            self.sitetable1.hideRow(1)
            self.sitetable1.showRow(3)
            self.sitetable1.showRow(4)
            self.sitetable1.showRow(5)
            self.sitetable1.showRow(6)
            self.sitetable1.showRow(7)
            if (re.search("potato", self.cropname)):
                self.sitetable1.showRow(9)
        else:
            self.sitetable1.showRow(1)
            self.sitetable1.hideRow(3)
            self.sitetable1.hideRow(4)
            self.sitetable1.hideRow(5)
            self.sitetable1.hideRow(6)
            self.sitetable1.hideRow(7)
            self.sitetable1.hideRow(9)

        # Quantity
        if (op == "Fertilizer-N"):
            print("Debug inside fertilizer-N")
            self.sitetable1.showRow(2)
            self.sitetable1.showRow(8)
        else:
            self.sitetable1.hideRow(2)
            self.sitetable1.hideRow(8)

        self.sitetable1.showRow(11)
        self.savebutton1.clicked.connect(self.on_savebutton_operation_clicked)
        self.sitetable1.resizeColumnsToContents()
        self.sitetable1.resizeRowsToContents()
        self.sitetable1.setShowGrid(False)

    def on_savebutton_operation_clicked(self, value):
        #print("Inside save operation")
        #print("value=",value)
        #print("treatment=", self.treatmentname)
        #print("experiment=", self.experimentname)
        #print("cropment=", self.cropname)
        op_id = self.record[0]
        #print("operation_id=",op_id)

        op = self.record[1]
        #print("operation=",op)

        print("record save=", self.record)
        # Quantity
        if (op == "Fertilizer-N"):
            if (self.quantitylabeledit.text() != ""):
                self.record[6] = float(self.quantitylabeledit.text())
            else:
                messageUser("Quantity should be a number.")

            if (self.fDepthlabeledit.text() != ""):
                self.record[19] = float(self.fDepthlabeledit.text())
            else:
                messageUser("Fertilizer Depth should be a number.")

        if (op == "Initial Field Values"):
            print("cultivar= ", self.combocropvariety.currentText())
            self.record[10] = float(self.poplabeledit.text())
            self.record[14] = float(self.yseedlabeledit.text())
            self.record[17] = float(self.rowspacinglabeledit.text())
            self.record[18] = self.combocropvariety.currentText()
            self.record[20] = float(self.seedMasslabeledit.text())
            # Validate row spacing
            if (self.record[17] < 1 or self.record[17] > 200):
                messageUser(
                    "Row spacing should be a value between 1 and 200 cm.")
                return False
            if self.cropname == "corn":
                # Validate plant density
                if (self.record[10] < 1 or self.record[10] > 20):
                    messageUser(
                        "Plant density for corn should be a value between 1 and 20 number of plants/m2."
                    )
                    return False
                # Validate seed depth
                if (self.record[14] < 2 or self.record[14] > 7):
                    messageUser(
                        "Seed depth for corn should be a value between 2 and 7 cm."
                    )
                    return False
            elif self.cropname == "potato":
                # Validate plant density
                if (self.record[10] < 1 or self.record[10] > 300):
                    messageUser(
                        "Plant density for potato should be a value between 1 and 25 number of plants/m2."
                    )
                    return False
                # Validate seed depth
                if (self.record[14] < 1 or self.record[14] > 20):
                    messageUser(
                        "Seed depth for potato should be a value between 1 and 20 cm."
                    )
                    return False
                # Validate seedpiece mass
                if (self.record[20] < 0 or self.record[20] > 50):
                    messageUser(
                        "Seedpiece mass for potato should be a value between 0 and 50 g."
                    )
                    return False
            if (self.comboeomult.currentText() == "Left"):
                self.record[16] = 0.5
            if (self.comboeomult.currentText() == "Middle"):
                self.record[16] = 1.0
            if (self.comboAutoIrrig.currentText() == "Yes"):
                self.record[11] = 1
            if (self.comboAutoIrrig.currentText() == "No"):
                self.record[11] = 0
            new_record = self.record[1:]
        else:
            new_record = self.record[1:]
            new_date = self.calendar.date().toString("MM/dd/yyyy")
            print("new date= ", new_date)
            new_record[6] = new_date

        print("record before save=", self.record)
        status = check_and_update_operationDB(op_id, self.treatmentname,
                                              self.experimentname,
                                              self.cropname, new_record)

        if status:
            self.udialog.setText("Success")
            self.sitetable1.setVisible(False)
            self.sig2.emit(1)

    def on_deletebutton_operation_clicked(self, value):
        print("Inside delete operation")
        print("value=", value)
        print("treatment=", self.treatmentname)
        print("experiment=", self.experimentname)
        print("cropment=", self.cropname)
        print("operation =", self.operationname)
        print("record=", self.record)
        op_id = self.record[0]
        print("operation_id=", op_id)

        status = check_and_delete_operationDB(op_id)
        if status:
            self.udialog.setText("Success")
            self.sitetable1.setVisible(False)
            self.sig2.emit(3)
    def initUI(self):

        frame = QFrame()
        # frame.setStyleSheet("background-color: rgb(30, 45, 66);")
        frame.setFrameShape(QFrame.StyledPanel)
        frame.setFrameShadow(QFrame.Raised)
        # frame.setMinimumWidth(430)
        # frame.setFixedHeight(395)
        frame.setStyleSheet("border: none")

        add_employee_button = QLabel(frame)
        add_employee_button.setAlignment(Qt.AlignCenter)
        add_employee_button.setGeometry(QRect(110, 30, 210, 41))
        add_employee_button.setStyleSheet(
            "font: 75 12pt \"MS Shell Dlg 2\";\n"
            "background-color: rgb(30, 45, 66);\n"
            "color: rgb(255, 255, 255);")
        add_employee_button.setText("Add Product Details")

        namelabel = QLabel(frame)
        namelabel.setText("Name")
        namelabel.setGeometry(QRect(70, 100, 47, 13))

        nametextbox = QLineEdit(frame)
        nametextbox.setGeometry(QRect(160, 90, 181, 31))
        nametextbox.setFixedWidth(180)

        categorylabel = QLabel(frame)
        categorylabel.setText("Category")
        categorylabel.setGeometry(QRect(70, 140, 61, 16))

        categorytextbox = QComboBox(frame)
        categorytextbox.setGeometry(QRect(160, 130, 181, 31))
        categorytextbox.setFixedWidth(180)
        categorytextbox.addItems(["Pizza", "Burger"])

        quantitylabel = QLabel(frame)
        quantitylabel.setText("Quantity")
        quantitylabel.setGeometry(QRect(70, 180, 47, 13))

        quantitytextbox = QLineEdit(frame)
        quantitytextbox.setGeometry(QRect(160, 170, 181, 31))
        quantitytextbox.setFixedWidth(180)

        pricelabel = QLabel(frame)
        pricelabel.setText("Price")
        pricelabel.setGeometry(QRect(70, 220, 47, 13))

        pricetextbox = QLineEdit(frame)
        pricetextbox.setGeometry(QRect(160, 210, 181, 31))
        pricetextbox.setFixedWidth(180)

        sellingpricelabel = QLabel(frame)
        sellingpricelabel.setText("Selling Price")
        sellingpricelabel.setGeometry(QRect(70, 260, 90, 16))

        sellingpricetextbox = QDateEdit(frame)
        sellingpricetextbox.setGeometry(QRect(160, 250, 181, 31))
        sellingpricetextbox.setFixedWidth(180)
        sellingpricetextbox.setDate(QDate.currentDate())
        sellingpricetextbox.setMinimumDate(QDate.currentDate())

        addbutton = QPushButton(frame)
        addbutton.setText("Add Product")
        addbutton.setGeometry(QRect(160, 300, 111, 31))
        addbutton.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";\n"
                                "background-color: rgb(30, 45, 66);\n"
                                "color: rgb(255, 255, 255);")

        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(frame)

        self.setLayout(layout)

        self.setWindowTitle("Add Employee Details")
        self.resize(430, 395)
        self.show()

        self.center()
Example #28
0
    def BillForm(self):
        self.formGroup = QGroupBox("Generate Bill")
        layout = QFormLayout()
        print("clicked")
        submit = QPushButton("Generate")

        submit.clicked.connect(self.increment)

        userName = QLineEdit()
        userName.setValidator(QtGui.QRegExpValidator(QRegExp("[a-z-A-Z_]+")))
        age = QLineEdit()
        age.setValidator(QtGui.QIntValidator(0, 100))

        # sex = QLineEdit()
        # sex.setValidator(QtGui.QRegExpValidator())

        sex = QComboBox()
        sex.addItem("Male")
        sex.addItem("Female")
        regNo = QLineEdit()
        GST = QLineEdit()
        self.medicine_name = QLineEdit()

        completer = QCompleter(self.medicine_names)
        # print(self.getMedicineName())
        self.medicine_name.setCompleter(completer)
        # medicine_name.textChanged.connect()

        qty = QLineEdit()
        qty.setValidator(QtGui.QIntValidator(0, 100))

        expiry_date = QDateEdit()
        expiry_date.setCalendarPopup(True)
        expiry_date.setMinimumDate(QDate.currentDate())

        price = QLineEdit()
        price.setValidator(QtGui.QDoubleValidator())

        bill_pay_by = QLineEdit()

        date = QDateEdit()
        date.setCalendarPopup(True)
        date.setDate(QDate.currentDate())
        discount = QLineEdit()
        discount.setValidator(QtGui.QDoubleValidator())

        layout.addRow(QLabel("Patient Name"), userName)
        layout.addRow(QLabel("Age"), age)
        layout.addRow(QLabel("Sex"), sex)
        layout.addRow(QLabel("Registration Number"), regNo)
        layout.addRow(QLabel("GST No."), GST)
        layout.addRow(QLabel("Medicine Name"), self.medicine_name)

        # layout.addRow(None,self.listwidget)

        layout.addRow(QLabel("Quantity"), qty)
        layout.addRow(QLabel("Expiry Date"), expiry_date)
        layout.addRow(QLabel("Price"), price)
        layout.addRow(QLabel("Bill Pay By"), bill_pay_by)
        layout.addRow(QLabel("Date"), date)
        layout.addRow(QLabel("Discount"), discount)
        layout.addWidget(submit)

        self.formGroup.setLayout(layout)
        return self.formGroup
Example #29
0
class MySpinBox(QGroupBox):
    def __init__(self):
        super().__init__()
        self.setTitle('QSpinBox')
        self.init_ui()

    def init_ui(self):
        layout_group1 = self.group_int_spinbox()
        layout_group2 = self.group_double_spinbox()
        layout_group3 = self.group_date_spinbox()
        layout_group4 = self.group_time_spinbox()
        layout_group5 = self.group_datetime_spinbox()

        layout = QVBoxLayout()
        layout.addLayout(layout_group1)
        layout.addLayout(layout_group2)
        layout.addLayout(layout_group3)
        layout.addLayout(layout_group4)
        layout.addLayout(layout_group5)

        self.setLayout(layout)

    def group_datetime_spinbox(self):
        group2 = QGroupBox('QDateTimeEdit')
        lbl = QLabel('QDateTimeEdit')
        date_time_edit = QDateTimeEdit(self)
        date_time_edit.setDateTime(QDateTime.currentDateTime())
        date_time_edit.setDateTimeRange(QDateTime(1900, 1, 1, 00, 00, 00),
                                        QDateTime(2100, 1, 1, 00, 00, 00))
        date_time_edit.setDisplayFormat('yyyy-MM-dd hh:mm:ss')
        date_time_edit.dateTimeChanged.connect(self.datetime_value_change)
        self.lbl5 = QLabel(
            date_time_edit.dateTime().toString('yyyy-MM-dd hh:mm:ss'))
        layout_group5 = QHBoxLayout()
        layout_group5.addWidget(lbl)
        layout_group5.addWidget(date_time_edit)
        layout_group5.addWidget(self.lbl5)
        return layout_group5

    def group_time_spinbox(self):
        group2 = QGroupBox('QTimeEdit')
        lbl = QLabel('QTimeEdit')
        timeedit = QTimeEdit(self)
        timeedit.setTime(QTime.currentTime())
        timeedit.setTimeRange(QTime(3, 00, 00), QTime(23, 30, 00))
        timeedit.setDisplayFormat('hh:mm:ss')
        timeedit.timeChanged.connect(self.time_value_change)
        # dateedit.setDateRange(QDate(1900, 1, 1), QDate(2100, 12, 31))
        # self.lbl4 = QLabel(QTime.toString(timeedit.dateTime, 'hh:mm:ss'))
        self.lbl4 = QLabel(timeedit.time().toString('hh:mm:ss'))
        layout_group4 = QHBoxLayout()
        layout_group4.addWidget(lbl)
        layout_group4.addWidget(timeedit)
        layout_group4.addWidget(self.lbl4)
        return layout_group4

    def group_date_spinbox(self):
        lbl = QLabel('QDateEdit')
        group2 = QGroupBox('QDateEdit')
        self.dateedit = QDateEdit(self)
        self.dateedit.setDate(QDate.currentDate())
        self.dateedit.setMinimumDate(QDate(1900, 1, 1))
        self.dateedit.setMaximumDate(QDate(2100, 12, 31))
        self.dateedit.setDisplayFormat('yyyy-MM-dd')
        self.dateedit.dateChanged.connect(self.date_value_change)
        # dateedit.setDateRange(QDate(1900, 1, 1), QDate(2100, 12, 31))
        self.lbl3 = QLabel(QDate.toString(self.dateedit.date(), 'yyyy-MM-dd'))
        layout_group3 = QHBoxLayout()
        layout_group3.addWidget(lbl)
        layout_group3.addWidget(self.dateedit)
        layout_group3.addWidget(self.lbl3)
        return layout_group3

    def group_double_spinbox(self):
        group2 = QGroupBox('Double QSpinbox')
        lbl = QLabel('QDoubleSpinBox')
        self.dspinbox = QDoubleSpinBox()
        self.dspinbox.setRange(0, 100)
        self.dspinbox.setSingleStep(0.5)
        self.dspinbox.setPrefix('$ ')
        self.dspinbox.setDecimals(1)
        self.lbl2 = QLabel('$ 0.0')
        self.dspinbox.valueChanged.connect(self.double_value_changed)
        layout_group2 = QHBoxLayout()
        layout_group2.addWidget(lbl)
        layout_group2.addWidget(self.dspinbox)
        layout_group2.addWidget(self.lbl2)
        return layout_group2

    def group_int_spinbox(self):
        group1 = QGroupBox('Integer QSpinBox')
        lbl = QLabel('QSpinBox')
        self.spinbox = QSpinBox()
        self.spinbox.setMinimum(-10)
        self.spinbox.setMaximum(30)
        # self.spinbox.setRange(-10, 30)
        self.spinbox.setSingleStep(2)
        self.lbl1 = QLabel(str(self.spinbox.value()))
        self.spinbox.valueChanged.connect(self.int_value_changed)
        layout_group1 = QHBoxLayout()
        layout_group1.addWidget(lbl)
        layout_group1.addWidget(self.spinbox)
        layout_group1.addWidget(self.lbl1)
        return layout_group1

    def int_value_changed(self):
        self.lbl1.setText(str(self.spinbox.value()))

    def double_value_changed(self):
        self.lbl2.setText(str(self.dspinbox.value()))

    def date_value_change(self, t):
        self.lbl3.setText(QDate.toString(t, 'yyyy-MM-dd'))

    def time_value_change(self, t):
        self.lbl4.setText(t.toString('hh:mm:ss'))

    def datetime_value_change(self, dt):
        self.lbl5.setText(dt.toString('yyyy-MM-dd hh:mm:ss'))
Example #30
0
class HeadWidget(QWidget):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.resize(700, 105)
        self.setMinimumWidth(700)

        # Widgets
        self.work_type = QComboBox(self)
        self.work_type.setToolTip('Тип работы')
        self.work_type.addItems(work_types)
        self.work_type.setSizePolicy(QSizePolicy.MinimumExpanding,
                                     QSizePolicy.Preferred)
        self.lesson = QComboBox(self)
        self.lesson.setToolTip('Урок')
        self.lesson.addItems(school_lessons)
        self.lesson.setSizePolicy(QSizePolicy.MinimumExpanding,
                                  QSizePolicy.Preferred)
        actuality_label = QLabel('Дата начала', self)
        self.actuality = QDateEdit(self)
        self.actuality.setDate(date.today())
        self.actuality.setMinimumDate(date(2017, 9, 1))
        self.actuality.setToolTip('Дата начала')
        deadline_label = QLabel('Дата окончания', self)
        self.deadline = QDateEdit(self)
        self.deadline.setDate(date.today() + timedelta(1))
        self.deadline.setMinimumDate(date.today())
        self.deadline.setToolTip('Дата окончания')
        priority_label = QLabel('Приоритет', self)
        self.priority = QDoubleSpinBox(self)
        # self.priority.setMaximumWidth(80)
        self.priority.setMaximum(1.0)
        self.priority.setSingleStep(0.01)
        self.priority.setValue(0.5)
        self.priority.setToolTip('Приоритет')
        time_label = QLabel('Время выполнения', self)
        self.time = QTimeEdit(self)
        # self.time.setMaximumWidth(80)
        self.time.setDisplayFormat('HH:mm')
        self.time.setToolTip('Время выполнения')
        self.add_button = QPushButton('Добавить', self)
        self.add_button.setToolTip('Добавить в список')

        # Layouts
        actuality_layout = QHBoxLayout()
        actuality_layout.setSizeConstraint(QHBoxLayout.SetFixedSize)
        actuality_layout.addWidget(actuality_label)
        actuality_layout.addWidget(self.actuality)
        deadline_layout = QHBoxLayout()
        deadline_layout.setSizeConstraint(QHBoxLayout.SetFixedSize)
        deadline_layout.addWidget(deadline_label)
        deadline_layout.addWidget(self.deadline)
        priority_layout = QHBoxLayout()
        priority_layout.setSizeConstraint(QHBoxLayout.SetFixedSize)
        priority_layout.addWidget(priority_label)
        priority_layout.addWidget(self.priority)
        time_layout = QHBoxLayout()
        time_layout.setSizeConstraint(QHBoxLayout.SetFixedSize)
        time_layout.addWidget(time_label)
        time_layout.addWidget(self.time)
        layout = QGridLayout(self)
        layout.addWidget(self.lesson, 0, 0)
        layout.addWidget(self.work_type, 1, 0)
        layout.addLayout(actuality_layout, 0, 2)
        layout.addLayout(deadline_layout, 1, 2)
        layout.addLayout(time_layout, 0, 3)
        layout.addLayout(priority_layout, 1, 3)
        layout.addWidget(self.add_button, 2, 3)

        # Tab order
        self.setTabOrder(self.lesson, self.work_type)
        self.setTabOrder(self.work_type, self.actuality)
        self.setTabOrder(self.actuality, self.deadline)
        self.setTabOrder(self.deadline, self.time)
        self.setTabOrder(self.time, self.priority)
        self.setTabOrder(self.priority, self.add_button)