Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 368245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:48:19+00:00 2026-05-12T13:48:19+00:00

I am writing an application which is used for drawing widgets/menus/controls etc to create

  • 0

I am writing an application which is used for drawing widgets/menus/controls etc to create application mockups. Each screen is represented as collection of widgets, and each widget is simple class e.g.

class Model(object):
    def __init__(self):
        self.widgets = []

class Widget(object):
    def __init__(self):
        self.x, self.y = 0, 0
        self.w, self.h = 100,20
        self.text = "Widget"

Now user can edit x,y,w,h in editor and it is rendered in many views(places), rendering itself may change w and h because we want to at least show best fit.
e.g. text “Widget” may need width 200 or 205 in different views

Question:

So problem is rendering/view itself modifes the model, how to avoid that? For now I have main view and main model, any other view if wants to render copies model and renders it hence avoiding the change in main model.

This approach is simple and code remains simple but needs a unnecessary copy of model, I have thought of many ways to avoid that but all will complicate code and may not be that efficient because anyway if model is not copied render-time-attributes needs to be placed somewhere e.g. in each renderer for each widget.

I am implementing it in python but that is not relevant for the answer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T13:48:20+00:00Added an answer on May 12, 2026 at 1:48 pm

    If the only thing that rendering changes in the model is the x,y,w,h, then you have a few options:

    1. Duplicate those fields: x,y,w,h and x_drawn, y_drawn, etc. Rendering can change the _drawn values, and make your models not mind that they have changed. For example, when saving a model, don’t save the _drawn values. Then the models can change during rendering, but it won’t matter.

    2. Move x,y,w,h into a RenderedGeometry class, and give each model an instance. Now you can still copy the model, but it can be a shallow copy, plus a new copy of the RenderedGeometry class, reducing the amount you have to copy.

    3. Duplicate the fields into a x_original, y_original set of fields. Before rendering, copy x,y into the _original fields. After rendering, copy them back. The model instances themselves don’t have to be copied, just a small amount of data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an application in which I got to lock the computer screen
I'm writing an application which reads large arrays of floats and performs some simple
I am writing an application which blocks on input from two istreams . Reading
I'm writing an application which has to be configurable to connect to Oracle, SQL
I am in the process of writing an application which, among other functionality, generates
I'm writing a C# application which downloads a compressed database backup via FTP. The
I am writing a console application which makes use of the F1 key (for
Greetings, I'm in the middle of writing a Flash application which has multilingual support.
I'm writing an application in Delphi which uses an SQLite3 database. I'd like to
I'm writing a Windows Forms application which is supposed to play three sound files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.