Freeze with wxpython on python 2.3 or python 2.4 on Win32 with Thread

Discussion in 'Python' started by Tsubasa[Hokage], Jan 27, 2005.

  1. Hello i have a problem with thread and wxpython on WIN32.

    With this script :

    I would like to SetValue to my gauge widget in a thread.
    I can GetValue without a hitch but if I SetValue it freezing.

    Try following script and go to AF-Tools Menu and click install

    Normally in the install thread, I wrote "yo" in the console and I
    SetValue of the gauge passed to the thread.

    from wxPython.wx import *
    from wxPython.wizard import *
    from os import *
    #import os
    #import win32wnet, win32netcon
    #import wmi
    #import win32api
    #import _winreg
    import time
    #import win32com,win32com.client
    import sys
    import shutil
    import dircache
    import struct, socket
    from optparse import OptionParser

    #import thread
    import threading
    #import Queue

    __auteur__="FLFRSPA"


    def map_drive(local, remote, username, password):
    ###self.map_drive("Z:",
    "\\\L00438\c$",r"localhost\administrator","")###
    return win32wnet.WNetAddConnection2(win32netcon.RESOURCETYPE_DISK,local,
    remote, None,username, password,0)

    class InstallThread(threading.Thread):
    ###La classe recoit
    login,password,workstation,checkboxdomaine,domaine,self.log,self.g1,package
    def __init__(self,login,password,workstation,checkboxdomaine,domaine,log,gauge,package):
    threading.Thread.__init__(self)
    self.result = None
    self.i=0
    self.login=login
    self.password=password
    self.workstation=workstation
    self.package=package
    self.checkboxdomaine=checkboxdomaine
    self.domaine=domaine
    self.log=log
    self.gauge=gauge

    def run(self):
    self.result=1
    print "yo"
    self.gauge.SetValue(10)
    self.result=1
    return

    class main_PyXrunAS(wx.Frame):
    def __init__(self, *args, **kwds):
    kwds["style"] = wx.DEFAULT_FRAME_STYLE
    wx.Frame.__init__(self, *args, **kwds)
    sizer = wxBoxSizer(wxVERTICAL)
    self.SetSizer(sizer)
    menuBar = wx.MenuBar()
    # 1st menu from left
    menu1 = wx.Menu()
    #menu1.Append(101, "&Options", "Options de la LoFBOX")
    menu1.Append(102, "&Quitter", "Quitter")
    #self.Bind(wx.EVT_MENU, self.quit, id=102)
    menu1.AppendSeparator()
    menuBar.Append(menu1, "&Fichier")
    # 2st menu from left
    menu2 = wx.Menu()
    menu2.Append(201, "&Test Connection", "Effectue un test de
    connection sur la machine distante")
    #self.Bind(wx.EVT_MENU, self.aide_dialog, id=201)
    self.Bind(wx.EVT_MENU, self.query_freespace, id=201)
    menu2.Append(202, "&Reboot Distant", "Effectue le reboot d'une
    machine")
    self.Bind(wx.EVT_MENU, self.query_reboot, id=202)
    #self.Bind(wx.EVT_MENU, self.Apropos, id=202)
    menu2.Append(202, "&Wake On Lan", "Effectue le démarrage
    distant d'une machine")
    menu2.Append(203, "&Install", "Install le package
    selectionné")
    self.Bind(wx.EVT_MENU, self.install_thread, id=203)
    menu2.AppendSeparator()
    menuBar.Append(menu2, "&AF-Tools")
    self.SetMenuBar(menuBar)
    ###Logo Titre
    self.remlogo = wx.StaticBitmap(self, -1,
    wx.Bitmap("data/remote_logo.jpg", wx.BITMAP_TYPE_ANY),pos=(5,5))
    sizer.AddWindow(self.remlogo, 0, wxALIGN_CENTRE|wxALL, 5)
    sizer.AddWindow(wxStaticLine(self, -1), 0, wxEXPAND|wxALL, 5)
    ###Creation de la liste des packages
    self.a=dircache.listdir('Package/')
    self.a=self.a[:] # Copy the return value so we can change 'a'
    t1=wx.Choice(self, -1, (60, 60), choices = self.a)
    self.tc1 = t1
    self.Bind(wx.EVT_CHOICE, self.Evtpackage, t1)
    t1.Bind(wx.EVT_TEXT, self.Evtpackage)
    l1 = wx.StaticText(self, -1, "Package: ",pos=(5,60))
    l1.SetBackgroundColour("white")
    ###Jauge d'evolution
    self.g1 = wx.Gauge(self, -1, 50, (220, 210), (190, 25))
    self.g1.SetBezelFace(3)
    self.g1.SetShadowWidth(3)
    self.g1.SetBackgroundColour("White")
    ###Label progression
    label_pro = wx.StaticText(self, -1, "Progression:
    ",pos=(220,190))
    label_pro.SetBackgroundColour("white")
    ###Multiline log
    label_log = wx.StaticText(self, -1, "Log: ",pos=(220,60))
    label_log.SetBackgroundColour("white")
    self.log = wx.TextCtrl(self, -1, "", size=(250,
    100),pos=(220,80),
    style = wx.TE_MULTILINE
    #| wx.TE_RICH
    | wx.TE_RICH2
    )
    ###Setmachine
    self.workstation = wx.TextCtrl(self, -1, "", size=(105,
    -1),pos=(60,100))
    label_workstation = wx.StaticText(self, -1, "Poste:
    ",pos=(6,100))
    label_workstation.SetBackgroundColour("white")
    #self.workstation.SetInsertionPoint(0)
    self.workstation.Bind(wx.EVT_TEXT, self.EvtChar)
    ###Bouton pour tester la connection
    #self.workstation_connect = wx.Button(self, -1, "Test
    Connection", (210,55))
    #self.workstation_connect.Disable()
    #self.label_freespace = wx.StaticText(self, -1,
    "",pos=(270,102))
    #self.label_freespace.SetBackgroundColour("white")
    #self.Bind(wx.EVT_BUTTON, self.query_freespace,
    self.workstation_connect)

    #self.Bind(wx.EVT_BUTTON, self.OnButton, b)
    ###Login/Password/Domain
    self.t2 = wx.TextCtrl(self, -1, "", size=(105,
    -1),pos=(60,140))
    l2 = wx.StaticText(self, -1, "Login: ",pos=(6,142))
    l2.SetBackgroundColour("white")
    self.t3 = wx.TextCtrl(self, -1, "", size=(105,
    -1),pos=(60,180),style=wx.TE_PASSWORD)
    l3 = wx.StaticText(self, -1, "Password: ",pos=(6,182))
    l3.SetBackgroundColour("white")
    self.t5 = wx.TextCtrl(self, -1, "", size=(105,
    -1),pos=(60,230))
    l4 = wx.StaticText(self, -1, "Domaine: ",pos=(6,230))
    self.t5.Disable()
    l4.SetBackgroundColour("white")
    self.cb1 = wx.CheckBox(self, -1, "Domaine", (60, 210), (90,
    20), wx.NO_BORDER)
    self.cb1.SetBackgroundColour("white")
    self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, self.cb1)
    self.__set_properties()
    self.__do_layout()

    def EvtChar(self, event):
    pass
    return

    def Evtpackage(self, event):
    pass
    return
    #print self.workstation.GetValue()
    #event.Skip()

    def EvtListBox(self, event):
    print 'EvtListBox: %s\n' % event.GetString()

    def EvtCheckListBox(self, event):
    index = event.GetSelection()
    label = self.lb.GetString(index)
    #status = 'un'
    if self.lb.IsChecked(index):
    self.list_option.append(label)
    else:
    self.list_option.remove(label)
    print self.list_option
    self.lb.SetSelection(index) # so that (un)checking also
    selects (moves the highlight)
    return


    def __set_properties(self):
    # begin wxGlade: MyFrame1.__set_properties
    #user=win32api.GetUserName()
    #self.t4.WriteText('%s' % user)
    #self.t4.Disable()
    self.SetTitle("AF-Remote-MSI "+__version__)
    self.SetBackgroundColour("white")
    self.SetSize((490, 350))
    # end wxGlade

    def __do_layout(self):
    # begin wxGlade: MyFrame1.__do_layout
    sizer_3 = wx.BoxSizer(wx.VERTICAL)
    self.SetAutoLayout(True)
    self.SetSizer(sizer_3)
    self.Layout()
    # end wxGlade

    def query_freespace(self,event):
    machine=self.workstation.GetValue()
    pi=0
    try:
    c = wmi.WMI (machine)
    pi=1
    except:
    self.log.WriteText(str(sys.exc_info()[1])+" \n")
    pi=0
    #self.label_freespace.SetLabel("Connection OK: ")
    if (pi!=0):
    for disk in c.Win32_LogicalDisk (DriveType=3):
    self.log.WriteText(self.log.GetValue()+str(disk.Caption)+str(int(disk.FreeSpace)/1000000)+
    "Mo Libres\n")
    return

    def query_reboot(self,event):
    pi=0
    try:
    machine=self.workstation.GetValue()
    c = wmi.WMI (computer=str(machine),
    privileges=["RemoteShutdown"])
    pi=1
    except:
    self.log.WriteText(str(sys.exc_info()[1])+" \n")
    pi=0
    if (pi!=0):
    os = c.Win32_OperatingSystem (Primary=1)[0]
    os.Reboot ()
    self.log.WriteText("Reboot [OK]")
    return

    def SendWol(self,event):
    if (str(self.mac.GetValue())!="aa-bb-cc-dd-ee \n"):
    self.WakeOnLan(self.mac.GetValue())
    else:
    self.log.WriteText("Erreur adresse mac")
    return

    def WakeOnLan(self,ethernet_address):
    pass

    def EvtCheckBox(self, event):
    #print 'EvtCheckBox: %d\n' % event.IsChecked()
    if (event.IsChecked()==1):
    self.t5.Enable()
    if (event.IsChecked()==0):
    self.t5.Disable()

    def OnButton(self, event):

    dlg = wx.DirDialog(self, "Choose a directory:",

    style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON)
    if dlg.ShowModal() == wx.ID_OK:
    # This returns a Python list of files that were selected.
    paths = dlg.GetPath()
    for path in paths:
    self.tc1.WriteText('%s' % path)
    dlg.Destroy()
    return

    def Ecrire_batch(self):
    #contenu="cscript //H:CScript //S \n"
    contenu="xrunas.vbs /profile /user:administrator /pwd:?????
    "+str(self.tc1.GetValue())
    #contenu=contenu+" -pw="+input+" -language=F -client=100
    -sysname=\"FP1 - Production\""
    batch="AFpyxras.bat"
    file = open(batch, "w")
    file.write(contenu)
    file.close()
    return

    def install_thread(self,event):
    subThread2 =
    InstallThread(self.t2.GetValue(),self.t3.GetValue(),self.workstation.GetValue(),self.t5.GetValue(),self.cb1,self.log,self.g1,self.a[self.tc1.GetSelection()])
    subThread2.start()
    subThread2.join()

    #result = subThread2.result
    #print result

    def install_vnc(self,name,time):
    pass
    return

    class GUIThread(threading.Thread):
    def __init__(self):
    threading.Thread.__init__(self)

    def run(self):
    class PyXrunAS(wx.App):
    def OnInit(self):
    wx.InitAllImageHandlers()
    frame_2 = main_PyXrunAS(None, -1, "")
    self.SetTopWindow(frame_2)
    frame_2.Show()
    return 1

    self.app = PyXrunAS(0)
    self.app.MainLoop()

    if __name__ == "__main__":
    subThread = GUIThread()
    subThread.start()
    subThread.join()
    #subThread.Run()

    Can someone help me ?
     
    Tsubasa[Hokage], Jan 27, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Storm
    Replies:
    2
    Views:
    907
    Storm
    Oct 16, 2004
  2. Wagner Dias
    Replies:
    3
    Views:
    3,079
    Andre Kostur
    Mar 28, 2005
  3. Tsubasa[Hokage]
    Replies:
    0
    Views:
    500
    Tsubasa[Hokage]
    Jan 26, 2005
  4. =?iso-8859-1?B?aWFuYXLp?=

    wxPython problem with freeze.py

    =?iso-8859-1?B?aWFuYXLp?=, Apr 5, 2006, in forum: Python
    Replies:
    0
    Views:
    402
    =?iso-8859-1?B?aWFuYXLp?=
    Apr 5, 2006
  5. Replies:
    5
    Views:
    262
    Olivier Renaud
    Mar 15, 2007
Loading...

Share This Page