Message from discussion
global variable issue on linux
Received: by 10.68.219.66 with SMTP id pm2mr357531pbc.8.1336788993622;
Fri, 11 May 2012 19:16:33 -0700 (PDT)
X-BeenThere: xsi_list@googlegroups.com
Received: by 10.68.229.8 with SMTP id sm8ls9064158pbc.0.gmail; Fri, 11 May
2012 19:16:33 -0700 (PDT)
Received: by 10.68.219.66 with SMTP id pm2mr357528pbc.8.1336788993579;
Fri, 11 May 2012 19:16:33 -0700 (PDT)
Received: by 10.68.219.66 with SMTP id pm2mr357526pbc.8.1336788993559;
Fri, 11 May 2012 19:16:33 -0700 (PDT)
Return-Path: <softimage-boun...@listproc.autodesk.com>
Received: from ussclpdadmta014.autodesk.com (ussclpdadmta014.autodesk.com. [132.188.64.239])
by gmr-mx.google.com with ESMTPS id gp10si3787010pbc.2.2012.05.11.19.16.33
(version=TLSv1/SSLv3 cipher=OTHER);
Fri, 11 May 2012 19:16:33 -0700 (PDT)
Received-SPF: pass (google.com: domain of softimage-boun...@listproc.autodesk.com designates 132.188.64.239 as permitted sender) client-ip=132.188.64.239;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of softimage-boun...@listproc.autodesk.com designates 132.188.64.239 as permitted sender) smtp.mail=softimage-boun...@listproc.autodesk.com
Received: from listproc.autodesk.com ([144.111.38.9])
by ussclpdadmta014.autodesk.com (8.14.3/8.12.6) with ESMTP id q4C2GEA7000988;
Fri, 11 May 2012 19:16:16 -0700 (PDT)
Received: from listproc.autodesk.com (localhost [127.0.0.1])
by listproc.autodesk.com (8.13.0/8.12.6) with ESMTP id q4C2G9rB018671;
Fri, 11 May 2012 19:16:10 -0700 (PDT)
Received: from ussclpeadmta005.autodesk.com (ussclpeadmta005.autodesk.com
[10.35.67.27])
by listproc.autodesk.com (8.13.0/8.12.6) with ESMTP id q4C2G6G9018667
for <softim...@listproc.autodesk.com>;
Fri, 11 May 2012 19:16:06 -0700 (PDT)
Received: from mail47.messagelabs.com (mail47.messagelabs.com [216.82.254.20])
by ussclpeadmta005.autodesk.com (8.14.3/8.12.6) with ESMTP id
q4C2G1Xl024396 for <softim...@listproc.autodesk.com>;
Fri, 11 May 2012 19:16:01 -0700 (PDT)
X-Env-Sender: xl.mailingl...@gmail.com
X-Msg-Ref: server-3.tower-47.messagelabs.com!1336788957!415086!1
X-Originating-IP: [209.85.214.181]
X-SpamReason: No, hits=0.4 required=7.0 tests=HTML_50_60,HTML_MESSAGE,
ML_RADAR_SPEW_LINKS_14,RCVD_BY_IP,spamassassin:
X-StarScan-Version: 6.5.7; banners=-,-,-
X-VirusChecked: Checked
Received: (qmail 26306 invoked from network); 12 May 2012 02:15:58 -0000
Received: from mail-ob0-f181.google.com (HELO mail-ob0-f181.google.com)
(209.85.214.181)
by server-3.tower-47.messagelabs.com with RC4-SHA encrypted SMTP;
12 May 2012 02:15:58 -0000
Received: by obbuo19 with SMTP id uo19so4564564obb.12
for <softim...@listproc.autodesk.com>;
Fri, 11 May 2012 19:15:57 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.60.22.38 with SMTP id a6mr355879oef.32.1336788957184; Fri, 11
May 2012 19:15:57 -0700 (PDT)
Received: by 10.60.169.228 with HTTP; Fri, 11 May 2012 19:15:57 -0700 (PDT)
In-Reply-To: <CAPaTLMS9q093g9aSGv4RhGUPWFUpZPDqyDGW5yAmT2qHkHH...@mail.gmail.com>
References: <CAO_EcGBvisDLsqg1+pyDpRfq15Vc7QVsyZk6-dHq4mZF+s-...@mail.gmail.com>
<CAO_EcGBHBVDfdryt0VP=PODLF9JKPTms4X=K9eu0SYcK2_Q...@mail.gmail.com>
<CAPaTLMTua4ss7bbFMT9+F5+Vfo96PPDmnW5Ov7KztKEQNAV...@mail.gmail.com>
<CAO_EcGDqmizNxAgM8F7=rFTomHmuCRm1T0_71ijCpYp=uga...@mail.gmail.com>
<CAPaTLMSmF79C0enAqdkMj8g+=DcYq913H9cQKwud=7hdtGp...@mail.gmail.com>
<CAO_EcGBSA9EYD9vhQGdinL5p3ZTsNOc5GM=ndsazY7HjXMp...@mail.gmail.com>
<CAPaTLMS9q093g9aSGv4RhGUPWFUpZPDqyDGW5yAmT2qHkHH...@mail.gmail.com>
Date: Fri, 11 May 2012 22:15:57 -0400
Message-ID: <CAO_EcGB-wGwXCT8jdBa6sNmC4uNxGitksnDGTEQ=8uenarR...@mail.gmail.com>
Subject: Re: [Python] global variable issue on linux
From: Xavier Lapointe <xl.mailingl...@gmail.com>
To: softim...@listproc.autodesk.com
Content-Type: multipart/alternative; boundary=e89a8ff1c538eec18804bfcd6ee0
X-BeenThere: softim...@listproc.autodesk.com
X-Mailman-Version: 2.1.8
Precedence: list
Reply-To: softim...@listproc.autodesk.com
List-Id: <softimage.listproc.autodesk.com>
List-Unsubscribe: <http://listproc.autodesk.com/mailman/listinfo/softimage>,
<mailto:softimage-requ...@listproc.autodesk.com?subject=unsubscribe>
List-Post: <mailto:softim...@listproc.autodesk.com>
List-Help: <mailto:softimage-requ...@listproc.autodesk.com?subject=help>
List-Subscribe: <http://listproc.autodesk.com/mailman/listinfo/softimage>,
<mailto:softimage-requ...@listproc.autodesk.com?subject=subscribe>
Sender: softimage-boun...@listproc.autodesk.com
Errors-To: softimage-boun...@listproc.autodesk.com
--e89a8ff1c538eec18804bfcd6ee0
Content-Type: text/plain; charset=ISO-8859-1
Tried your solution but could not get it to work :(
Found a way, but I would need to understand the internal mechanism to
reproduce it more cleanly.
from win32com.client import constants
> constants.__dicts__.append({'PLUGIN_GLOBAL_SCOPE': None,'project':
> {},'category': '','entities': []})
> container = [d for d in constants.__dicts__ if 'PLUGIN_GLOBAL_SCOPE' in
> d][0]
Far from being ideal ...
2012/5/11 Alok Gandhi <alok.gandhi2...@gmail.com>
> One last thing, I checked one plugin where this works, of course in
> windows, but in my code I do not use 'global ' keyword when accesing the
> global dict. Something like this:
> globalDict = {}
>
> def _setGlobalDict(inObj=None, meshData=None):
> if inObj:
> globalDict['obj'] = inObj # no use of 'global' here.
>
> if meshData:
> globalDict['data'] = meshData
>
> return True
>
> and then I call _setGlobalDict() wherever I need to.
>
>
> On Fri, May 11, 2012 at 9:37 PM, Xavier Lapointe <xl.mailingl...@gmail.com
> > wrote:
>
>> I'll add some context:
>>
>> - everything lives in the same plugin
>> - I tried storing it in a container coming from an imported module
>> - tried accessing and setting the global variable directly in the
>> globals() dictionary
>> - Grumble Gumble.
>>
>>
>>
>>
>> 2012/5/11 Alok Gandhi <alok.gandhi2...@gmail.com>
>>
>>> Yes if PPG is not getting refreshed then this seems weird. The only
>>> thing that comes to mind is maybe the custom command execution is making
>>> things go wrong. What if you use a function declared inside the plugin
>>> instead of calling the custom command ? or maybe the custom command should
>>> be implemented in the same plugin as the PPG, this does not make sense but
>>> is worth a try.
>>>
>>>
>>> On Fri, May 11, 2012 at 9:24 PM, Xavier Lapointe <
>>> xl.mailingl...@gmail.com> wrote:
>>>
>>>> Hm, yes I could store it in a parameter or another way ... just this
>>>> feels hacky to get something basic done (granted no refresh happend during
>>>> the plugin execution).
>>>>
>>>> This should work, like Matt mentioned :/
>>>>
>>>> Oh well.
>>>>
>>>>
>>>>
>>>>
>>>> 2012/5/11 Alok Gandhi <alok.gandhi2...@gmail.com>
>>>>
>>>>> I am not sure whether this works under windows as well, the plugin
>>>>> script can get refreshed and all your global variables will be
>>>>> re-initialized. The only good approaches that I have been using is to store
>>>>> the varaibles in UIITems lists. This works well for the 3D com objects as
>>>>> well. Another idea would be to pass on objects returning through a safe
>>>>> array from the commands itself.
>>>>>
>>>>>
>>>>> On Fri, May 11, 2012 at 9:13 PM, Xavier Lapointe <
>>>>> xl.mailingl...@gmail.com> wrote:
>>>>>
>>>>>>
>>>>>> hit another PPG UI Item ***
>>>>>>
>>>>>> ... All happening under the same Property page.
>>>>>>
>>>>>> 2012/5/11 Xavier Lapointe <xl.mailingl...@gmail.com>
>>>>>>
>>>>>>> Hey guys,
>>>>>>>
>>>>>>> This one really surprised me. I tend to avoid global variable in
>>>>>>> Softimage plugins as much as I can, but sometimes it might be convenient.
>>>>>>>
>>>>>>> So basically, I wanted to use a global variable ( simple Python
>>>>>>> Dictionary ) to keep some stuff in reference while interacting with a PPG.
>>>>>>> I remember clearly that it was working well under Windows, so
>>>>>>> I assume this is a python 2.5 Linux issue (if this is an issue -
>>>>>>> please tell me if this is normal under Soft with python 2.5).
>>>>>>>
>>>>>>> Here's basically what I was trying to do:
>>>>>>>
>>>>>>> [imports ....]
>>>>>>>>
>>>>>>>> # Global Scope
>>>>>>>
>>>>>>>> LAST_SELECTION = {
>>>>>>>> 'project': {},
>>>>>>>> 'category': '',
>>>>>>>> 'entities': [],
>>>>>>>> }
>>>>>>>>
>>>>>>>> def CustomCommand_Execute():
>>>>>>>> global LAST_SELECTION
>>>>>>>> [Do some modifications to LAST_SELECTION]
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Following this pattern:
>>>>>>>
>>>>>>> - Prompt the PPG
>>>>>>> - Interact with the UI
>>>>>>> - The custom command is fired - do some modifications to
>>>>>>> LAST_SELECTION
>>>>>>> - hit another PPG UI
>>>>>>> - Hell the LAST_SELECTION global is back to the inital value!
>>>>>>>
>>>>>>> I've been tracing the LAST_SELECTION variable with id(), and it's
>>>>>>> changing every time I interact with the UI; showing clearly that there is
>>>>>>> something nasty going on under the hood (?)
>>>>>>>
>>>>>>> Any idea to get this working?
>>>>>>>
>>>>>>> Alan mentioned the
>>>>>>> Application.SetGlobal/Application.GetGlobal functions ... but still, this
>>>>>>> should be working natively, isn't?
>>>>>>>
>>>>>>> Thanks!
>>>>>>>
>>>>>>> --
>>>>>>> Xavier
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Xavier
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Xavier
>>>>
>>>
>>>
>>>
>>> --
>>>
>>>
>>
>>
>> --
>> Xavier
>>
>
>
>
> --
>
>
--
Xavier
--e89a8ff1c538eec18804bfcd6ee0
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Tried your solution but could not get it to work :(<div><br></div><div><br>=
</div><div>Found a way, but I would need to understand the internal mechani=
sm to reproduce it more cleanly.</div><div><br></div><div><blockquote class=
=3D"gmail_quote" style=3D"margin-top:0px;margin-right:0px;margin-bottom:0px=
;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204)=
;border-left-style:solid;padding-left:1ex">
from win32com.client import constants<br>constants.__dicts__.append({'P=
LUGIN_GLOBAL_SCOPE': None,'project': {},'category': =
9;','entities': []})<br>container =3D [d for d in constants.__d=
icts__ if 'PLUGIN_GLOBAL_SCOPE' in d][0]</blockquote>
<div><br></div><div><br></div><div>Far from being ideal ...</div></div><div=
><br><br><div class=3D"gmail_quote">2012/5/11 Alok Gandhi <span dir=3D"ltr"=
><<a href=3D"mailto:alok.gandhi2...@gmail.com" target=3D"_blank">alok.ga=
ndhi2...@gmail.com</a>></span><br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">One last thing, I checked one plugin where t=
his works, of course in windows, but in my code I do not use 'global &#=
39; keyword when accesing the global dict. Something like this:<br>
globalDict =3D {}<br><br>def _setGlobalDict(inObj=3DNone, meshData=3DNone):=
<br>
=A0=A0=A0 if inObj:<br>=A0=A0=A0=A0=A0=A0=A0 globalDict['obj'] =3D =
inObj # no use of 'global' here.<br>=A0=A0=A0 <br>=A0=A0=A0 if mesh=
Data:<br>=A0=A0=A0=A0=A0=A0=A0 globalDict['data'] =3D meshData<br>=
=A0=A0=A0 <br>=A0=A0=A0 return True<br><br>and then I call _setGlobalDict()=
wherever I need to.<div class=3D"HOEnZb">
<div class=3D"h5"><br>
<br><div class=3D"gmail_quote">On Fri, May 11, 2012 at 9:37 PM, Xavier Lapo=
inte <span dir=3D"ltr"><<a href=3D"mailto:xl.mailingl...@gmail.com" targ=
et=3D"_blank">xl.mailingl...@gmail.com</a>></span> wrote:<br><blockquote=
class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc soli=
d;padding-left:1ex">
<span>I'll add some context:</span><div><ul><li style=3D"margin-left:15=
px">everything lives in the same plugin</li><li style=3D"margin-left:15px">=
I tried storing it in a container coming from an imported module</li>
<li style=3D"margin-left:15px">tried accessing and setting the global varia=
ble directly in the globals() dictionary</li><li style=3D"margin-left:15px"=
>Grumble Gumble.</li></ul></div><div><div><div><br>
</div><div><br></div><br><div class=3D"gmail_quote">
2012/5/11 Alok Gandhi <span dir=3D"ltr"><<a href=3D"mailto:alok.gandhi20=
0...@gmail.com" target=3D"_blank">alok.gandhi2...@gmail.com</a>></span><br=
><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1=
px #ccc solid;padding-left:1ex">
Yes if PPG is not getting refreshed then this seems weird. The only thing t=
hat comes to mind is maybe the custom command execution is making things go=
wrong. What if you use a function declared inside the plugin instead of ca=
lling the custom command ? or maybe the custom command should be implemente=
d in the same plugin as the PPG, this does not make sense but is worth a tr=
y.<div>
<div><br>
<br><div class=3D"gmail_quote">On Fri, May 11, 2012 at 9:24 PM, Xavier Lapo=
inte <span dir=3D"ltr"><<a href=3D"mailto:xl.mailingl...@gmail.com" targ=
et=3D"_blank">xl.mailingl...@gmail.com</a>></span> wrote:<br><blockquote=
class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc soli=
d;padding-left:1ex">
Hm, yes I could store it in a parameter or another way ... just this feels =
hacky to get something basic done (granted no refresh happend during the pl=
ugin execution).<div><br></div><div>This should work, like Matt mentioned :=
/<div>
<br></div><div>Oh well.</div><div><br></div><div><br></div><div><div><div><=
br><br><div class=3D"gmail_quote">2012/5/11 Alok Gandhi <span dir=3D"ltr">&=
lt;<a href=3D"mailto:alok.gandhi2...@gmail.com" target=3D"_blank">alok.gand=
hi2...@gmail.com</a>></span><br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">I am not sure whether this works under windo=
ws as well, the plugin script can get refreshed and all your global variabl=
es will be re-initialized. The only good approaches that I have been using =
is to store the varaibles in UIITems lists. This works well for the 3D com =
objects as well. Another idea would be to pass on objects returning through=
a safe array from the commands itself.<div>
<div><br>
<br><div class=3D"gmail_quote">On Fri, May 11, 2012 at 9:13 PM, Xavier Lapo=
inte <span dir=3D"ltr"><<a href=3D"mailto:xl.mailingl...@gmail.com" targ=
et=3D"_blank">xl.mailingl...@gmail.com</a>></span> wrote:<br><blockquote=
class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc soli=
d;padding-left:1ex">
<div><span><br></span></div><span>hit another PPG UI Item ***=A0</span><div=
><font color=3D"#222222" face=3D"arial, sans-serif"><br></font></div><div><=
font color=3D"#222222" face=3D"arial, sans-serif">... All happening under t=
he same Property page.<br>
</font><div><div><br><div class=3D"gmail_quote">2012/5/11 Xavier Lapointe <=
span dir=3D"ltr"><<a href=3D"mailto:xl.mailingl...@gmail.com" target=3D"=
_blank">xl.mailingl...@gmail.com</a>></span><br><blockquote class=3D"gma=
il_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-lef=
t:1ex">
Hey guys,<div><br></div><div>This one really surprised me. I tend to avoid =
global variable in Softimage plugins as much as I can, but sometimes it mig=
ht be convenient.</div><div><br></div><div>So basically, I wanted to use a =
global variable ( simple Python Dictionary ) to keep some stuff in referenc=
e while interacting with a PPG. I remember clearly that it was working well=
under Windows, so=A0</div>
<div>I assume this is a python 2.5 Linux issue (if this is an issue - pleas=
e tell me if this is normal under Soft with python 2.5).</div><div><br></di=
v><div>Here's basically what I was trying to do:</div><br><blockquote c=
lass=3D"gmail_quote" style=3D"margin-top:0px;margin-right:0px;margin-bottom=
:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,=
204);border-left-style:solid;padding-left:1ex">
[imports ....]<br><br></blockquote><div># Global Scope=A0</div><blockquote =
class=3D"gmail_quote" style=3D"margin-top:0px;margin-right:0px;margin-botto=
m:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204=
,204);border-left-style:solid;padding-left:1ex">
LAST_SELECTION =3D {<br>=A0 =A0 'project': {},<br>=A0 =A0 'cate=
gory': '',<br>=A0 =A0 'entities': [],<br>}<br><br>def C=
ustomCommand_Execute():<br>=A0 =A0 global=A0LAST_SELECTION<br>=A0 =A0 [Do s=
ome modifications to LAST_SELECTION]<br>
=A0</blockquote><div><br clear=3D"all"><div>Following this pattern:</div><d=
iv><ul><li>Prompt the PPG</li><li>Interact with the UI</li><li>The custom c=
ommand is fired - do some modifications to LAST_SELECTION</li><li>hit anoth=
er PPG UI</li>
<li>Hell the LAST_SELECTION global is back to the inital value!</li></ul><d=
iv>I've been tracing the LAST_SELECTION variable with id(), and it'=
s changing every time I interact with the UI; showing clearly that there is=
something nasty going on under the hood (?)</div>
</div><div><br></div><div>Any idea to get this working?</div><div><br></div=
><div>Alan mentioned the Application.SetGlobal/Application.GetGlobal=A0func=
tions ... but still, this should be working natively, isn't?</div><div>
<br></div><div>Thanks!</div><span><font color=3D"#888888"><div><br></div>--=
<br>Xavier<br>
</font></span></div>
</blockquote></div><br><br clear=3D"all"><div><br></div></div></div><span><=
font color=3D"#888888">-- <br>Xavier<br>
</font></span></div>
</blockquote></div><br><br clear=3D"all"><br></div></div><span><font color=
=3D"#888888">-- <br><img alt=3D""><br>
<div></div>
</font></span></blockquote></div><br><br clear=3D"all"><div><br></div></div=
></div><span><font color=3D"#888888">-- <br>Xavier<br>
</font></span></div></div>
</blockquote></div><br><br clear=3D"all"><br></div></div><span><font color=
=3D"#888888">-- <br><img alt=3D""><br>
<div></div>
</font></span></blockquote></div><br><br clear=3D"all"><div><br></div></div=
></div><span><font color=3D"#888888">-- <br>Xavier<br>
</font></span></blockquote></div><br><br clear=3D"all"><br></div></div><spa=
n class=3D"HOEnZb"><font color=3D"#888888">-- <br><img alt=3D""><br>
<div></div>
</font></span></blockquote></div><br><br clear=3D"all"><div><br></div>-- <b=
r>Xavier<br>
</div>
--e89a8ff1c538eec18804bfcd6ee0--