jeudi 17 mars 2016

wxPython check box not setting value

So I have a wxPython window I've made that was working fine, until I tried to add a new check box to give the user an option for asymmetry.

import poser
import random
import wx
import wx.py
import wx.aui


scene = poser.Scene()
man = poser.WxAuiManager()
root = man.GetManagedWindow()

fig = scene.CurrentFigure()
allowAsymetric = False
paramList = []

lst = ["Full Body Morphs","All Head/Face", "Face Shape", "Forehead","Eyes", "Ear",  "Nose", "Cheek", "Chin/Jaw", "Lips"]


# Our dialog box
class userInput(wx.Frame):

    def __init__(self, parent) :

        # Call the parent class initialisation method
        wx.Frame.__init__(self, parent = parent, pos=wx.Point(675, 323), size=wx.Size(400, 400), style=wx.DEFAULT_FRAME_STYLE, title = "Random Hive")

        global lst, allowAsymetric


        # Set up the UI
        #self.CenterOnScreen(wx.BOTH)
        self.panel = wx.Panel(self,id=-1,size=(400,350))
        self.panel.SetBackgroundColour("#4B4B4B")


        # Checklist
        self.lb = wx.CheckListBox(self.panel, -1, (20, 20), (350,200), lst)



        #Select All Button
        self.SelectALL = wx.Button(self.panel,id=100,pos=(20,260),size=(-1,- 1),label="Select All")
        self.SelectALL.SetBackgroundColour("#5D5D5D") 
        self.SelectALL.SetForegroundColour("#CBCBCB") 
        self.SelectALL.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseOver) 
        self.SelectALL.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave) 
        self.Bind(wx.EVT_BUTTON, self.OnSelectALL, self.SelectALL)

        #Select None Button
        self.SelectNONE = wx.Button(self.panel,id=110,pos=(150,260),size=(-1,- 1),label="Select None")
        self.SelectNONE.SetBackgroundColour("#5D5D5D") 
        self.SelectNONE.SetForegroundColour("#CBCBCB") 
        self.SelectNONE.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseOver) 
        self.SelectNONE.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave) 
        self.Bind(wx.EVT_BUTTON, self.OnSelectNONE, self.SelectNONE)

        #Inversion Button
        self.SelectINVERT = wx.Button(self.panel,id=120,pos=(275,260),size=(- 1,-1),label="Invert Selection")
        self.SelectINVERT.SetBackgroundColour("#5D5D5D") 
        self.SelectINVERT.SetForegroundColour("#CBCBCB") 
        self.SelectINVERT.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseOver) 
        self.SelectINVERT.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave) 
        self.Bind(wx.EVT_BUTTON, self.OnSelectINVERT, self.SelectINVERT)

        # Cancel button
        self.Cancel = wx.Button(self.panel,id=140,pos=(20,310),size=(-1,-1),label="Close")
        self.Cancel.SetBackgroundColour("#5D5D5D")
        self.Cancel.SetForegroundColour("#CBCBCB")
        self.Cancel.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseOver)
        self.Cancel.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
        self.Cancel.Bind(wx.EVT_BUTTON, self.OnSelectCancel, self.Cancel)

        # Ok button
        self.OK = wx.Button(self.panel,id=150, pos=(275,310),size=(-1,-1),label="Apply")
        self.OK.SetDefault()
        self.OK.SetBackgroundColour("#5D5D5D")
        self.OK.SetForegroundColour("#CBCBCB")
        self.OK.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseOver)
        self.OK.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave)
        self.Bind(wx.EVT_BUTTON, self.OnSelectOK, self.OK)

        #Undoe Button
        self.Undo = wx.Button(self.panel, id = 130, pos = (150,310), size= (-1,-1), label = "Undo Morphs")
        self.Undo.SetBackgroundColour("#5D5D5D")
        self.Undo.SetForegroundColour("#CBCBCB")
        self.Undo.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseOver) 
        self.Undo.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave) 
        self.Bind(wx.EVT_BUTTON, self.OnUndo, self.Undo)

        #static text
        self.infoLable = wx.StaticText(self.panel, pos = (20,230),label = 'Enter Morph Value')
        self.morphNumber = wx.TextCtrl(self.panel, pos = (150,230))

        self.asym = wx.CheckBox(self.panel, label='Asymetric', pos=(275, 230))
        #asym.SetValue(False)

        #asym.Bind(wx.EVT_CHECKBOX, self.AsymetricOn)
        self.Bind(wx.EVT_CHECKBOX, self.AsymetricOn, self.asym)


    def AsymetricOn(self, event):
        sender = event.GetEventObject()
        if sender.GetValue() == True:
            allowAsymetric = True
        else:
            allowAsymetric = False
        print allowAsymetric

    def OnSelectALL(self,event): 
        i=0
        while i < len(lst): 
            self.lb.Check(i,True) 
            i=i+1

    def OnSelectNONE(self,event):
        i=0
        while i < len(lst): 
            self.lb.Check(i,False) 
            i=i+1

    def OnSelectINVERT(self,event): 
        i=0
        while i < len(lst):
            if self.lb.IsChecked(i) == True:
                action = False
                self.lb.Check(i,action)
                i=i +1
                continue
            elif self.lb.IsChecked(i) == False:
                action = True 
                self.lb.Check(i,action) 
                i=i+1
                continue
            i=i+1

    def OnSelectOK(self,event):
        fig.Memorize()
        smn = self.morphNumber.GetString(0,self.morphNumber.GetLineLength(0))       
        try:
            mN = float(smn)
            print "before function choice asymetric is ", allowAsymetric
            functionChoice(self.lb.GetCheckedStrings(), mN) 
            print "after is it ", allowAsymetric
        except:
            print 'Enter a morph value'


    def OnUndo(self,event):
        fig.Reset()
        scene.Draw()

    def OnSelectCancel(self,event):
        #print "Cancel clicked"
        self.Destroy()

    def OnMouseOver(self,event):
        element = event.GetEventObject()
        element.SetBackgroundColour("#737373")
        event.Skip()

    def OnMouseLeave(self,event):
        element = event.GetEventObject()
        element.SetBackgroundColour("#5D5D5D")
        event.Skip()

When the window pops up I can check and uncheck the box just fine, and I get printed out a correct value for allowAsymetry according to what I've clicked like so:

False True False True

But as soon as I click my Ok/Apply button the value is false no matter what the check box shows:

before function choice asymetric is False in function choice allowAsymetric is False

I can't figure out why the value of allowAsymetric keeps setting back to False.




Aucun commentaire:

Enregistrer un commentaire