-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApiConfig.py
40 lines (37 loc) · 1.45 KB
/
ApiConfig.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
from tkinter import *
from configparser import ConfigParser
class ApiConfig:
def __init__(self):
self.__setupApiWindow = Tk()
self.__config = ConfigParser()
self.__config.read('config.ini')
self.__setupApiWindow.title("Personal Access Token")
self.__heading = Label(self.__setupApiWindow, text='Personal Access Token')
self.__apiKeyText = Text(self.__setupApiWindow)
if 'elytica' in self.__config.sections():
if 'apikey' in self.__config['elytica']:
self.__apiKeyText.insert(END,\
self.__config['elytica']['apikey'])
self.__installButton = Button(self.__setupApiWindow, text="Install",\
command=self.saveConfiguration)
self.__quitButton = Button(self.__setupApiWindow, text="Close",\
command=self.__setupApiWindow.destroy)
self.__heading.pack(fill=X)
self.__apiKeyText.pack(fill=BOTH)
self.__installButton.pack(fill=X)
self.__quitButton.pack(fill=X)
def saveConfiguration(self):
apiKey=self.__apiKeyText.get("1.0", END)
if not self.__config.has_section('elytica'):
self.__config.add_section('elytica')
self.__config.set('elytica', 'apiKey', apiKey)
with open('config.ini', 'w') as f:
self.__config.write(f)
self.__setupApiWindow.quit()
self.__setupApiWindow.destroy()
def show(self):
self.__setupApiWindow.update()
self.__setupApiWindow.deiconify()
self.__setupApiWindow.mainloop()
def hide(self):
self.__setupApiWindow.withdraw()