-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.py
119 lines (98 loc) · 4.05 KB
/
options.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import os
from PyQt5.QtWidgets import QDialog, QVBoxLayout, QLabel, QLineEdit, QPushButton, QMessageBox
import json
#import requests
# Global variables.
toggl_api_key = os.getenv('TOGGL_API_KEY')
jira_api_key = os.getenv('JIRA_API_KEY')
jira_user_name = os.getenv('JIRA_USER_NAME')
toggl_username = ""
toggl_password = ""
toggl_logged_in = False
company = ""
maconomy_prod = ""
# Class to create the settings window.
class SettingsWindow(QDialog):
def __init__(self, parent=None):
super().__init__()
self.setWindowTitle("Settings")
self.layout = QVBoxLayout()
#import the options from the config file
with open('json/options.json') as f:
options_json = json.load(f)
self.company = options_json.get('company')
self.maconomy_prod = options_json.get('maconomy_prod')
self.company_label = QLabel("Company:")
self.layout.addWidget(self.company_label)
self.company_field = QLineEdit()
self.company_field.setText(self.company)
self.layout.addWidget(self.company_field)
self.maconomy_prod_label = QLabel("Maconomy Prod:")
self.layout.addWidget(self.maconomy_prod_label)
self.maconomy_prod_field = QLineEdit()
self.maconomy_prod_field.setText(self.maconomy_prod)
self.layout.addWidget(self.maconomy_prod_field)
self.save_button = QPushButton("Save")
self.save_button.clicked.connect(self.save_options)
self.layout.addWidget(self.save_button)
self.cancel_button = QPushButton("Cancel")
self.cancel_button.clicked.connect(self.cancel_options)
self.layout.addWidget(self.cancel_button)
self.setLayout(self.layout)
# Function to save the options to the config file. FIXME: Fix bugs in url checks and evaluate if good to use.
def save_options(self):
# jira_url = "https://" + self.company_field.text().lower() + ".atlassian.net/jira/your-work"
# if url_ok(jira_url) == False:
# message_string = "Company is not valid."
# print(message_string)
# show_options_url_check_failed(message_string)
# return
# maconomy_url = "https://" + self.maconomy_prod_field.text().lower() + "-webclient.deltekfirst.com"
# print(maconomy_url)
# print(url_ok(maconomy_url))
# if url_ok(maconomy_url) == False:
# message_string = "Maconomy prod is not valid."
# print(message_string)
# show_options_url_check_failed(message_string)
# return
global company
global maconomy_prod
company = self.company_field.text().lower()
maconomy_prod = self.maconomy_prod_field.text().lower()
with open('json/options.json', 'w') as f:
json.dump({'company': company, 'maconomy_prod': maconomy_prod}, f)
self.close()
# Function to cancel and close the options window.
def cancel_options(self):
self.close()
# Function to show the settings window.
def showSettingsWindow():
settingsWindow = SettingsWindow()
settingsWindow.exec_()
# Function to get the options from the config file.
def getOptions():
with open('json/options.json') as f:
options_json = json.load(f)
company = options_json.get('company')
maconomy_prod = options_json.get('maconomy_prod')
return company, maconomy_prod
# Function to check if the url is valid. FIXME: Fix bugs in url checks and evaluate if good to use.
# def url_ok(url):
# # exception block
# try:
# # pass the url into
# # request.hear
# response = requests.head(url)
# print(response.status_code)
# if response.status_code == 200:
# return True
# else:
# return False
# except requests.ConnectionError as e:
# return e
def show_options_url_check_failed(message_string):
msg = QMessageBox()
msg.setWindowTitle("Options Error")
msg.setText(message_string + "Please check the options and try again.")
msg.setIcon(QMessageBox.Information)
msg.exec_()