Advertisement
Guest User

Untitled

a guest
Jan 16th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.46 KB | None | 0 0
  1. class MyApplication(Gtk.Application):
  2. # Main initialization routine
  3. def __init__(self, application_id, flags):
  4. self.App=Gtk.Application.__init__(self, application_id=application_id, flags=flags)
  5.  
  6.  
  7. #main_Window(self)
  8.  
  9. # create and activate a MyWindow, with self (the MyApplication) as
  10. # application the window belongs to.
  11. # Note that the function in C activate() becomes do_activate() in Python
  12. def do_activate(self):
  13. self.win1 = start_Connection_Window(self)
  14. # show the window and all its content
  15. # this line could go in the constructor of MyWindow as well
  16.  
  17.  
  18. # start up the application
  19. # Note that the function in C startup() becomes do_startup() in Python
  20. def do_startup(self):
  21. Gtk.Application.do_startup(self)
  22.  
  23. def main_Window(self,socket, username, password):
  24. self.win1.close()
  25. self.win2 = main_Window(self,socket, username, password)
  26.  
  27.  
  28.  
  29. class start_Connection_Window(Gtk.ApplicationWindow):
  30.  
  31. def __init__(self, application):
  32. self.Application = application
  33. print self.Application
  34.  
  35. # Read GUI from file and retrieve objects from Gtk.Builder
  36. try:
  37. GtkBuilder = Gtk.Builder.new_from_file(os.path.dirname(os.path.realpath(__file__))+"someGladefile")
  38. GtkBuilder.connect_signals(self)
  39. except GObject.GError:
  40. print("Error reading GUI file")
  41. raise
  42.  
  43. # Fire up the main window
  44. self.start_Connection_Window = GtkBuilder.get_object("start_Connection")
  45. self.start_Connection_Window.set_application(application)
  46.  
  47. self.ServerIP_Input = GtkBuilder.get_object("ServerIP_Input")
  48. self.Server_Port_Input = GtkBuilder.get_object("Server_Port-Input")
  49. self.Username_Input = GtkBuilder.get_object("Username_Input")
  50. self.Password_Input = GtkBuilder.get_object("Password_Input")
  51.  
  52. self.start_Connection_Window.show()
  53.  
  54. def on_btn_Connect_clicked(self, button):
  55. button.set_sensitive(False)
  56. #self.host = str(self.ServerIP_Input.get_text())
  57.  
  58.  
  59. self.host = str(self.ServerIP_Input.get_text())
  60.  
  61. self.username = str(self.Username_Input.get_text())
  62. print self.username
  63.  
  64. self.password = str(self.Password_Input.get_text())
  65. print self.password
  66. try:
  67. try:
  68. self.port = self.Server_Port_Input.get_text()
  69. print self.port == ""
  70. if self.port == "":
  71. self.port =int(1312)
  72. else:
  73. self.port = int(self.port)
  74.  
  75.  
  76. except:
  77. print "wrong Serverport"
  78. raise
  79. self.clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  80. self.clientsocket.connect((self.host, self.port))
  81. self.LENGTH_SIZE = 16
  82. data = self.username+"<|<-username{|}password->|>"+self.password
  83. lenght = str(len(data))
  84. self.clientsocket.send(lenght.zfill(self.LENGTH_SIZE))
  85. print data
  86. self.clientsocket.send(data)
  87.  
  88.  
  89. lenght = self.clientsocket.recv(self.LENGTH_SIZE)
  90. data = self.clientsocket.recv(int(lenght))
  91. print data
  92.  
  93. if (data == str("ok")):
  94. self.Application.main_Window(self.clientsocket,self.username, self.password)
  95.  
  96. else:
  97. print "Fail from Server: "+ data
  98.  
  99.  
  100.  
  101. except:
  102. print "can't find Host"
  103. button.set_sensitive(True)
  104.  
  105.  
  106.  
  107. def close(self, *args):
  108.  
  109. self.start_Connection_Window.destroy()
  110.  
  111. def on_MainWindow_destroy(self, window):
  112. #self.Application.main_Window()
  113. print "Bye from startupManager"
  114.  
  115. def on_Window_destroy(self):
  116.  
  117. print("Bye from destroyed")
  118.  
  119.  
  120.  
  121. class main_Window(Gtk.ApplicationWindow):
  122.  
  123. def __init__(self, application, socket, username, password):
  124.  
  125. self.Application = application
  126. self.socket = socket
  127. self.username= username
  128. self.password = password
  129.  
  130.  
  131. # Read GUI from file and retrieve objects from Gtk.Builder
  132. try:
  133. GtkBuilder = Gtk.Builder.new_from_file(os.path.dirname(os.path.realpath(__file__))+"galde file")
  134. GtkBuilder.connect_signals(self)
  135. except GObject.GError:
  136. print("Error reading GUI file")
  137. raise
  138.  
  139. # Fire up the main window
  140. self.MainWindow = GtkBuilder.get_object("main_Window")
  141. self.MainWindow.set_application(application)
  142.  
  143. self.image = GtkBuilder.get_object("image2")
  144.  
  145. #self.start(self.socket, self.username, self.password)
  146. #self.SClient.start()
  147.  
  148. self.MainWindow.show()
  149.  
  150. def on_btn_Connect_clicked(self, button):
  151. print "Would Start Conn"
  152.  
  153. def close(self, *args):
  154. print "closing"
  155. self.MainWindow.destroy()
  156.  
  157. def on_MainWindow_destroy(self, window):
  158. #self.Application.new_window()
  159. print "Bye"
  160.  
  161. def on_Window_destroy(self, window):
  162. #self.Application.new_window()
  163. print "Trying to say goodbye"
  164. self.SClient.stopMe()
  165. self.SClient.join()
  166. print "Bye from mainWindow"
  167.  
  168. def on_Window_delete(self, window):
  169. #self.Application.new_window()
  170. print "Trying to say goodbye"
  171. self.SClient.stopMe()
  172. self.SClient.join()
  173. print "Bye from mainWindow"
  174. def start(self, socket, username, password):
  175. self.SClient = SC(socket, username, password, self)
  176.  
  177.  
  178. def __str__(self):
  179. print "I'am the Window"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement