0
Good night! I am working with Gtk3 and Python3 and am structuring my project to build an ERP for GNU/LINUX platform. I’m using Glade to build the GUI and using Gtk Builder to manipulate the GUI components. In the example below I intended to exemplify my idea in a very generic way with two acquisitions . py one for each window as I want to structure my design into separate modules where I can call one at a time not to overload the machines where it will run, always taking into account that I need to build a light system for machines that are already outdated :(.
File 1 (Window 1) :
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import gi
import base64
import zlib
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
ui = Gtk.Builder()
ui.add_from_string(zlib.decompress(base64.b64decode(b'eJyNksFSwjAQhu88xbpXp0D14qGtM86IL6DjsbNNFhpZE0xSkEfyOXwxgxUBYdRbJvn23/33T3H9+iywZB+MsyXmwzECW+W0sbMSH+4n2RVeV4PiLMvgji17iqxhZWILMyHNcDm8uBjmkGUJMjayn5LiagBQeH7pjOcAYpoSZ3F+jrtGqWyMo0/ONU+sIiihEEq8i/NHY7VbIRhd4hNZFspxQyZ24d2CfVyDpWcuUZGtp051AasJSeBitAW++GBmluSL1hyid2uElqwW9iWSqwMZX/dd6hwhrGix4NTYun68JKJaI7o/b0aQZLB1otlvgdEe8YM+MnfTxehsb66J9aG/Ux6FGhaE6MkGoUiNpMs1J8u3IRK8vwFBrwL5T/+n9JYmmKSB1b3vjhb2x5L/W+JZsVlyqDVPqZP4S+VBQkqMmrPeS2hz47rvNZ3KZxNAv+ajOHYPxWjvc34Ayi/vWQ==')).decode("utf-8"))
class Janela1(object):
def __init__(self, *args, **kwargs):
super(Handler, self).__init__(*args, **kwargs)
# --> Inicialização
self.usuario = "TESTE" # --> Gostaria de herdar a variável de inicialização dessa janela1 para janela2
# -- ao sair da janela1 destroy a aplicação
def ao_sair_janela_1(self, *args):
Gtk.main_quit()
# -- Ao clicar no botão da janela1 é impresso na saida padrão a
# -- mensagem e posteriormente chamo a janela2
def clicou_janela1(self, *args):
print("Clicou janela 1")
import janela2 as janela #--> Aqui importo o script da janela2 e apelido de "janela"
janela.execucao(classe=janela.Janela2) #--> Chamo minha função na janela2 aonde ligo os sinais
#--> da janela e crio um loop do Gtk para segunda Janela
ui.connect_signals(Janela1())
window = ui.get_object("janela1")
window.show_all()
if __name__ == '__main__':
Gtk.main()
File 2 (Window 2):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import gi
import os
import base64
import zlib
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
ui = Gtk.Builder()
# --> (Dúvida: da linha 4 a 10 não queria importar esses módulos novamente,
# --> gostaria de herdar eles da primeira janela)
# --> Arquivo da janela2
def modulo(string=b'eJyNkk1SAjEQhfecou2tNfy5cTEDVVYJF8BySfUkDQSaBJMMyJE8hxczOFCgQ6G7VPK9/nkv+fB9LbBlH4yzBfbaXQS2ymlj5wW+TEbZIw4Hrfwuy2DMlj1F1rAzcQFzIc3w0O732z3IsgQZG9nPSPGgBZB7fquM5wBiygLncXWP50ZJ1sXON+fKJasISiiEAsdx9WqsdjsEowtckmWhPh7IxG6827CPe7C05gIV2enMqSrgYEQSOO+cgOv82mkSHEx81USDmVuSI6g5RO/2CAuyWtgXSG4ayPjpaSAIO9psOI1oXb1IqqEWRnR9PjSXZMXCiWZ/AjoXxC+6YcNTFaOztQ1lPDbu4UnQ3E6oZEGInmwQilRKutxzMuc5RILPDyCoq0D/9/rX6m1NMKnGdb/+iOO/Es+KzZbDVPOMKok3lD8CUmLUivVFQIcbV93M5xBAbXMjjvND3rn4xl9Nhv2k'):
return string
# --> Conexão dos sinais e criação do Loop para janela
def execucao(classe=None):
ui.connect_signals(classe())
Gtk.main()
class Janela2(object):
def __init__(self, interface=modulo(), *args, **kwargs):
ui.add_from_string(zlib.decompress(base64.b64decode(interface)).decode("utf-8"))
super(Janela2, self).__init__(*args, **kwargs)
# --> Inicialização
self.janela2 = ui.get_object("janela2")
self.janela2.show_all()
# -- Fecha a janela2
def ao_sair_janela2(self, *args):
Gtk.main_quit()
# -- Exibe a mensagem quando clicado no botão da janela2
def clicou_janela2(self, *args):
print("Clicou na janela 2")
My doubt is even how to inherit the modules already imported in window 1 to window 2, as well as the variables of startup of window 1 to window 2
If anyone can give me a hand I’d appreciate it! Thanks!
Boa Tarde jsbueno!
– Michael Mattos
thank you for answering I believe I am on the right track so I was a little afraid to keep importing modules to each window and cause a problem of excess memory used.
– Michael Mattos
Regarding gtk.main() I will restructure the process and any questions I ask again.
– Michael Mattos
now regarding boot variables for example when I call a new module I want to pass to it some information, example the user who called this module among other things, when I am working on a project that exists a single file of Glade I use only Gtk calls to windows now when I left for a separate structuring in modules I had this doubt, and ended up assembling this gambiarra to work in part.
– Michael Mattos
I don’t know if there is any content that addresses this issue specifically, using Python or C so I can study.
– Michael Mattos
you cannot pass variables by "modules' -but since it is defined your window without classes - yes, when you create a class, you can pass parameters, which have seen parameters in Métod 'init" - and these parameters can be gtk controls in the first window, where methods in the second window can read values, for example - do not need to be frozen values.
– jsbueno