Skip to content

Commit e1b942f

Browse files
Add option for connecting to OpenGolfSim
1 parent 91f1b55 commit e1b942f

15 files changed

Lines changed: 658 additions & 51 deletions

src/MainWindow.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
from src.devices import Devices
1717
from src.log_message import LogMessage, LogMessageSystems, LogMessageTypes
1818
from src.putting_settings import PuttingSettings
19-
from src.settings import Settings, LaunchMonitor
19+
from src.settings import Settings, LaunchMonitor, Simulator
2020
from src.PuttingForm import PuttingForm
2121
from src.gspro_connection import GSProConnection
22+
from src.ogs_connection import OpenGolfSimConnection
2223
from src.device_launch_monitor_screenshot import DeviceLaunchMonitorScreenshot
2324
from src.putting import Putting
2425

@@ -49,6 +50,7 @@ def __init__(self, app):
4950
self.__setup_logging()
5051
self.settings = Settings(self.app_paths)
5152
self.gspro_connection = GSProConnection(self)
53+
self.ogs_connection = OpenGolfSimConnection(self)
5254
self.settings_form = SettingsForm(settings=self.settings, app_paths=self.app_paths)
5355
self.putting_settings = PuttingSettings(self.app_paths)
5456
self.putting_settings_form = PuttingForm(main_window=self)
@@ -125,7 +127,7 @@ def __setup_ui(self):
125127

126128
def __auto_start(self):
127129
if self.settings.auto_start_all_apps == 'Yes':
128-
if len(self.settings.gspro_path) > 0 and len(self.settings.grspo_window_name) and os.path.exists(self.settings.gspro_path):
130+
if self.settings.simulator_api == Simulator.GSPRO and len(self.settings.gspro_path) > 0 and len(self.settings.grspo_window_name) and os.path.exists(self.settings.gspro_path):
129131
self.log_message(LogMessageTypes.LOG_WINDOW, LogMessageSystems.CONNECTOR, f'Starting GSPro')
130132
self.gspro_connection.gspro_start(self.settings, True)
131133
if self.settings.device_id != LaunchMonitor.RELAY_SERVER and \
@@ -206,10 +208,18 @@ def __shop(self):
206208
webbrowser.open(url, new=2) # 2 = open in new tab
207209

208210
def __gspro_connect(self):
209-
if self.gspro_connection.connected:
210-
self.gspro_connection.disconnect_from_gspro()
211-
else:
212-
self.gspro_connection.connect_to_gspro()
211+
if self.settings.simulator_api == Simulator.GSPRO:
212+
if self.gspro_connection.connected:
213+
self.gspro_connection.disconnect_from_gspro()
214+
else:
215+
self.gspro_connection.connect_to_gspro()
216+
elif self.settings.simulator_api == Simulator.OPENGOLFSIM:
217+
logging.debug(f'{MainWindow.app_name} Connecting to OpenGolfSim API...')
218+
if self.ogs_connection.connected:
219+
self.ogs_connection.disconnect_from_ogs()
220+
else:
221+
self.ogs_connection.connect_to_ogs()
222+
213223

214224
def __about(self):
215225
QMessageBox.information(self, "About", f"{MainWindow.app_name}\nVersion: {MainWindow.version}")

src/MainWindow.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<item>
4949
<widget class="QGroupBox" name="groupBox">
5050
<property name="title">
51-
<string>GSPro Connection</string>
51+
<string>Simulator Connection</string>
5252
</property>
5353
<layout class="QHBoxLayout" name="horizontalLayout">
5454
<property name="sizeConstraint">

src/MainWindow_ui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ def retranslateUi(self, MainWindow):
691691
#if QT_CONFIG(tooltip)
692692
self.connector_tab.setToolTip("")
693693
#endif // QT_CONFIG(tooltip)
694-
self.groupBox.setTitle(QCoreApplication.translate("MainWindow", u"GSPro Connection", None))
694+
self.groupBox.setTitle(QCoreApplication.translate("MainWindow", u"Simulator Connection", None))
695695
self.gspro_connect_button.setText(QCoreApplication.translate("MainWindow", u"Connect", None))
696696
self.gspro_status_label.setText(QCoreApplication.translate("MainWindow", u"TextLabel", None))
697697
self.club_selection.setText("")

src/SettingsForm.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from src.SettingsForm_ui import Ui_SettingsForm
66
from src.appdata import AppDataPaths
77
from src.devices import Devices
8-
from src.settings import Settings, LaunchMonitor
8+
from src.settings import Settings, LaunchMonitor, Simulator
99

1010

1111
class SettingsForm(QWidget, Ui_SettingsForm):
@@ -26,6 +26,13 @@ def __init__(self, settings: Settings, app_paths: AppDataPaths):
2626
self.mevo_offline_mode_combo.addItems(['Yes', 'No'])
2727
self.launch_monitor_combo.clear()
2828
self.launch_monitor_combo.addItems(SettingsForm.launchmonitor_as_list())
29+
30+
self.simulator_combo.clear()
31+
self.simulator_combo.addItems(SettingsForm.simulator_as_list())
32+
33+
# self.ogs_settings_groupbox
34+
# self.gspro_settings_groupbox
35+
2936
self.close_button.clicked.connect(self.__close)
3037
self.save_button.clicked.connect(self.__save)
3138
self.file_browse_button.clicked.connect(self.__file_dialog)
@@ -39,6 +46,14 @@ def showEvent(self, event: QShowEvent) -> None:
3946
def __close(self):
4047
self.close()
4148

49+
@staticmethod
50+
def simulator_as_list():
51+
keys = []
52+
for key in Simulator.__dict__:
53+
if key != '__' not in key:
54+
keys.append(getattr(Simulator, key))
55+
return keys
56+
4257
@staticmethod
4358
def launchmonitor_as_list():
4459
keys = []
@@ -49,11 +64,14 @@ def launchmonitor_as_list():
4964

5065
def __save(self):
5166
if self.__valid():
67+
self.settings.simulator_api = self.simulator_combo.currentText()
5268
self.settings.ip_address = self.ipaddress_edit.toPlainText()
5369
self.settings.port = int(self.port_edit.toPlainText())
5470
self.settings.gspro_path = self.gspro_path_edit.toPlainText()
5571
self.settings.grspo_window_name = self.gspro_window_name.toPlainText()
5672
self.settings.gspro_api_window_name = self.gspro_api_window_name.toPlainText()
73+
self.settings.ogs_ip_address = self.ogs_ipaddress.toPlainText()
74+
self.settings.ogs_port = int(self.ogs_port.toPlainText())
5775
self.settings.device_id = self.launch_monitor_combo.currentText()
5876
self.settings.default_device = self.default_device_combo.currentText()
5977
self.settings.relay_server_ip_address = self.relay_server_ip_edit.toPlainText()
@@ -89,11 +107,16 @@ def __valid(self):
89107
return error
90108

91109
def __load_values(self):
110+
self.simulator_combo.setCurrentText(self.settings.simulator_api)
92111
self.ipaddress_edit.setPlainText(self.settings.ip_address)
93112
self.port_edit.setPlainText(str(self.settings.port))
94113
self.gspro_path_edit.setPlainText(str(self.settings.gspro_path))
95114
self.gspro_window_name.setPlainText(str(self.settings.grspo_window_name))
96115
self.gspro_api_window_name.setPlainText(str(self.settings.gspro_api_window_name))
116+
117+
self.ogs_ipaddress.setPlainText(self.settings.ogs_ip_address)
118+
self.ogs_port.setPlainText(str(self.settings.ogs_port))
119+
97120
self.launch_monitor_combo.setCurrentText(self.settings.device_id)
98121
device = 'None'
99122
if hasattr(self.settings, 'default_device') and self.settings.default_device != '':

src/SettingsForm.ui

Lines changed: 111 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<class>SettingsForm</class>
44
<widget class="QWidget" name="SettingsForm">
55
<property name="windowModality">
6-
<enum>Qt::ApplicationModal</enum>
6+
<enum>Qt::WindowModality::ApplicationModal</enum>
77
</property>
88
<property name="geometry">
99
<rect>
@@ -22,7 +22,32 @@
2222
<item>
2323
<layout class="QVBoxLayout" name="verticalLayout_8">
2424
<item>
25-
<widget class="QGroupBox" name="r10_settings_groupbox_2">
25+
<widget class="QGroupBox" name="groupBox_3">
26+
<property name="title">
27+
<string>Simulator</string>
28+
</property>
29+
<layout class="QHBoxLayout" name="horizontalLayout_18">
30+
<item>
31+
<widget class="QLabel" name="simulator_label">
32+
<property name="text">
33+
<string>Simulator API</string>
34+
</property>
35+
</widget>
36+
</item>
37+
<item>
38+
<widget class="QComboBox" name="simulator_combo">
39+
<item>
40+
<property name="text">
41+
<string>None</string>
42+
</property>
43+
</item>
44+
</widget>
45+
</item>
46+
</layout>
47+
</widget>
48+
</item>
49+
<item>
50+
<widget class="QGroupBox" name="gspro_settings_groupbox">
2651
<property name="title">
2752
<string>GSPro</string>
2853
</property>
@@ -48,7 +73,7 @@
4873
</size>
4974
</property>
5075
<property name="contextMenuPolicy">
51-
<enum>Qt::PreventContextMenu</enum>
76+
<enum>Qt::ContextMenuPolicy::PreventContextMenu</enum>
5277
</property>
5378
<property name="toolTip">
5479
<string>GSPro IP Address</string>
@@ -177,7 +202,7 @@
177202
<string>Application Path(Opyional)</string>
178203
</property>
179204
<property name="lineWrapMode">
180-
<enum>QPlainTextEdit::WidgetWidth</enum>
205+
<enum>QPlainTextEdit::LineWrapMode::WidgetWidth</enum>
181206
</property>
182207
<property name="placeholderText">
183208
<string>GSPro Path</string>
@@ -196,10 +221,87 @@
196221
</layout>
197222
</widget>
198223
</item>
224+
<item>
225+
<widget class="QGroupBox" name="ogs_settings_groupbox">
226+
<property name="title">
227+
<string>OpenGolfSim</string>
228+
</property>
229+
<layout class="QVBoxLayout" name="verticalLayout_11">
230+
<item>
231+
<widget class="QPlainTextEdit" name="ogs_ipaddress">
232+
<property name="sizePolicy">
233+
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
234+
<horstretch>0</horstretch>
235+
<verstretch>0</verstretch>
236+
</sizepolicy>
237+
</property>
238+
<property name="minimumSize">
239+
<size>
240+
<width>0</width>
241+
<height>31</height>
242+
</size>
243+
</property>
244+
<property name="maximumSize">
245+
<size>
246+
<width>16777215</width>
247+
<height>31</height>
248+
</size>
249+
</property>
250+
<property name="contextMenuPolicy">
251+
<enum>Qt::ContextMenuPolicy::PreventContextMenu</enum>
252+
</property>
253+
<property name="toolTip">
254+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The IP address of the computer running OpenGolfSim&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
255+
</property>
256+
<property name="tabChangesFocus">
257+
<bool>true</bool>
258+
</property>
259+
<property name="placeholderText">
260+
<string>OpenGolfSim IP Address</string>
261+
</property>
262+
</widget>
263+
</item>
264+
<item>
265+
<widget class="QPlainTextEdit" name="ogs_port">
266+
<property name="enabled">
267+
<bool>true</bool>
268+
</property>
269+
<property name="sizePolicy">
270+
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
271+
<horstretch>0</horstretch>
272+
<verstretch>0</verstretch>
273+
</sizepolicy>
274+
</property>
275+
<property name="minimumSize">
276+
<size>
277+
<width>0</width>
278+
<height>31</height>
279+
</size>
280+
</property>
281+
<property name="maximumSize">
282+
<size>
283+
<width>16777215</width>
284+
<height>31</height>
285+
</size>
286+
</property>
287+
<property name="toolTip">
288+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The port of the OpenGolfSim API&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
289+
</property>
290+
<property name="tabChangesFocus">
291+
<bool>true</bool>
292+
</property>
293+
<property name="placeholderText">
294+
<string>OpenGolfSim Port</string>
295+
</property>
296+
</widget>
297+
</item>
298+
</layout>
299+
</widget>
300+
</item>
199301
<item>
200302
<spacer name="verticalSpacer_2">
201303
<property name="orientation">
202-
<enum>Qt::Vertical</enum>
304+
<enum>Qt::Orientation::Vertical</enum>
203305
</property>
204306
<property name="sizeHint" stdset="0">
205307
<size>
@@ -574,7 +676,7 @@
574676
<item>
575677
<spacer name="verticalSpacer_3">
576678
<property name="orientation">
577-
<enum>Qt::Vertical</enum>
679+
<enum>Qt::Orientation::Vertical</enum>
578680
</property>
579681
<property name="sizeHint" stdset="0">
580682
<size>
@@ -593,7 +695,7 @@
593695
<item>
594696
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="0">
595697
<property name="sizeConstraint">
596-
<enum>QLayout::SetMinimumSize</enum>
698+
<enum>QLayout::SizeConstraint::SetMinimumSize</enum>
597699
</property>
598700
<item>
599701
<layout class="QHBoxLayout" name="horizontalLayout_9">
@@ -731,7 +833,7 @@
731833
<item>
732834
<spacer name="verticalSpacer">
733835
<property name="orientation">
734-
<enum>Qt::Vertical</enum>
836+
<enum>Qt::Orientation::Vertical</enum>
735837
</property>
736838
<property name="sizeHint" stdset="0">
737839
<size>
@@ -746,7 +848,7 @@
746848
<item>
747849
<spacer name="horizontalSpacer">
748850
<property name="orientation">
749-
<enum>Qt::Horizontal</enum>
851+
<enum>Qt::Orientation::Horizontal</enum>
750852
</property>
751853
<property name="sizeHint" stdset="0">
752854
<size>

0 commit comments

Comments
 (0)