bevel_center.py - avoid 2 python errors. (doing recursive before bevel, now UI preven...
authorCampbell Barton <ideasman42@gmail.com>
Tue, 12 Dec 2006 05:29:42 +0000 (05:29 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 12 Dec 2006 05:29:42 +0000 (05:29 +0000)
console.py - if the scriptdir didnt exist it would do an error, now just ignore and dont try to do the console_autoexec.py stuff
doc_browser.py - If you typed in an invalid module it would give an error and exit, now have a message instead.

release/scripts/bevel_center.py
release/scripts/console.py
release/scripts/doc_browser.py

index baa228de1b846ecbf9e699f1790b8103fbabeb56..2b8ee4d20a200c14299dfdea36b91362f8631e21 100644 (file)
@@ -66,6 +66,16 @@ except:
 global E_selected
 E_selected = NMesh.EdgeFlags['SELECT']
 
+old_dist = None
+
+def act_mesh_ob():
+       scn = Scene.GetCurrent()
+       ob = scn.getActiveObject()
+       if ob == None or ob.getType() != 'Mesh': 
+               PupMenu('ERROR%t|Select a mesh object.')
+               return
+       return ob
+
 def make_sel_vert(*co):
        v= NMesh.Vert(*co)
        v.sel = 1
@@ -341,7 +351,7 @@ EVENT_RECURS = 4
 EVENT_EXIT = 5
 
 def draw():
-       global dist, left, right, num
+       global dist, left, right, num, old_dist
        global EVENT_NOEVENT, EVENT_BEVEL, EVENT_UPDATE, EVENT_RECURS, EVENT_EXIT
 
        glClear(GL_COLOR_BUFFER_BIT)
@@ -352,8 +362,12 @@ def draw():
                        "Thickness of the bevel, can be changed even after bevelling")
        glRasterPos2d(8,40)
        Text('To finish, you can use recursive bevel to smooth it')
-       num=Number('',  EVENT_NOEVENT,10,10,40, 16,num.val,1,100,'Recursion level')
-       Button("Recursive",EVENT_RECURS,55,10,100,16)
+       
+       
+       if old_dist != None:
+               num=Number('',  EVENT_NOEVENT,10,10,40, 16,num.val,1,100,'Recursion level')
+               Button("Recursive",EVENT_RECURS,55,10,100,16)
+       
        Button("Exit",EVENT_EXIT,210,10,80,20)
 
 def event(evt, val):
@@ -373,15 +387,12 @@ Register(draw, event, bevent)
 def bevel():
        """ The main function, which creates the bevel """
        global me,NV,NV_ext,NE,NC, old_faces,old_dist
-       t= Blender.sys.time()
-       scn = Scene.GetCurrent()
-       ob = scn.getActiveObject() 
-       if ob == None or ob.getType() != 'Mesh': 
-               Draw.PupMenu('ERROR%t|Select a mesh object.')
-               return
        
-       Window.WaitCursor(1) # Change the Cursor
+       ob = act_mesh_ob()
+       if not ob: return
        
+       Window.WaitCursor(1) # Change the Cursor
+       t= Blender.sys.time()
        is_editmode = Window.EditMode() 
        if is_editmode: Window.EditMode(0)
        
@@ -411,6 +422,10 @@ def bevel_update():
        global dist, old_dist
        is_editmode = Window.EditMode()
        if is_editmode: Window.EditMode(0)
+       
+       if old_dist == None:
+               PupMenu('ERROR%t|Must bevel first.')
+       
        fac = dist.val - old_dist
        old_dist = dist.val
 
@@ -427,7 +442,7 @@ def recursive():
        """ Make a recursive bevel... still experimental """
        global dist
        from math import pi, sin
-
+       
        if num.val > 1:
                a = pi/4
                ang = []
index c1268096952966a53c345e6d0f0c9555a16fc9d0..b0c7628d6e7d2c36595556e2858a5ea3824de551 100644 (file)
@@ -762,17 +762,18 @@ histIndex = cursor = -1 # How far back from the first letter are we? - in curren
 
 # Autoexec, startup code.
 scriptDir = Get('scriptsdir')
-if not scriptDir.endswith(Blender.sys.sep):
-       scriptDir += Blender.sys.sep
-
-console_autoexec  = '%s%s' % (scriptDir, 'console_autoexec.py')
+if scriptDir:
+       if scriptDir.endswith(Blender.sys.sep):
+               scriptDir += Blender.sys.sep
+       
+       console_autoexec  = '%s%s' % (scriptDir, 'console_autoexec.py')
 
-if not sys.exists(console_autoexec):
-       # touch the file
-       cmdBuffer.append(cmdLine('...console_autoexec.py not found, making new in scripts dir', 1, None))
-       open(console_autoexec, 'w').close()
-else:
-       cmdBuffer.append(cmdLine('...Using existing console_autoexec.py in scripts dir', 1, None))
+       if not sys.exists(console_autoexec):
+               # touch the file
+               cmdBuffer.append(cmdLine('...console_autoexec.py not found, making new in scripts dir', 1, None))
+               open(console_autoexec, 'w').close()
+       else:
+               cmdBuffer.append(cmdLine('...Using existing console_autoexec.py in scripts dir', 1, None))
 
 
 
@@ -790,7 +791,9 @@ def include_console(includeFile):
                # Execute the local > global coversion.
                exec('%s%s' % ('__CONSOLE_VAR_DICT__[__TMP_VAR_NAME__]=', __TMP_VAR_NAME__))
                
-include_console(console_autoexec) # pass the blender module
+if scriptDir:
+       include_console(console_autoexec) # pass the blender module
+
 #-end autoexec-----------------------------------------------------------------#
 
 
index 8820e98716bc655c6bbb83bfd76d057b6341eb2f..ad200ccb7c3bf0e81ab63e80cdc4529722d24de0 100644 (file)
@@ -141,6 +141,10 @@ browse_scrollstart= 0
 def browse_module(num):
        global browsing, selected, browse_scrollstart
        
+       # cant go back from Blender
+       if browsing.val == 'Blender' and num == -1:
+               return
+       
        if (num>=0): newstr= browsing.val + "." + browselist[num][0]
        else:
                modules= split(browsing.val, ".")
@@ -160,10 +164,17 @@ def browse_module(num):
 
 def make_browselist():
        global browselist
-
+       
+       try:
+               module= eval(browsing.val)
+       except:
+               Blender.Draw.PupMenu('Error%t|Module is invalid')
+               browsing.val = 'Blender'
+               return
+       
        browselist= []
-
-       module= eval(browsing.val)
+       
+       
        items= dir(module)
 
        for item_name in items: