Re: gettext again

2005-08-08 Thread stas
On Mon, 08 Aug 2005 17:01:21 +0200, cantabile wrote:

> stasz a écrit :

> Wht ! Working at last, after three days... It wasn't the LANG param 
[...]
> Anyways, you made my day my friend !
> Many many thanks !
Your welcome :-)

Stas

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gettext again

2005-08-08 Thread stas
On Mon, 08 Aug 2005 17:39:34 +0200, cantabile wrote:

> BTW stasz,
> Maybe you'll have still some time for the following question. Trying my 
> luck :))
> 
> Suppose I have several units (.py files), say test.py test1.py tets2.py 
> , test.py being my main file.
> I've read I can import gettext and install in the main unit. Then, must 
> I create .po files for each unit or is there a way to make a single .po 
> file for the whole app. ?
Yes there is.

As a reminder, make sure that you install gettext in the namespace
of your toplevel module.
What I mean is this:

test1.py imports test2.py and test3.py
test2.py imports test4.py

Now you have to place the gettext.install call in test1.py and
then the other modules can access it.
If you place the gettext call in, for example, test2.py then only
test2.py and test4.py have access to it.
So when it don't work as you expect make sure to check if every
module has access to the "_" from gettext.

So now for your question about one po/mo file for multiple
modules.
I use this file for a project of mine it also includes some
explanation in case I forget it myself :-)

The project is called "Guido van Robot".
http://gvr.sf.net


The files mentioned inside this file are used in the above project
and serve as an example in this case.
You could replace the files with your own to try it.
The file itself is called "FilesForTrans" so you could put this
file together with your test modules inside a directory and follow
the instructions in side "FilesForTrans".

Stas Z


Contents of "FilesForTrans"
 cut here -
## These files contain i18n strings
## Use: xgettext -f ./FilesForTrans -p /tmp
## The message.po will be located in /tmp
## Now do: msgmerge ./po/nl/gvr.po /tmp/messages.po > /tmp/new_nl.po
## compile the .po to mo (place the .po after editing in ./po/nl/)
## msgfmt ./po/nl/gvr.po -o ./locale/nl/LC_MESSAGES/gvr.mo 

gvr.py
gvrparser.py
world.py
worldMap.py
Editorwindows.py





-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wx.MessageDialog displayed without components inside

2005-08-13 Thread stas
On Sat, 13 Aug 2005 09:37:15 -0700, perchef wrote:

> Is there a reason why a wx.MessageDialog would be displayed without
> components inside ?
> 
> this :
> 
> md = wx.MessageDialog(None,'foo','bar',wx.YES_NO)
Here you create a dialog

> result = md.ShowModal()
Now you show it

> md.Destroy()
But right after showing it, you destroy it.
 
> In my application, give me :
> http://img252.imageshack.us/my.php?image=messagedialog6nw.jpg
> 
> This isn't a bug in wxPython because when I use the same code in
> pyshell I obtain the expected result. So, there must be a reason but I
> can't figure out why.
Because in the shell you first have to type the Destroy call
so the dialog has some time to live. :-)

Stas



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wx.MessageDialog displayed without components inside

2005-08-14 Thread stas
On Sat, 13 Aug 2005 16:34:17 -0700, perchef wrote:

> nope, I have put md.Destroy() away and it didn't change something.
> I don't think that's the problem because ShowModal() is a blocking
> method, execution is stop until you press YES or NO (in my case with
> wx.YES_NO)
Just a thought, do you cal the event loop ?
Because this minimal example just works like it should.

import wx
app = wx.PySimpleApp() 
md = wx.MessageDialog(None,'foo','bar',wx.YES_NO)
result = md.ShowModal()
app.MainLoop()

Stas

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wx.MessageDialog displayed without components inside

2005-08-14 Thread stas
On Sun, 14 Aug 2005 07:45:10 -0700, perchef wrote:

> 
>> Just a thought, do you call the event loop ?
> yes i do.
> I really can't see my a MessageDialog would appear without components
> inside. maybe a thread problem ?
Does the example I gave work?
I mean when you copy and paste it does it show a normal dialog?

Stas

-- 
http://mail.python.org/mailman/listinfo/python-list


Unknown locale nb_NO ?

2004-12-07 Thread Stas Z
Hello,

Just noticed that the locale 'nb_NO' is not supported in Python?!

[EMAIL PROTECTED]:~$ locale
LANG=nb_NO
[...]

[EMAIL PROTECTED]:~$ python
Python 2.3.4 (#2, Sep 24 2004, 08:39:09) 
[GCC 3.3.4 (Debian 1:3.3.4-12)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getdefaultlocale()
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.3/locale.py", line 346, in getdefaultlocale
return _parse_localename(localename)
  File "/usr/lib/python2.3/locale.py", line 280, in _parse_localename
raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: nb_NO
>>> 

Any help would appreciated.

Thanks,
Stas


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unknown locale nb_NO ?

2004-12-07 Thread Stas Z
On Tue, 07 Dec 2004 15:22:00 +0100, Ola Natvig wrote:

> Stas Z wrote:
>> Hello,
>> 
>> Just noticed that the locale 'nb_NO' is not supported in Python?!
>> 
[...]
> I believe the standard locale for "Norsk bokmål" is 'no_NO'. You could 
> try that.
When I 'googled' for it, I saw that no_NO has become nn_NO/nb_NO.
However it strikes me as odd, that Python2.3.4 raises an exception when
querying for a valid locale. I tend to call it a bug :-(

Stas
-- 
http://mail.python.org/mailman/listinfo/python-list


how to trouble shoot - RuntimeError: Open Failed

2013-09-06 Thread stas poritskiy
hey guys,
I am working on application. App is processing a list of files in folders.
Folders act as a NEW-LOOP. so if all files in one folder had been worked on, 
file is then saved and next folder is picked up.
it works fine only if i have a SINGLE folder, however, when another folder is 
there, i get this RuntimeError: Open Failed.
I checked if those could be the files by leaving only single (another folder), 
however all was fine.
Questions - How can i trouble shoot what is causing the problem? i don't know 
where to begin.

Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to trouble shoot - RuntimeError: Open Failed

2013-09-06 Thread stas poritskiy
The code in development is mine, and i am using the API provided by a main 
developer.

At the moment, i am not using any try/except functionality. 

here is the full Exception output:
[CODE]
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python27\32bit\lib\lib-tk\Tkinter.py", line 1470, in __call__
return self.func(*args)
  File "E:\sporitskiy\HON\Project\scene7\s7operator\gui.py", line 59, in 

cmd1 = lambda: vntProcessor.colData(folders.path, folders.subFolders)
  File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 184, 
in colData
setVars()
  File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 79, 
in __call__
self.batchFiles()
  File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 55, 
in batchFiles
self.vntConnect.createVNTobjects(self.vntObjMgroup.keyList, 
self.vntLtoF.keyValList, self.vntObjFile.keyList, myPath)
  File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 113, 
in createVNTobjects
self.createImage(groupName, layerName, fileName, imagePath, self.vntGroups)
  File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 137, 
in createImage
img = open_image(imageFile)
  File "", line 2, in open_image
  File "C:\Python27\32bit\lib\site-packages\s7vampy\arg_validator.py", line 
213, in __call__
return func(*args, **keywords)
  File "C:\Python27\32bit\lib\site-packages\s7vampy\image.py", line 181, in 
open_image
return Image(_S7VAM_IMAGE.Open(filename))
RuntimeError: Open Failed: 
'C:/Users/sporitskiy/Desktop/Practice/HIWM2MSB/hiwm2mpa_upholstery_esq_leather_ro_12_0001.tif'

[/CODE]

-- Just a few words on what this all does --

Structure: 3 modules 
Module 1 - dataPreparation.py -responsible for string processing - made of 
several classes and methods that receive PATH to directory, collect all files 
in a LIST, after that for each file based on type of file name it sorts it out 
to appropriate categories that can be accessed through class instances.

Module 2 - gui.py - Responsible for GUI. It crates a simple GUi-layout that 
offer BROWSE button (to get the PATH), QUIT button to exit application, LISTBOX 
that lists subfolders from the PATH, and BATCH button that must execute the 
main processor.

Module 3 - vntProcessor.py - Responsible for processing of collected data. This 
module is based of an API of another application. It receives the values from 
the BATCH-button and invokes specific methods based on sorting that was 
performed using MODULE 1.

My approach:

i created an instance of GUI and call it to start interface ( have a window 
open) in the interface, i browse for specific folder, so my PATH variable is 
set. my list box is populated with subfolders.(using Tkinter for gui)

my next step should be to press the BATCH folder and forward all of the values 
(PATH and ARRAY of SUBFOLDERS) to my Module 3 (processor).
and as soon as my script tries to open NEXT FOLDER is when i get this 
RuntimeError, but if i leave the same folder by itself - everything is fine.

If by looking at the Exception Log i posted, you could tell me what portion of 
the code i should show here - it would be very helpful. thanks!

On Friday, September 6, 2013 10:39:04 AM UTC-5, Neil Cerutti wrote:
> On 2013-09-06, stas poritskiy  wrote:
> 
> > I am working on application. App is processing a list of files
> 
> > in folders. Folders act as a NEW-LOOP. so if all files in one
> 
> > folder had been worked on, file is then saved and next folder
> 
> > is picked up. it works fine only if i have a SINGLE folder,
> 
> > however, when another folder is there, i get this RuntimeError:
> 
> > Open Failed. I checked if those could be the files by leaving
> 
> > only single (another folder), however all was fine. Questions -
> 
> > How can i trouble shoot what is causing the problem? i don't
> 
> > know where to begin.
> 
> 
> 
> We can help better if you show some of your code; a minimal
> 
> cut-down version that exhibits the error is ideal.
> 
> 
> 
> Are you literally getting a RuntimeError? That would be weird.
> 
> 
> 
> -- 
> 
> Neil Cerutti
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to trouble shoot - RuntimeError: Open Failed

2013-09-06 Thread stas poritskiy
Guys, as i was writing a very detailed message with code samples, following the 
guide that Steven linked, i found the problem. a pretty lame one, actually.

in my class that was processing the images, i created an object instance, via 
__INIT__ , self.data = attributes()
but i was iterating through list of folders, so object was filled with the 
correct data, but it was never re-initialized for the new one.

i move my objects into a function, and called the function on each loop-start, 
so objects are re-created and re-filled with the data.


Terry, yeah, your confusion was right, and pointing out that i was supposed to 
get IOError. that lead me to inspect code again and again :)

anyways, thanks and sorry for the mess )





On Friday, September 6, 2013 1:49:57 PM UTC-5, Terry Reedy wrote:
> On 9/6/2013 1:05 PM, stas poritskiy wrote:
> 
> > The code in development is mine, and i am using the API provided by a main 
> > developer.
> 
> >
> 
> > At the moment, i am not using any try/except functionality.
> 
> >
> 
> > here is the full Exception output:
> 
> > [CODE]
> 
> > Exception in Tkinter callback
> 
> > Traceback (most recent call last):
> 
> >File "C:\Python27\32bit\lib\lib-tk\Tkinter.py", line 1470, in __call__
> 
> >  return self.func(*args)
> 
> >File "E:\sporitskiy\HON\Project\scene7\s7operator\gui.py", line 59, in 
> > 
> 
> >  cmd1 = lambda: vntProcessor.colData(folders.path, folders.subFolders)
> 
> >File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 
> > 184, in colData
> 
> >  setVars()
> 
> >File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 
> > 79, in __call__
> 
> >  self.batchFiles()
> 
> >File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 
> > 55, in batchFiles
> 
> >  self.vntConnect.createVNTobjects(self.vntObjMgroup.keyList, 
> > self.vntLtoF.keyValList, self.vntObjFile.keyList, myPath)
> 
> >File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 
> > 113, in createVNTobjects
> 
> >  self.createImage(groupName, layerName, fileName, imagePath, 
> > self.vntGroups)
> 
> >File "E:\sporitskiy\HON\Project\scene7\s7operator\vntProcessor.py", line 
> > 137, in createImage
> 
> >  img = open_image(imageFile)
> 
> >File "", line 2, in open_image
> 
> >File "C:\Python27\32bit\lib\site-packages\s7vampy\arg_validator.py", 
> > line 213, in __call__
> 
> >  return func(*args, **keywords)
> 
> >File "C:\Python27\32bit\lib\site-packages\s7vampy\image.py", line 181, 
> > in open_image
> 
> >  return Image(_S7VAM_IMAGE.Open(filename))
> 
> > RuntimeError: Open Failed: 
> > 'C:/Users/sporitskiy/Desktop/Practice/HIWM2MSB/hiwm2mpa_upholstery_esq_leather_ro_12_0001.tif'
> 
> 
> 
> We were confused because the failed open should be an IOError. If Image 
> 
> is indeed converting such to RuntimeError, it should not. It should just 
> 
> let the original error bubble up. It is possibly tossing information in 
> 
> the process. The first thing I would do is to look at the code around 
> 
> that line in image.py and remove the exception replacement if there is one.
> 
> 
> 
> -- 
> 
> Terry Jan Reedy
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Dealing with Lists

2013-09-10 Thread stas poritskiy
there is a little bit more to this, but i think when i will be able to process 
the list the way i need it i can continue on my own. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Dealing with Lists

2013-09-10 Thread stas poritskiy
Greetings to all!

i ran into a little logic problem and trying to figure it out.

my case is as follows:

i have a list of items each item represents a Group 

i need to create a set of nested groups,

so, for example:

myGroups = ["head", "neck", "arms", "legs"]

i need to get them to be represented like this:
(if you can imaging a folder structure)

head
  |_> neck
|_> arms
  |_>legs

and so on until i hit the last element.

what i thought would work (but don't know really how to advance here) is:

def createVNTgroups(self, groupsData):
#function recieves the LIST of group elements, INDEX0 is always the
#MAIN-ROOT of the tree

for i in range(len(groupsData)):
print groupsData[i]

for q in range(1, len(groupsData)):

print groupsData[q]

could someone give me a hint?

thanks in advance!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Dealing with Lists

2013-09-10 Thread stas poritskiy
Those simbols are just for visual representation.

I need to store each of the first elements of a par, so I can reference to them 
as to a parent of another group.

So head is parent of neck,  while neck is parent of arms and so on.

I'm not sure I understand how to apply your chop list example, dave
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Dealing with Lists

2013-09-10 Thread stas poritskiy
Guys,
i appreciate the effort put in here, i guess i should've started a little wider 
on description.

sorry for confusion, here it goes:

I am developing a script/application that uses adobe Scene7 API. the idea here 
is mass process a ton of files (hundreds of thousands), we generate image files 
from 3d applications (3d max in our case), and each rendered file carries a 
specific naming convention such as this:
name_group-subgroup-subgroup_layer_type_zdepth.extention.

this translates in a nice array, that i first split using uderscore " _ ".
this results in a list that has always the same size.

Please note that in the section with group-subgroup-subroug - number of 
subgroups should can be ANY, and the separator there is dash " - ",

so when the first split " _ " occurs, i generate a separate element in my FIRST 
LIST that has all these groups. 

I then take the groups and run another split using the dash " - ", to create a 
new list for only groups.

In the second list, what i have is the first element at index 0 - being alwasy 
the most top (root) group. and all the subgroups are nested inside there. Each 
subgroup is a parent of the following subroup, thus - above in my diagram i 
used the body parts as example of logical dependency (sorry if this was 
unclear, again),

now, the next step is using API and its classes i create an instance of an 
object that generates the group for the file that will created via series of 
additional methods,

the file structure (think of Photoshop as an reference)
would have the main group, and a subgroup in it, and so on, depending on the 
type of the element that we are creating identified in the file name. (this 
would be using the FIRST LIST created originally)

For me to create a subgroup using the API, the first (parent) group should be 
already created, otherwise, i cannot use a non-existing element to assign a 
subgroup, 
therefore , i first my create the ROOT group located at index0
i then must make a subgroup, so the line of code would look similar to this:

#creating first group(root)
group = intance.add_group(str(name))

#creating subgroup(child of root)
subgroup = group.add_group(str(name))

since i don't know how many subgroups each file would have, i want to create a 
loop, that will do that for me
but i am running in a problem, trying to understand the logic for that loop.

let me know if you guys need more info from me.

On Tuesday, September 10, 2013 10:13:48 PM UTC-5, Steven D'Aprano wrote:
> On Wed, 11 Sep 2013 02:24:44 +, Dave Angel wrote:
> 
> 
> 
> > On 10/9/2013 22:14, Steven D'Aprano wrote:
> 
> > 
> 
> >> On Tue, 10 Sep 2013 14:08:45 -0700, stas poritskiy wrote:
> 
> >>
> 
> >>> Greetings to all!
> 
> >>> 
> 
> >>> i ran into a little logic problem and trying to figure it out.
> 
> >>> 
> 
> >>> my case is as follows:
> 
> >>> 
> 
> >>> i have a list of items each item represents a Group i need to create a
> 
> >>> set of nested groups, so, for example:
> 
> >>> 
> 
> >>> myGroups = ["head", "neck", "arms", "legs"]
> 
> >>
> 
> >>
> 
> >> What is the rule for grouping these items? Below, you suggest:
> 
> >>
> 
> >> head encloses neck
> 
> >> neck encloses arms
> 
> >> arms encloses legs
> 
> >>
> 
> >> which seems rather strange. But if it is *always* the case that each
> 
> >> item encloses the next item:
> 
> >>
> 
> >> def print_nested_list(alist):
> 
> >> spaces = ' '*4
> 
> >> for level, item in enumerate(alist):
> 
> >> if level != 0:
> 
> >> indent = spaces*(level-1) + '  '
> 
> >> print (indent + '|_>'),  # note comma
> 
> >> print item
> 
> >>
> 
> >>
> 
> >> which gives us this:
> 
> >>
> 
> >> py> print_nested_list(['head', 'neck', 'arms', 'legs']) head
> 
> >>   |_> neck
> 
> >>   |_> arms
> 
> >>   |_> legs
> 
> >>
> 
> >>
> 
> >> as requested.
> 
> >>
> 
> >>
> 
> >>
> 
> > Very nice.  But what I want to know is how did you know that Stan (the
> 
> > OP) wanted his printed output to be formatted that way?
> 
> 
> 
> I don't. Stan's email is unclear. But he does show an example:
> 
> 
> 
> [quote]
> 
> so, for example:
> 
> 
> 
> myGrou

Re: Dealing with Lists

2013-09-10 Thread stas poritskiy
Steven,
i think you got on the right track with your proposal,
although i am not going after the "visual" represenatation that you were able 
to create, rather a structural one, i think this might work for me,
instead of printing, i could be using my commands to make elements (instances 
of API objects to create my groups inside the file)

but one question i might have is :

once i created first instance object which in my example is :
groups = intance.add_group(str(name))

how would i temporary preserve this name as a reference for the next iteration 
for the subroups?

On Tuesday, September 10, 2013 10:13:48 PM UTC-5, Steven D'Aprano wrote:
> On Wed, 11 Sep 2013 02:24:44 +, Dave Angel wrote:
> 
> 
> 
> > On 10/9/2013 22:14, Steven D'Aprano wrote:
> 
> > 
> 
> >> On Tue, 10 Sep 2013 14:08:45 -0700, stas poritskiy wrote:
> 
> >>
> 
> >>> Greetings to all!
> 
> >>> 
> 
> >>> i ran into a little logic problem and trying to figure it out.
> 
> >>> 
> 
> >>> my case is as follows:
> 
> >>> 
> 
> >>> i have a list of items each item represents a Group i need to create a
> 
> >>> set of nested groups, so, for example:
> 
> >>> 
> 
> >>> myGroups = ["head", "neck", "arms", "legs"]
> 
> >>
> 
> >>
> 
> >> What is the rule for grouping these items? Below, you suggest:
> 
> >>
> 
> >> head encloses neck
> 
> >> neck encloses arms
> 
> >> arms encloses legs
> 
> >>
> 
> >> which seems rather strange. But if it is *always* the case that each
> 
> >> item encloses the next item:
> 
> >>
> 
> >> def print_nested_list(alist):
> 
> >> spaces = ' '*4
> 
> >> for level, item in enumerate(alist):
> 
> >> if level != 0:
> 
> >> indent = spaces*(level-1) + '  '
> 
> >> print (indent + '|_>'),  # note comma
> 
> >> print item
> 
> >>
> 
> >>
> 
> >> which gives us this:
> 
> >>
> 
> >> py> print_nested_list(['head', 'neck', 'arms', 'legs']) head
> 
> >>   |_> neck
> 
> >>   |_> arms
> 
> >>   |_> legs
> 
> >>
> 
> >>
> 
> >> as requested.
> 
> >>
> 
> >>
> 
> >>
> 
> > Very nice.  But what I want to know is how did you know that Stan (the
> 
> > OP) wanted his printed output to be formatted that way?
> 
> 
> 
> I don't. Stan's email is unclear. But he does show an example:
> 
> 
> 
> [quote]
> 
> so, for example:
> 
> 
> 
> myGroups = ["head", "neck", "arms", "legs"]
> 
> 
> 
> i need to get them to be represented like this: (if you can imaging a
> 
> folder structure)
> 
> 
> 
> head
> 
>   |_> neck
> 
> |_> arms
> 
>   |_>legs
> 
> 
> 
> and so on until i hit the last element.
> 
> [end quote]
> 
> 
> 
> 
> 
> so I just provided that.
> 
> 
> 
> > He said:
> 
> > 
> 
> >>>>>> i need to create a set of nested groups,
> 
> > and
> 
> >>>>>> store each of the first elements of a par, so I can reference to
> 
> >>>>>> them as to a parent of another group.
> 
> 
> 
> 
> 
> I have no idea what that means :-)
> 
> 
> 
> 
> 
> I *guess* that what Stan is actually looking for is something like a 
> 
> dictionary-based solution, not lists:
> 
> 
> 
> {'head': {'neck': {'arms': {}, 'legs': {
> 
> 
> 
> which gives:
> 
> 
> 
> head encloses neck
> 
> neck encloses arms and legs
> 
> arms enclose nothing
> 
> legs enclose nothing
> 
> 
> 
> 
> 
> or:
> 
> 
> 
> {'head': {'neck': {'arms': {'legs': {}
> 
> 
> 
> which gives:
> 
> 
> 
> head encloses neck
> 
> neck encloses arms
> 
> arms encloses legs
> 
> legs enclose nothing
> 
> 
> 
> 
> 
> but I can't really tell for sure. In this second case, using dicts, I 
> 
> might try something like this recursive solution:
> 
> 
> 
> 
> 
> def print_nested_dict(adict, level=0):
> 
> if adict == {}:
> 
> return
> 
> for key, subdict in sorted(adict.items()):
> 
> if level != 0:
> 
> spaces = ' '*4
> 
> indent = spaces*(level-1) + '  '
> 
> print (indent + '|_>'),  # note comma
> 
> if subdict == {}:
> 
> print key
> 
> else:
> 
> print "%s:-" % key
> 
> print_nested_dict(subdict, level+1)
> 
> 
> 
> 
> 
> Given:
> 
> 
> 
> d = {'head': {'neck': {'legs': {'toes': {}}, 'arms': {'thumbs': {}, 
> 
> 'fingers': {}
> 
> 
> 
> we can see this output:
> 
> 
> 
> py> print_nested_dict(d)
> 
> head:-
> 
>   |_> neck:-
> 
>   |_> arms:-
> 
>   |_> fingers
> 
>   |_> thumbs
> 
>   |_> legs:-
> 
>   |_> toes
> 
> 
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Dealing with Lists

2013-09-11 Thread stas poritskiy
ok, so i think that getting the nested list is a little more for what i need,
however, i could be wrong here,
i got confused with Dave's suggestion. so, i got my lists broken up in a list 
of lists, but how would i access each of the elements?
When i implement this solution my output list (the new one, after CHOPPING) 
prints like this:

[u'arms', [u'a', [u'super', [u'group', [u'type', [u'is', [u'here']]]
so i assume the "indexing" here would be similar to this:
01
 0   1
 0   1
0 1
  0  1
 0   
[u'arms', [u'a', [u'super', [u'group', [u'type', [u'is', [u'here']]]

Basically speaking ( each generated list would be the len=2 ?

so, in my understanding, if i need to call the parenet for my FIRST group(most 
fist created),
i would go and call
chopGrps[0] 
this would get me "arms"
and if i need to get the second element, (which should be "a"
i would call chopGrps[1]
but instead, i get the REST of the lists stored there.

so what position does "a" take in this nested list?
and this same question would apply to the rest of the items

Thanks guys!


On Tuesday, September 10, 2013 10:52:20 PM UTC-5, stas poritskiy wrote:
> Steven,
> 
> i think you got on the right track with your proposal,
> 
> although i am not going after the "visual" represenatation that you were able 
> to create, rather a structural one, i think this might work for me,
> 
> instead of printing, i could be using my commands to make elements (instances 
> of API objects to create my groups inside the file)
> 
> 
> 
> but one question i might have is :
> 
> 
> 
> once i created first instance object which in my example is :
> 
> groups = intance.add_group(str(name))
> 
> 
> 
> how would i temporary preserve this name as a reference for the next 
> iteration for the subroups?
> 
> 
> 
> On Tuesday, September 10, 2013 10:13:48 PM UTC-5, Steven D'Aprano wrote:
> 
> > On Wed, 11 Sep 2013 02:24:44 +, Dave Angel wrote:
> 
> > 
> 
> > 
> 
> > 
> 
> > > On 10/9/2013 22:14, Steven D'Aprano wrote:
> 
> > 
> 
> > > 
> 
> > 
> 
> > >> On Tue, 10 Sep 2013 14:08:45 -0700, stas poritskiy wrote:
> 
> > 
> 
> > >>
> 
> > 
> 
> > >>> Greetings to all!
> 
> > 
> 
> > >>> 
> 
> > 
> 
> > >>> i ran into a little logic problem and trying to figure it out.
> 
> > 
> 
> > >>> 
> 
> > 
> 
> > >>> my case is as follows:
> 
> > 
> 
> > >>> 
> 
> > 
> 
> > >>> i have a list of items each item represents a Group i need to create a
> 
> > 
> 
> > >>> set of nested groups, so, for example:
> 
> > 
> 
> > >>> 
> 
> > 
> 
> > >>> myGroups = ["head", "neck", "arms", "legs"]
> 
> > 
> 
> > >>
> 
> > 
> 
> > >>
> 
> > 
> 
> > >> What is the rule for grouping these items? Below, you suggest:
> 
> > 
> 
> > >>
> 
> > 
> 
> > >> head encloses neck
> 
> > 
> 
> > >> neck encloses arms
> 
> > 
> 
> > >> arms encloses legs
> 
> > 
> 
> > >>
> 
> > 
> 
> > >> which seems rather strange. But if it is *always* the case that each
> 
> > 
> 
> > >> item encloses the next item:
> 
> > 
> 
> > >>
> 
> > 
> 
> > >> def print_nested_list(alist):
> 
> > 
> 
> > >> spaces = ' '*4
> 
> > 
> 
> > >> for level, item in enumerate(alist):
> 
> > 
> 
> > >> if level != 0:
> 
> > 
> 
> > >> indent = spaces*(level-1) + '  '
> 
> > 
> 
> > >> print (indent + '|_>'),  # note comma
> 
> > 
> 
> > >> print item
> 
> > 
> 
> > >>
> 
> > 
> 
> > >>
> 
> > 
> 
> > >> which gives us this:
> 
> > 
> 
> > >>
> 
> > 
> 
> > >> py>

Re: Dealing with Lists

2013-09-11 Thread stas poritskiy
ok, while writing this, i figured out where those elements are located,
so each element is always at the position 0, and to get deeper i have to follow 
something similar to this 
chopGrp = [[u'arms', [u'a', [u'super', [u'group', [u'type', [u'is', 
[u'here']]] 

print chopGrp[1][1][1][1][0] (this would get me "type" from the list)
>>>type

this is getting somewhere, now, i am confused what type of iteration loop i 
should make, where each element is being called by itself,

so i could reference the previous element as its Parent.
so if i make this manually as a pseudo code:

chopGrp[0] #gets me "arms"
print "Parent is: " + chopGrp[0]
chopGrp[1][0] #gets me "a"
print "Child is: " + chopGrp[1][0]

and the next iteration should take the

chopGrp[1][0] and make it a parent of chopGrp[1][1][0]

any hints?

On Wednesday, September 11, 2013 9:47:30 AM UTC-5, stas poritskiy wrote:
> ok, so i think that getting the nested list is a little more for what i need,
> 
> however, i could be wrong here,
> 
> i got confused with Dave's suggestion. so, i got my lists broken up in a list 
> of lists, but how would i access each of the elements?
> 
> When i implement this solution my output list (the new one, after CHOPPING) 
> prints like this:
> 
> 
> 
> [u'arms', [u'a', [u'super', [u'group', [u'type', [u'is', [u'here']]]
> 
> so i assume the "indexing" here would be similar to this:
> 
> 01
> 
>  0   1
> 
>  0   1
> 
> 0 1
> 
>   0  1
> 
>  0   
> 
> [u'arms', [u'a', [u'super', [u'group', [u'type', [u'is', [u'here']]]
> 
> 
> 
> Basically speaking ( each generated list would be the len=2 ?
> 
> 
> 
> so, in my understanding, if i need to call the parenet for my FIRST 
> group(most fist created),
> 
> i would go and call
> 
> chopGrps[0] 
> 
> this would get me "arms"
> 
> and if i need to get the second element, (which should be "a"
> 
> i would call chopGrps[1]
> 
> but instead, i get the REST of the lists stored there.
> 
> 
> 
> so what position does "a" take in this nested list?
> 
> and this same question would apply to the rest of the items
> 
> 
> 
> Thanks guys!
> 
> 
> 
> 
> 
> On Tuesday, September 10, 2013 10:52:20 PM UTC-5, stas poritskiy wrote:
> 
> > Steven,
> 
> > 
> 
> > i think you got on the right track with your proposal,
> 
> > 
> 
> > although i am not going after the "visual" represenatation that you were 
> > able to create, rather a structural one, i think this might work for me,
> 
> > 
> 
> > instead of printing, i could be using my commands to make elements 
> > (instances of API objects to create my groups inside the file)
> 
> > 
> 
> > 
> 
> > 
> 
> > but one question i might have is :
> 
> > 
> 
> > 
> 
> > 
> 
> > once i created first instance object which in my example is :
> 
> > 
> 
> > groups = intance.add_group(str(name))
> 
> > 
> 
> > 
> 
> > 
> 
> > how would i temporary preserve this name as a reference for the next 
> > iteration for the subroups?
> 
> > 
> 
> > 
> 
> > 
> 
> > On Tuesday, September 10, 2013 10:13:48 PM UTC-5, Steven D'Aprano wrote:
> 
> > 
> 
> > > On Wed, 11 Sep 2013 02:24:44 +, Dave Angel wrote:
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > On 10/9/2013 22:14, Steven D'Aprano wrote:
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >> On Tue, 10 Sep 2013 14:08:45 -0700, stas poritskiy wrote:
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >>
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >>> Greetings to all!
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >>> 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >>> i ran into a lit

Making it a MultiThread!

2013-09-20 Thread stas poritskiy
Hello All!

I have a general question, 
i was posting here earlier while trying to troubleshoot a few things while 
developing an application, i was able to hit all of my goals, and make things 
work! Thank you all who contributed to my research, and again, sorry for poor 
formatting of the threads, i am slowly learning;)

I am working on integration of multiple GUI (Tkinter) elements, such a progress 
bar, label update, etc, and throughout my research i discovered that i need to 
have Threading modules used to distribute the calls for GUI update and 
processing of my main App.

My Application is broken into multiple Classes(modules), and i wanted to hear 
your thought on the best practices to implement the Threading model.

I was thinking to create a new py-module, and reference all other modules/class 
to it, and create thread.start() objects, that would execute the GUI part, 
other will handle GUI Updates, and other - will be doing the processing.

Please share some of your thought on this approach, or maybe you may suggest a 
more effective way.
thanks !
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: dynamic function parameters for **kwargs

2013-09-20 Thread stas poritskiy
On Friday, September 20, 2013 10:51:46 AM UTC-5, bab mis wrote:
> Hi ,
> 
> I have a function as below:
> 
> 
> 
> def func(**kwargs):
> 
> ...
> 
> ...
> 
> 
> 
> 
> 
> 
> 
> 
> 
> args="a='b',c='d'"
> 
> 
> 
> i want to call func(args) so that my function call will take a var as an 
> parameter.
> 
> 
> 
> it fails with an error "typeError: fun() takes exactly 0 arguments (1 given)" 
> 
> 
> 
> . Is there any other way to get the same.

Hi, may be this will be useful to you:
http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/

Go to Section 11 in the document.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Making it a MultiThread!

2013-09-20 Thread stas poritskiy
On Friday, September 20, 2013 7:56:16 AM UTC-5, stas poritskiy wrote:
> Hello All!
> 
> 
> 
> I have a general question, 
> 
> i was posting here earlier while trying to troubleshoot a few things while 
> developing an application, i was able to hit all of my goals, and make things 
> work! Thank you all who contributed to my research, and again, sorry for poor 
> formatting of the threads, i am slowly learning;)
> 
> 
> 
> I am working on integration of multiple GUI (Tkinter) elements, such a 
> progress bar, label update, etc, and throughout my research i discovered that 
> i need to have Threading modules used to distribute the calls for GUI update 
> and processing of my main App.
> 
> 
> 
> My Application is broken into multiple Classes(modules), and i wanted to hear 
> your thought on the best practices to implement the Threading model.
> 
> 
> 
> I was thinking to create a new py-module, and reference all other 
> modules/class to it, and create thread.start() objects, that would execute 
> the GUI part, other will handle GUI Updates, and other - will be doing the 
> processing.
> 
> 
> 
> Please share some of your thought on this approach, or maybe you may suggest 
> a more effective way.
> 
> thanks !

Here is some CODE that i wrote to present the working case.
my main program is split in multiple modules, but this structure should 
represent what i am trying to get.

module name: multiProcessLauncher.py

import multiprocessing
import gui

def main():
jobs = []
p = multiprocessing.Process(target=gui.basicGui)
jobs.append(p)
p.start()

if __name__ == '__main__':
main()
pass


Module Name: gui.py

from Tkinter import *
import tkMessageBox
import Tkinter
import multiProcessLauncher
import action

def basicGui():
g = action.Action()
print "GUI"
processor = multiProcessLauncher
name = processor.multiprocessing.current_process().name
print name, "starting"
print name, "exiting"
  
top = Tk()
button = Button(top, text = "Press Me", command = g.do_something)
button.pack()
top.mainloop()

def main():
pass
if __name__ == "__main__":
main()

Module Name: action.py

class Action(object):
def __init__(self):
self.text = "Running Action"
def do_something(self):
print self.text

i am trying to figure out how to make use of multiprocessing access the PRINT 
from the action.py using the GUI button. if you run the code and press the 
button, the console will read nothing, but as soon as you close the GUI, it 
spits out the text to console. I read about using Que, but i am not sure how to 
implement, could someone suggest how? thank you
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Making it a MultiThread!

2013-09-23 Thread stas poritskiy
Thanks for getting back to me, so i assume it is OK to have a very very long 
file? The sample code i posted here is basically the barebones of the main app. 
so, combining the GUI-file(gui.py)  with main code is acceptable? Separating 
them into modules was initially the attempt to keep things in order.

On Saturday, September 21, 2013 8:00:29 PM UTC-5, Piet van Oostrum wrote:
> stas poritskiy  writes:
> 
> 
> 
> >> I am working on integration of multiple GUI (Tkinter) elements, such
> 
> >> a progress bar, label update, etc, and throughout my research i
> 
> >> discovered that i need to have Threading modules used to distribute
> 
> >> the calls for GUI update and processing of my main App.
> 
> 
> 
> In general your GUI should be in your main process/thread. For example
> 
> your program doesn't run on Mac OS X because you cannot run the GUI in
> 
> another process or thread.
> 
> 
> 
> Now if your GUI actions are starting some actions that last more than a
> 
> few tenths of a second, you should run these actions in another thread
> 
> or process (usually a thread will work), otherwise the GUI becomes
> 
> unresponsive. If you want to exchange some information between the GUI
> 
> and that thread/process you can use a Queue object, or just give the
> 
> information from the GUI at the start of the thread.
> 
> 
> 
> >> My Application is broken into multiple Classes(modules), and i wanted
> 
> >> to hear your thought on the best practices to implement the Threading
> 
> >> model.
> 
> 
> 
> The structure of you modules isn't good. There are circular imports, and
> 
> that is a sign the the design needs to be simplified:
> 
> 
> 
> multiProcessLauncher imports gui.
> 
> gui imports multiProcessLauncher.
> 
> 
> 
> The latter import isn't necessary. 
> 
> 
> 
> Instead of
> 
> 
> 
> import multiProcessLauncher
> 
> processor = multiProcessLauncher
> 
> name = processor.multiprocessing.current_process().name
> 
> 
> 
> you can just use:
> 
> 
> 
> import multiprocessing
> 
> name = multiprocessing.current_process().name
> 
> 
> 
> My advice would be to just do the GUI in the main module, and if the
> 
> Action needs more time, the create a new Thread or Process in the Action
> 
> class.
> 
> 
> 
> -- 
> 
> Piet van Oostrum 
> 
> WWW: http://pietvanoostrum.com/
> 
> PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list