class DeleteWindow(QMainWindow): def __init__(self, character_id, gui_queue, parent=None): super(DeleteWindow, self).__init__(parent) self.dbHandler = DatabaseHandler() self.user = self.dbHandler.getUser(character_id) self.gui_queue = gui_queue self.set_main_window() self.centralwidget = QWidget(self) self.layout = QVBoxLayout(self.centralwidget) if self.user.id is None: self.layout.addWidget(QLabel("No User selected")) self.layout.addStretch(1) hBox = QHBoxLayout() hBox.addStretch(1) button = QPushButton("OK") button.clicked.connect(self.close) hBox.addWidget(button) self.layout.addLayout(hBox) else: self.layout.addWidget( QLabel("You are about to delete the Character: " + self.user.CharacterName)) self.layout.addWidget( QLabel("All Data will be lost! Are you sure?")) self.layout.addStretch(1) hBox = QHBoxLayout() deleteButton = QPushButton("Delete") deleteButton.clicked.connect(self.deleteUser) cancelButton = QPushButton("Cancel") cancelButton.clicked.connect(self.close) hBox.addStretch(1) hBox.addWidget(deleteButton) hBox.addWidget(cancelButton) self.layout.addLayout(hBox) self.setCentralWidget(self.centralwidget) self.show() def deleteUser(self): self.dbHandler.deleteUser(self.user.id) self.gui_queue.put("Reprint MainWindow") self.close() def set_main_window(self): # Standard Values for this Window standard_width = 400 standard_height = 180 """Sets the size policies of the main window""" self.resize(standard_width, standard_height) size_policy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) size_policy.setHorizontalStretch(0) size_policy.setVerticalStretch(0) size_policy.setHeightForWidth(self.sizePolicy().hasHeightForWidth()) self.setSizePolicy(size_policy) self.setMinimumSize(QSize(standard_width, standard_height)) self.setMaximumSize(QSize(standard_width, standard_height)) # main window icon self.setWindowIcon(QIcon(config.APP_ICON)) self.setWindowTitle("Delete Character")
class Esi(): def __init__(self, queue): """ A note on login/logout events: the character login events happen whenever a characters is logged into via the SSO, regardless of mod. However, the mode should be send as an argument. Similarily, the Logout even happens whenever the character is deleted for either mode. The mode is sent as an argument, as well as the umber of characters still in the cache (if USER mode) """ # self.settings = CRESTSettings.getInstance() self.dbHandler = DatabaseHandler() # ToDo: Dangerous to start an own instance of dbHandler self.updateHandler = UpdateHandler() # ToDo: Dangerous to start an own instance of updateHandler self.gui_queue = queue # these will be set when needed self.httpd = None self.state = None self.ssoTimer = None self.login() def login(self): """ this redirects the user to the EVE SSO login """ # token = generate_token() # requests.session['token'] = token self.startServer() return webbrowser.open(esisecurity.get_auth_uri(scopes=config.ESI_SCOPES)) def logout(self): """Logout of implicit character""" print("Character logout") self.implicitCharacter = None def stopServer(self): print("Stopping Server") self.httpd.stop() self.httpd = None def startServer(self): print("Starting server") if self.httpd: self.stopServer() time.sleep(1) # we need this to ensure that the previous get_request finishes, and then the socket will close self.httpd = StoppableHTTPServer((config.HOST, config.PORT), AuthHandler) self.serverThread = threading.Thread(target=self.httpd.serve, args=(self.callback,)) self.serverThread.name = "ESIServer" self.serverThread.daemon = True self.serverThread.start() return def callback(self, parts): """ This is where the user comes after he logged in SSO """ # get the code from the login process code = str(parts['code'][0]) # token = str(parts['code'][0]) # compare the state with the saved token for CSRF check # now we try to get tokens try: auth_response = esisecurity.auth(code) except APIException as e: return print('Login EVE Online SSO failed: %s' % e) # we get the character informations cdata = esisecurity.verify() # if the user is already authed, we log him out #if current_user.is_authenticated: # logout_user() # now we check in database, if the user exists # actually we'd have to also check with character_owner_hash, to be # sure the owner is still the same, but that's an example only... user = User() user.CharacterID = cdata['CharacterID'] user.CharacterOwnerHash = cdata['CharacterOwnerHash'] user.CharacterName = cdata['CharacterName'] user.update_token(auth_response) ''' try: user.id = self.dbHandler.saveUser(user) except Exception as e: print("Exception in Esi.callback1: " + str(e)) try: if user.id is not None: # We don't want DB Entrys without owner self.updateHandler.updateUser(user) self.writeToQueue() except Exception as e: print("Exception in Esi.callback2: " + str(e)) ''' try: u = self.dbHandler.saveUser(user) user = self.dbHandler.getUser(u.CharacterID) if user is not None and user.id is not None: print("") self.updateHandler.updateUser(user) self.writeToQueue() except Exception as e: print("Exception in Esi.callback: " + str(e)) def writeToQueue(self): self.gui_queue.put("Reprint MainWindow")