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

  • SEARCH
  • Home
  • 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 7182981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:53:10+00:00 2026-05-28T17:53:10+00:00

I’m working on a text-based UI widget library, and have decided it’s high time

  • 0

I’m working on a text-based UI widget library, and have decided it’s high time that I provide the ability for a user of my library to encapsulate application-wide configuration via an application object, like so:

class App:

    def __init__(self, screen_size_tuple):
        self.screen_size = screen_size_tuple

    def get_screen_size(self):
        return self.screen_size

class Widget:

    def __init__(self, rows, cols, y, x, foo, bar, app):
        self.rows = rows
        self.original_dimensions = (rows, cols)
        self.original_coords = (y, x)
        #etc, etc
        self.app = app
        self.fullscreen = False     

    def self.toggle_fullscreen(self):
        if self.fullscreen != True:
            self.y = 0
            self.x = 0
            self.rows = self.app.screen_size[0] # y value from the application object
            self.cols = self.app.screen_size[1] # x value from the application object
        else:
            self.y = self.original_coords[0]
            self.x = self.original_coords[1]
            self.rows = self.original_dimensions[0]
            self.cols = self.original-dimensions[1]

My question is two-fold: Firstly, when I employ this tactic, how can I avoid having to pass the instance of the App class to each widget upon creation? Is the best practice to delegate widget creation to the app object itself? Secondly, is there a name for this design pattern when properly employed? It seems like a bit like an observer or dependency injection, but I’m not certain those patterns apply here.

Thanks in advance =)

  • 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-28T17:53:10+00:00Added an answer on May 28, 2026 at 5:53 pm

    If you want “application-wide but not global” configuration there are a few common patterns:

    1. Use your app object to create the widget objects, e.g. app.create(WidgetClass)
    2. Pass down the app through your widget hierarchy, like so:

    a = App()
    
    f = FrameWidget()
    a.add(f) # sets FrameWidget's config to a's config
    
    b = ButtonWidget()
    f.add(b) # sets ButtonWidget's config to f's config, which happens to be a's
    
    c = CheckboxWidget()
    f.add(c) # sets CheckboxWidget's config to f's config, also a's
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.