Python Forum
Should I be able to do this?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Should I be able to do this?
#1
I think I already know the answer to my question, but wanted a different perspective so
that I can verify that I should not do what I'd love to be able to do.

I have a widget that is part of a widget constructor class
       self.showdata = ShowData()
       ...
       self.search = wx.SearchCtrl(self.leftpanel, id=wx.ID_ANY)
       self.Bind(wx.EVT_TEXT, showdata.OnKeyDown, self.search)
and in class ShowData:
   def OnKeyDown(self):
       ...
Is this OK?
I have a very guilty feeling like I am breaking some sort of cardinal rule.
Reply
#2
I think ShowData() might be doing too much work here.

Let's see if I've got it:
You've got two widgets, a search box, and some sort of container which shows search results.
You've got two classes, one which handles the search box's events, and another which displays content into the search results box.
And you've got ShowData() watching events on the search box, so it can populate the results.

I think whatever it is that's handling the search box, should handle the search box and all of it's events. Then it can poke the secondary class every now and then to tell it to refresh the search results.
Reply
#3
There are a lot more widgets, all defined in a MainFrame class. splitter methods panels ListCtrl, text, and buttons

There is a class which fetches data from an external module (which scrapes a web page) called by ShowData

The widget class is dumb and knows nothing about the data class, however the search widget is defined there,

When a there is an item ready in the search widget, I need to search the data which is contained in the ShowData class

So, I am trying to bind the event of an item being entered into the search widget to the method in ShowData class,
where the search actually takes place.

I can post the entire project, but it's too much code, and I haven't put it in github yet
Reply
#4
Ok I was very tired when I put this post together last night and couldn't see the solution.

This morning, I solved it by creating a class which separates the data from both the GUI, and the display (or Show) classes.
now both the classes can have access to the data.
the search event can operate entirely within the gui class and still
be re-displayed by the Show class.

All is well.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020