9_progress_bar.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Simple window - Just a simple window
  4. # Copyright (c) 2016 Jorge Maldonado Ventura
  5. #
  6. # This file is part of Simple window
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. import gi
  19. import sys
  20. gi.require_version('Gtk', '3.0')
  21. from gi.repository import Gtk
  22. import time
  23. import threading
  24. class Window(Gtk.Window):
  25. def __init__(self):
  26. Gtk.Window.__init__(self, title='Saludar')
  27. self.set_tooltip_text('Este programa es una farsa')
  28. self.set_default_size(400, 300)
  29. self.set_border_width(140)
  30. self.set_position(Gtk.WindowPosition.CENTER)
  31. self.grid = Gtk.Grid()
  32. self.grid.set_column_homogeneous(True)
  33. self.user_name = Gtk.Entry()
  34. self.user_name.set_tooltip_text('Aquí debes poner tu nombre')
  35. self.passwd = Gtk.Entry()
  36. self.passwd.set_visibility(False)
  37. self.login_button = Gtk.Button('Iniciar sesión')
  38. self.login_button.connect('clicked', self.login)
  39. self.login_button.set_tooltip_text('Accede a tu cuenta')
  40. self.exit_button = Gtk.Button('Salir')
  41. self.exit_button.connect('clicked', self.exit)
  42. self.progress_bar = Gtk.ProgressBar()
  43. self.grid.attach(self.user_name, 0, 0, 2, 1)
  44. self.grid.attach(self.passwd, 0, 1, 2, 1)
  45. self.grid.attach(self.exit_button, 0, 2, 1, 1)
  46. self.grid.attach(self.login_button, 1, 2, 1, 1)
  47. self.grid.attach(self.progress_bar, 0, 3, 2, 1)
  48. self.add(self.grid)
  49. def connect_to_server(self):
  50. for i in range(101):
  51. self.progress_bar.set_fraction(i / 100)
  52. time.sleep(.2)
  53. print('Bienvenido a tu cuenta, ' + self.user_name.get_text() + '.')
  54. def login(self, widget):
  55. if self.passwd.get_text() == 'secreta':
  56. thread = threading.Thread(target=self.connect_to_server)
  57. thread.start()
  58. else:
  59. print('Lo siento, la contraseña introducida es incorrecta.')
  60. sys.exit(1)
  61. def exit(self, widget):
  62. print('Hasta otra. Gracias por usar el programa.')
  63. sys.exit(0)
  64. if __name__ == '__main__':
  65. win = Window()
  66. win.connect('delete-event', Gtk.main_quit)
  67. win.show_all()
  68. Gtk.main()