示例#1
0
def main():
    """Main del proyecto. Aquí se inicializan los objetos principales, comienza todo el código.
    """
    client_id = 2  #ID del cliente en Laravel Passport. Por defecto es 2, y no debería cambiarse.

    #Secreto del cliente. Debe ser generado por Laravel Passport en la API.
    client_secret = ""

    try:
        main_app = QtSingleApplication(client_secret, sys.argv)
        if main_app.isRunning():
            sys.exit(0)
        QCoreApplication.setApplicationName("CAPOUNET Sync")
        QCoreApplication.setOrganizationName("CAPOUNET")
        QCoreApplication.setOrganizationDomain("capounet.unet.edu.ve")

        Settings.load_settings(client_id, client_secret)
        main_app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
        main_app.setWindowIcon(Settings.app_icon)

        return_code = 1
        while return_code:
            return_code = 2
            if not Settings.is_init():
                Settings.delete_settings()
                return_code = AccessDialog.obtain_configuration()
                if return_code == 1:
                    return_code = OptionsDialog.open_dialog()

            if return_code >= 1:
                main_window = MainWindow()
                sync_thread = SyncThread(main_window)
                sync_thread.start()
                if return_code == 1:
                    main_window.show()
                return_code = main_app.exec_()
                sync_thread.stop_sync()
                main_window.close()
                sync_thread.join()
                if return_code:
                    Settings.delete_settings()
                    Settings.load_settings(client_id, client_secret)

        sys.exit(0)

    except NameError:
        print("Nombre del error:", sys.exc_info()[1])
    except SystemExit:
        print("Cerrando la ventana...")
示例#2
0
文件: guiDriver.py 项目: jotk/GHAR
class driver:
    def __init__(self):
        self.app = QApplication(sys.argv)
        self.DBconnection = None
        self.user = None
        self.login = None
        self.mw = None
        self.stylesheet = """
        QMainWindow{
            background-color: #97CBE1;
        }
        QLabel{
            color: #031523;
        }
        QLineEdit{
            background-color: #C4F3C4;
        }
        QPushButton{
            background-color: #031523;
            color: white;
        }
        QPixMap{
            box-shadow: 10px 10px 5px #B8F9C3;
        }
        """
        self.app.setStyleSheet(self.stylesheet)

    def createDBConnect(self, host='laspjot.cc3mhnvgoaaz.us-east-2.rds.amazonaws.com', database='proj', user='******', password='******'):
        if self.DBconnection == None:
            try:
                self.DBconnection = DBconnect(host, database, user, password)
            except:
                print("Cannot connect to DB.")
                self.closeApp()
        else:
            print("DB connection already exists")



    def openLoginWindow(self):
        self.login = LogInWindow(self, self.DBconnection)
        self.login.li_widget.newuser.clicked.connect(self.makeNewUser)
        self.login.user_found.connect(self.openMainWindow)
        self.login.show()  # self.login.exec()
        #self.user = self.login.getUser()
        # Get email and password from logIn and set class variables

    def makeNewUser(self):
        webbrowser.open('https://ghar-property-manager.herokuapp.com/signup')

    def getApp(self):
        return self.app

    def openMainWindow(self, userID):
        if self.login != None:
            self.login.close()
        self.user = Landlord(userID, self.DBconnection)  # create landlord in mw
        self.mw = MainWindow(self.user, self.DBconnection)
        #slots
        self.mw.signOut.triggered.connect(self.logOut) #logout when "sign out" is clicked in mw's menu bar

        self.mw.openInBrowser.triggered.connect(self.openSite)
        self.mw.mainWidget.propertiesWidget.closeOut.clicked.connect(self.mw.close)
        self.mw.mainWidget.propertiesWidget.goToSite.clicked.connect(self.openSite)
        self.mw.show()

    def openSite(self):
        """
        Opens the GHAR homepage
        :return:
        """
        webbrowser.open('https://ghar-property-manager.herokuapp.com/home')

    def logOut(self):
        self.user = None
        self.mw.close()
        self.mw = None
        self.openLoginWindow()

    def runApp(self):
        self.app.exec()
        if self.DBconnection != None:
            self.DBconnection.closeConnection()