-
Notifications
You must be signed in to change notification settings - Fork 0
/
clientConfig.py
114 lines (92 loc) · 3.78 KB
/
clientConfig.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
from tkinter import *
from tkinter import messagebox
import tkinter.font as tkFont
import os
path = os.path.expanduser("~/")
host = ""
port = ""
try:
file = open(path + "clientConfig.config", "r")
file.readline()
host = file.readline().replace("ip:", "").replace("\n", "")
port = file.readline().replace("port:", "")
file.close()
except:
host = "localhost"
port = 0
class Client:
def __init__(self, master=None):
def testVal(inStr,acttyp):
if acttyp == '1': #insert
if not inStr.isdigit():
return False
return True
#Definição da janela
self.window = master
self.window.title("Configurações Iniciais - IM")
self.window.geometry("300x150+250+250")
self.window.resizable(width=False, height=False)
#Frame master
self.container = Frame(master)
self.container.pack(pady=10, padx=10)
#Frames
self.conn = LabelFrame(self.container, text="Connection")
self.conn.pack(side=TOP)
self.buttons = Frame(self.container)
self.buttons.pack(pady=10, padx=10)
#Objectos
self.englob = Frame(self.conn)
self.englob.pack(pady=10, padx=10)
self.lblIp = Label(self.englob, text="IP")
self.lblIp.grid(row = 0, column = 0)
self.txtIp = Entry(self.englob)
self.txtIp.grid(row = 0, column = 1)
if host != "localhost":
self.txtIp.insert(0, host)
self.lblPort = Label(self.englob, text="Port")
self.lblPort.grid(row = 1, column = 0)
self.txtPort = Entry(self.englob, validate="key")
self.txtPort["validatecommand"] = (self.txtIp.register(testVal),"%P","%d")
self.txtPort.grid(row = 1, column = 1)
if port != 0:
self.txtPort.insert(0, port)
#Buttons
self.btnDone = Button(self.buttons, text="Done", font="Verdana 10 bold")
self.btnDone.bind("<ButtonRelease>", self.done)
self.btnDone.pack(side=LEFT, padx=20)
self.btnSave = Button(self.buttons, text="Save", font="Verdana 10 bold")
self.btnSave.bind("<ButtonRelease>", self.save)
self.btnSave.pack(side=RIGHT, padx=20)
def done(self, event):
self.window.destroy()
def save(self, event):
name = ""
if self.txtIp.get() != "" and self.txtPort.get() != "":
try:
file = open(path + "clientConfig.config", "r")
name = file.readline().replace("name:", "").replace("\n", "")
file.close()
try:
file = open(path + "clientConfig.config", "w")
file.writelines("name:" + name + "\n")
file.writelines("ip:" + self.txtIp.get() + "\n")
file.writelines("port:" + self.txtPort.get())
file.close()
self.window.destroy()
except:
messagebox.showwarning(title="Error - IM", message="Impossible create or modify file clientConfig.config")
except:
file = open(path + "clientConfig.config", "w")
file.writelines("name:" + name + "\n")
file.writelines("ip:" + self.txtIp.get() + "\n")
file.writelines("port:" + self.txtPort.get())
file.close()
self.window.destroy()
else:
messagebox.showinfo(title="Failure - IM", message="IP e Porta devem ser preenchidos")
#window = Tk()
#Client(window)
#window.title("Configurações Iniciais - IM")
#window.geometry("300x150")
#window.resizable(width=False, height=False)
#window.mainloop()