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 930453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:20:12+00:00 2026-05-15T20:20:12+00:00

Im trying to refactor my application (with 1000+ lines of GUI code) to an

  • 0

Im trying to refactor my application (with 1000+ lines of GUI code) to an MVC style pattern.
The logic code is already seperate from the GUI so that is not a problem. My concern is seperation of the view from the controller. I understand the basic principal of MVC and this tutorial in the wxpython wiki has been very helpfull but the code example is a little simplistic and leaves me with doubts when I try to apply the principal to my own project which is quite a bit more complex.

A snippet of the structure..

I have a MainWindow with a number of widgets including a noteBook (tabbed section),
the noteBook has a number of tabs one of the tabs (which I call FilterTab)holds two instances of a
class (that I call a FilterPanel)that is a panel with a listbox, three buttons, one to clear, one to remove and one to add items to/from the list. Depending on flags passed to the
class on instantiation the add buttons event can create different types of dialogs, eg a text entry dialog or directoryPicker etc..

Thats just one part of the GUI which is quite layered -with event handlers buried in the FilterPanel class.

If I were to convert that part to MVC I would have to bind the button events for each instance of the FilterPanel in my controller(instead of in the filterPanel class) -in this case there are two (filterPanel instances)

So I would have something like this for each button, (3 buttons per filterPanel * number of panel instances) plus the handlers..

 self.mainWindow.filterTab.dirFilterPnl.Bind(wx.EVT_BUTTON,
                                    self.onAdd_dirFilterPnl, 
                            self.mainWindow.filterTab.dirFilterPnl.addBtn,
                            self.mainWindow.filterTab.dirFilterPnl.addBtn.GetId()
                                    )

Which adds alot of extra code, (double the amount of event handlers if I have only two filterPanel instances)

So Id like to know am I taking the right approach?

  • 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-15T20:20:13+00:00Added an answer on May 15, 2026 at 8:20 pm

    If I were to convert that part to MVC
    I would have to bind the button events
    for each instance of the FilterPanel
    in my controller(instead of in the
    filterPanel class)

    Not necessarily! MVC’s philosophy and practice do not imply that “views” are elementary widgets; your FilterPanel could well be thought of / implemented as a “rich/composite” widget which generate its own, higher-level “events” (directed to the controller) and update appropriately. So, that composite widget can have handlers for lower-level “events” and synthetize higher-level events from them, sending them on to the controller; the controller does not have to know or care about every button etc, just about the higher-abstraction events it receives, such as “the user wants to pick a directory for purpose X” or “the user wants to enter text for purpose Y” — and respond to them by telling the view what to do.

    The key point is that the view takes no “semantic” decisions based on the events it handles, nor does it ever send any command to the model — the controller is the indispensable “middleman” for all such interactions.

    For an analogy, consider that the lowest layer of the GUI has very low level events such as “left mouse button down” and “left mouse button up” — a “pushbutton widget” reacts directly to them by changing the button’s appearance (a “visual” decision, not a “strategic” one) and eventually, if and when appropriate, synthesizing a higher-abstraction event such as “pushbutton was clicked” (when a mouse button down is followed by a mouse button up without intermediate mouse movements invalidating the “clicking” hypothesis, for example). The latter is then directed to whatever higher layer needs to “respond” to button clicks.

    Similarly, your rich/composite widgets can take such events and synthesize higher-abstraction ones for the controller to react to. (The same abstract event could be generated by a pushbutton click, a menu selection, certain keystrokes… the controller doesn’t care about these lower-layer “visual” considerations, that’s the view’s/widget’s job, and the view/widget does not hardcode “strategic” decisions and actions to such user interactions, that’s the controller’s job).

    The separation of concerns helps with such issues as testing and application flexibility; it’s not unheard of, for such advantages to be bought at the price of having some more code wrt an alternative where everything’s hardcoded… but if you choose MVC you imply that the price, for you, is well worth paying.

    wx may not be the ideal framework to implement this, but you can subclass wx.Event — or you could use a separate event system like pydispatcher for the higher-abstraction events that flow between separate subsystems, in order to decouple the controller from the specific choice of GUI framework. I normally use Qt, whose signals/slots model, IMNSHO, extends/scales better than typical GUI frameworks’ event systems. But, this is a different choice and a different issue.

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

Sidebar

Related Questions

I have an unnormalized events-diary CSV from a client that I'm trying to load
I'm trying to refactor some python code and I'm stuck with an import error
Trying to learn ASP MVC coming from Linux/LAMP background (in other words I'm a
Good Morning All, I'm trying to refactor an SQL stored procedure. I'm no SQL
Trying to learn Regex in Python to find words that have consecutive vowel-consonant or
Trying to use this following script to load a page so that I can
I've been attempting to refactor a fairly simple three or four page site to
All, I am fairly new to XCode and am trying to get a handle
I'm dealing with a design problem that I'm sure has a simple answer and/or
I've always thought of code refactoring as only improving implementation details. I want to

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.