123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Simple window - Just a simple window
- # Copyright (c) 2016 Jorge Maldonado Ventura
- #
- # This file is part of Simple window
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- import gi
- import sys
- gi.require_version('Gtk', '3.0')
- from gi.repository import Gtk
- import time
- import threading
- class Window(Gtk.Window):
- def __init__(self):
- Gtk.Window.__init__(self, title='Saludar')
- self.set_tooltip_text('Este programa es una farsa')
- self.set_default_size(400, 300)
- self.set_border_width(140)
- self.set_position(Gtk.WindowPosition.CENTER)
- self.grid = Gtk.Grid()
- self.grid.set_column_homogeneous(True)
- self.user_name = Gtk.Entry()
- self.user_name.set_tooltip_text('Aquí debes poner tu nombre')
- self.passwd = Gtk.Entry()
- self.passwd.set_visibility(False)
- self.login_button = Gtk.Button('Iniciar sesión')
- self.login_button.connect('clicked', self.login)
- self.login_button.set_tooltip_text('Accede a tu cuenta')
- self.exit_button = Gtk.Button('Salir')
- self.exit_button.connect('clicked', self.exit)
- self.progress_bar = Gtk.ProgressBar()
- self.grid.attach(self.user_name, 0, 0, 2, 1)
- self.grid.attach(self.passwd, 0, 1, 2, 1)
- self.grid.attach(self.exit_button, 0, 2, 1, 1)
- self.grid.attach(self.login_button, 1, 2, 1, 1)
- self.grid.attach(self.progress_bar, 0, 3, 2, 1)
- self.add(self.grid)
- def connect_to_server(self):
- for i in range(101):
- self.progress_bar.set_fraction(i / 100)
- time.sleep(.2)
- print('Bienvenido a tu cuenta, ' + self.user_name.get_text() + '.')
- def login(self, widget):
- if self.passwd.get_text() == 'secreta':
- thread = threading.Thread(target=self.connect_to_server)
- thread.start()
- else:
- print('Lo siento, la contraseña introducida es incorrecta.')
- sys.exit(1)
- def exit(self, widget):
- print('Hasta otra. Gracias por usar el programa.')
- sys.exit(0)
- if __name__ == '__main__':
- win = Window()
- win.connect('delete-event', Gtk.main_quit)
- win.show_all()
- Gtk.main()
|