I have a small program that batch handles files. These files use a map file to load certain settings. The map file has a line at the top that specifies for what directory it is for.
Currently I am able to read the line and assign it to the source path variable (sPath). I want to update the TextCtrl for the Source Directory, however it is in the MainFrame class and I load the map file in a different class.
class Process(wx.Panel):
def loadMap(self, event):
MainFrame.sPath = str(mapFile.readline()).strip("\n")
MainFrame.loadSource(MainFrame())
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="DICOM Toolkit", size=(800,705))
self.srcTc = wx.TextCtrl(self.panel, 131, '', size=(600,25), style=wx.TE_READONLY)
def loadSource(self):
self.srcTc.SetValue(MainFrame.sPath)
I eliminated most of the code and what’s above is where it is giving me trouble. How do I change self.srcTc in the MainFrame class from either the Process class or a function in the MainFrame class? I am having trouble actually pointing to self.srcTc without a handler that stems from the MainFrame class.
I think what you want has to look like something like that (without a working example):
when using
MainFrame.sPath = ...you’re not actually changing sPath to a MainFrame you created, but to the class itself, then you create it, inMainFrame()without storing a reference to it (assign it to a variable for example). So, you can’t access it from somewhere other than “inside” the class itself asself.The solution is to create an instance of a
MainFrameand operate on it. Once you create it and assign it to a variable, you can manipulate the.sPathattribute and callloadSource().UPDATE: From you code snippet, it seems you create the
MainFrameinstance in the end of the file:MainFrame().Show(), and then in theloadMapmethod, you create a new one.What you should do is this, in the end of your file:
and in the
loadMapmethod:Now this way, it should work.
The problem was that you are creating another frame, changing its path and updating its text, but you are not showing it. The correction is to store the actual window that is being shown, and update this one.