Created
March 10, 2018 09:25
-
-
Save JuniorPolegato/47df82ece1559bffe166e192abe9bb6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import time | |
try: | |
import gi | |
gi.require_version('Gtk', '3.0') | |
from gi.repository import Gtk | |
except Exception: | |
raise | |
class Janela(Gtk.Window): | |
def __init__(self, *args, **kwargs): | |
super(Janela, self).__init__(*args, **kwargs) | |
self.set_title('Janela de teste') | |
button1 = Gtk.Button('Botão de teste') | |
self.add(button1) | |
button1.connect('clicked', self.fazer_alguma_coisa) | |
self.connect('delete-event', Gtk.main_quit) | |
self.continuar = True # Controle do código em "segundo plano" | |
self.set_default_size(500, 200) | |
self.show_all() | |
def fazer_alguma_coisa(self, button): | |
TITLE = 'Teste' | |
message = '<b>Fazendo alguma <i>coisa</i></b>' | |
def fechar(widget, *args, **kwargs): | |
widget.get_toplevel().hide() | |
widget.get_toplevel().destroy() | |
self.continuar = False | |
messagedialog = Gtk.MessageDialog(message_format="MessageDialog") | |
messagedialog.set_transient_for(self) | |
messagedialog.set_modal(True) # usuário preso no dialog | |
messagedialog.set_title(TITLE) | |
messagedialog.set_markup(message) | |
btn = messagedialog.add_button("I _Understand", Gtk.ResponseType.CLOSE) | |
btn.connect('clicked', fechar) | |
messagedialog.connect('delete-event', fechar) | |
messagedialog.show() | |
# agora o código continua | |
while self.continuar: | |
self.set_title(time.ctime() + ' - ' + str(time.time())) | |
# Atualizar a tela e permitir que o usuário interaja | |
while Gtk.events_pending(): | |
Gtk.main_iteration() | |
time.sleep(.1) # Dorme por 0,1 segundo (100 ms) | |
self.continuar = True | |
if __name__ == '__main__': | |
janela = Janela() | |
Gtk.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment