コード例 #1
0
def main():
    a = QApplication(sys.argv)

    splash_img = QPixmap('splash-600.png')
    splash = QSplashScreen(splash_img, QtCore.Qt.WindowStaysOnTopHint)
    splash.show()
    time.sleep(3)
    splash.hide()
    app = MainGui()
    app.show()


    sys.exit(a.exec_())
コード例 #2
0
ファイル: pyc_main.py プロジェクト: xavrb/pycosts
def main():
    app = QApplication(sys.argv)

    splash_pix = QPixmap("./assets/splash_loading.png")
    splash = QSplashScreen(splash_pix)
    splash.show()
    app.processEvents()

    # Simulate something that takes time
    time.sleep(2)
    splash.hide()
    main_window = MainWindow()
    main_window.show()
    sys.exit(app.exec_())
コード例 #3
0
ファイル: run.py プロジェクト: ChrisK91/MultiColoc
def main():
    """
    Executes the application
    """

    APP = QApplication(sys.argv)
    splash = QSplashScreen(QPixmap('files/splash.png'))
    splash.show()

    from gui.multicolocmw import MultiColocMW
    MW = MultiColocMW()
    MW.show()
    splash.hide()
    sys.exit(APP.exec_())
コード例 #4
0
class Window(QMainWindow):
    def __init__(self):
        super().__init__()

        self.window = QtWidgets.QMainWindow()
        self.PosUi = Ui_PosWindow()
        self.LicenceUi = Ui_LicenceWindow()


        self.splash = QSplashScreen(QPixmap('pos.jpg'))

        if not (path.exists(system_path)):
            os.makedirs(system_path)
            os.makedirs(db_path)
            initDB()
            initDBTables()
            if not (path.exists(system_path + "config.INI")):
                config['DEFAULT']['user_id'] = ''  # create
                config['DEFAULT']['token'] = ''
                config['DEFAULT']['login_status'] = "False"
                status = "False"
                with open(system_path + "config.INI", "w") as configFile:
                    config.write(configFile)
        else:
            config.read(system_path + 'config.INI')
            print("Status: " + str(config['DEFAULT']['login_status']))

        self.splash.show()
        QTimer.singleShot(5000, self.navigate)

    def navigate(self):
        if status == "False" or str(config['DEFAULT']['login_status']) == "False":
            self.window = QtWidgets.QMainWindow()
            self.LicenceUi = Ui_LicenceWindow()
            self.LicenceUi.setupUi(self.window)
            self.window.show()
            self.splash.hide()
        else:
            self.window = QtWidgets.QMainWindow()
            self.PosUi = Ui_PosWindow()
            self.PosUi.setupUi(self.window)
            self.window.show()
            self.splash.hide()
コード例 #5
0
ファイル: ChemDB.py プロジェクト: dedichan/ChemDB
class tempapp(QMainWindow, tempwin):
    def __init__(self,parent=None):
        #splash screen initialisation
        self.splash_pix = QPixmap('data/loading.jpg')
        self.splash = QSplashScreen(self.splash_pix, QtCore.Qt.WindowStaysOnTopHint)
        self.splash.setMask(self.splash_pix.mask())
        self.splash.show()

        super(tempapp, self).__init__(parent)
        self.setupUi(self)
    def main(self):
        #launching program
        self.hide()
        self.launch()
    def launch(self):
        #reading configuration
        config=open('data/configure')
        config=config.readlines()
        envir=main.principal
        self.result={}
        for info in range(len(config)) :
            temp=config[info].split('=')
            temp[1]=temp[1].split('\n')[0]
            self.result[temp[0]]=temp[1]

        if self.result['db']=='' :
            #if no databatse, asking user for creating/pointing
            h=QMessageBox(parent=self, text="No DB has been pointed. \nDo you want to create a new database or to load an existing database ?")
            h.addButton(QPushButton('Close'), QMessageBox.YesRole)
            h.addButton(QPushButton('Load an Existing DB'), QMessageBox.NoRole)
            h.addButton(QPushButton('New DB'), QMessageBox.HelpRole)
            self.splash.hide()
            tot = h.exec_()
            if tot==0 :
                self.terminer()
            if tot==1 :
                self.loaddb()
            if tot==2 :
                self.newdb()
        else :
            #if already configured : checking if the DB still exist
            if os.path.exists(self.result['db'])==True :
                None
            else :
                #if db do not exist : delete configuration and reboot program
                self.splash.hide()
                h=QMessageBox(parent=self, text="Corrupted file or non existent : Deleting configuration")
                self.result['db']=""
                new_conf=''
                for i in self.result :
                    new_conf+='%s=%s\n' % (i,self.result[i])
                config=open('data/configure','w')
                config.write(new_conf)
                config.close()
                h.exec_()
                python = sys.executable
                os.execl(python, python, * sys.argv)
            #launching program if all checkpoints are ok
            self.splash.hide()
            prog=main.principal()
            prog.main()
            sys.exit(app.exec_())
    def loaddb (self) :
        #loading db file
        fname=QFileDialog.getOpenFileName(self, 'Choose a DB', '/','SQLite Databse (*.sqlite)')[0]
        if fname=='' :
            z=QMessageBox(parent=self, text="No DB has been selected, closing program")
            z.exec_()
            z.exec_()
            self.terminer()
        isvalid=cursor.verif(str(fname))
        #checking is the DB is valid
        if isvalid==False :
            z=QMessageBox(parent=self, text="Wrong File/File Corruption. \nClosing programm")
            z.exec_()
            self.terminer()
        else :
            #writiing new configuration
            self.result['db']=str(fname)
            new_conf=''
            for i in self.result :
                new_conf+='%s=%s\n' % (i,self.result[i])
            config=open('data/configure','w')
            config.write(new_conf)
            config.close()
            python = sys.executable
            os.execl(python, python, * sys.argv)
    def terminer (self) :
        #QApplication.quit()
        #sys.exit(app.exec_())
        sys.exit(0)

    def newdb (self) :
        #new db creation
        fname=QFileDialog.getSaveFileName(self, 'Create a DB', '/','SQLite Databse (*.sqlite)')[0]
        shutil.copy('data/model.sqlite',fname)
        self.result['db']=str(fname)
        new_conf=''
        for i in self.result :
            new_conf+='%s=%s\n' % (i,self.result[i])
        config=open('data/configure','w')
        config.write(new_conf)
        config.close()
        python = sys.executable
        os.execl(python, python, * sys.argv)
コード例 #6
0
ファイル: splashScreen.py プロジェクト: lisa-simon/resipy
        if percentage > 50 and percentage < 70:
            splash.showMessage("Copying temp files", Qt.AlignBottom | Qt.AlignCenter, Qt.black)
        if percentage >= 70 and percentage < 80:
            splash.showMessage("Checking files", Qt.AlignBottom | Qt.AlignCenter, Qt.black)
        if percentage >= 80 and percentage < 90:
            splash.showMessage("Loading PyQt", Qt.AlignBottom | Qt.AlignCenter, Qt.black)
        if percentage >= 90 and percentage < 98:
            splash.showMessage("Loading App", Qt.AlignBottom | Qt.AlignCenter, Qt.black)
        if percentage >= 98:
            splash.showMessage("Almost there!", Qt.AlignBottom | Qt.AlignCenter, Qt.black)
        app.processEvents()
        zf.extract(file, extractDir)
    zf.close()
    print('finished unzipping')
    
    splash.hide()
    splash.close()
    appDir = os.path.join(bundle_dir, 'ui', 'ui') # zip always putting a double dir ... don't know why
    print('Main app will be run in appDir = ', appDir)
    os.chdir(appDir)
#    os.system(['python3', 'ui.py']) # this work fine
    if OS == 'Linux':
        os.system(os.path.join(appDir, 'ResIPy'))
    else:
        p = Popen(os.path.join(appDir, 'ResIPy.exe'), shell=False, stdout=None, stdin=None) # this works now as well !
        p.communicate() # block and wait for the main program to finish
    # this last one doesn't work on linux WHEN COMPILED and I don't know why
    
    print('splashScreen is exiting')
    sys.exit(0) # send the SIGTERM signal -> works
#    sys.exit(app.exec_()) # doesn't work
コード例 #7
0
ファイル: mainwindow.py プロジェクト: tuxta/myquerytutor
class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        if getattr(sys, 'frozen', False):
            self.dir_path = os.path.dirname(sys.executable)
        else:
            # The application is not frozen
            self.dir_path = os.path.dirname(os.path.realpath(__file__))

        self.splash_screen = QSplashScreen()
        self.splash_screen.setPixmap(
            QPixmap(os.path.join(self.dir_path, 'splash.png')))
        self.splash_screen.show()

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.setWindowTitle("My Query Tutor - 2.3")
        self.ui.queryTextArea.setFontPointSize(15)
        self.app_settings = AppSettings()
        self.settings_cancelled = False
        self.erd = None
        self.sync_results = {}
        self.thread_pool = QThreadPool()

        first_run = False
        if not self.app_settings.has_settings():
            first_run = True
            wiz = FirstRunWiz(self.app_settings)
            wiz.setMinimumWidth(650)
            self.splash_screen.hide()
            wiz_result = wiz.exec()
            if wiz_result == 0:
                self.settings_cancelled = True
                sys.exit()

        self.db_ctrl = self.initial_checks()
        self.build_selection_tree()
        self.topic = ''
        self.question = ''
        self.question_id = 0

        # Connect signals to slots #
        self.ui.questionSelectTree.clicked.connect(
            self.on_question_select_tree_clicked)
        self.ui.runQuery_button.clicked.connect(self.run_query_clicked)
        self.ui.expectedResult_button.clicked.connect(
            self.expected_result_clicked)
        self.ui.help_button.clicked.connect(self.help_clicked)
        self.ui.progress_button.clicked.connect(self.show_progress)
        self.ui.syncButton.clicked.connect(self.sync_progress)
        self.ui.erdButton.clicked.connect(self.show_erd)

        # Disable the right click menu in the WebEngineView
        self.ui.questionTextArea.setContextMenuPolicy(Qt.NoContextMenu)
        self.ui.questionTextArea.setContextMenuPolicy(Qt.PreventContextMenu)

        self.ui.questionTextArea.settings().setAttribute(
            QWebEngineSettings.LocalContentCanAccessFileUrls, True)
        self.ui.questionTextArea.settings().setAttribute(
            QWebEngineSettings.LocalContentCanAccessRemoteUrls, True)

        # Set the initial Webview content - Credits
        self.ui.questionTextArea.setHtml('''
                                         <style>

                                         body {
                                           background-color: white;
                                         }

                                         h1 {
                                           text-align:center;
                                           text-decoration:underline;
                                           font-weight:bold;
                                         }
                                         
                                         .syntaxbox {
                                           box-sizing: border-box;
                                           border: 4px solid black;
                                           float: center;
                                           font: italic bold 15px Monospace;
                                           background: wheat;
                                           padding: 20px;
                                           margin-left: 40px;
                                           margin-right: 40px;
                                           text-align: center;
                                         }
                                         
                                         .examplebox {
                                           box-sizing: border-box;
                                           border: 4px solid black;
                                           float: center;
                                           font: bold 16px Arial;
                                           background: PaleTurquoise;
                                           padding: 20px;
                                           margin-left: 40px;
                                           margin-right: 40px;
                                           text-align: center;
                                         }
                                         
                                         </style>
                                         
                                         <body>
                                           <h1>My Query Tutor</h1>
                                           <div class="syntaxbox">
                                             <p>Software Developer</p>
                                             Steven Tucker
                                           </div>
                                           
                                           <div class="examplebox">
                                             <p>Content Developer</p>
                                             Peter Darcy
                                           </div>
                                           
                                           <div class="syntaxbox">
                                             <p>Content Designer</p>
                                             Keshlan Chinia
                                           </div>
                                         
                                         </body>
                                         ''')

        # Part of the horrible hack!!
        self.ui.queryTextArea.textChanged.connect(self.reset_font_query_edit)

        if not first_run:
            self.restoreGeometry(self.app_settings.get_geometry())
            self.ui.splitter.setSizes(
                self.app_settings.get_splitter_1_geometry())
            self.ui.splitter_2.setSizes(
                self.app_settings.get_splitter_2_geometry())
        else:
            self.splash_screen.show()
            self.ui.splitter.setSizes([393, 161])
            self.ui.splitter_2.setSizes([206, 565])

        self.splash_screen.finish(self)
        self.ui.questionTextArea.settings().setAttribute(
            QWebEngineSettings.LocalContentCanAccessFileUrls, True)

    def closeEvent(self, event):
        if not self.settings_cancelled:
            self.app_settings.set_geometry(self.saveGeometry(),
                                           self.ui.splitter.sizes(),
                                           self.ui.splitter_2.sizes())
        event.accept()

    @staticmethod
    def initial_checks():
        db_ctrl = DatabaseController()
        db_ctrl.connect()
        return db_ctrl

    def reset_font_query_edit(self):
        """
        Horrible, Horrible, Horrible Hack!
        Necessary to get around the font resetting if the current text is deleted
        Every time something changes, the font size is set
        """
        self.ui.queryTextArea.setFontPointSize(15)
        self.ui.queryTextArea.setFontWeight(-1)

    def show_erd(self):
        if self.question != '':
            image_dialog = QDialog()
            image_dialog.setModal(False)

            if self.erd is None:
                image_label = QLabel("No Diagram set for Question")
            else:
                image_label = QLabel(self.erd)
                image = QPixmap(os.path.join(self.dir_path, "images",
                                             self.erd))
                image_label.setPixmap(
                    image.scaled(1024, 768, Qt.KeepAspectRatio))
            layout = QBoxLayout(QBoxLayout.LeftToRight)
            layout.addWidget(image_label)
            image_label.setScaledContents(True)
            image_label.setMinimumHeight(100)
            image_label.setMinimumWidth(100)
            image_dialog.setLayout(layout)
            image_dialog.setModal(False)
            image_dialog.exec()

    def run_query_clicked(self):
        query = self.ui.queryTextArea.toPlainText()
        if query != '':

            self.ui.syncButton.setText("Sync with server")
            self.ui.syncButton.setStyleSheet(
                " QPushButton { background-color : lightsalmon; color : black }"
            )

            column_names, row_data = self.db_ctrl.run_query(query)

            expected_result_query = self.db_ctrl.get_question_query(
                self.question_id)
            expected_names, expected_data = self.db_ctrl.run_query(
                expected_result_query)

            if column_names == expected_names and row_data == expected_data:
                result_color = 1
                self.db_ctrl.set_question_query(query, self.topic,
                                                self.question, 1)
            else:
                result_color = 2
                self.db_ctrl.set_question_query(query, self.topic,
                                                self.question, 0)

            # Compare the exemplar query with the user query to identify errors
            query_comparison_html = self.compare_queries(
                expected_result_query, query)

            result_dialog = ExpectedResult(self, self.question, column_names,
                                           row_data, result_color)
            result_dialog.setModal(False)
            result_dialog.ui.textBrowser.setHtml(query_comparison_html)
            result_dialog.show()

    def expected_result_clicked(self):
        if self.question != '':
            query = self.db_ctrl.get_question_query(self.question_id)
            if query != '':
                column_names, row_data = self.db_ctrl.run_query(query)

                answer_dialog = ExpectedResult(
                    self, 'Expected Result for ' + self.question, column_names,
                    row_data)

                answer_dialog.setModal(False)
                answer_dialog.ui.label_correct.setText('')
                answer_dialog.ui.textBrowser.deleteLater()
                answer_dialog.show()

    def help_clicked(self):
        if not self.topic == '':
            lesson = self.db_ctrl.get_lesson(self.topic)
            lesson_dialog = LessonDialog(self, self.topic, lesson)
            lesson_dialog.setModal(False)
            lesson_dialog.show()

    def build_selection_tree(self):
        self.ui.questionSelectTree.setColumnCount(1)
        self.ui.questionSelectTree.header().close()

        questions_map, questions_list = self.db_ctrl.get_questions_list()

        for topic in questions_list:
            topic_item = QTreeWidgetItem(self.ui.questionSelectTree)
            topic_item.setText(0, topic)
            for question in questions_map[topic]:
                QTreeWidgetItem(topic_item).setText(0, question)

    def on_question_select_tree_clicked(self, index: QModelIndex):

        topic_item = index.parent()
        if not topic_item.isValid():
            return

        self.topic = topic_item.data()
        self.question = index.data()

        self.question_id, description, self.erd = self.db_ctrl.get_question(
            self.topic, self.question)

        global installer_building
        # Replace relative path to absolute
        soup = BeautifulSoup(description, "html.parser")
        for img in soup.findAll('img'):
            img['src'] = os.path.join(self.dir_path, "images", img['src'])

        for style in soup.find('style'):
            style_str = str(style)
            finds = re.findall('url\(.+?\)', style_str)
            for find in finds:
                sub_str = find[5:-2]
                file_type = os.path.splitext(sub_str)[1][1:]
                image_path = os.path.join(self.dir_path, 'images', sub_str)
                with open(image_path, "rb") as image_file:
                    encoded_string = base64.b64encode(
                        image_file.read()).decode('utf-8')
                    new_url = 'url("data:image/' + file_type + ' ;base64, ' + encoded_string + '")'
                style_str = style_str.replace(find, new_url)
            style.replaceWith(BeautifulSoup(style_str, features="html.parser"))
        description = str(soup)

        self.ui.questionTextArea.setHtml(description)

        # Load last query attempted for this question if on exists
        last_query = self.db_ctrl.get_last_query(self.topic, self.question)
        self.ui.queryTextArea.setText(last_query)

    def show_progress(self):
        questions_map, questions_list = self.db_ctrl.get_questions_list()

        progress_dialog = ProgressDialog(self, questions_map, questions_list,
                                         self.db_ctrl)

        progress_dialog.setModal(False)
        progress_dialog.ui.label_correct.setText('')
        progress_dialog.ui.textBrowser.deleteLater()
        progress_dialog.show()

    def sync_progress(self):
        server_address, class_key, ssl_set = self.app_settings.get_server_details(
        )
        first_name, surname, email = self.app_settings.get_user_details()

        QApplication.setOverrideCursor(Qt.WaitCursor)

        server_sync = ServerSync(
            self, (server_address, class_key, ssl_set),
            (first_name, surname, email),
            self.db_ctrl.get_sync_up_data(first_name, surname, email,
                                          self.app_settings.get_time_stamp()),
            self.sync_results)
        server_sync.signals.result.connect(self.sync_return)

        QThreadPool.globalInstance().start(server_sync)

    def sync_return(self):
        print("In Sync return")
        if self.sync_results['successful']:
            # Update timestamp from returned json
            self.app_settings.set_time_stamp(
                self.sync_results['synced_down_data']["timestamp"])
            # Mark all entries at synced
            self.db_ctrl.mark_synced()
            # insert new records.
            self.db_ctrl.insert_synced_records(
                self.sync_results['synced_down_data']["results"])
            # Change sync button to green if all completes successfully
            self.ui.syncButton.setText("In Sync")
            self.ui.syncButton.setStyleSheet(
                " QPushButton { background-color : lightgreen; color : black }"
            )
        else:
            # Dialog saying syn failed - with error
            server_address, class_key, ssl_set = self.app_settings.get_server_details(
            )
            self.update_server_settings(server_address, class_key, ssl_set)

        QApplication.setOverrideCursor(Qt.ArrowCursor)

    def update_server_settings(self, server_address, class_key, ssl):
        # Show dialog with server settings, test settings and return true on success, false on fail
        settings_dialog = SettingsDialog(self, self.app_settings,
                                         server_address, class_key, ssl)
        settings_dialog.exec()
        self.ui.syncButton.setText("Sync with server")
        self.ui.syncButton.setStyleSheet(
            " QPushButton { background-color : lightsalmon; color : black }")

    @staticmethod
    def compare_queries(exemplar_query, user_query):

        html_string_list = []

        # Set style rules
        html_header = '''
                    <style>
                      .Correct {
                        color:green;
                      }
                      .Incorrect {
                        color:red;
                      }
                    </style>
                    
                    <html>
                    '''
        # Break both queries into lists
        # Step through the user_query checking if each word
        # is in the exemplar. Set color and add to html string

        exemplar_list = exemplar_query.split()
        query_list = user_query.split()
        html_string_list.append(html_header)

        for word in query_list:
            if word in exemplar_list:
                html_string_list.append('<span class=Correct>' + word +
                                        '</span>')
            else:
                html_string_list.append('<span class=Incorrect>' + word +
                                        '</span>')

        html_string_list.append('''
                                
                                </html>
                                ''')

        html_string = ' '.join(html_string_list)

        return html_string