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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:07:04+00:00 2026-05-24T16:07:04+00:00

I’m working on a program that is going to be used with a Time

  • 0

I’m working on a program that is going to be used with a Time Motion study. There are times that the user may have to create add new objects (Observer, Subject, Clinic). In order to accomplish this I have employed the use of a modal dialog box, (since all data is associated to a subject, observer, and clinic).

I have created a general class for the dialog boxes, and then just create an instance of this class for each dialog box. However, when the user creates a new entry with one class, and then the other, the previous classes input is created again, thus causing a duplicate in data.

I’m not exactly sure what’s going on and looking for some help:

Here’s my general dialog box class:

class NewDataDialog(wx.Dialog):
def __init__(self, parent, id, title, databoxes, pubsubmessage):
    wx.Dialog.__init__(self,parent,id, title)

    self.databoxes = databoxes
    self.pubsubmessage = pubsubmessage
    # MainSizer Creation
    self.MainSizer = wx.BoxSizer(wx.VERTICAL)

    # Top Label Creation and addition to Main Sizer
    self.TopLbl = wx.StaticText(self, -1, "Create a " + title)
    self.TopLbl.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
    self.MainSizer.Add(self.TopLbl, 0, wx.ALL|wx.ALIGN_CENTER, 5)

    self.SubSizer = wx.BoxSizer(wx.HORIZONTAL)

    # Labels
    self.LblSizer = wx.BoxSizer(wx.VERTICAL)

    for lbl in databoxes:
        self.lbl = wx.StaticText(self, -1, lbl+":")
        self.LblSizer.Add(self.lbl, 0, wx.ALL|wx.ALIGN_LEFT, 5)


    self.SubSizer.Add(self.LblSizer, 0, wx.ALL|wx.ALIGN_LEFT, 5)

    # Boxes
    self.InputSizer = wx.BoxSizer(wx.VERTICAL)

    for lbl in databoxes:
        self.box = wx.TextCtrl(self, -1, style=wx.ALIGN_LEFT)
        self.InputSizer.Add(self.box, 0, wx.ALL, 1)

    self.SubSizer.Add(self.InputSizer, 0, wx.ALL|wx.ALIGN_LEFT, 5)
    self.MainSizer.Add(self.SubSizer, 0, wx.ALL|wx.ALIGN_CENTER, 5)

    # Save and Cancel Buttons
    self.buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
    self.saveButton = SaveButton(self, 'Save')
    self.cancelButton = CancelButton(self, 'Cancel')
    self.buttonSizer.Add(self.saveButton, 0, wx.ALL|wx.ALIGN_CENTER, 5)
    self.buttonSizer.Add(self.cancelButton, 0, wx.ALL|wx.ALIGN_CENTER, 5)

    self.MainSizer.Add(self.buttonSizer, 0, wx.ALL|wx.ALIGN_CENTER, 5)
    self.SetSizerAndFit(self.MainSizer)

    pub.subscribe(self.cancelbutton, "mainpanel.CancelButton")
    pub.subscribe(self.savebutton, "mainpanel.SaveButton")

def cancelbutton(self, message):

    self.Close()


def savebutton(self, message):

    results = []

    for lbl in self.databoxes:
        results.append(self.box.GetValue())

    pub.sendMessage(self.pubsubmessage, results)
    self.Close()

class CancelButton(wx.Panel):
    def __init__(self, parent, title):

        wx.Panel.__init__(self, parent)

        self.dialogbutton = wx.Button(self, -1, title)

        self.Bind(wx.EVT_BUTTON, self.OnButtonActivate, self.dialogbutton)


    def OnButtonActivate(self, event):

        pub.sendMessage("mainpanel.CancelButton", "")


class SaveButton(CancelButton):

    def OnButtonActivate(self, event):

        pub.sendMessage("mainpanel.SaveButton", "")

And here’s the creation of each instance of the dialog box:

def newsubject(self, message):

    titles = ["Full Name", "Initials", "Job Title"]
    self.newsubject = NewDataDialog(self, 0, 'New Subject', titles, "MainPanel.NewSubjectDialog.Save")
    self.newsubject.ShowModal()

def newobserver(self, message):

    titles = ["Full Name", "Initials"]
    self.newobserver = NewDataDialog(self, 1, 'New Observer', titles, "MainPanel.NewObserverDialog.Save")
    self.newobserver.ShowModal()

def newclinic(self, message):

    titles = ["Clinic Name","Location","Initials"]
    self.newclinic = NewDataDialog(self, 2, 'New Clinic', titles, "MainPanel.NewClinicDialog.Save")
    self.newclinic.ShowModal()

Where each of these are called if the user selects a button labeled for the action that they desire. I.e. “Create a New Observer” will run the function newobserver

For a full view of the code you can look here. Note: Not all comments are correctly annotated, and there are other files as a part of this and so therefore won’t run, but will hopefully give you a little more insight to what’s going on

  • 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-24T16:07:05+00:00Added an answer on May 24, 2026 at 4:07 pm

    You are storing references to the NewDataDialog instances in self.newsubject, self.newobserver and self.newclinic. This means the objects continue to exist, and to listen for "mainpanel.SaveButton" events, even after the newsubject, newobserver, and newclinic methods exit. Once you’ve opened one of each kind of dialog box, there will always be three such objects hanging around, and each "mainpanel.SaveButton" event will cause all three to try and save their data.

    If you did not store these references, then the objects would apparently be garbage collected, and the subscriptions automatically removed. If you do need to store the references, then you should arrange for an unsubscribe to happen after the ShowModal().

    def cancelbutton(self, message):
    
        pub.unsubscribe(self.savebutton, "mainpanel.SaveButton")
        pub.unsubscribe(self.cancelbutton, "mainpanel.CancelButton")
        self.Close()
    
    
    def savebutton(self, message):
    
        results = []
    
        for lbl in self.databoxes:
            results.append(self.box.GetValue())
    
        pub.sendMessage(self.pubsubmessage, results)
        pub.unsubscribe(self.savebutton, "mainpanel.SaveButton")
        pub.unsubscribe(self.cancelbutton, "mainpanel.CancelButton")
        self.Close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

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'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
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
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't

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.