Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
blender-addons
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-addons
Commits
d1b70c20
Commit
d1b70c20
authored
Mar 29, 2011
by
Campbell Barton
Browse files
Options
Downloads
Patches
Plain Diff
- added search path support if files cant be found.
- added next/previous buttons so you can skip demos.
parent
395821bc
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
system_demo_mode/config.py
+1
-0
1 addition, 0 deletions
system_demo_mode/config.py
system_demo_mode/demo_mode.py
+96
-26
96 additions, 26 deletions
system_demo_mode/demo_mode.py
with
97 additions
and
26 deletions
system_demo_mode/config.py
+
1
−
0
View file @
d1b70c20
...
@@ -47,6 +47,7 @@ def as_string(dirpath, random_order, **kwargs):
...
@@ -47,6 +47,7 @@ def as_string(dirpath, random_order, **kwargs):
cfg_str
+=
[
"
\n
"
]
cfg_str
+=
[
"
\n
"
]
cfg_str
+=
[
"
# edit the search path so other systems may find the files below
\n
"
]
cfg_str
+=
[
"
# edit the search path so other systems may find the files below
\n
"
]
cfg_str
+=
[
"
# based on name only if the absolute paths cant be found
\n
"
]
cfg_str
+=
[
"
# based on name only if the absolute paths cant be found
\n
"
]
cfg_str
+=
[
"
# Use
'
//
'
for current blend file path.
\n
"
]
cfg_str
+=
[
"
\n
"
]
cfg_str
+=
[
"
\n
"
]
cfg_str
+=
[
"
search_path = %r
\n
"
%
dirpath
]
cfg_str
+=
[
"
search_path = %r
\n
"
%
dirpath
]
cfg_str
+=
[
"
\n
"
]
cfg_str
+=
[
"
\n
"
]
...
...
This diff is collapsed.
Click to expand it.
system_demo_mode/demo_mode.py
+
96
−
26
View file @
d1b70c20
...
@@ -110,12 +110,10 @@ def demo_mode_auto_select():
...
@@ -110,12 +110,10 @@ def demo_mode_auto_select():
return
mode
return
mode
def
demo_mode_next_file
():
def
demo_mode_next_file
(
step
=
1
):
global_state
[
"
demo_index
"
]
+=
1
print
(
global_state
[
"
demo_index
"
])
global_state
[
"
demo_index
"
]
=
(
global_state
[
"
demo_index
"
]
+
step
)
%
len
(
global_config_files
)
if
global_state
[
"
demo_index
"
]
>=
len
(
global_config_files
):
print
(
global_state
[
"
demo_index
"
],
"
....
"
)
global_state
[
"
demo_index
"
]
=
0
print
(
"
func:demo_mode_next_file
"
,
global_state
[
"
demo_index
"
])
print
(
"
func:demo_mode_next_file
"
,
global_state
[
"
demo_index
"
])
filepath
=
global_config_files
[
global_state
[
"
demo_index
"
]][
"
file
"
]
filepath
=
global_config_files
[
global_state
[
"
demo_index
"
]][
"
file
"
]
bpy
.
ops
.
wm
.
open_mainfile
(
filepath
=
filepath
)
bpy
.
ops
.
wm
.
open_mainfile
(
filepath
=
filepath
)
...
@@ -289,7 +287,6 @@ class DemoMode(bpy.types.Operator):
...
@@ -289,7 +287,6 @@ class DemoMode(bpy.types.Operator):
bl_label
=
"
Demo
"
bl_label
=
"
Demo
"
enabled
=
False
enabled
=
False
first_run
=
True
first_run
=
True
def
cleanup
(
self
,
disable
=
False
):
def
cleanup
(
self
,
disable
=
False
):
...
@@ -301,7 +298,7 @@ class DemoMode(bpy.types.Operator):
...
@@ -301,7 +298,7 @@ class DemoMode(bpy.types.Operator):
DemoKeepAlive
.
remove
()
DemoKeepAlive
.
remove
()
def
modal
(
self
,
context
,
event
):
def
modal
(
self
,
context
,
event
):
print
(
"
DemoMode.modal
"
,
global_state
[
"
anim_cycles
"
])
#
print("DemoMode.modal", global_state["anim_cycles"])
if
not
self
.
__class__
.
enabled
:
if
not
self
.
__class__
.
enabled
:
self
.
cleanup
(
disable
=
True
)
self
.
cleanup
(
disable
=
True
)
return
{
'
CANCELLED
'
}
return
{
'
CANCELLED
'
}
...
@@ -335,7 +332,7 @@ class DemoMode(bpy.types.Operator):
...
@@ -335,7 +332,7 @@ class DemoMode(bpy.types.Operator):
# toggle
# toggle
if
self
.
__class__
.
enabled
and
self
.
__class__
.
first_run
==
False
:
if
self
.
__class__
.
enabled
and
self
.
__class__
.
first_run
==
False
:
# this actually cancells the previous running instance
# this actually cancells the previous running instance
self
.
__class__
.
enabled
=
False
# should never happen now, DemoModeControl is for this.
return
{
'
CANCELLED
'
}
return
{
'
CANCELLED
'
}
else
:
else
:
self
.
__class__
.
enabled
=
True
self
.
__class__
.
enabled
=
True
...
@@ -349,21 +346,60 @@ class DemoMode(bpy.types.Operator):
...
@@ -349,21 +346,60 @@ class DemoMode(bpy.types.Operator):
self
.
cleanup
()
self
.
cleanup
()
return
None
return
None
# call from DemoModeControl
@classmethod
def
disable
(
cls
):
if
cls
.
enabled
and
cls
.
first_run
==
False
:
# this actually cancells the previous running instance
# should never happen now, DemoModeControl is for this.
cls
.
enabled
=
False
class
DemoModeControl
(
bpy
.
types
.
Operator
):
bl_idname
=
"
wm.demo_mode_control
"
bl_label
=
"
Control
"
mode
=
bpy
.
props
.
EnumProperty
(
items
=
(
(
'
PREV
'
,
"
Prev
"
,
""
),
(
'
PAUSE
'
,
"
Pause
"
,
""
),
(
'
NEXT
'
,
"
Next
"
,
""
),
),
name
=
"
Mode
"
)
def
execute
(
self
,
context
):
mode
=
self
.
mode
if
mode
==
'
PREV
'
:
demo_mode_next_file
(
-
1
)
elif
mode
==
'
NEXT
'
:
demo_mode_next_file
(
1
)
else
:
# pause
DemoMode
.
disable
()
return
{
'
FINISHED
'
}
def
menu_func
(
self
,
context
):
def
menu_func
(
self
,
context
):
# print("func:menu_func - DemoMode.enabled:", DemoMode.enabled, "bpy.app.driver_namespace:", DemoKeepAlive.secret_attr not in bpy.app.driver_namespace, 'global_state["timer"]:', global_state["timer"])
# print("func:menu_func - DemoMode.enabled:", DemoMode.enabled, "bpy.app.driver_namespace:", DemoKeepAlive.secret_attr not in bpy.app.driver_namespace, 'global_state["timer"]:', global_state["timer"])
layout
=
self
.
layout
layout
=
self
.
layout
layout
.
operator_context
=
'
EXEC_DEFAULT
'
layout
.
operator_context
=
'
EXEC_DEFAULT
'
layout
.
operator
(
"
wm.demo_mode
"
,
icon
=
'
PLAY
'
if
not
DemoMode
.
enabled
else
'
PAUSE
'
)
box
=
layout
.
row
()
# BOX messes layout
row
=
box
.
row
(
align
=
True
)
row
.
label
(
"
Demo Mode:
"
)
if
not
DemoMode
.
enabled
:
row
.
operator
(
"
wm.demo_mode
"
,
icon
=
'
PLAY
'
,
text
=
""
)
else
:
row
.
operator
(
"
wm.demo_mode_control
"
,
icon
=
'
REW
'
,
text
=
""
).
mode
=
'
PREV
'
row
.
operator
(
"
wm.demo_mode_control
"
,
icon
=
'
PAUSE
'
,
text
=
""
).
mode
=
'
PAUSE
'
row
.
operator
(
"
wm.demo_mode_control
"
,
icon
=
'
FF
'
,
text
=
""
).
mode
=
'
NEXT
'
def
register
():
def
register
():
bpy
.
utils
.
register_class
(
DemoMode
)
bpy
.
utils
.
register_class
(
DemoMode
)
bpy
.
utils
.
register_class
(
DemoModeControl
)
bpy
.
types
.
INFO_HT_header
.
append
(
menu_func
)
bpy
.
types
.
INFO_HT_header
.
append
(
menu_func
)
def
unregister
():
def
unregister
():
bpy
.
utils
.
unregister_class
(
DemoMode
)
bpy
.
utils
.
unregister_class
(
DemoMode
)
bpy
.
utils
.
unregister_class
(
DemoModeControl
)
bpy
.
types
.
INFO_HT_header
.
remove
(
menu_func
)
bpy
.
types
.
INFO_HT_header
.
remove
(
menu_func
)
...
@@ -398,18 +434,52 @@ def load_config(cfg_name=DEMO_CFG):
...
@@ -398,18 +434,52 @@ def load_config(cfg_name=DEMO_CFG):
exec
(
demo_data
,
namespace
,
namespace
)
exec
(
demo_data
,
namespace
,
namespace
)
for
filecfg
in
namespace
[
"
config
"
]:
demo_config
=
namespace
[
"
config
"
]
demo_search_path
=
namespace
.
get
(
"
search_path
"
)
if
demo_search_path
is
None
:
print
(
"
reading: %r, no search_path found, missing files wont be searched.
"
%
demo_path
)
if
demo_search_path
.
startswith
(
"
//
"
):
demo_search_path
=
os
.
path
.
relpath
(
demo_search_path
)
if
not
os
.
path
.
exists
(
demo_search_path
):
print
(
"
reading: %r, search_path %r does not exist.
"
%
(
demo_path
,
demo_search_path
))
demo_search_path
=
None
blend_lookup
=
{}
# initialize once, case insensitive dict
def
lookup_file
(
filepath
):
filename
=
os
.
path
.
basename
(
filepath
).
lower
()
if
not
blend_lookup
:
# ensure only ever run once.
blend_lookup
[
None
]
=
None
def
blend_dict_items
(
path
):
for
dirpath
,
dirnames
,
filenames
in
os
.
walk
(
path
):
# skip '.svn'
if
dirpath
.
startswith
(
"
.
"
):
continue
for
filename
in
filenames
:
if
filename
.
lower
().
endswith
(
"
.blend
"
):
filepath
=
os
.
path
.
join
(
dirpath
,
filename
)
yield
(
filename
.
lower
(),
filepath
)
# defaults
blend_lookup
.
update
(
dict
(
blend_dict_items
(
demo_search_path
)))
#filecfg["display_render"] = filecfg.get("display_render", 0)
#filecfg["animate"] = filecfg.get("animate", 0)
#filecfg["screen_switch"] = filecfg.get("screen_switch", 0)
if
not
os
.
path
.
exists
(
filecfg
[
"
file
"
]):
# fallback to orginal file
return
blend_lookup
.
get
(
filename
,
filepath
)
# done with search lookup
for
filecfg
in
demo_config
:
filepath_test
=
filecfg
[
"
file
"
]
if
not
os
.
path
.
exists
(
filepath_test
):
filepath_test
=
os
.
path
.
join
(
basedir
,
filecfg
[
"
file
"
])
filepath_test
=
os
.
path
.
join
(
basedir
,
filecfg
[
"
file
"
])
if
not
os
.
path
.
exists
(
filepath_test
):
filepath_test
=
lookup_file
(
filepath_test
)
# attempt to get from searchpath
if
not
os
.
path
.
exists
(
filepath_test
):
if
not
os
.
path
.
exists
(
filepath_test
):
print
(
"
Cant find %r or %r, skipping!
"
)
print
(
"
Cant find %r or %r, skipping!
"
)
continue
continue
filecfg
[
"
file
"
]
=
os
.
path
.
normpath
(
filepath_test
)
filecfg
[
"
file
"
]
=
os
.
path
.
normpath
(
filepath_test
)
# sanitize
# sanitize
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment