Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyApplication(Gtk.Application):
- # Main initialization routine
- def __init__(self, application_id, flags):
- self.App=Gtk.Application.__init__(self, application_id=application_id, flags=flags)
- #main_Window(self)
- # create and activate a MyWindow, with self (the MyApplication) as
- # application the window belongs to.
- # Note that the function in C activate() becomes do_activate() in Python
- def do_activate(self):
- self.win1 = start_Connection_Window(self)
- # show the window and all its content
- # this line could go in the constructor of MyWindow as well
- # start up the application
- # Note that the function in C startup() becomes do_startup() in Python
- def do_startup(self):
- Gtk.Application.do_startup(self)
- def main_Window(self,socket, username, password):
- self.win1.close()
- self.win2 = main_Window(self,socket, username, password)
- class start_Connection_Window(Gtk.ApplicationWindow):
- def __init__(self, application):
- self.Application = application
- print self.Application
- # Read GUI from file and retrieve objects from Gtk.Builder
- try:
- GtkBuilder = Gtk.Builder.new_from_file(os.path.dirname(os.path.realpath(__file__))+"someGladefile")
- GtkBuilder.connect_signals(self)
- except GObject.GError:
- print("Error reading GUI file")
- raise
- # Fire up the main window
- self.start_Connection_Window = GtkBuilder.get_object("start_Connection")
- self.start_Connection_Window.set_application(application)
- self.ServerIP_Input = GtkBuilder.get_object("ServerIP_Input")
- self.Server_Port_Input = GtkBuilder.get_object("Server_Port-Input")
- self.Username_Input = GtkBuilder.get_object("Username_Input")
- self.Password_Input = GtkBuilder.get_object("Password_Input")
- self.start_Connection_Window.show()
- def on_btn_Connect_clicked(self, button):
- button.set_sensitive(False)
- #self.host = str(self.ServerIP_Input.get_text())
- self.host = str(self.ServerIP_Input.get_text())
- self.username = str(self.Username_Input.get_text())
- print self.username
- self.password = str(self.Password_Input.get_text())
- print self.password
- try:
- try:
- self.port = self.Server_Port_Input.get_text()
- print self.port == ""
- if self.port == "":
- self.port =int(1312)
- else:
- self.port = int(self.port)
- except:
- print "wrong Serverport"
- raise
- self.clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- self.clientsocket.connect((self.host, self.port))
- self.LENGTH_SIZE = 16
- data = self.username+"<|<-username{|}password->|>"+self.password
- lenght = str(len(data))
- self.clientsocket.send(lenght.zfill(self.LENGTH_SIZE))
- print data
- self.clientsocket.send(data)
- lenght = self.clientsocket.recv(self.LENGTH_SIZE)
- data = self.clientsocket.recv(int(lenght))
- print data
- if (data == str("ok")):
- self.Application.main_Window(self.clientsocket,self.username, self.password)
- else:
- print "Fail from Server: "+ data
- except:
- print "can't find Host"
- button.set_sensitive(True)
- def close(self, *args):
- self.start_Connection_Window.destroy()
- def on_MainWindow_destroy(self, window):
- #self.Application.main_Window()
- print "Bye from startupManager"
- def on_Window_destroy(self):
- print("Bye from destroyed")
- class main_Window(Gtk.ApplicationWindow):
- def __init__(self, application, socket, username, password):
- self.Application = application
- self.socket = socket
- self.username= username
- self.password = password
- # Read GUI from file and retrieve objects from Gtk.Builder
- try:
- GtkBuilder = Gtk.Builder.new_from_file(os.path.dirname(os.path.realpath(__file__))+"galde file")
- GtkBuilder.connect_signals(self)
- except GObject.GError:
- print("Error reading GUI file")
- raise
- # Fire up the main window
- self.MainWindow = GtkBuilder.get_object("main_Window")
- self.MainWindow.set_application(application)
- self.image = GtkBuilder.get_object("image2")
- #self.start(self.socket, self.username, self.password)
- #self.SClient.start()
- self.MainWindow.show()
- def on_btn_Connect_clicked(self, button):
- print "Would Start Conn"
- def close(self, *args):
- print "closing"
- self.MainWindow.destroy()
- def on_MainWindow_destroy(self, window):
- #self.Application.new_window()
- print "Bye"
- def on_Window_destroy(self, window):
- #self.Application.new_window()
- print "Trying to say goodbye"
- self.SClient.stopMe()
- self.SClient.join()
- print "Bye from mainWindow"
- def on_Window_delete(self, window):
- #self.Application.new_window()
- print "Trying to say goodbye"
- self.SClient.stopMe()
- self.SClient.join()
- print "Bye from mainWindow"
- def start(self, socket, username, password):
- self.SClient = SC(socket, username, password, self)
- def __str__(self):
- print "I'am the Window"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement