Exemple #1
0
class MainWindow(QMainWindow):

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

        self.image_extension = ['png', 'jpg']
        self.species_list = ['proso_millet', 'green_gram', 'perilla', 'peanut',
                             'great_millet', 'corn', 'foxtail_millet', 'sesame', 'bean', 'red_bean']
        self.degree_list = ['0', '45', '90']
        self.setting_options = ['ip', 'user', 'path', 'name']
        self.selected_species = self.species_list[0]
        self.selected_degree = self.degree_list[0]
        self.settings = dict()
        self.image_path = None

        self.initUI()

    def initUI(self):
        self.setWindowTitle('Plants Image Uploader')
        self.setWindowIcon(QIcon('res/leaf.png'))

        openFile = QAction(QIcon('res/folder.png'), 'select folder', self)
        # openFile.setShortcut('Ctrl+O')
        openFile.triggered.connect(self.show_dialog)

        openInfo = QAction(QIcon('res/info.png'), 'Info', self)
        openInfo.triggered.connect(self.show_info)
        
        openclassdetail = QAction(QIcon('res/info.png'), 'classes_detail', self)
        openclassdetail.triggered.connect(self.show_class_detail)

        openStatus = QAction(QIcon('res/info.png'), 'Status', self)
        openStatus.triggered.connect(self.show_status)

        menubar = self.menuBar()
        menubar.setStyleSheet("background-color: rgb(230,230,230)")
        menubar.setNativeMenuBar(False)
        filemenu = menubar.addMenu('&File')
        filemenu.addAction(openFile)

        infomenu = menubar.addMenu('&Info')
        infomenu.addAction(openInfo)
        infomenu.addAction(openStatus)
        infomenu.addAction(openclassdetail)

        self.label1 = QLabel('Selected path :', self)
        self.label1.move(10, 50)
        self.label2 = QLabel('', self)
        self.label2.move(100, 50)
        self.label2.resize(self.frameGeometry().width() - self.label1.frameGeometry().width(), self.label1.frameGeometry().height())

        self.species = QComboBox(self)
        self.species.move(10, 80)
        self.species.resize(100, 23)
        [self.species.addItem(sp) for sp in self.species_list]
        self.species.activated[str].connect(self.on_activated_species)

        self.degrees = QComboBox(self)
        self.degrees.move(self.species.frameGeometry().width() + 15, 80)
        self.degrees.resize(100, 23)
        [self.degrees.addItem(de) for de in self.degree_list]
        self.degrees.activated[str].connect(self.on_activated_degree)

        self.btn = QPushButton('upload', self)
        self.btn.resize(50, 23)
        self.btn.move(self.species.frameGeometry().width() + self.degrees.frameGeometry().width() + 25, 80)
        self.btn.clicked.connect(self.upload_clicked)

        self.statusBar().setStyleSheet("border-width: 1px;border-top-style : solid;border-color : lightgray;margin : 2px")
        self.statusBar().showMessage('Ready')

        self.progressbar = QProgressBar()
        self.progressbar.setMinimum(0)
        self.progressbar.setMaximum(100)
        self.progressbar.setAlignment(Qt.AlignCenter)
        self.statusBar().addPermanentWidget(self.progressbar)

        # load setting.
        if self.load_setting():

            # setup uploader name.
            self.label0 = QLabel(f'{self.settings["name"].upper()}', self)
            self.label0.move(10, 20)
            font0 = self.label0.font()
            font0.setBold(True)
            font0.setPointSize(12)
            self.label0.setFont(font0)
            self.label0.resize(self.frameGeometry().width(), self.label0.frameGeometry().height())

            # setup ui.
            self.move(300, 300)
            self.resize(600, 134)
            self.setFixedSize(600, 134)
            self.show()

            mes = '[IMPORTANT]\n"setup.bin" 파일을 텍스트 에디터로 열어서 알맞게 수정해주세요.\n\n1. 특정 각도, 한 종류의 식물 사진을 특정 디렉터리로 옮깁니다.\n2. "File - select folder"를 클릭해서 사진이 있는 디렉터리를 선택합니다.\n3. 하단의 식물 종류와 각도를 선택하고 upload를 누릅니다.'
            mes_en = '[IMPORTANT]\nPlease open the "setup.bin" file as a text editor and modify it accordingly.\n\n1. Move a picture of a particular angle, one type of plant, to a particular directory.\n2. Click "File - select folder" to select the directory where the pictures are located.\n3. Select the plant type and angle at the bottom and press upload.'
            self.show_message('Instruction', mes + '\n\n' + mes_en, False)

        else:
            self.show_message('Warning', 'There is a problem with the setup.bin file.\nCheck this file and run again.', True)

    def on_activated_species(self, item):
        self.selected_species = item
        print(item)

    def on_activated_degree(self, item):
        self.selected_degree = item
        print(item)

    def load_setting(self):
        setting_path = './setup.bin'
        if os.path.exists(setting_path):
            f = open(setting_path, 'r')
            settings = f.readlines()
            for item in settings:
                if not item.startswith('//') and '=' in item:
                    setup = list(map(str.strip, item.replace('\n', '').split('=')))
                    self.settings[setup[0]] = setup[1]

            f.close()
            return True
        return False

    def upload_clicked(self):
        if self.image_path:
            print('uploading...')

            # return False or filtered file names.
            filtered = self.is_files_exists()
            if filtered:
                print('start uploading..')
                reply = QMessageBox.question(self,
                                             'Check',
                                             f'Please Check information.\n\n1.Name: {self.settings["name"]}\n2.Species: {self.selected_species}\n3.Degree: {self.selected_degree}',
                                             QMessageBox.Yes | QMessageBox.No, QMessageBox.No)

                if reply == QMessageBox.Yes:
                    print('processing....')
                    # upload pictures.
                    self.upload_images(filtered)

                else:
                    print('canceled.')
        else:
            self.show_message('Path Alert', 'Please select the folder first.', False)

    def show_status(self):
        msg = SearchingStatusDialog(self.settings, self.species_list)
        msg.show()
        msg.exec_()

    def show_info(self):
        msgbox = QMessageBox()
        msgbox.setWindowIcon(QIcon('res/info.png'))
        msgbox.setText('Plants data uploader (1.0.3)\n\nIf it\'s useful, put a tip on Jong Hyeok\'s desk... \n(I just love doing lots of homework on Saturdays~****)')
        msgbox.show()
        msgbox.exec_()
    ###########
    def show_class_detail(self):
        msgbox = QMessageBox()
        msgbox.setWindowIcon(QIcon('res/info.png'))
        msgbox.setText(tabulate(np.ndarray.tolist(result), headers = header, tablefmt="youtrack"))
        msgbox.show()
        msgbox.exec_()
    ########
    def show_dialog(self):
        get_path = QFileDialog.getExistingDirectory(self, 'select target folder', './')
        if get_path:
            self.image_path = get_path
            self.statusBar().showMessage(f'Path loaded', 3000)
            self.label2.setText(f'{self.image_path}')
            self.update()

    def is_files_exists(self):
        item_list = os.listdir(self.image_path)
        if len(item_list) > 0:
            filtered = [i for i in item_list if len(i.split('.')) == 2 and i.split('.')[1].lower() in self.image_extension]
            if len(filtered) > 0:
                return filtered
            else:
                # miss match extension recognized.
                self.show_message('Message', 'This program only support (*png, *jpg) extensions.\nImage file not found.', False)

        elif len(item_list) == 0:
            # no file.
            self.show_message('Message', 'Image files not exist in this path.', False)

        return False

    def show_message(self, title, text, exit_sys):
        msg_box = QMessageBox()
        msg_box.setWindowTitle(title)
        msg_box.setWindowIcon(QIcon('res/info.png'))
        msg_box.setText(text)
        msg_box.show()
        msg_box.exec_()
        if exit_sys:
            sys.exit()

    def upload_images(self, filtered_list):
        self.f = open(f"./log/log_{str(int(datetime.now().timestamp() * 1000))}.txt", 'w')
        try:
            try:
                # set ftp.
                ftp = FTP()
                ftp.connect(self.settings['ip'], 21)
                ftp.login(self.settings['user'], self.settings['pass'])
                ftp.encoding = 'cp949'
                ftp.cwd(self.settings['target_path'] + self.selected_species + '/images')
            except Exception as e:
                self.statusBar().showMessage('Upload Error : Connection Failed', 5000)
                self.show_message('Warning', 'Server Connection Failed', False)
                self.f.write('Server Connection Failed\n')
                self.f.write(str(e))
                self.f.close()

                return

            for idx, i_name in enumerate(filtered_list):
                m_path = self.image_path + '/' + i_name
                img = Image.open(m_path)
                try:
                    meta_date = img._getexif()[36867].split()[0].replace(':', '-')
                except:
                    meta_date = '0000-00-00'
                time_mark = str(int(datetime.now().timestamp() * 1000))

                final_file_name = meta_date + '_' + \
                                  self.settings['name'] + '_' + \
                                  self.selected_species + '_' + \
                                  self.selected_degree + '_' + time_mark + '.' + i_name.split('.')[1]

                self.statusBar().showMessage(f'Uploading: {i_name}')
                self.progressbar.setValue(idx * 100 // (len(filtered_list) - 1))
                print(final_file_name)

                # upload images.

                try:
                    m_image = open(m_path, 'rb')
                    ftp.storbinary('STOR ' + final_file_name, m_image)
                    self.f.write(f'[Success] {m_path},{final_file_name}\n')
                except:
                    self.statusBar().showMessage('Upload Error : target_name')
                    self.f.write(f'[Fail] {m_path},{final_file_name}\n')
                # upload end.

            if ftp:
                ftp.close()

        except Exception as eall:
            self.f.write('[Upload Failed]\n')
            self.f.write(str(eall))
            self.f.close()

        self.f.close()
        self.statusBar().showMessage('Finish', 5000)
        self.progressbar.reset()
        self.show_message('Finish', 'Upload finished!', False)
Exemple #2
0
class mainwindow(QWidget):
    def __init__(self, username, dataoptions, driver, semesters):
        self.username = username
        self.dataoptions = dataoptions
        self.driver = driver
        self.semesters = semesters
        self.subThread = submitThread(self)
        self.subThread.finished.connect(self.completed)
        super().__init__()

        self.initUI()

    def initUI(self):
        self.center()

        #add the data type label and C C C combobox
        self.datatypelabel = QLabel(self)
        self.datatypelabel.setText("Data Pull Type")
        self.datatypelabel.setAlignment(Qt.AlignCenter)

        self.datacombo = QComboBox(self)
        #Sorted by alphabet
        self.datacombo.addItems(sorted(self.dataoptions.keys()))
        self.datacombo.currentTextChanged.connect(self.combochange)

        #add the filter label
        self.filterlabel = QLabel(self)
        self.filterlabel.setText('Filters')
        self.filterlabel.setAlignment(Qt.AlignCenter)

        #add all of the other filter things
        self.usernamelabel = QLabel(self)
        self.usernamelabel.setText("Created By: ")

        self.usernamecombo = QComboBox(self)

        self.assignedlabel = QLabel(self)
        self.assignedlabel.setText("Assigned To: ")

        self.assignedcombo = QComboBox(self)

        self.locationlabel = QLabel(self)
        self.locationlabel.setText("Location: ")

        self.locationcombo = QComboBox(self)

        self.categorylabel = QLabel(self)
        self.categorylabel.setText("Category: ")

        self.categorycombo = QComboBox(self)
        self.statuslabels = QLabel(self)
        self.statuslabels.setText("Status: ")

        self.statuscombo = QComboBox(self)

        #add the startdate and end date calendars
        self.startcal = QCalendarWidget(self)
        self.startcal.setSelectedDate(date.today() - timedelta(days=30))
        self.startcal.setVerticalHeaderFormat(QCalendarWidget.NoVerticalHeader)
        self.startcal.setGridVisible(True)
        self.startcal.clicked.connect(self.startdatechange)

        self.startlabel = QLabel(self)
        self.startlabel.setText("Start Date: " +
                                self.startcal.selectedDate().toString())

        self.startdroplabel = QLabel(self)
        self.startdroplabel.setText('Autoselect start of :  ')
        self.startdroplabel.setObjectName('desctext')

        self.startcombo = QComboBox(self)
        self.startcombo.addItems(self.semesters.keys())
        self.startcombo.currentTextChanged.connect(self.startcomboselect)

        self.endcal = QCalendarWidget(self)
        self.endcal.setSelectedDate(date.today())
        self.endcal.setVerticalHeaderFormat(QCalendarWidget.NoVerticalHeader)
        self.endcal.setGridVisible(True)
        self.endcal.clicked.connect(self.enddatechange)

        self.endlabel = QLabel(self)
        self.endlabel.setText("End Date: " +
                              self.endcal.selectedDate().toString())

        self.enddroplabel = QLabel(self)
        self.enddroplabel.setText('Autoselect end of :  ')
        self.enddroplabel.setObjectName('desctext')

        self.endcombo = QComboBox(self)
        self.endcombo.addItems(self.semesters.keys())
        self.endcombo.currentTextChanged.connect(self.endcomboselect)

        #create the maxreturns things
        self.maxlabel = QLabel(self)
        self.maxlabel.setText("Max Returns: ")
        self.maxlabel.hide()

        self.maxbox = QLineEdit(self)
        self.maxbox.setText('10000000')
        self.maxbox.hide()

        #add close button
        self.closebutton = QPushButton('Close', self)
        self.closebutton.clicked.connect(self.close)

        #add submit button
        self.submitbutton = QPushButton('Submit', self)
        self.submitbutton.clicked.connect(self.subThread.start)

        self.tabs = QTabWidget()

        #everything for the data pull tab
        self.datapulltab = QWidget()

        datatypelabhbox = QHBoxLayout()
        datatypelabhbox.addWidget(self.datatypelabel)

        datatypehbox = QHBoxLayout()
        datatypehbox.addWidget(self.datacombo)

        filternamehbox = QHBoxLayout()
        filternamehbox.addWidget(self.filterlabel)

        usernamehbox = QHBoxLayout()
        usernamehbox.addWidget(self.usernamelabel)

        assignedhbox = QHBoxLayout()
        assignedhbox.addWidget(self.assignedlabel)

        locationhbox = QHBoxLayout()
        locationhbox.addWidget(self.locationlabel)

        categoryhbox = QHBoxLayout()
        categoryhbox.addWidget(self.categorylabel)

        statushbox = QHBoxLayout()
        statushbox.addWidget(self.statuslabels)

        dataselectlayout = QVBoxLayout()
        dataselectlayout.addLayout(datatypelabhbox)
        dataselectlayout.addLayout(datatypehbox)
        verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum,
                                     QSizePolicy.Expanding)
        dataselectlayout.addSpacerItem(verticalSpacer)
        dataselectlayout.addLayout(filternamehbox)
        dataselectlayout.addLayout(usernamehbox)
        dataselectlayout.addWidget(self.usernamecombo)
        dataselectlayout.addLayout(assignedhbox)
        dataselectlayout.addWidget(self.assignedcombo)
        dataselectlayout.addLayout(locationhbox)
        dataselectlayout.addWidget(self.locationcombo)
        dataselectlayout.addLayout(categoryhbox)
        dataselectlayout.addWidget(self.categorycombo)
        dataselectlayout.addLayout(statushbox)
        dataselectlayout.addWidget(self.statuscombo)
        dataselectlayout.setSpacing(3)
        dataselectlayout.addStretch(1)

        startdrophlayout = QHBoxLayout()
        startdrophlayout.addWidget(self.startdroplabel)
        startdrophlayout.addWidget(self.startcombo)
        startdrophlayout.setSpacing(0)
        startdrophlayout.addStretch(0)

        enddropylayout = QHBoxLayout()
        enddropylayout.addWidget(self.enddroplabel)
        enddropylayout.addWidget(self.endcombo)
        enddropylayout.setSpacing(0)
        enddropylayout.addStretch(0)

        calendarlayout = QVBoxLayout()
        calendarlayout.addWidget(self.startlabel)
        calendarlayout.addLayout(startdrophlayout)
        calendarlayout.addWidget(self.startcal)
        calendarlayout.addSpacing(10)
        calendarlayout.addWidget(self.endlabel)
        calendarlayout.addLayout(enddropylayout)
        calendarlayout.addWidget(self.endcal)
        calendarlayout.setSpacing(3)
        calendarlayout.addStretch(1)

        datapullhlayout = QHBoxLayout()
        datapullhlayout.addLayout(dataselectlayout)
        datapullhlayout.addSpacing(10)
        datapullhlayout.addLayout(calendarlayout)

        datapullvlayout = QVBoxLayout()
        datapullvlayout.addSpacing(15)
        datapullvlayout.addLayout(datapullhlayout)

        self.datapulltab.setLayout(datapullvlayout)

        #Report things?

        self.reporttab = QWidget()

        self.startrepcal = QCalendarWidget(self)
        self.startrepcal.setSelectedDate(date.today() - timedelta(days=30))
        self.startrepcal.setVerticalHeaderFormat(
            QCalendarWidget.NoVerticalHeader)
        self.startrepcal.setGridVisible(True)
        self.startrepcal.clicked.connect(self.startrepdatechange)

        self.startreplabel = QLabel(self)
        self.startreplabel.setText("Start Date: " +
                                   self.startrepcal.selectedDate().toString())

        self.endrepcal = QCalendarWidget(self)
        self.endrepcal.setSelectedDate(date.today())
        self.endrepcal.setVerticalHeaderFormat(
            QCalendarWidget.NoVerticalHeader)
        self.endrepcal.setGridVisible(True)
        self.endrepcal.clicked.connect(self.endrepdatechange)

        self.endreplabel = QLabel(self)
        self.endreplabel.setText("End Date: " +
                                 self.endrepcal.selectedDate().toString())

        self.reporttypelabel = QLabel(self)
        self.reporttypelabel.setText('Report Type')
        self.reporttypelabel.setAlignment(Qt.AlignCenter)

        self.reportdrop = QComboBox(self)
        self.reportdrop.addItems([x.name for x in report.report_list])
        self.reportdrop.currentTextChanged.connect(self.reportcombochange)

        self.reportactivelabel = QLabel(self)
        self.reportactivelabel.setText("Active")

        self.reportactive = QLabel(self)
        self.reportactive.setText("")
        self.reportactive.setObjectName('desctext')

        self.reportauthorlabel = QLabel(self)
        self.reportauthorlabel.setText("Author")

        self.reportauthor = QLabel(self)
        self.reportauthor.setText("")
        self.reportauthor.setObjectName('desctext')

        self.reportdesclabel = QLabel(self)
        self.reportdesclabel.setText("Report Description")

        self.descbox = QLabel(self)
        self.descbox.setText("")
        self.descbox.setWordWrap(True)
        self.descbox.setFixedWidth(self.usernamecombo.frameGeometry().width() +
                                   53)
        self.descbox.setObjectName('desctext')

        self.startrepdroplabel = QLabel(self)
        self.startrepdroplabel.setObjectName('desctext')
        self.startrepdroplabel.setText('Autoselect start of :  ')

        self.startrepcombo = QComboBox(self)
        self.startrepcombo.addItems(self.semesters.keys())
        self.startrepcombo.currentTextChanged.connect(self.startrepcomboselect)

        self.enddropreplabel = QLabel(self)
        self.enddropreplabel.setText('Autoselect end of :  ')
        self.enddropreplabel.setObjectName('desctext')

        self.endrepcombo = QComboBox(self)
        self.endrepcombo.addItems(self.semesters.keys())
        self.endrepcombo.currentTextChanged.connect(self.endrepcomboselect)

        newreportlayout = QVBoxLayout()

        newreportlayout.addWidget(self.reporttypelabel)
        newreportlayout.addWidget(self.reportdrop)
        verticalSpacernew = QSpacerItem(10, 20, QSizePolicy.Minimum,
                                        QSizePolicy.Expanding)
        newreportlayout.addSpacerItem(verticalSpacernew)
        newreportlayout.addWidget(self.reportauthorlabel)
        newreportlayout.addWidget(self.reportauthor)
        verticalSpacernewest = QSpacerItem(10, 20, QSizePolicy.Minimum,
                                           QSizePolicy.Expanding)
        newreportlayout.addSpacerItem(verticalSpacernewest)
        newreportlayout.addWidget(self.reportactivelabel)
        newreportlayout.addWidget(self.reportactive)
        verticalSpacernewer = QSpacerItem(10, 20, QSizePolicy.Minimum,
                                          QSizePolicy.Expanding)
        newreportlayout.addSpacerItem(verticalSpacernewer)
        newreportlayout.addWidget(self.reportdesclabel)
        newreportlayout.addWidget(self.descbox)
        newreportlayout.setSpacing(3)
        newreportlayout.addStretch(1)

        startrepdrophlayout = QHBoxLayout()
        startrepdrophlayout.addWidget(self.startrepdroplabel)
        startrepdrophlayout.addWidget(self.startrepcombo)
        startrepdrophlayout.setSpacing(0)
        startrepdrophlayout.addStretch(0)

        endrepdropylayout = QHBoxLayout()
        endrepdropylayout.addWidget(self.enddropreplabel)
        endrepdropylayout.addWidget(self.endrepcombo)
        endrepdropylayout.setSpacing(0)
        endrepdropylayout.addStretch(0)

        repcallayout = QVBoxLayout()
        repcallayout.addWidget(self.startreplabel)
        repcallayout.addLayout(startrepdrophlayout)
        repcallayout.addWidget(self.startrepcal)
        repcallayout.addSpacing(10)
        repcallayout.addWidget(self.endreplabel)
        repcallayout.addLayout(endrepdropylayout)
        repcallayout.addWidget(self.endrepcal)
        repcallayout.setSpacing(3)
        repcallayout.addStretch(1)

        reportouterlayout = QHBoxLayout()
        reportouterlayout.addLayout(newreportlayout)
        reportouterlayout.addSpacing(10)
        reportouterlayout.addLayout(repcallayout)

        reportouterlayoutout = QVBoxLayout()
        reportouterlayoutout.addSpacing(15)
        reportouterlayoutout.addLayout(reportouterlayout)
        self.reporttab.setLayout(reportouterlayoutout)

        self.tabs.addTab(self.datapulltab, "Data Pull")
        self.tabs.addTab(self.reporttab, "Reporting")

        buttonlayout = QHBoxLayout()
        buttonlayout.addWidget(self.closebutton)
        buttonlayout.addWidget(self.submitbutton)

        self.statuslabel = QLabel(self)
        self.statuslabel.setText("Ready")
        self.statuslabel.setObjectName('statuslabel')
        self.statuslabel.setAlignment(Qt.AlignRight)

        outerlayout = QVBoxLayout()
        outerlayout.addWidget(self.tabs)
        outerlayout.addSpacing(15)
        outerlayout.addLayout(buttonlayout)
        outerlayout.addWidget(self.statuslabel)
        self.setLayout(outerlayout)

        self.current_report = False
        self.dframe = False

        self.reportcombochange()
        self.combochange()
        self.setWindowTitle('PIEthon: logged in as ' + self.username)
        self.setWindowIcon(
            QIcon(functions.resource_path('resources\\PIEcon.png')))

        #style things
        self.setStyleSheet(
            open(functions.resource_path("resources\\iu_stylesheet.qss"),
                 "r").read())
        self.show()

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

    def statusUpdate(self, newstat):
        #print('in status update')
        self.statuslabel.setText(newstat)
        QCoreApplication.processEvents()

    def startdatechange(self):
        self.startcombo.setCurrentIndex(0)
        self.startlabel.setText("Start Date:  " +
                                self.startcal.selectedDate().toString())
        self.startreplabel.setText("Start Date:  " +
                                   self.startcal.selectedDate().toString())
        self.startrepcal.setSelectedDate(self.startcal.selectedDate())

    def enddatechange(self):
        self.endcombo.setCurrentIndex(0)
        self.endlabel.setText("End Date:  " +
                              self.endcal.selectedDate().toString())
        self.endreplabel.setText("End Date:  " +
                                 self.endcal.selectedDate().toString())
        self.endrepcal.setSelectedDate(self.endcal.selectedDate())

    def startrepdatechange(self):
        self.startrepcombo.setCurrentIndex(0)
        self.startreplabel.setText("Start Date:  " +
                                   self.startrepcal.selectedDate().toString())
        self.startlabel.setText("Start Date:  " +
                                self.startrepcal.selectedDate().toString())
        self.startcal.setSelectedDate(self.startrepcal.selectedDate())

    def endrepdatechange(self):
        self.endrepcombo.setCurrentIndex(0)
        self.endreplabel.setText("End Date:  " +
                                 self.endrepcal.selectedDate().toString())
        self.endlabel.setText("End Date:  " +
                              self.endrepcal.selectedDate().toString())
        self.endcal.setSelectedDate(self.endrepcal.selectedDate())

    def startcomboselect(self):
        self.startrepcombo.setCurrentIndex(self.startcombo.currentIndex())
        conv = self.semesters[self.startcombo.currentText()].getStart()
        if conv == '':
            return
        self.startlabel.setText("Start Date:  " + conv.strftime('%a %b %d %Y'))
        self.startreplabel.setText("Start Date:  " +
                                   conv.strftime('%a %b %d %Y'))
        self.startcal.setSelectedDate(conv)
        self.startrepcal.setSelectedDate(conv)

    def endcomboselect(self):
        self.endrepcombo.setCurrentIndex(self.endcombo.currentIndex())
        conv = self.semesters[self.endcombo.currentText()].getEnd()
        if conv == '':
            return
        self.endlabel.setText("End Date:  " + conv.strftime('%a %b %d %Y'))
        self.endreplabel.setText("End Date:  " + conv.strftime('%a %b %d %Y'))
        self.endcal.setSelectedDate(conv)
        self.endrepcal.setSelectedDate(conv)

    def startrepcomboselect(self):
        self.startcombo.setCurrentIndex(self.startrepcombo.currentIndex())
        conv = self.semesters[self.startrepcombo.currentText()].getStart()
        if conv == '':
            return
        self.startreplabel.setText("Start Date:  " +
                                   conv.strftime('%a %b %d %Y'))
        self.startlabel.setText("Start Date:  " + conv.strftime('%a %b %d %Y'))
        self.startrepcal.setSelectedDate(conv)
        self.startcal.setSelectedDate(conv)

    def endrepcomboselect(self):
        self.endcombo.setCurrentIndex(self.endrepcombo.currentIndex())
        conv = self.semesters[self.endrepcombo.currentText()].getEnd()
        if conv == '':
            return
        self.endreplabel.setText("End Date:  " + conv.strftime('%a %b %d %Y'))
        self.endlabel.setText("End Date:  " + conv.strftime('%a %b %d %Y'))
        self.endrepcal.setSelectedDate(conv)
        self.endcal.setSelectedDate(conv)

    def reportcombochange(self):
        self.current_report = report.report_list[
            self.reportdrop.currentIndex()]
        self.descbox.setText(self.current_report.description)
        self.reportactive.setText(str(self.current_report.active))
        self.reportauthor.setText(str(self.current_report.author))

    def combochange(self):
        datatype = self.dataoptions.get(self.datacombo.currentText())

        if (datatype is None):
            return

        if (len(datatype.createdbyDict) > 1):
            self.usernamecombo.clear()
            self.usernamecombo.addItems(datatype.createdbyDict.keys())
            self.usernamecombo.setEnabled(True)
            if datatype.createdbyPost:
                self.usernamelabel.setText("Created By (POST): ")
            else:
                self.usernamelabel.setText("Created By: ")
        else:
            self.usernamelabel.setText("Created By: ")
            self.usernamecombo.clear()
            self.usernamecombo.setEnabled(False)

        if (len(datatype.locationDict) > 1):
            self.locationcombo.clear()
            self.locationcombo.addItems(datatype.locationDict.keys())
            self.locationcombo.setEnabled(True)
            if datatype.locationPost:
                self.locationlabel.setText("Location (POST): ")
            else:
                self.locationlabel.setText("Location: ")
        else:
            self.locationlabel.setText("Location: ")
            self.locationcombo.clear()
            self.locationcombo.setEnabled(False)

        if (len(datatype.statusDict) > 1):
            self.statuscombo.clear()
            self.statuscombo.addItems(datatype.statusDict)
            self.statuscombo.setEnabled(True)
            if datatype.statusPost:
                self.statuslabels.setText("Status (POST):")
            else:
                self.statuslabels.setText("Status:")
        else:
            self.statuslabels.setText("Status:")
            self.statuscombo.clear()
            self.statuscombo.setEnabled(False)

        if (len(datatype.categoryDict) > 1):
            self.categorycombo.clear()
            self.categorycombo.addItems(datatype.categoryDict.keys())
            self.categorycombo.setEnabled(True)
            if datatype.categoryPost:
                self.categorylabel.setText("Category (POST):")
            else:
                self.categorylabel.setText("Category:")
        else:
            self.categorylabel.setText("Category:")
            self.categorycombo.clear()
            self.categorycombo.setEnabled(False)

        if (len(datatype.assignedToDict) > 1):
            self.assignedcombo.clear()
            self.assignedcombo.addItems(datatype.assignedToDict.keys())
            self.assignedcombo.setEnabled(True)
            if datatype.assignedToPost:
                self.assignedlabel.setText("Assigned To (POST):")
            else:
                self.assignedlabel.setText("Assigned To:")
        else:
            self.assignedlabel.setText("Assigned To:")
            self.assignedcombo.clear()
            self.assignedcombo.setEnabled(False)

        self.endcal.setEnabled(datatype.allowDates)
        self.startcal.setEnabled(datatype.allowDates)
        self.startcombo.setEnabled(datatype.allowDates)
        self.endcombo.setEnabled(datatype.allowDates)

    def completed(self):
        self.statusUpdate('Ready')
        self.current_report.reset()
        if self.datecheck() or self.dframe is False:
            return
        if (self.tabs.currentIndex() == 0):
            self.mainwind = previewGui.preview(
                self.dframe, self.datacombo.currentText(),
                self.startcal.selectedDate().toPyDate(),
                self.endcal.selectedDate().toPyDate())
            self.mainwind.show()
        self.dframe = False
        self.dataoptions.get(self.datacombo.currentText()).reset()
        self.current_report.reset()
        self.statusUpdate('Ready')

    def datecheck(self):
        return ((self.startcal.selectedDate().daysTo(
            self.endcal.selectedDate()) < 0)
                or (self.startrepcal.selectedDate().daysTo(
                    self.endrepcal.selectedDate()) < 0))