21.12.2022 Views

python_para_desenvolvedores_2ed

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

222 Interface Gráfica

callbacks = {

'on_main_destroy': self.on_main_destroy,

'on_btn_fechar_clicked': self.on_main_destroy,

'on_btn_rodar_clicked': self.on_btn_rodar_clicked

}

self.tree.signal_autoconnect(callbacks)

def on_btn_rodar_clicked(self, widget):

"""

Roda o comando.

"""

ntr_cmd = self.tree.get_widget('ntr_cmd')

chk_shell = self.tree.get_widget('chk_shell')

cmd = ntr_cmd.get_text()

if cmd:

# chk_shell.state será 1 se chk_shell estiver marcado

if chk_shell.state:

cmd = 'cmd start cmd /c ' + cmd

subprocess.Popen(args=cmd)

else:

# Caixa de dialogo

dialog = gtk.MessageDialog(parent=self.tree.get_widget('main'),

flags=gtk.DIALOG_MODAL |

gtk.DIALOG_DESTROY_WITH_PARENT,

type=gtk.MESSAGE_OTHER, buttons=gtk.BUTTONS_OK,

message_format='Digite um comando.')

dialog.set_title('Mensagem')

dialog.set_position(gtk.WIN_POS_CENTER_ALWAYS)

# Exibe a caixa

dialog.run()

dialog.destroy()

return True

def on_main_destroy(self, widget):

"""

Termina o programa.

"""

raise SystemExit

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!