473,706 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_de fining_dimensio n = self._width self._height *
self.ratio
make_log( ' _height_definin g_dimension =' + str(
self._height_de fining_dimensio n ) )
if self._height_de fining_dimensio n:
self._max_linea r_size = self._height
# This, and the corresponding line in the else clause is what is
causing trouble.
# self.linear_siz e is, as far as I can tell, the property I define last
in the class
# If I replace it with _set_linear_siz e, which it is supposed to call,
everything works
self.linear_siz e = self._height
#
else:
self._max_linea r_size = self._width
self.linear_siz e = self._width
self.center_box ( self._width / 2, self._height / 2 )
# Lots of methods snipped
def _set_linear_siz e( self, value ):
if value >= self._min_linea r_size:
if value <= self._max_linea r_size:
self._linear_si ze = value
else:
self._linear_si ze = self._max_linea r_size
else:
self._linear_si ze = self._min_linea r_size
self._scale_box ()
# Some more snippage
# The property that is causing grief
linear_size = property( _get_linear_siz e, _set_linear_siz e )
rectangle = property( _get_rectangle )
centre = property( _get_centre, _set_centre )
By adding some logging I found out that _set_linear_siz e never is
called, so the rectangle remains the default size forever.

/Oldarick

Oct 23 '06 #1
3 996
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_siz e, _set_linear_siz e )

By adding some logging I found out that _set_linear_siz e 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******@hotma il.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
1847
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 add only new records and not all the records. As an example, this query filters a list of property owners for duplicates and then appends to a table where they are assigned autonumer IDs. The problem is that I'm constantly entering new owners in and...
3
1751
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 runtime. Any assistance would be greatly appreciated. The code is as follows: In the class I declared the private variable strDatabasePath public partial class UserControl1 : UserControl { //... other code private string strDatabasePath;
4
11568
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 the image and some display as an icon with the file name below. The process I'm following is as follows; Right click Choose "Insert Object..." Select "Create from File"
4
1837
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" %> In another custom web user control, I use this web control: <%@ Register Src="~/Controls/EditUserBox.ascx" TagName="Eub" TagPrefix="mb"
0
8781
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8697
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9156
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9055
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7911
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5939
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4453
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4709
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.