~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/scripts/templates/operator_file_import.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import bpy
 
2
 
 
3
 
 
4
def read_some_data(context, filepath, use_some_setting):
 
5
    print("running read_some_data...")
 
6
    f = open(filepath, 'r', encoding='utf-8')
 
7
    data = f.read()
 
8
    f.close()
 
9
 
 
10
    # would normally load the data here
 
11
    print(data)
 
12
 
 
13
    return {'FINISHED'}
 
14
 
 
15
 
 
16
# ImportHelper is a helper class, defines filename and
 
17
# invoke() function which calls the file selector.
 
18
from bpy_extras.io_utils import ImportHelper
 
19
from bpy.props import StringProperty, BoolProperty, EnumProperty
 
20
from bpy.types import Operator
 
21
 
 
22
 
 
23
class ImportSomeData(Operator, ImportHelper):
 
24
    '''This appears in the tooltip of the operator and in the generated docs'''
 
25
    bl_idname = "import_test.some_data"  # important since its how bpy.ops.import_test.some_data is constructed
 
26
    bl_label = "Import Some Data"
 
27
 
 
28
    # ImportHelper mixin class uses this
 
29
    filename_ext = ".txt"
 
30
 
 
31
    filter_glob = StringProperty(
 
32
            default="*.txt",
 
33
            options={'HIDDEN'},
 
34
            )
 
35
 
 
36
    # List of operator properties, the attributes will be assigned
 
37
    # to the class instance from the operator settings before calling.
 
38
    use_setting = BoolProperty(
 
39
            name="Example Boolean",
 
40
            description="Example Tooltip",
 
41
            default=True,
 
42
            )
 
43
 
 
44
    type = EnumProperty(
 
45
            name="Example Enum",
 
46
            description="Choose between two items",
 
47
            items=(('OPT_A', "First Option", "Description one"),
 
48
                   ('OPT_B', "Second Option", "Description two")),
 
49
            default='OPT_A',
 
50
            )
 
51
 
 
52
    def execute(self, context):
 
53
        return read_some_data(context, self.filepath, self.use_setting)
 
54
 
 
55
 
 
56
# Only needed if you want to add into a dynamic menu
 
57
def menu_func_import(self, context):
 
58
    self.layout.operator(ImportSomeData.bl_idname, text="Text Import Operator")
 
59
 
 
60
 
 
61
def register():
 
62
    bpy.utils.register_class(ImportSomeData)
 
63
    bpy.types.INFO_MT_file_import.append(menu_func_import)
 
64
 
 
65
 
 
66
def unregister():
 
67
    bpy.utils.unregister_class(ImportSomeData)
 
68
    bpy.types.INFO_MT_file_import.remove(menu_func_import)
 
69
 
 
70
 
 
71
if __name__ == "__main__":
 
72
    register()
 
73
 
 
74
    # test call
 
75
    bpy.ops.import_test.some_data('INVOKE_DEFAULT')