Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #60710 > unrolled thread

Jython - Can't access enumerations?

Started byEamonn Rea <eamonnrea@gmail.com>
First post2013-11-28 09:22 -0800
Last post2013-11-30 06:40 +1100
Articles 4 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Jython - Can't access enumerations? Eamonn Rea <eamonnrea@gmail.com> - 2013-11-28 09:22 -0800
    Re: Jython - Can't access enumerations? Tim Delaney <timothy.c.delaney@gmail.com> - 2013-11-29 07:50 +1100
    Re: Jython - Can't access enumerations? Eamonn Rea <eamonnrea@gmail.com> - 2013-11-29 08:15 -0800
      Re: Jython - Can't access enumerations? Tim Delaney <timothy.c.delaney@gmail.com> - 2013-11-30 06:40 +1100

#60710 — Jython - Can't access enumerations?

FromEamonn Rea <eamonnrea@gmail.com>
Date2013-11-28 09:22 -0800
SubjectJython - Can't access enumerations?
Message-ID<7633df1c-5c4d-40ea-b9a5-51637d2fef89@googlegroups.com>
Hello! I'm using Jython to write a game with Python/Jython/LibGDX. I wasn't having any trouble, and everything was going well, but sadly I can't access items in enumerations.

If you know about the LibGDX library and have used it, you'll probably know about the BodyType enumeration for Box2D. I was trying to access the BodyType item in the enumeration. This didn't work, as Jython couldn't find the BodyType enumeration. I asked on the LibGDX forum and no one could help. So I'm hoping that someone here could help :-)

So, is this a problem with LibGDX or Jython? I'm using the latest version of Jython.

Thanks!

[toc] | [next] | [standalone]


#60731

FromTim Delaney <timothy.c.delaney@gmail.com>
Date2013-11-29 07:50 +1100
Message-ID<mailman.3377.1385671831.18130.python-list@python.org>
In reply to#60710

[Multipart message — attachments visible in raw view] — view raw

On 29 November 2013 04:22, Eamonn Rea <eamonnrea@gmail.com> wrote:

> Hello! I'm using Jython to write a game with Python/Jython/LibGDX. I
> wasn't having any trouble, and everything was going well, but sadly I can't
> access items in enumerations.
>
> If you know about the LibGDX library and have used it, you'll probably
> know about the BodyType enumeration for Box2D. I was trying to access the
> BodyType item in the enumeration. This didn't work, as Jython couldn't find
> the BodyType enumeration. I asked on the LibGDX forum and no one could
> help. So I'm hoping that someone here could help :-)
>
> So, is this a problem with LibGDX or Jython? I'm using the latest version
> of Jython.
>

There is no problems accessing the elements of enumerations with Jython.
The following was tested using Jython 2.7b1:

Jython 2.7b1 (default:ac42d59644e9, Feb 9 2013, 15:24:52)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_40
Type "help", "copyright", "credits" or "license" for more information.
>>> import java.util.Collections as Collections
>>> import java.util.Arrays as Arrays
>>>
>>> a = Arrays.asList(1, 2, 3)
>>> print(a)
[1, 2, 3]
>>> e = Collections.enumeration(a)
>>> print(e)
java.util.Collections$2@f48007e
>>>
>>> for i in e:
...     print(i)
...
1
2
3

Therefore the problem is either with LibGDX or (more likely) way you are
using it. Please post a minimal example that demonstrates the problem plus
the exact error message you get (I don't know LibGLX at all, but someone
else might, plus trimming it down to a minimal example may reveal the
problem to you).

Tim Delaney

[toc] | [prev] | [next] | [standalone]


#60769

FromEamonn Rea <eamonnrea@gmail.com>
Date2013-11-29 08:15 -0800
Message-ID<f4e27f1a-1c7c-46b8-8959-7aa05df6cf50@googlegroups.com>
In reply to#60710
Ok, here's the code:

body_def = BodyDef() # Imports the BodyDef class fine.

body_def.type = BodyDef.DynamicBody # Says it can't find a module from LibGDX called BodyDef.

All my code:

from com.badlogic.gdx import Game, Gdx, Screen
from com.badlogic.gdx.backends.lwjgl import LwjglApplicationConfiguration, \
    LwjglApplication
from com.badlogic.gdx.graphics import OrthographicCamera, GL20
from com.badlogic.gdx.graphics.g2d import SpriteBatch
from com.badlogic.gdx.math import Vector2
from com.badlogic.gdx.physics.box2d import Box2DDebugRenderer, World, BodyDef, \
    FixtureDef, PolygonShape

import Player


class Playing(Screen):
    def __init__(self):
        self.batch = None
        self.renderer = None
        self.world = None
        self.camera = None
        self.player = None
        self.player_body_def = None
        self.player_fixture_def = None
        self.player_shape = None
    
    
    def show(self):
        self.batch = SpriteBatch()
        self.renderer = Box2DDebugRenderer()
        self.camera = OrthographicCamera()
        self.player_body_def = BodyDef()
        self.player_fixture_def = FixtureDef()
        self.player_shape = PolygonShape()
        
        self.world = World(Vector2(0, -9.81), True)
        
        self.player_shape.setAsBox(0.5, 1)
        
        self.player_body_def.fixedRotation = True
        self.player_body_def.position.set(0, 0)
        self.player_body_def.type = BodyDef.DynamicBody
        
        self.player_fixture_def.density = 1
        self.player_fixture_def.friction = 0.5
        self.player_fixture_def.shape = self.player_shape
        self.player_fixture_def.restitution = 0.01
        
        
        
        self.player = Player(self.world, self.player_body_def, self.player_fixture_def)
    
    
    def resize(self, width, height):
        pass
    
    
    def pause(self):
        pass
    
    
    def resume(self):
        pass
    
    
    def dispose(self):
        pass
    
    
    def render(self, delta):
        Gdx.gl.glClearColor(0, 0, 0, 1)
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
        
        self.renderer.render(self.camera.combined, self.world)

BodyDef.DynamicBody is defiantly in the BodyType Enumeration. I've tested it in Java.

[toc] | [prev] | [next] | [standalone]


#60778

FromTim Delaney <timothy.c.delaney@gmail.com>
Date2013-11-30 06:40 +1100
Message-ID<mailman.3407.1385754062.18130.python-list@python.org>
In reply to#60769

[Multipart message — attachments visible in raw view] — view raw

On 30 November 2013 03:15, Eamonn Rea <eamonnrea@gmail.com> wrote:

> Ok, here's the code:
> [elided]
>

As I said, please also show the *exact* error - copy and paste the stack
trace.

Tim Delaney

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web