ogl, changing position of a shape ?

If I try to move an ogl shape by program code,
I get (at least for me) completely strange effects.

I derive a new class
    self.shape = ogl.CircleShape(self.Size[0])
    self.shape.SetX(30)

This hives no errors

Now if I put the SetX in another method of that new class

    self.shape.SetX ( 100)

I get:
TypeError: 'str' object is not callable

So what am I doing wrong ?
How should I change the position of an ogl-shape ?

thanks,
Stef Mientki

If this code is within the derived object, then it
should be:

self.SetX(100)

Gre7g

···

--- Stef Mientki <s.mientki@ru.nl> wrote:

If I try to move an ogl shape by program code,
I get (at least for me) completely strange effects.

I derive a new class

   self.shape = ogl.CircleShape(self.Size[0])
    self.shape.SetX(30)

This hives no errors

Now if I put the SetX in another method of that new
class

    self.shape.SetX ( 100)

____________________________________________________________________________________
We won't tell. Get more on shows you hate to love
(and love to hate): Yahoo! TV's Guilty Pleasures list.
http://tv.yahoo.com/collections/265

Gre7g Luterman wrote:

If I try to move an ogl shape by program code,
I get (at least for me) completely strange effects.

I derive a new class
    self.shape = ogl.CircleShape(self.Size[0])
    self.shape.SetX(30)

This hives no errors

Now if I put the SetX in another method of that new
class

    self.shape.SetX ( 100)
    
If this code is within the derived object, then it
should be:

self.SetX(100)

Gre7g

thanks Greg,

it was some stupid mistake :wink:
But I'm not there yet,
I can move the shape by calling SetX and redraw the shape,
but how do I get rid of the shape at the old position ?

Then I have another weird problem,
which might have nothing to do with ogl but but general Python knowledge
(I hope I give enough information)

I have a class tDevice (my "base" class), consisting of an ogl shape and some other properties
# ***********************************************************************
class tDevice:
    # extra initialization that can be overridden by descendants
    def init (self): pass

    def __init__ (self, Name = 'NoName', Color = (220,220,220),
                Pos = [-1,-1], Size = [-1,-1], Timer_On = False, TimerValue = 200):

     # make the container available for descendants
      from JALsPy_main import Container
      self.my_Container = Container
      self.my_nr = Container.diagram.GetCount()

      # *********************************
      # here the extra initalisation
      # *********************************
      self.init()
      # *********************************

     # add the shape to the canvas container
      Container.MyAddShape( self.shape, self.Pos[0], self.Pos[1],
                          wx.Pen(wx.BLUE, 1), self.Color_Off, self.Name)
# ***********************************************************************

Then I have descendant classes from the above base class,
which set's the actual shape and draw the shape
(and a lot of other things left out of here)
# ***********************************************************************
class tLED (tDevice):
    # ************************************
    # __init__ of ancestor, will call init
    # ************************************
    def init (self):

        # create the visual shape
        self.shape = ogl.CircleShape(self.Size[0])

        self.shape.SetX(30)

    # ************************************
    # called by internal timer or program
    # ************************************
    def execute (self):
          dc = wx.ClientDC ( self.my_Container )
          self.my_Container.PrepareDC ( dc )
          self.shape.SetBrush ( self.Color_Off )
          self.my_Container.Redraw ( dc )
# ***********************************************************************

Now I can create an instance: and print it
  global LED
  LED = tLED ( 'A3', wx.CYAN )
  print LED

which give me te correct answer I guess
  <device_LED.tLED instance at 0x01C37198>

now I can also move the shape
      LED.shape.SetX(LED.shape.GetX()+20)
      dc = wx.ClientDC ( LED.my_Container )
      LED.my_Container.PrepareDC ( dc )
      LED.shape.SetBrush ( LED.Color_Off )
      LED.my_Container.Redraw ( dc )

and get the new shape drawn perfectly

Now I want to store the reference into a list, and then when troubles start
  Devices =
  print LED

gives me, so still ok
  <device_LED.tLED instance at 0x01C37198>

Now add it to a list
  Devices.append(LED)
  print LED
  print Devices

gives
  <device_LED.tLED instance at 0x01C37198>
  [<device_LED.tLED instance at 0x01C37198>]

so it still looks perfect
... but when I move the shape now I get an error
    print LED
    LED.shape.SetX(LED.shape.GetX()+20)
TypeError: 'float' object is not callable

The print statement before the position change is still
  <device_LED.tLED instance at 0x01C37198>
so it looks OK.

What does adding the object to a list change ??
any clue would be very much appreciated.

thanks,
Stef Mientki

···

--- Stef Mientki <s.mientki@ru.nl> wrote:

Stef Mientki wrote:

[...]

so it still looks perfect
... but when I move the shape now I get an error
   print LED
   LED.shape.SetX(LED.shape.GetX()+20)
TypeError: 'float' object is not callable

The print statement before the position change is still
<device_LED.tLED instance at 0x01C37198>
so it looks OK.

What does adding the object to a list change ??

Absolutely nothing. The problem is elsewhere. Can you provide a runnable
example? Or at least split that line above which causes the error so that we can
see which object is the 'float' object. I looks like you have overridden SetX or
GetX in your class.

Christian

Christian K wrote:

Stef Mientki wrote:
  [...]
  

so it still looks perfect
... but when I move the shape now I get an error
   print LED
   LED.shape.SetX(LED.shape.GetX()+20)
TypeError: 'float' object is not callable

The print statement before the position change is still
<device_LED.tLED instance at 0x01C37198>
so it looks OK.

What does adding the object to a list change ??
    
Absolutely nothing. The problem is elsewhere. Can you provide a runnable
example? Or at least split that line above which causes the error so that we can
see which object is the 'float' object. I looks like you have overridden SetX or
GetX in your class.
  

thanks very much Cristian,

this is the right hint that triggers the solution:

somewhere there was:
      Devices[i].shape.SetX = ini.read_integer('X',0)

which should be:
      Devices[i].shape.SetX ( ini.read_integer('X',0) )

cheers,
Stef Mientki

Kamer van Koophandel - handelsregister 41055629 / Netherlands Chamber of Commerce - trade register 41055629

Stef Mientki wrote:

I can move the shape by calling SetX and redraw the shape,
but how do I get rid of the shape at the old position ?

The canvas probably just needs to be refreshed.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Stef Mientki wrote:

I can move the shape by calling SetX and redraw the shape,
but how do I get rid of the shape at the old position ?

The canvas probably just needs to be refreshed.

thanks Robin,

that did the trick,
and there seemed to be also a "Move",
so both codes below works equally well.

    dc = wx.ClientDC ( self.my_Container )
    self.shape.Move(dc, newX, newY)
    self.my_Container.diagram.GetCanvas().Refresh()

    self.shape.SetX(newX)
    self.my_Container.diagram.GetCanvas().Refresh()

cheers,
Stef Mientki