[Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57153] trunk/blender/source/blender/ makesrna/intern/rna_text.c: Made text datablock properties 'is_in_memory' and 'is_dirty' editable in Python.

Tamito KAJIYAMA rd6t-kjym at asahi-net.or.jp
Fri May 31 23:18:15 CEST 2013


The idea was to implement a short-cut button in the Freestyle Python
Scripting mode for loading a script file as a text datablock and appending
it to the style module stack.  As part of the modal file selection dialog
I wanted to have a checkbox to optionally make the selected script file
internal after loading (exactly in the same way when loading files in the
Text Editor window).  The operator implementation looks as follows at
the moment (not in the SVN yet):

    filepath = StringProperty(subtype='FILE_PATH')

    make_internal = BoolProperty(
        name="Make internal",
        description="Make module file internal after loading",
        default=True)

    def invoke(self, context, event):
        self.freestyle_module = context.freestyle_module
        wm = context.window_manager
        wm.fileselect_add(self)
        return {'RUNNING_MODAL'}

    def execute(self, context):
        text = bpy.data.texts.load(self.filepath)
        if self.make_internal:
            text.is_in_memory = True
            text.is_dirty = True
            text.filepath = ""
        self.freestyle_module.script = text
        return {'FINISHED'}

For this specific purpose, text.make_internal() would make more sense
since what is necessary here is essentially the functionality of the "Make
Internal" command that would be accessible from outside the Text Editor.
I also tried the following:

  override = {'edit_text': text}
  bpy.ops.text.make_internal(override)

This is very enough for making the loaded text datablock internal, but
unfortunately with a few lines of warning like below on console:

PyContext 'window' not found
PyContext 'window' not found
PyContext 'area' not found
PyContext 'area' not found
PyContext 'window' not found
PyContext 'region' not found

Hope this explains better the intended use of the "Make Internal" function
from within Python.

Regards,

-- 
KAJIYAMA, Tamito <rd6t-kjym at asahi-net.or.jp>


-----Original Message----- 
From: Sergey Sharybin
Sent: Friday, May 31, 2013 8:58 PM
To: bf-blender developers
Subject: Re: [Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57153] trunk/blender/source/blender/ 
makesrna/intern/rna_text.c: Made text datablock properties 'is_in_memory' and 'is_dirty' editable in Python.

Eeeh. Didn't know we've got both is_modifier and is_dirty :S This is just
became much more confusing.

But still IMO API shall do the same what user could do from the interface.
Meaning if you could make text internal/packed, it shall be as good enough
as if pack/unpack buttons are exposed to the interface. Just IMO :)

Would indeed be interesting how this is intended to be used, maybe then
some clear proposal of API will appear. And if not, well. Let's go this way
and break api once in the future :)


On Sat, Jun 1, 2013 at 1:34 AM, Campbell Barton <ideasman42 at gmail.com>wrote:

> On Sat, Jun 1, 2013 at 4:45 AM, Sergey Sharybin <sergey.vfx at gmail.com>
> wrote:
> > That'd be really confusing situation when you'll set is-internal to False
> > for the textblock which originally was internal. You'll basically loose
> all
> > the data i guess.
> The general idea with rna is to expose blender data as-is, hiding how
> blender works gets into all sorts of troubles.
> This area is weak design IMHO depends on filename being NULL and flags
> being set, but as in my prev reply, I think this whole area could be
> re-worked.
>
> we have .is_modified .is_dirty .is_in_memory and .filename == "".
> Its already quite confusing.
>
> > Also is_dirty pretty dangerous thing. Setting it to false will also lead
> to
> > nothing else than confuse.
> >
> > This is probably acceptable for short-term solution, but for longer term
> > is't more like a confusing way to reach the goal. And in context of
> recent
> > API breakage discussing think it's better to support nice way of reaching
> > the goal from the start, rather than breaking api later.
> >
> > And for long term, not sure how pack/unpack is different from
> > make_internal/make_external. Sounds more like a pseudonyms to the same
> > thing, and perhaps we could already call functions this way?
>
> If text is made to work like image packing, then there is no
> difference, but currently adding a function and calling it
> pack()/unpack() would be confusing since thats now how the text editor
> works.
>
> Not this topic is raised Im curious as to what Tamito intends to use this
> for.
>
> > On Sat, Jun 1, 2013 at 12:30 AM, Campbell Barton <ideasman42 at gmail.com
> >wrote:
> >
> >> I requested Tamito use flags rather then a function,
> >> The reason for this is that making a text internal/external is fairly
> >> low-level (not something regular script devs would care about
> >> typically).
> >> if you add make_internal() then theres the chance you'll want a
> >> make_external() function (which could be OK but adds more API calls).
> >>
> >> Longer term, I think it would be good if we could have text that isn't
> >> necessarily stored inside a blend file (like how images aren't stored
> >> unless packed),
> >> in that case text blocks can have pack(), unpack() functions as
> mentioned.
> >>
> >> On Sat, Jun 1, 2013 at 4:08 AM, Tamito KAJIYAMA
> >> <rd6t-kjym at asahi-net.or.jp> wrote:
> >> > Hi Sergey,
> >> >
> >> > Indeed .make_internal() was exactly what I was proposing initially.
> >> > http://www.pasteall.org/42705/diff
> >> > Then I was suggested to address the issue in the present way.
> >> > I tend to agree with your opinion from the scripter perspective.
> >> >
> >> > --
> >> > KAJIYAMA, Tamito <rd6t-kjym at asahi-net.or.jp>
> >> >
> >> >
> >> > -----Original Message-----
> >> > From: Sergey Sharybin
> >> > Sent: Friday, May 31, 2013 10:17 AM
> >> > To: Blender Developers
> >> > Subject: Re: [Bf-committers] [Bf-blender-cvs] SVN commit:
> >> /data/svn/bf-blender [57153] trunk/blender/source/blender/
> >> > makesrna/intern/rna_text.c: Made text datablock properties
> >> 'is_in_memory' and 'is_dirty' editable in Python.
> >> >
> >> > Hi,
> >> >
> >> > Not sure this is the best way to go. IMO this is rather confusing from
> >> > scripter POV and confuses system a bit.
> >> >
> >> > Why not make it a TextBlock.make_internal() method? Name of the
> method is
> >> > discussable -- could be pack/unpack to match other datablocks, but
> think
> >> > callback is the way to go to achieve things you want :)
> >> >
> >> >
> >> > On Fri, May 31, 2013 at 1:40 PM, Tamito Kajiyama
> >> > <rd6t-kjym at asahi-net.or.jp>wrote:
> >> >
> >> >> Revision: 57153
> >> >>
> >> >>
> >>
> http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57153
> >> >> Author:   kjym3
> >> >> Date:     2013-05-31 07:40:03 +0000 (Fri, 31 May 2013)
> >> >> Log Message:
> >> >> -----------
> >> >> Made text datablock properties 'is_in_memory' and 'is_dirty'
> editable in
> >> >> Python.
> >> >>
> >> >> The rationale of this revision is to provide an easy way to make text
> >> >> datablocks internal
> >> >> from within Python (i.e., by setting these properties to True and the
> >> >> 'filepath' property
> >> >> to empty string).
> >> >>
> >> >> Modified Paths:
> >> >> --------------
> >> >>     trunk/blender/source/blender/makesrna/intern/rna_text.c
> >> >>
> >> >> Modified: trunk/blender/source/blender/makesrna/intern/rna_text.c
> >> >> ===================================================================
> >> >> --- trunk/blender/source/blender/makesrna/intern/rna_text.c
> >> 2013-05-31
> >> >> 06:28:11 UTC (rev 57152)
> >> >> +++ trunk/blender/source/blender/makesrna/intern/rna_text.c
> >> 2013-05-31
> >> >> 07:40:03 UTC (rev 57153)
> >> >> @@ -148,7 +148,6 @@
> >> >>
> >> >>         prop = RNA_def_property(srna, "is_dirty", PROP_BOOLEAN,
> >> PROP_NONE);
> >> >>         RNA_def_property_boolean_sdna(prop, NULL, "flags",
> TXT_ISDIRTY);
> >> >> -       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
> >> >>         RNA_def_property_ui_text(prop, "Dirty", "Text file has been
> >> edited
> >> >> since last save");
> >> >>
> >> >>         prop = RNA_def_property(srna, "is_modified", PROP_BOOLEAN,
> >> >> PROP_NONE);
> >> >> @@ -158,7 +157,6 @@
> >> >>
> >> >>         prop = RNA_def_property(srna, "is_in_memory", PROP_BOOLEAN,
> >> >> PROP_NONE);
> >> >>         RNA_def_property_boolean_sdna(prop, NULL, "flags",
> TXT_ISMEM);
> >> >> -       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
> >> >>         RNA_def_property_ui_text(prop, "Memory", "Text file is in
> >> memory,
> >> >> without a corresponding file on disk");
> >> >>
> >> >>         prop = RNA_def_property(srna, "use_module", PROP_BOOLEAN,
> >> >> PROP_NONE);
> >> >
> >> > _______________________________________________
> >> > Bf-committers mailing list
> >> > Bf-committers at blender.org
> >> > http://lists.blender.org/mailman/listinfo/bf-committers
> >>
> >>
> >>
> >> --
> >> - Campbell
> >> _______________________________________________
> >> Bf-committers mailing list
> >> Bf-committers at blender.org
> >> http://lists.blender.org/mailman/listinfo/bf-committers
> >>
> >
> >
> >
> > --
> > With best regards, Sergey Sharybin
> > _______________________________________________
> > Bf-committers mailing list
> > Bf-committers at blender.org
> > http://lists.blender.org/mailman/listinfo/bf-committers
>
>
>
> --
> - Campbell
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers
>



-- 
With best regards, Sergey Sharybin
_______________________________________________
Bf-committers mailing list
Bf-committers at blender.org
http://lists.blender.org/mailman/listinfo/bf-committers 



More information about the Bf-committers mailing list