473,394 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

passing [class-scope] variables to between methods?

46
Hey Guys

I know I am missing some important points on how to use the python language. Is it possible to pass variables between methods (is that what theyare called?)

in my attempt below I have an initial definition that gets users input in 2 text fields and uses that later down the script to create a bunch of directories once the button "GO!!!" is clicked.

I get this error:
jobfolder = a
NameError: global name 'a' is not defined


but i defined it up in the beginning of the script.

Any ideas?

Apologies for all the questions forum posts - I'll stop soon!

AT


Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/usr/bin/python
  3.  
  4. # newjob.py
  5.  
  6. import wx
  7. import os
  8.  
  9. APP_SIZE_X = 400
  10. APP_SIZE_Y = 210
  11.  
  12. class NewJob(wx.Dialog):
  13.     def __init__(self, parent, id, title):
  14.         wx.Dialog.__init__(self, parent, id, title, size=(APP_SIZE_X, APP_SIZE_Y))
  15.  
  16.         a = wx.StaticText(self, -1, 'Enter a job name:', (25, 20), style=wx.ALIGN_LEFT)        
  17.         wx.TextCtrl(self, 3, '', (25,50), (200, -1))
  18.         b = wx.StaticText(self, -1, 'Enter number of shots:', (25, 85), style=wx.ALIGN_LEFT)        
  19.         wx.TextCtrl(self, 4, '', (25,110), (85, -1))
  20.  
  21.         wx.Button(self, 2, 'Quit', (50, 150))
  22.         wx.Button(self, 1, 'GO!!!', (150, 150), (210, -1))
  23.  
  24.         self.Bind(wx.EVT_BUTTON, self.OnClose, id=2)
  25.         self.Bind(wx.EVT_BUTTON, self.OnCreateJob, id=1)
  26.  
  27.         self.Centre()
  28.         self.ShowModal()
  29.         self.Destroy()
  30.  
  31.     def OnClose(self, event):
  32.         self.Close(True)
  33.  
  34.     def OnCreateJob(self, event):
  35.  
  36.         jobfolder = a
  37.         shotamount = b
  38.  
  39.         jobroot = os.getcwd()
  40.  
  41.         def GLOBALSDIR():
  42.  
  43.             os.mkdir( "_global")
  44.  
  45.             os.mkdir( "_global/2d")
  46.             os.mkdir( "_global/2d/ae")
  47.             os.mkdir( "_global/2d/ae/render")
  48.             os.mkdir( "_global/2d/ae/script")
  49.             os.mkdir( "_global/2d/ai")
  50.             os.mkdir( "_global/2d/ai/project")    
  51.             os.mkdir( "_global/2d/ai/export") 
  52.             os.mkdir( "_global/2d/psd")
  53.             os.mkdir( "_global/2d/psd/project")
  54.             os.mkdir( "_global/2d/psd/export")
  55.             os.mkdir( "_global/2d/shk")
  56.             os.mkdir( "_global/2d/shk/script")
  57.             os.mkdir( "_global/2d/shk/render")
  58.             os.mkdir( "_global/2d/output")
  59.  
  60.             os.mkdir( "_global/3d")
  61.             os.mkdir( "_global/3d/boujou")
  62.             os.mkdir( "_global/3d/maya")
  63.             os.mkdir( "_global/3d/max")
  64.             os.mkdir( "_global/3d/syntheyes")
  65.             os.mkdir( "_global/3d/output")
  66.  
  67.             os.mkdir( "_global/color")
  68.  
  69.             os.mkdir( "_global/edit")
  70.             os.mkdir( "_global/edit/audio")
  71.             os.mkdir( "_global/edit/fcp")
  72.             os.mkdir( "_global/edit/fcp/projects")
  73.             os.mkdir( "_global/edit/graphics")
  74.             os.mkdir( "_global/edit/edl")
  75.             os.mkdir( "_global/edit/xml")
  76.  
  77.             os.mkdir( "_global/plates")
  78.  
  79.             os.mkdir( "_global/ref")
  80.  
  81.  
  82.         def SUBFOLDERS():
  83.  
  84.             os.mkdir( "2d")
  85.             os.mkdir( "2d/ae")
  86.             os.mkdir( "2d/ae/render")
  87.             os.mkdir( "2d/ae/script")
  88.             os.mkdir( "2d/ai")
  89.             os.mkdir( "2d/ai/project")    
  90.             os.mkdir( "2d/ai/export") 
  91.             os.mkdir( "2d/psd")
  92.             os.mkdir( "2d/psd/project")
  93.             os.mkdir( "2d/psd/export")
  94.             os.mkdir( "2d/shk")
  95.             os.mkdir( "2d/shk/render")
  96.             os.mkdir( "2d/shk/script")
  97.             os.mkdir( "2d/output")
  98.  
  99.             os.mkdir( "3d")
  100.             os.mkdir( "3d/boujou")
  101.             os.mkdir( "3d/maya")
  102.             os.mkdir( "3d/max")
  103.             os.mkdir( "3d/syntheyes")
  104.             os.mkdir( "3d/output")
  105.  
  106.             os.mkdir( "plates")
  107.  
  108.             os.chdir( "../")
  109.  
  110.  
  111.         #CREATE JOB DIRECTORY
  112.         os.mkdir( jobfolder)
  113.  
  114.         #CREATE OFFLINE & ONLINE DIRECTORIES
  115.         os.mkdir( jobfolder + "/offline")
  116.  
  117.         #CHANGE INTO OFFLINE DIRECTORY TO CREATE ALL THE SHOT DIRECTORIES
  118.         os.chdir( jobfolder + "/offline")
  119.  
  120.         GLOBALSDIR()
  121.  
  122.         #CREATE SHOT DIRECTORY AND AND SUB-DIRECTORIES
  123.  
  124.         for i in range(1, shotamount + 1):
  125.             shotname = '%03d' % (i)
  126.             os.mkdir( shotname)
  127.             os.chdir( shotname)
  128.             SUBFOLDERS()
  129.  
  130.         #CHANGE INTO ONLINE DIRECTORY TO CREATE ALL THE SHOT DIRECTORIES
  131.         os.chdir( jobroot)
  132.         os.mkdir( jobfolder + "/online")
  133.         os.chdir( jobfolder + "/online")
  134.  
  135.         GLOBALSDIR()
  136.  
  137.         #CREATE SHOT DIRECTORY AND AND SUB-DIRECTORIES
  138.  
  139.         for i in range(1, shotamount + 1):
  140.             shotname = '%03d' % (i)
  141.             os.mkdir( shotname)
  142.             os.chdir( shotname)
  143.             SUBFOLDERS()
  144.  
  145.  
  146. app = wx.App(0)
  147. NewJob(None, -1, 'newjob')
  148. app.MainLoop()
  149.  
  150.  
Jun 19 '07 #1
13 2105
bartonc
6,596 Expert 4TB
It's all about the "scope" of a variable.
Inside your __init__() function, the variable a only has life in that scope (the method - or function, if you prefer- scope). The object that is directing the show is the Dialog. The reason that self (this Dialog) is present in every method definition is so that the given method has access to the object scope (self.whatever). So, if you want a variable to live outside a function, make it an attribute of the object:
Expand|Select|Wrap|Line Numbers
  1. self.useDescriptiveNamesForAttributes = .....
These are in effect "global", but only in the object scope (encapsulation).

Hope that's not too confusing...
Jun 19 '07 #2
BjornB
6
Hi,

attach the variable to your class,

line 15: self.myVariable

then in the method

def OnCreateJob():
self.myVariable...

br,
Björn
Jun 19 '07 #3
bartonc
6,596 Expert 4TB
I notice that you are doing several things in a debatable manner.
1) Assigning IDs as absolutes is a definite no-no. It's bound to cause problems down the road:
Expand|Select|Wrap|Line Numbers
  1. wxID_SEGMENTDIALOGRECORDBUTTON = wx.NewId()
That's actually a generated name, yours could be shorter.

2) Button events should be bound to the button and not the parent:
Expand|Select|Wrap|Line Numbers
  1. # <snipped from Dialog subclass>
  2.         self.RecordButton = wx.Button(id=wxID_SEGMENTDIALOGRECORDBUTTON, label='Record Station', name='RecordButton', parent=self.panel1, pos=wx.Point(816, 20), size=wx.Size(173, 36), style=0)
  3.         self.RecordButton.Bind(wx.EVT_BUTTON, self.OnRecordButton, id=wxID_SEGMENTDIALOGRECORDBUTTON)
Jun 19 '07 #4
bartonc
6,596 Expert 4TB
I notice that you are doing several things in a debatable manner.
1) Assigning IDs as absolutes is a definite no-no. It's bound to cause problems down the road:
Expand|Select|Wrap|Line Numbers
  1. wxID_SEGMENTDIALOGRECORDBUTTON = wx.NewId()
That's actually a generated name, yours could be shorter.

2) Button events should be bound to the button and not the parent:
Expand|Select|Wrap|Line Numbers
  1. # <snipped from Dialog subclass>
  2.         self.RecordButton = wx.Button(id=wxID_SEGMENTDIALOGRECORDBUTTON, label='Record Station', name='RecordButton', parent=self.panel1, pos=wx.Point(816, 20), size=wx.Size(173, 36), style=0)
  3.         self.RecordButton.Bind(wx.EVT_BUTTON, self.OnRecordButton, id=wxID_SEGMENTDIALOGRECORDBUTTON)
Making a Button (or even StaticText) an attribute of the Dialog may seem like just an extra variable in you class's name space, but it actually comes in handy very quickly. You may soon find that you want to disable, change the color of, (or a host of other things) any one of these little GUI devils (it happens to me, anyway).
Jun 19 '07 #5
ateale
46
Hey Guys

Thanks for your help. I kind of understand but a lot of it is flying right over my head. :)

BjornB I tried what I think you said to do - but I think I didn't really understand.

I changed the variables "a" & "b" to self.a & self.b in the "class NewJob" in the "def __int__".

Mind taking a look?



Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/python
  2.  
  3. # newjob.py
  4.  
  5. import wx
  6. import os
  7.  
  8. APP_SIZE_X = 400
  9. APP_SIZE_Y = 210
  10.  
  11. class NewJob(wx.Dialog):
  12.     def __init__(self, parent, id, title):
  13.         wx.Dialog.__init__(self, parent, id, title, size=(APP_SIZE_X, APP_SIZE_Y))
  14.  
  15.         wx.StaticText(self, -1, 'Enter a job name:', (25, 20), style=wx.ALIGN_LEFT)        
  16.         self.a = str(wx.TextCtrl(self, 3, '', (25,50), (200, -1)))
  17.         wx.StaticText(self, -1, 'Enter number of shots:', (25, 85), style=wx.ALIGN_LEFT)        
  18.         self.b = str(wx.TextCtrl(self, 4, '', (25,110), (85, -1)))
  19.  
  20.         wx.Button(self, 2, 'Quit', (50, 150))
  21.         wx.Button(self, 1, 'GO!!!', (150, 150), (210, -1))
  22.  
  23.         self.Bind(wx.EVT_BUTTON, self.OnClose, id=2)
  24.         self.Bind(wx.EVT_BUTTON, self.OnCreateJob, id=1)
  25.  
  26.         self.Centre()
  27.         self.ShowModal()
  28.         self.Destroy()
  29.  
  30.     def OnClose(self, event):
  31.         self.Close(True)
  32.  
  33.     def OnCreateJob(self, event):
  34.  
  35.         jobfolder = self.a
  36.         shotamount = self.b
  37.  
  38.         jobroot = os.getcwd()
  39.  
  40.         def GLOBALSDIR():
  41.  
  42.             os.mkdir( "_global")
  43.  
  44.             os.mkdir( "_global/2d")
  45.             os.mkdir( "_global/2d/ae")
  46.             os.mkdir( "_global/2d/ae/render")
  47.             os.mkdir( "_global/2d/ae/script")
  48.             os.mkdir( "_global/2d/ai")
  49.             os.mkdir( "_global/2d/ai/project")    
  50.             os.mkdir( "_global/2d/ai/export") 
  51.             os.mkdir( "_global/2d/psd")
  52.             os.mkdir( "_global/2d/psd/project")
  53.             os.mkdir( "_global/2d/psd/export")
  54.             os.mkdir( "_global/2d/shk")
  55.             os.mkdir( "_global/2d/shk/script")
  56.             os.mkdir( "_global/2d/shk/render")
  57.             os.mkdir( "_global/2d/output")
  58.  
  59.             os.mkdir( "_global/3d")
  60.             os.mkdir( "_global/3d/boujou")
  61.             os.mkdir( "_global/3d/maya")
  62.             os.mkdir( "_global/3d/max")
  63.             os.mkdir( "_global/3d/syntheyes")
  64.             os.mkdir( "_global/3d/output")
  65.  
  66.             os.mkdir( "_global/color")
  67.  
  68.             os.mkdir( "_global/edit")
  69.             os.mkdir( "_global/edit/audio")
  70.             os.mkdir( "_global/edit/fcp")
  71.             os.mkdir( "_global/edit/fcp/projects")
  72.             os.mkdir( "_global/edit/graphics")
  73.             os.mkdir( "_global/edit/edl")
  74.             os.mkdir( "_global/edit/xml")
  75.  
  76.             os.mkdir( "_global/plates")
  77.  
  78.             os.mkdir( "_global/ref")
  79.  
  80.  
  81.         def SUBFOLDERS():
  82.  
  83.             os.mkdir( "2d")
  84.             os.mkdir( "2d/ae")
  85.             os.mkdir( "2d/ae/render")
  86.             os.mkdir( "2d/ae/script")
  87.             os.mkdir( "2d/ai")
  88.             os.mkdir( "2d/ai/project")    
  89.             os.mkdir( "2d/ai/export") 
  90.             os.mkdir( "2d/psd")
  91.             os.mkdir( "2d/psd/project")
  92.             os.mkdir( "2d/psd/export")
  93.             os.mkdir( "2d/shk")
  94.             os.mkdir( "2d/shk/render")
  95.             os.mkdir( "2d/shk/script")
  96.             os.mkdir( "2d/output")
  97.  
  98.             os.mkdir( "3d")
  99.             os.mkdir( "3d/boujou")
  100.             os.mkdir( "3d/maya")
  101.             os.mkdir( "3d/max")
  102.             os.mkdir( "3d/syntheyes")
  103.             os.mkdir( "3d/output")
  104.  
  105.             os.mkdir( "plates")
  106.  
  107.             os.chdir( "../")
  108.  
  109.  
  110.         #CREATE JOB DIRECTORY
  111.         os.mkdir( jobfolder)
  112.  
  113.         #CREATE OFFLINE & ONLINE DIRECTORIES
  114.         os.mkdir( jobfolder + "/offline")
  115.  
  116.         #CHANGE INTO OFFLINE DIRECTORY TO CREATE ALL THE SHOT DIRECTORIES
  117.         os.chdir( jobfolder + "/offline")
  118.  
  119.         GLOBALSDIR()
  120.  
  121.         #CREATE SHOT DIRECTORY AND AND SUB-DIRECTORIES
  122.  
  123.         for i in range(1, shotamount + 1):
  124.             shotname = '%03d' % (i)
  125.             os.mkdir( shotname)
  126.             os.chdir( shotname)
  127.             SUBFOLDERS()
  128.  
  129.         #CHANGE INTO ONLINE DIRECTORY TO CREATE ALL THE SHOT DIRECTORIES
  130.         os.chdir( jobroot)
  131.         os.mkdir( jobfolder + "/online")
  132.         os.chdir( jobfolder + "/online")
  133.  
  134.         GLOBALSDIR()
  135.  
  136.         #CREATE SHOT DIRECTORY AND AND SUB-DIRECTORIES
  137.  
  138.         for i in range(1, shotamount + 1):
  139.             shotname = '%03d' % (i)
  140.             os.mkdir( shotname)
  141.             os.chdir( shotname)
  142.             SUBFOLDERS()
  143.  
  144.  
  145. app = wx.App(0)
  146. NewJob(None, -1, 'newjob')
  147. app.MainLoop()
  148.  
  149.  
Jun 20 '07 #6
ateale
46
I notice that you are doing several things in a debatable manner.
1) Assigning IDs as absolutes is a definite no-no. It's bound to cause problems down the road:
Expand|Select|Wrap|Line Numbers
  1. wxID_SEGMENTDIALOGRECORDBUTTON = wx.NewId()
That's actually a generated name, yours could be shorter.

2) Button events should be bound to the button and not the parent:
Expand|Select|Wrap|Line Numbers
  1. # <snipped from Dialog subclass>
  2.         self.RecordButton = wx.Button(id=wxID_SEGMENTDIALOGRECORDBUTTON, label='Record Station', name='RecordButton', parent=self.panel1, pos=wx.Point(816, 20), size=wx.Size(173, 36), style=0)
  3.         self.RecordButton.Bind(wx.EVT_BUTTON, self.OnRecordButton, id=wxID_SEGMENTDIALOGRECORDBUTTON)
Hey BartonC,

does that mean that rather than doing this:
wx.Button(self, 2, 'Quit', (50, 150))

i should do:
self.QuitButton = wx.Button(self, 2, 'Quit', (50, 150))

Thanks for all your help!
Jun 20 '07 #7
bartonc
6,596 Expert 4TB
Hey BartonC,

does that mean that rather than doing this:
wx.Button(self, 2, 'Quit', (50, 150))

i should do:
self.QuitButton = wx.Button(self, 2, 'Quit', (50, 150))

Thanks for all your help!
First: Yes, you got what Bjorn was conveying.

Second: I treat (well, I would if I wrote the GUI layout part - Boa Constructor does that for me) GUI elements the same as other variables that are needed in the Class Scope (such as self.a and self.b in your post). And I can't stress enough how important it is to use better naming for your variables. Here is a thread discussing naming conventions in Python. You'll like yourself much more when you go back into a piece of code later and find things like "veryDescriptiveNameStr" rather than "a".

Hope that make sense.
Jun 20 '07 #8
ateale
46
hey guys

thanks for all your help so far - sorry I havent got back to your replies - distracted with work

I think I understand what u mean by giving everything descriptive names and assigning them as self. and flexible IDs

Does this look better?

It still doesn't work - I cant seem to convert a string to an integer - this error:

line 128, in OnCreateJob
os.mkdir( self.jobfolder)
TypeError: coercing to Unicode: need string or buffer, TextCtrl found

Any ideas how to get that to convert to a string?
i thought this would work:
int( self.NumberOfShots)

but get this:
TypeError: int() argument must be a string or a number

Cheers!!

Adam



Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/usr/bin/python
  3.  
  4. # newjob.py
  5.  
  6. import wx
  7. import os
  8.  
  9. class MyFrame(wx.Frame):
  10.     def __init__(self, parent, id, title):
  11.         wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(400, 200))
  12.  
  13.         panel = wx.Panel(self, -1)
  14.  
  15.         wxID_ENTERJOBNAME = wx.NewId()
  16.         wxID_JOBNAME = wx.NewId()
  17.         wxID_ENTERSHOTNAME = wx.NewId()
  18.         wxID_SHOTAMOUNT = wx.NewId()
  19.         wxID_QUITBUTTON = wx.NewId()
  20.         wxID_GOBUTTON = wx.NewId()
  21.  
  22.         self.EnterJobname = wx.StaticText(panel, wxID_ENTERJOBNAME, 'Enter a job name:', (10, 20), style=wx.ALIGN_LEFT)
  23.         self.JobName = wx.TextCtrl(panel, wxID_JOBNAME, '', (25,50), (200, -1))
  24.  
  25.         self.EnterShotAmount = wx.StaticText(panel, wxID_ENTERSHOTNAME, 'Enter number of shots:', (10, 80), style=wx.ALIGN_LEFT)        
  26.         self.NumberOfShots = wx.TextCtrl(panel, wxID_SHOTAMOUNT, '', (25,110), (85, -1))
  27.         self.NumberOfShots.Bind(wx.EVT_TEXT, self.OnCreateJob, id=wxID_SHOTAMOUNT)
  28.  
  29.         self.jobfolder = str( self.JobName)
  30.         self.shotamount = self.NumberOfShots
  31.  
  32.         self.QuitButton = wx.Button(panel, wxID_QUITBUTTON, "Quit", (10,140))
  33.         self.QuitButton.Bind(wx.EVT_BUTTON, self.OnClose, id=wxID_QUITBUTTON)
  34.  
  35.         self.GoButton = wx.Button(panel, wxID_GOBUTTON, "GO!!!", (200,140))
  36.         self.GoButton.Bind(wx.EVT_BUTTON, self.OnCreateJob, id=wxID_GOBUTTON)
  37.  
  38.  
  39.     def OnClose(self, event):
  40.         self.Close(True)
  41.  
  42.  
  43.     def OnCreateJob(self, event):
  44.  
  45.         jobroot = os.getcwd()
  46.  
  47.         def GLOBALSDIR():
  48.  
  49.             os.mkdir( "global")
  50.  
  51.             os.mkdir( "global/2d")
  52.             os.mkdir( "global/2d/ae")
  53.             os.mkdir( "global/2d/ae/render")
  54.             os.mkdir( "global/2d/ae/script")
  55.             os.mkdir( "global/2d/ai")
  56.             os.mkdir( "global/2d/ai/project")    
  57.             os.mkdir( "global/2d/ai/export")
  58.             os.mkdir( "global/2d/motion")
  59.             os.mkdir( "global/2d/motion/scripts")
  60.             os.mkdir( "global/2d/motion/render")
  61.             os.mkdir( "global/2d/psd")
  62.             os.mkdir( "global/2d/psd/project")
  63.             os.mkdir( "global/2d/psd/export")
  64.             os.mkdir( "global/2d/shk")
  65.             os.mkdir( "global/2d/shk/script")
  66.             os.mkdir( "global/2d/shk/render")
  67.             os.mkdir( "global/2d/output")
  68.  
  69.             os.mkdir( "global/3d")
  70.             os.mkdir( "global/3d/boujou")
  71.             os.mkdir( "global/3d/maya")
  72.             os.mkdir( "global/3d/max")
  73.             os.mkdir( "global/3d/syntheyes")
  74.             os.mkdir( "global/3d/output")
  75.  
  76.             os.mkdir( "global/color")
  77.  
  78.             os.mkdir( "global/output")
  79.             os.mkdir( "global/output/dvd")
  80.             os.mkdir( "global/output/dvd/projects")
  81.             os.mkdir( "global/output/dvd/builds")
  82.             os.mkdir( "global/output/quicktime")
  83.  
  84.             os.mkdir( "global/edit")
  85.             os.mkdir( "global/edit/audio")
  86.             os.mkdir( "global/edit/fcp")
  87.             os.mkdir( "global/edit/fcp/projects")
  88.             os.mkdir( "global/edit/graphics")
  89.             os.mkdir( "global/edit/edl")
  90.             os.mkdir( "global/edit/xml")
  91.  
  92.             os.mkdir( "global/plates")
  93.             os.mkdir( "global/ref")
  94.  
  95.  
  96.         def SUBFOLDERS():
  97.  
  98.             os.mkdir( "2d")
  99.             os.mkdir( "2d/ae")
  100.             os.mkdir( "2d/ae/render")
  101.             os.mkdir( "2d/ae/script")
  102.             os.mkdir( "2d/ai")
  103.             os.mkdir( "2d/ai/project")    
  104.             os.mkdir( "2d/ai/export")
  105.             os.mkdir( "2d/motion")
  106.             os.mkdir( "2d/motion/scripts")
  107.             os.mkdir( "2d/motion/render")
  108.             os.mkdir( "2d/psd")
  109.             os.mkdir( "2d/psd/project")
  110.             os.mkdir( "2d/psd/export")
  111.             os.mkdir( "2d/shk")
  112.             os.mkdir( "2d/shk/render")
  113.             os.mkdir( "2d/shk/script")
  114.             os.mkdir( "2d/output")
  115.  
  116.             os.mkdir( "3d")
  117.             os.mkdir( "3d/boujou")
  118.             os.mkdir( "3d/maya")
  119.             os.mkdir( "3d/max")
  120.             os.mkdir( "3d/syntheyes")
  121.             os.mkdir( "3d/output")
  122.  
  123.             os.mkdir( "plates")
  124.  
  125.             os.chdir( "../")
  126.  
  127.  
  128.         #CREATE JOB DIRECTORY
  129.         os.mkdir( self.jobfolder)
  130.  
  131.         #CREATE OFFLINE & CHANGE INTO OFFLINE DIRECTORY TO CREATE ALL THE SHOT DIRECTORIES & GLOBALS
  132.         os.mkdir( self.jobfolder + "/offline")
  133.         os.chdir( self.jobfolder + "/offline")
  134.         GLOBALSDIR()
  135.  
  136.         #CREATE SHOT DIRECTORY AND AND SUB-DIRECTORIES
  137.  
  138.         for i in range(1, self.shotamount + 1):
  139.             shotname = '%03d' % (i)
  140.             os.mkdir( shotname)
  141.             os.chdir( shotname)
  142.             SUBFOLDERS()
  143.  
  144.         #CREATE ONLINE & CHANGE INTO ONLINE DIRECTORY TO CREATE ALL THE SHOT DIRECTORIES
  145.         os.chdir( jobroot)
  146.         os.mkdir( self.jobfolder + "/online")
  147.         os.chdir( self.jobfolder + "/online")
  148.         GLOBALSDIR()
  149.  
  150.         #CREATE SHOT DIRECTORY AND AND SUB-DIRECTORIES
  151.  
  152.         for i in range(1, self.shotamount + 1):
  153.             shotname = '%03d' % (i)
  154.             os.mkdir( shotname)
  155.             os.chdir( shotname)
  156.             SUBFOLDERS()
  157.  
  158.  
  159.         print
  160.         print "job " + self.jobfolder + " created"
  161.  
  162.  
  163.  
  164.  
  165. class MyApp(wx.App):
  166.     def OnInit(self):
  167.         frame = MyFrame(None, -1, New Job')
  168.         frame.Show(True)
  169.         frame.Centre()
  170.         return True
  171.  
  172. app = MyApp(0)
  173. app.MainLoop()
Jun 23 '07 #9
ateale
46
Sweet!!!
I think I worked it out.

Can anyone confirm this works & is ok (code wise?)

Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/usr/bin/python
  3.  
  4. # newjob.py
  5.  
  6. import wx
  7. import os
  8.  
  9. class MyFrame(wx.Frame):
  10.     def __init__(self, parent, id, title):
  11.         wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(400, 200))
  12.  
  13.         panel = wx.Panel(self, -1)
  14.  
  15.         wxID_ENTERJOBNAME = wx.NewId()
  16.         wxID_JOBNAME = wx.NewId()
  17.         wxID_ENTERSHOTNAME = wx.NewId()
  18.         wxID_SHOTAMOUNT = wx.NewId()
  19.         wxID_QUITBUTTON = wx.NewId()
  20.         wxID_GOBUTTON = wx.NewId()
  21.  
  22.         self.EnterJobname = wx.StaticText(panel, wxID_ENTERJOBNAME, 'Enter a job name:', (10, 20), style=wx.ALIGN_LEFT)
  23.         self.JobName = wx.TextCtrl(panel, wxID_JOBNAME, '', (25,50), (200, -1))
  24.  
  25.         self.EnterShotAmount = wx.StaticText(panel, wxID_ENTERSHOTNAME, 'Enter number of shots:', (10, 80), style=wx.ALIGN_LEFT)        
  26.         self.NumberOfShots = wx.TextCtrl(panel, wxID_SHOTAMOUNT, '', (25,110), (85, -1))
  27.  
  28.         self.QuitButton = wx.Button(panel, wxID_QUITBUTTON, "Quit", (10,140))
  29.         self.QuitButton.Bind(wx.EVT_BUTTON, self.OnClose, id=wxID_QUITBUTTON)
  30.  
  31.         self.GoButton = wx.Button(panel, wxID_GOBUTTON, "GO!!!", (200,140))
  32.         self.GoButton.Bind(wx.EVT_BUTTON, self.OnCreateJob, id=wxID_GOBUTTON)
  33.  
  34.  
  35.     def OnClose(self, event):
  36.         self.Close(True)
  37.  
  38.  
  39.     def OnCreateJob(self, event):
  40.  
  41.         jobfolder = str( self.JobName.GetValue())
  42.         shotamount = int( self.NumberOfShots.GetValue())
  43.  
  44.         print shotamount
  45.  
  46.         jobroot = os.getcwd()
  47.  
  48.         def GLOBALSDIR():
  49.  
  50.             os.mkdir( "global")
  51.  
  52.             os.mkdir( "global/2d")
  53.             os.mkdir( "global/2d/ae")
  54.             os.mkdir( "global/2d/ae/render")
  55.             os.mkdir( "global/2d/ae/script")
  56.             os.mkdir( "global/2d/ai")
  57.             os.mkdir( "global/2d/ai/project")    
  58.             os.mkdir( "global/2d/ai/export")
  59.             os.mkdir( "global/2d/motion")
  60.             os.mkdir( "global/2d/motion/scripts")
  61.             os.mkdir( "global/2d/motion/render")
  62.             os.mkdir( "global/2d/psd")
  63.             os.mkdir( "global/2d/psd/project")
  64.             os.mkdir( "global/2d/psd/export")
  65.             os.mkdir( "global/2d/shk")
  66.             os.mkdir( "global/2d/shk/script")
  67.             os.mkdir( "global/2d/shk/render")
  68.             os.mkdir( "global/2d/output")
  69.  
  70.             os.mkdir( "global/3d")
  71.             os.mkdir( "global/3d/boujou")
  72.             os.mkdir( "global/3d/maya")
  73.             os.mkdir( "global/3d/max")
  74.             os.mkdir( "global/3d/syntheyes")
  75.             os.mkdir( "global/3d/output")
  76.  
  77.             os.mkdir( "global/color")
  78.  
  79.             os.mkdir( "global/output")
  80.             os.mkdir( "global/output/dvd")
  81.             os.mkdir( "global/output/dvd/projects")
  82.             os.mkdir( "global/output/dvd/builds")
  83.             os.mkdir( "global/output/quicktime")
  84.  
  85.             os.mkdir( "global/edit")
  86.             os.mkdir( "global/edit/audio")
  87.             os.mkdir( "global/edit/fcp")
  88.             os.mkdir( "global/edit/fcp/projects")
  89.             os.mkdir( "global/edit/graphics")
  90.             os.mkdir( "global/edit/edl")
  91.             os.mkdir( "global/edit/xml")
  92.  
  93.             os.mkdir( "global/plates")
  94.             os.mkdir( "global/ref")
  95.  
  96.  
  97.         def SUBFOLDERS():
  98.  
  99.             os.mkdir( "2d")
  100.             os.mkdir( "2d/ae")
  101.             os.mkdir( "2d/ae/render")
  102.             os.mkdir( "2d/ae/script")
  103.             os.mkdir( "2d/ai")
  104.             os.mkdir( "2d/ai/project")    
  105.             os.mkdir( "2d/ai/export")
  106.             os.mkdir( "2d/motion")
  107.             os.mkdir( "2d/motion/scripts")
  108.             os.mkdir( "2d/motion/render")
  109.             os.mkdir( "2d/psd")
  110.             os.mkdir( "2d/psd/project")
  111.             os.mkdir( "2d/psd/export")
  112.             os.mkdir( "2d/shk")
  113.             os.mkdir( "2d/shk/render")
  114.             os.mkdir( "2d/shk/script")
  115.             os.mkdir( "2d/output")
  116.  
  117.             os.mkdir( "3d")
  118.             os.mkdir( "3d/boujou")
  119.             os.mkdir( "3d/maya")
  120.             os.mkdir( "3d/max")
  121.             os.mkdir( "3d/syntheyes")
  122.             os.mkdir( "3d/output")
  123.  
  124.             os.mkdir( "plates")
  125.  
  126.             os.chdir( "../")
  127.  
  128.  
  129.         #CREATE JOB DIRECTORY
  130.         os.mkdir( jobfolder)
  131.  
  132.         #CREATE OFFLINE & CHANGE INTO OFFLINE DIRECTORY TO CREATE ALL THE SHOT DIRECTORIES & GLOBALS
  133.         os.mkdir( jobfolder + "/offline")
  134.         os.chdir( jobfolder + "/offline")
  135.         GLOBALSDIR()
  136.  
  137.         #CREATE SHOT DIRECTORY AND AND SUB-DIRECTORIES
  138.  
  139.         for i in range(1, shotamount + 1):
  140.             shotname = '%03d' % (i)
  141.             os.mkdir( shotname)
  142.             os.chdir( shotname)
  143.             SUBFOLDERS()
  144.  
  145.         #CREATE ONLINE & CHANGE INTO ONLINE DIRECTORY TO CREATE ALL THE SHOT DIRECTORIES
  146.         os.chdir( jobroot)
  147.         os.mkdir( jobfolder + "/online")
  148.         os.chdir( jobfolder + "/online")
  149.         GLOBALSDIR()
  150.  
  151.         #CREATE SHOT DIRECTORY AND AND SUB-DIRECTORIES
  152.  
  153.         for i in range(1, shotamount + 1):
  154.             shotname = '%03d' % (i)
  155.             os.mkdir( shotname)
  156.             os.chdir( shotname)
  157.             SUBFOLDERS()
  158.  
  159.  
  160.         print
  161.         print "job " + jobfolder + " created"
  162.  
  163.  
  164.  
  165.  
  166. class MyApp(wx.App):
  167.     def OnInit(self):
  168.         frame = MyFrame(None, -1, 'New Job')
  169.         frame.Show(True)
  170.         frame.Centre()
  171.         return True
  172.  
  173. app = MyApp(0)
  174. app.MainLoop()
  175.  
  176.  
Jun 23 '07 #10
bartonc
6,596 Expert 4TB
hey guys

thanks for all your help so far - sorry I havent got back to your replies - distracted with work

I think I understand what u mean by giving everything descriptive names and assigning them as self. and flexible IDs

Does this look better?

It still doesn't work - I cant seem to convert a string to an integer - this error:

line 128, in OnCreateJob
os.mkdir( self.jobfolder)
TypeError: coercing to Unicode: need string or buffer, TextCtrl found

Any ideas how to get that to convert to a string?
i thought this would work:
int( self.NumberOfShots)

but get this:
TypeError: int() argument must be a string or a number

Cheers!!

Adam
It's starting to look good (even better with "=python" in the code tags).
A couple of things:
str() will convert pure python Types (objects with __str__() methods) to strings.
In order to get a value from a GUI object, call one of its "getter" (almost always starts with "Get") functions.

I'm not going to run this on my machine so we'll just have to work out the bugs long-distance.

Get rid of
Expand|Select|Wrap|Line Numbers
  1.         self.jobfolder = str( self.JobName)
In the event handler (and I'm beginning to doubt the logic behind creating so many directories in response to an event) where you need the value of a GUI element,
Expand|Select|Wrap|Line Numbers
  1. #
  2.  
  3. #
  4.         #CREATE JOB DIRECTORY
  5.         jobFolderName = self.JobName.GetValue() 
  6.         os.mkdir( jobFolderName)
Jun 23 '07 #11
ateale
46
ahhhhh cool! I get it!
Thanks for all your help so far!
Will keep refining it!
Thanks again!
This is very addictive
Jun 23 '07 #12
bartonc
6,596 Expert 4TB
ahhhhh cool! I get it!
Thanks for all your help so far!
Will keep refining it!
Thanks again!
This is very addictive
You are welcome.

I highly recommend hitting the "buy the book" link on the wxPython home page. Your purchase helps pay for the project is some small way and the info in there is invaluable.
Jun 23 '07 #13
ateale
46
You are welcome.

I highly recommend hitting the "buy the book" link on the wxPython home page. Your purchase helps pay for the project is some small way and the info in there is invaluable.
great idea! Will definitely do that! Cheers!
Jun 23 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Andy Read | last post by:
Dear all, I thought I understood passing parameters ByVal and ByRef but I clearly don't! If I define a simple class of: Public Class Person Public Name as String Public Age as Integer End...
9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
2
by: Kyzer | last post by:
Hi all, I have created a class which contains many TShapes, TLabels and TPanels. What I want to be able to do is when creating this class, is passing in a pointer to OnMouseDown and OnMouseUp...
13
by: Amadeus W. M. | last post by:
I have a member static const int x defined in class Foo, and I'm passing it by reference, and by value elsewhere (see the code below). Passing it by value works, but by reference it doesn't: it...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
11
by: Arsen Vladimirskiy | last post by:
Hello, If I have a few simple classes to represent Entities such as Customers and Orders. What is the proper way to pass information to the Data Access Layer? 1) Pass the actual ENTITY to...
4
by: Ron Rohrssen | last post by:
I want to show a dialog and when the form (dialog) is closed, return to the calling form. The calling form should then be able to pass the child form to another object with the form as a...
7
by: Ken Allen | last post by:
I have a .net client/server application using remoting, and I cannot get the custom exception class to pass from the server to the client. The custom exception is derived from ApplicationException...
12
by: scottt | last post by:
hi, I am having a little problem passing in reference of my calling class (in my ..exe)into a DLL. Both programs are C# and what I am trying to do is pass a reference to my one class into a DLL...
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.