Bad parsing of kv language #881

Closed
kamillezole opened this Issue Dec 28, 2012 · 4 comments

Comments

Projects
None yet
5 participants

Hi,

Kivy v1.5.0

if I have a comment after an ID statement in a kv file, the id contains the comment !

Example from tshirtman :

DraggableLabel:
    size_hint_y: None
    top: root.top
    id: dg # assign its id to "dg" so we can reference it elsewhere

in kivy/kivy/lang.py :

    # if we got an id, put it in the root rule for a later global usage
    if rule.id:
        print "#############################################"
        print rule.id
        rctx['ids'][rule.id] = widget

output :

#############################################
dg # assign its id to "dg" so we can reference it elsewhere
Traceback (most recent call last):
File "main.py", line 47, in <module>
    TabApp().run()
File "D:\Portable\Kivy\kivy\kivy\app.py", line 527, in run
    root = self.build()
File "main.py", line 43, in build
    return MyFloatLayout()
File "D:\Portable\Kivy\kivy\kivy\uix\floatlayout.py", line 66, in __init__
    super(FloatLayout, self).__init__(**kwargs)
File "D:\Portable\Kivy\kivy\kivy\uix\layout.py", line 61, in __init__
    super(Layout, self).__init__(**kwargs)
File "D:\Portable\Kivy\kivy\kivy\uix\widget.py", line 150, in __init__
    Builder.apply(self)
File "D:\Portable\Kivy\kivy\kivy\lang.py", line 1236, in apply
    self._apply_rule(widget, rule, rule)
File "D:\Portable\Kivy\kivy\kivy\lang.py", line 1352, in _apply_rule
    value, rule, rctx['ids'])
File "D:\Portable\Kivy\kivy\kivy\lang.py", line 1052, in create_handler
    raise BuilderException(rule.ctx, rule.line, str(e))
kivy.lang.BuilderException: Parser: File ".\tab.kv", line 15:
...
    13:    ScrollView:
    14:        # container for the "notifications"
>>   15:        y: dg.top # let's stick it to the top
    16:        x: root.x # and to the left
    17:        size_hint_y: None
...
name 'dg' is not defined

Kamillezole

tito was assigned Dec 28, 2012

Contributor

alexandre-mbm commented Apr 24, 2013

The community on #kivy IRC channel rediscovered the problem yesterday with the "[Kivy] android-like pulldown menu" @tshirtman's example. The example code in that post has been fixed.

@tito, where is the code parser? Isn't it Python, It is?

Owner

akshayaurora commented Apr 24, 2013

I just ran the following code ::

from kivy.app import App 
from kivy.uix.label import Label
from kivy.animation import Animation
from kivy.lang import Builder

class DraggableLabel(Label):
    '''A label you can drag upside-down'''
    def on_touch_down(self, touch):
        if self.collide_point(*touch.pos):
            # assure ourselves we will get the updates of this motion
            touch.grab(self)
            return True

        return super(DraggableLabel, self).on_touch_down(touch)

    def on_touch_move(self, touch):
        if touch.grab_current is self:
            # really straightforward...
            self.y = touch.y
            return True

        return super(DraggableLabel, self).on_touch_move(touch)

    def on_touch_up(self, touch):
        if touch.grab_current is self:
            # check if the movement direction was up or down
            if touch.dy < 0:
                a = Animation(y=0) # down? put the bar all the way down
            else:
                a = Animation(top=self.parent.top) # up? put it at the top

            a.start(self) # actually start the animation
            return True

        return super(DraggableLabel, self).on_touch_up(touch)

root = Builder.load_string('''
FloatLayout:
    FloatLayout:
        # placeholder for the "normal screen"
        Label:
            center: root.center
            text: 'test content'
            size_hint: None, None
            size: self.texture_size

    ScrollView:
        # container for the "notifications"
        y: dg.top # let's stick it to the top
        x: root.x # and to the left
        size_hint_y: None
        do_scroll_x: False # only vertical scrolling
        do_scroll_y: True

        # most of the magic is there, auto adjust size to follow the draggable label
        height: root.top - dg.y

        # let's put a nearly opaque black background
        canvas:
            Color:
                rgba: 0, 0, 0, .8
            Rectangle:
                pos: self.pos
                size: self.size

        # the actual notification container, with placeholder content
        BoxLayout:
            size_hint_y: None
            height: 1000
            orientation: 'vertical'
            Label:
                text: 'test'
            Label:
                text: 'test'
            Label:
                text: 'test'
            Label:
                text: 'test'
            Label:
                text: 'test'
            Label:
                text: 'test'
            Label:
                text: 'test'
            Label:
                text: 'test'
            Label:
                text: 'test'

    # the draggable label, which behaviour is defined in python file
    DraggableLabel:
        # some decoration behind the text
        canvas.before:
            Color:
                rgba: 0, 0, 0, 1
            Rectangle:
                pos: self.pos
                size: self.size
            Color:
                rgba: .5, .5, .5, 1
            Rectangle:
                pos: self.pos
                size: self.width, 1

        size_hint_y: None
        top: root.top
        # assign its id to "dg" so we can reference it elsewhere
        id: dg
        height: '20pt'
        text: 'drag me'
''')

class TabApp(App):

    def build(self):
        return root


TabApp().run()

It seems to run without any errors for me.
Which version of Kivy did you test with?
Could you re-test with latest development version of kivy from github.

Contributor

alexandre-mbm commented Apr 24, 2013

@akshayaurora, this code had been fixed.

If I'm not mistaken, before it was so:

id: dg  # assign its id to "dg" so we can reference it elsewhere

Today:

# assign its id to "dg" so we can reference it elsewhere
id: dg

But the bug remains in the parser of the Kivy.

Owner

tshirtman commented Apr 24, 2013

Yes, i edited my blog post after the discussion the other day, to avoid
issues to others, it was indeed like you said before.

On Wed, Apr 24, 2013 at 02:29:46AM -0700, Alexandre Magno wrote:

@akshayaurora, this code had been fixed.

If I'm not mistaken, before it was so:

id: dg  # assign its id to "dg" so we can reference it elsewhere

Today:

# assign its id to "dg" so we can reference it elsewhere
id: dg

But the bug remains in the parser of the Kivy.


Reply to this email directly or view it on GitHub:
#881 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment