473,378 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Trouble with property

I'm having some trouble with using property. This class is supposed to
represent a rectangle that can never be outside an area.

I'll snip the parts I don't think are relevant. Or should I? I dunno.

class ConstrainedBox:
def __init__( self, size, ratio ):
# Various instance variables initialized
self.reset( size )

def reset( self, size ):
self._width, self._height = size
self._height_defining_dimension = self._width self._height *
self.ratio
make_log( ' _height_defining_dimension =' + str(
self._height_defining_dimension ) )
if self._height_defining_dimension:
self._max_linear_size = self._height
# This, and the corresponding line in the else clause is what is
causing trouble.
# self.linear_size is, as far as I can tell, the property I define last
in the class
# If I replace it with _set_linear_size, which it is supposed to call,
everything works
self.linear_size = self._height
#
else:
self._max_linear_size = self._width
self.linear_size = self._width
self.center_box( self._width / 2, self._height / 2 )
# Lots of methods snipped
def _set_linear_size( self, value ):
if value >= self._min_linear_size:
if value <= self._max_linear_size:
self._linear_size = value
else:
self._linear_size = self._max_linear_size
else:
self._linear_size = self._min_linear_size
self._scale_box()
# Some more snippage
# The property that is causing grief
linear_size = property( _get_linear_size, _set_linear_size )
rectangle = property( _get_rectangle )
centre = property( _get_centre, _set_centre )
By adding some logging I found out that _set_linear_size never is
called, so the rectangle remains the default size forever.

/Oldarick

Oct 23 '06 #1
3 981
At Monday 23/10/2006 20:28, Odalrick wrote:
>I'm having some trouble with using property. This class is supposed to
represent a rectangle that can never be outside an area.

class ConstrainedBox:
# The property that is causing grief
linear_size = property( _get_linear_size, _set_linear_size )

By adding some logging I found out that _set_linear_size never is
called, so the rectangle remains the default size forever.
You must use a new-style class for properties to work. That is: class
ConstrainedBox(object):

--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ˇgratis!
ˇAbrí tu cuenta ya! - http://correo.yahoo.com.ar
Oct 24 '06 #2

Gabriel Genellina skrev:
You must use a new-style class for properties to work. That is: class
ConstrainedBox(object):

--
Gabriel Genellina
Softlab SRL
Thank you, I've seen it mentioned, but never knew what it meant.

/Odalrick

Oct 24 '06 #3
"Odalrick" <od******@hotmail.comwrites:
Gabriel Genellina skrev:
You must use a new-style class for properties to work. That is:
class ConstrainedBox(object):

Thank you, I've seen it mentioned, but never knew what it meant.
More generally, a "new-style class" is important in this instance
because it inherits, directly or indirectly, from a built-in type,
becoming part of the main class hierarchy.

There are very few reasons to use old-style classes these days (and I
don't know what those reasons are anymore). Avoid them unless you know
you want them for some specific reason.

--
\ "I got some new underwear the other day. Well, new to me." -- |
`\ Emo Philips |
_o__) |
Ben Finney

Oct 24 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: harry12 | last post by:
Hello- I'm fairly new at using Microsoft Access and I'm having trouble getting a couple of things to work in my database. The first is that I have yet to find a way to get an append query to...
3
by: dave | last post by:
I am having trouble accessing a property set during run-time in a user control that I have built. The control is supposed to connect to a database using the path supplied by the developer at...
4
by: Rico | last post by:
Hello, I have an MDE application where I use a bound object frame to display an image. This frame is updatable and bested on the contents of an OLE field. My problem is, some images display as...
4
by: Jeff | last post by:
hi asp.net 2.0 I have created a custom web control, here is it's header: <%@ Control Language="C#" AutoEventWireup="true" CodeFile="EditUserBox.ascx.cs" Inherits="Controls_EditUserBox" %> ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.