Jiri,

Probably this idea should be files in the development wiki at
http://www.zim-wiki.org/wiki . That way we can add comments and work
out the details.

Regards,

Jaap


2010/7/1 Jiří Janoušek <janousek.j...@gmail.com>:
> Hi everybody.
>
> I have some ideas about embedding custom objects in PageView, but I'm a 
> beginner in Python and I don't have any experiences with the whole TextView 
> stuff. I wonder if somebody could try to implement it. A custom object is a 
> object which can't be rendered directly by TextView, inserting a GTK widget 
> into TextView is needed. See examples bellow.
>
>        I. Wiki syntax
> Example 1: tables
> {{{Table:
> | foo | bar | baz |
> | foo | bar | baz |
> }}}
>
> * Example 2: source code snippets
> {{{Source: lang="python" linenumbers="true"
> import gtk
> w=gtk.Window()
> ...
> w.show_all()
> gtk.main()
> }}}
>
> * Example 3: LaTeX without external *.tex file
> {{{LaTeX:
> \bold{moo}
> }}}
>
> * Example 4: Dummy object for further explanation
> {{{AnotherObject: name="foo" attr2="bar" attr3="baz"
> some data
> }}}
>
>        II. ParseTree representation
> In ParseTree it could be represented by element 'object':
>
> builder.start('object', {'objectname':'AnotherObject', 'name':'foo', 
> 'attr2':'bar', 'attr3':'baz'})
> builder.data('some data')
> builder.end('object')
>
>        III. Rendering and manipulating with data
> Rendering and manipulating with object's data is provided by ObjectManager 
> class.
>
> class AnotherObjectManager(ObjectManagerClass):
>        # ObjectManagerClass is an abstract class
>        def __init__(self, attrs):
>                self.attrs=attrs
>                # initiate gui
>                self.entry=gtk.Entry()
>
>        def set_data(self, data):
>                # parse data and fill the gui
>                self.entry.set_text(data)
>
>        def get_data(self):
>                #get data from gui and dump them
>                return self.entry.get_text()
>
>        def get_widget(self):
>                # return widget to be
>                # included in PageView
>                return self.entry
>
>        def export(self, format):
>                # exporting object,
>                # returns None if format is not
>                # supported by this ObjectManager
>                # and the fallback should be verbatim
>                # paragraph
>                if format == 'html':
>                        return '<input name="'+
>                        self.attrs['name']+
>                        '" value="'+self.get_data()+'">'
>                else: return None
>
>        IV. Registering of ObjectManager
> It should be some mechanism to register ObjectManager easily by plugins.
>
> # zim/plugins/anotherobject.py
>
> class AnotherObjectPlugin(PluginClass):
>        def __init__(self, ui):
>                PluginClass.__init__(self, ui)
>                ...
>                ui.register_object_manager('AnotherObject', 
> AnotherObjectManager)
>                ...
>
> The fallback for unknown object could be verbatim paragraph.
>
>        V. Insertion into PageView
> if ObjectManager for current object is registered:
>        manager = ObjectManager(attrs)
>        manager.set_data(data)
>        widget=manager.get_widget()
>        Insert widget into PageView
> else:
>        Fallback to verbatim paragraph
>        (whole {{{ }}} block to preserve
>        objectname and attrs)
>
>        VI. Conclusion
> This feature is very complex, but it will allow to write variety of new 
> plugins.
>
> Best regards
> -- Jiří Janoušek
>
> _______________________________________________
> Mailing list: https://launchpad.net/~zim-wiki
> Post to     : zim-wiki@lists.launchpad.net
> Unsubscribe : https://launchpad.net/~zim-wiki
> More help   : https://help.launchpad.net/ListHelp
>
>

_______________________________________________
Mailing list: https://launchpad.net/~zim-wiki
Post to     : zim-wiki@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zim-wiki
More help   : https://help.launchpad.net/ListHelp

Reply via email to