Skip to content

Commit

Permalink
Login with CREST from GUI working
Browse files Browse the repository at this point in the history
Getting player location from GUI working
  • Loading branch information
Valtyr Farshield committed Feb 29, 2016
1 parent 37607c6 commit aeaa594
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 12 deletions.
2 changes: 1 addition & 1 deletion resources/ui/gui_main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
<item>
<widget class="QPushButton" name="pushButton_eve_login">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
Expand Down
63 changes: 59 additions & 4 deletions src/pathfinder/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from model.navigation import Navigation
from model.navprocessor import NavProcessor
from model.evedb import EveDb
from model.crestprocessor import CrestProcessor


def dict_from_csvqfile(file_path):
Expand Down Expand Up @@ -96,6 +97,8 @@ def __init__(self, parent=None):

# Additional GUI setup
self.additional_gui_setup()
self.label_status_bar = QtGui.QLabel("Not connected to EvE")
self.statusBar().addWidget(self.label_status_bar, 1)

# Thread initial config
self.worker_thread = QtCore.QThread()
Expand All @@ -105,6 +108,13 @@ def __init__(self, parent=None):
# noinspection PyUnresolvedReferences
self.worker_thread.started.connect(self.nav_processor.process)

# CREST
self.eve_connected = False
self.crestp = CrestProcessor()
self.crestp.login_response.connect(self.login_handler)
self.crestp.location_response.connect(self.location_handler)
self.crestp.destination_response.connect(self.destination_handler)

def additional_gui_setup(self):
# Additional GUI setup
self.graphicsView_banner.mouseDoubleClickEvent = MainWindow.banner_double_click
Expand Down Expand Up @@ -135,6 +145,10 @@ def additional_gui_setup(self):

# Signals
# noinspection PyUnresolvedReferences
self.pushButton_eve_login.clicked.connect(self.btn_eve_login_clicked)
# noinspection PyUnresolvedReferences
self.pushButton_player_location.clicked.connect(self.btn_player_location_clicked)
# noinspection PyUnresolvedReferences
self.pushButton_find_path.clicked.connect(self.btn_find_path_clicked)
# noinspection PyUnresolvedReferences
self.pushButton_trip_config.clicked.connect(self.btn_trip_config_clicked)
Expand Down Expand Up @@ -265,6 +279,9 @@ def _path_message(self, message, message_type):
def _trip_message(self, message, message_type):
MainWindow._label_message(self.label_trip_status, message, message_type)

def _statusbar_message(self, message, message_type):
MainWindow._label_message(self.label_status_bar, message, message_type)

def avoidance_enabled(self):
return self.checkBox_avoid_enabled.isChecked()

Expand Down Expand Up @@ -386,6 +403,26 @@ def banner_double_click(event):
event.accept()
AboutDialog(__author__, __version__).exec_()

@QtCore.Slot(str)
def login_handler(self, char_name):
if char_name:
self._statusbar_message("Welcome, {}".format(char_name), MainWindow.MSG_OK)
self.pushButton_eve_login.setText("Logout")
self.pushButton_player_location.setEnabled(True)
self.pushButton_set_dest.setEnabled(True)
self.eve_connected = True
else:
self._statusbar_message("Error: Unable to connect with CREST", MainWindow.MSG_ERROR)

@QtCore.Slot(str)
def location_handler(self, location):
self.pushButton_player_location.setEnabled(True)
self.lineEdit_source.setText(location)

@QtCore.Slot(bool)
def destination_handler(self, response):
pass

@QtCore.Slot(int)
def thread_done(self, connections):
self.worker_thread.quit()
Expand All @@ -402,6 +439,24 @@ def thread_done(self, connections):
self.pushButton_trip_get.setEnabled(True)
self.pushButton_find_path.setEnabled(True)

@QtCore.Slot()
def btn_eve_login_clicked(self):
if not self.eve_connected:
url = self.crestp.login()
QtGui.QDesktopServices.openUrl(QtCore.QUrl(url, QtCore.QUrl.TolerantMode))
else:
self.crestp.logout()
self._statusbar_message("Not connected to EvE", MainWindow.MSG_INFO)
self.pushButton_eve_login.setText("Log in with EvE")
self.pushButton_player_location.setEnabled(False)
self.pushButton_set_dest.setEnabled(False)
self.eve_connected = False

@QtCore.Slot()
def btn_player_location_clicked(self):
self.pushButton_player_location.setEnabled(False)
self.crestp.get_location()

@QtCore.Slot()
def btn_find_path_clicked(self):
self.find_path()
Expand Down Expand Up @@ -433,6 +488,10 @@ def btn_trip_get_clicked(self):
else:
self._trip_message("Error! Process already running", MainWindow.MSG_ERROR)

@QtCore.Slot()
def btn_set_dest_clicked(self):
pass

@QtCore.Slot()
def btn_avoid_add_clicked(self):
self.avoid_system()
Expand All @@ -446,10 +505,6 @@ def btn_avoid_delete_clicked(self):
def btn_avoid_clear_clicked(self):
self.listWidget_avoid.clear()

@QtCore.Slot()
def btn_set_dest_clicked(self):
pass

@QtCore.Slot()
def btn_reset_clicked(self):
msg_box = QtGui.QMessageBox()
Expand Down
6 changes: 4 additions & 2 deletions src/pathfinder/model/crest/crest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ def __init__(self, login_callback):
def start_server(self):
if self.httpd:
self.stop_server()
time.sleep(1)
time.sleep(0.1)
logging.debug("Starting server")
self.httpd = StoppableHTTPServer(('127.0.0.1', 7444), AuthHandler)
threading.Thread(target=self.httpd.serve, args=(self.handle_login, )).start()
server_thread = threading.Thread(target=self.httpd.serve, args=(self.handle_login, ))
server_thread.setDaemon(True)
server_thread.start()

self.state = str(uuid.uuid4())
return self.eve.auth_uri(scopes=self.scopes, state=self.state)
Expand Down
36 changes: 36 additions & 0 deletions src/pathfinder/model/crestprocessor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# crestprocessor.py

import threading
from PySide import QtCore
from crest.crest import Crest


class CrestProcessor(QtCore.QObject):
"""
CREST Middle-ware
"""
login_response = QtCore.Signal(str)
location_response = QtCore.Signal(str)
destination_response = QtCore.Signal(bool)

def __init__(self, parent=None):
super(CrestProcessor, self).__init__(parent)
self.crest = Crest(self._login_callback)

def login(self):
return self.crest.start_server()

def logout(self):
self.crest.logout()

def get_location(self):
server_thread = threading.Thread(target=self._get_location)
server_thread.setDaemon(True)
server_thread.start()

def _get_location(self):
location = self.crest.get_char_location()
self.location_response.emit(location)

def _login_callback(self, char_name):
self.login_response.emit(char_name)
2 changes: 1 addition & 1 deletion src/pathfinder/view/gui_about.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'resources\ui\gui_about.ui'
#
# Created: Sat Feb 27 18:40:49 2016
# Created: Mon Feb 29 19:34:55 2016
# by: pyside-uic 0.2.15 running on PySide 1.2.4
#
# WARNING! All changes made in this file will be lost!
Expand Down
4 changes: 2 additions & 2 deletions src/pathfinder/view/gui_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'resources\ui\gui_main.ui'
#
# Created: Sat Feb 27 18:40:48 2016
# Created: Mon Feb 29 19:34:53 2016
# by: pyside-uic 0.2.15 running on PySide 1.2.4
#
# WARNING! All changes made in this file will be lost!
Expand Down Expand Up @@ -121,7 +121,7 @@ def setupUi(self, MainWindow):
self.verticalLayout_3 = QtGui.QVBoxLayout(self.groupBox__options)
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.pushButton_eve_login = QtGui.QPushButton(self.groupBox__options)
self.pushButton_eve_login.setEnabled(False)
self.pushButton_eve_login.setEnabled(True)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
Expand Down
2 changes: 1 addition & 1 deletion src/pathfinder/view/gui_tripwire.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'resources\ui\gui_tripwire.ui'
#
# Created: Sat Feb 27 18:40:48 2016
# Created: Mon Feb 29 19:34:54 2016
# by: pyside-uic 0.2.15 running on PySide 1.2.4
#
# WARNING! All changes made in this file will be lost!
Expand Down
2 changes: 1 addition & 1 deletion src/pathfinder/view/resources_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Resource object code
#
# Created: S 27. feb. 18:40:49 2016
# Created: L 29. feb. 19:34:55 2016
# by: The Resource Compiler for PySide (Qt v4.8.7)
#
# WARNING! All changes made in this file will be lost!
Expand Down

0 comments on commit aeaa594

Please sign in to comment.