> cmq i problemi rimarranno se blocchi il mainloop lanciando dei processi
esterni
> e questo mi fa pensare che ho ragione.

Si effettivamente il problema รจ proprio il blocco della mainloop.

Ho provato ad utilizzare Tread, ma ottengo lo stesso risultato

from threading import Thread
from gi.repository import Gtk
class Windows(object):

    def __init__(self):
        self.ApplicazioneGlade = Gtk.Builder()
        self.ApplicazioneGlade.add_from_file(PercorsoGlade)
        self.ApplicazioneGlade.connect_signals(self)
        self.statusbar = self.ApplicazioneGlade.get_object('statusbar')
        self.context_id = self.statusbar.get_context_id('statusbar')
        self.statusbar.push(self.context_id, 'Status . . . . . . . ')

    def run(self, *args):

        self.ApplicazioneGlade.get_object("FinestraPrincipale").show()
        self.model = Gtk.ListStore(str,str,str,str,str)
        elencoimpianti = self.ApplicazioneGlade.get_object('ElencoImpianti')
        elencoimpianti.get_selection().set_mode(Gtk.SelectionMode.SINGLE)
        col1,col2,col3,col4,col5 = range(5)
        elencoimpianti.set_model(self.model)
        cell = Gtk.CellRendererText()
        column2 = Gtk.TreeViewColumn("- Nome Impianto -", cell, text = col2)
        column2.set_resizable (True)
        column2.set_sort_column_id(col2)
        elencoimpianti.append_column (column2)
        column3 = Gtk.TreeViewColumn("- Codice Impianto -", cell, text =
col3)
        column3.set_resizable (True)
        column3.set_sort_column_id(col3)
        elencoimpianti.append_column (column3)
        column4 = Gtk.TreeViewColumn(" Pers ", cell, text = col4)
        column4.set_resizable (True)
        column4.set_sort_column_id(col4)
        elencoimpianti.append_column (column4)
        column5 = Gtk.TreeViewColumn(" -PBX- ", cell, text = col5)
        column5.set_resizable (True)
        column5.set_sort_column_id(col5)
        elencoimpianti.append_column (column5)
        datiDB =
pyodbc.connect('DRIVER={};DBQ={};PWD={}'.format(DriverMDB,PercorsoMDB,PwdMDB))
        cur = datiDB.cursor()
        cur.execute("select
CapoImpianto,NomeImpianto,CodiceImpianto,NomeSW,TipoCentrale from Impianti
where Gestione = '"+gestione+"'")
        dati = cur.fetchall()
        for dato in dati:
            if str(dato[0]) == "None":
                var1= ''
            else:
                var1=str(dato[0])
            var2=str(dato[1])
            var3=str(dato[2])
            var4=str(dato[3])
            if str(dato[4]) == "None":
                var5= ''
            else:
                var5=str(dato[4])
            record = self.model.append([var1,var2,var3,var4,var5])
        cur.close()
        datiDB.close()
        Gtk.main()

    def on_statusbar_show(self, button,obj,data=None):
        self.statusbar = self.ApplicazioneGlade.get_object('statusbar')
        self.context_id = self.statusbar.get_context_id('statusbar')
        self.statusbar.push(self.context_id, self.MessaggioStatusbar)

    def on_VerTab_clicked(self, button):
        self.MessaggioStatusbar = 'Hai premuto Verifica Tabella'
        thread1 = Thread(target=self.on_statusbar_show(self,
button,data=None),args=[])
        thread1.start()
        thread1.join()

        thread2 = Thread(target=self.on_VerTab_clicked2(self),args=[])
        thread2.start()
        thread2.join()

    def on_VerTab_clicked2(self, button):
        ... codice che controlla parecchi file di testo ......
        ... insert INTO DB .........
Windows().run()



Posso risolvere questo problema facilmente senza stravolgere il programma?

Ciao
Marcello
_______________________________________________
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python

Rispondere a