473,549 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passing [class-scope] variables to between methods?

46 New Member
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 2116
bartonc
6,596 Recognized Expert Expert
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 New Member
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 Recognized Expert Expert
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 Recognized Expert Expert
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 New Member
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 New Member
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 Recognized Expert Expert
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 "veryDescriptiv eNameStr" rather than "a".

Hope that make sense.
Jun 20 '07 #8
ateale
46 New Member
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.NumberOfSh ots)

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 New Member
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

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

Similar topics

3
16822
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 Class
9
4770
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 am using vector class(STL), the compiler does not allow me to do this. I do realize there is a pitfall in this approach(size of arrays not...
2
2902
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 events. Thereby, the user of the class can create their own event handlers for those events. The idea is that by passing in the event handlers,...
13
2565
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 thinks x is undefined. Could someone explain what's going on here? Why can't I pass a static const member by reference? This is how I compile it: ...
7
2836
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 parameter to the XSLT stylesheet XsltArgumentList xsltArgList = new XsltArgumentList(); xsltArgList.AddParam("pmID", "", pmID);...
11
3163
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 the Data Access Layer method -or- 2) Pass some kind of a unique id to the Data Access Layer method
4
4861
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 parameter. For example, FormOptions formOptions = new FormOptions(); if (formOptions.ShowDialog(this) == DialogResult.OK) {
7
4734
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 and is defined in an assembly common to the client and server components. The custom class merely defines three (3) constructors -- the null...
12
3008
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 function. When I try and compile the DLL I get "The type or namespace name "MyForm" could not be found. I think I have to reference the class but...
7
3292
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 object is a reference type? my code is not proving that. I have a web project i created from a web service that is my object: public class...
0
7457
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7723
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7965
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7483
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7817
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3504
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
771
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.