OK, I have a Class for a Frame that is basically 24 labels in a stack like an old terminal Screen.

There are two Functions included in the Class: AddLine and Clear (Will add "Exit")

I want to launch an instance of this Class in it's own Thread and Pass Information to it.

I suspect I can do this with PubSub using three Messages: "Clear", "AddLine" and "Exit"

Publisher().sendMessage("Clear", True)
Publisher().sendMessage("AddLine", message_information)
Publisher().sendMessage("Exit", True)


My problem is that the Long Running Process example has things backwards from what I need. The Example has the Worker Thread being the "Sender"

My Worker Thread needs to be the "Subscriber" and my "Main" Script needs to be the "Sender".

Once the Thread is Started and the Frame displayed in the Thread, I want to be able to "Send" 'AddLine' messages to the thread throughout the life of the Main Application and when I am ready to Close the Application "Send" an "Exit" message and shut everything down Gracefully.

This, to me, infers I would be "Listening" for three distinct messages, requiring three separate Publisher event monitors?

Publisher().subscribe(self.Clear, "Clear")
Publisher().subscribe(self.AddLine, "AddLine")
Publisher().subscribe(self.Exit, "Exit")


I suspect that I could also do thid using three events...

Recommended Answers

All 6 Replies

{BUMP} Come on guys... I'm dying here... Hasn't anyone *ever* Created a Visible form inside a Thread and sent data to it from the main app to display?


Yes, I know I am trying to fly before I am walking all that well.

If there was a course I could afford, or a book I could buy that covered *THIS* specific issue I'd gladly pay for it...

Of, course that cost may exceed my allowance... :)

I can not speak of everybody, but for me impression of your design looks overcomplicating simple things by bad design joices. I do not see why you need threads, how long running the processes are. Examples you have shown look simple input forms, but maybe you have long running database operations...

If you have use case motivating your design and making it more understandable for us what you want to accomplish (the big picture is necessary to understand the parts), maybe somebody of us could help.

For me sounds just that you need to send the output to common instance of the display object. Actually I would implement this kind of functionality by using logging (actually you said threading so simple approach should suffice) ]in program and having log viewer program "tailing the output" from the file, if I understood correctly what you are after.

I *really* do apprecciate your taking the time to help!

Well, other than not using a spelling checker. :) I have come to the same conclusion.

Maybe not for the same reason, though...

I have found that I can instantiate three frames at one time, have one active for the duration.

What I did not understand from the beginning is that a Frame cannot be made Modal. But, a Dialog can.

So two of my Frames are going to have to be re-crafted into Dialogs.

I am still running into "referencing issues". But, that'll be another thread.

As to what I am doing...

I am trying to craft a Test Control Program structure for testing various Instruments and devices. UUT's (Unit Under Test)

The overall Control, which is common to all testing, is called the test Control Program, or pyTC.py

Each UUT will have a unique .py program that will include all the functionality required to test it. The Test procedure is started by running that unique .py file.

That's just the way it's been done since before I got here... Besides, if we started the process with pcTC.py then we would have to allow every follow on programmer to modify our reference.

My biggest single problem, I think, right now is being able to reference functionality in the other module.

I am using a Dictionary referenced in my common file TC_Config.py called ptf to pass references to the pyTC.py module of the functions it needs to reference back into.

I could pass them in a parameter list. But, I can create a single entry dictionary then stack the additional entries line by line. While a bit verbose it's easier to see what is included or not included for a newbie.

# Create the Dictionary used to Call Back Up Into Main
ptf={"UUT_Info":UUT_Info}
# Add or Modify Dictionary Entries
ptf["Menu_Info"]=Menu_Info
ptf["Module_Launcher"]=Module_Launcher
ptf["SafeToTurnOn"]=SafeToTurnOn
Test_Control(ptf)

finally, the following code sort'ave works. But, UUT_Info and Main_Menu need to be Modal...

def Test_Control(ptf):
    print "Inside Test Control"
    # Initialize the UUT  and Menu Information
    ptf.get("UUT_Info")()
    ptf.get("Menu_Info")()

    # The False prevent print statement from opening a command window?
    app = wx.App(False)
    wx.InitAllImageHandlers()
    # Create the Logging Screen
    print "Creating Logging Screen"
    LogScrn = Lines_24(None, -1, "")
    LogScrn.AddLine("This is the Initial Log Screen Entry: ")
    LogScrn.Show()

    # TestThread()

    # Create the UUT Information Display
    print "Creating UUT Information Display"
    LogScrn.AddLine("Creating UUT Information Display")
    UUTInfo = InfoUUT(None, -1, "")
    UUTInfo.Man_Name.SetLabel(" " + TC_Config.Man_Name)
    UUTInfo.ModNumber.SetLabel(" " + TC_Config.ModNumber)
    UUTInfo.MilDesig.SetLabel(" " + TC_Config.MilDesig)
    UUTInfo.Nomen.SetLabel(" " + TC_Config.Nomen)
    UUTInfo.PartNo.SetLabel(" " + TC_Config.PartNo)
    UUTInfo.SerNo.SetLabel(" " + TC_Config.SerNo)
    #UUTInfo.MenuName.SetLabel(" " + TC_Config.MenuName)
    #UUTInfo.Rev.SetLabel(" " + TC_Config.Rev)
    UUTInfo.Show()
    
    # Create the Main Menu
    print "Creating the Main Menu"
    LogScrn.AddLine("Creating the Main Menu")
    Main_Menu = Menu_2(None, -1, "")
    Main_Menu.Show()
         
    app.SetTopWindow(UUTInfo)
    app.MainLoop()

the Print and AddLine are currently for debug. But, later I will need to be able to pass Test Module, Sub-Test, Pass/Fail, Upper Limit, Measured Value, and Lower Limit to it from the "unique" UUT .py module.

You could just use

Test_Control(globals())

as the names are defined in the calling context. Looks stupid thing to do though. That is only my opinion though.

Did you study Tkinter documentation? Log window is their example for using text widget: http://www.tkdocs.com/tutorial/text.html

from tkinter import *
from tkinter import ttk

root = Tk()
log = Text(root, state='disabled', width=80, height=24, wrap='none')
log.grid()

def writeToLog(msg):
    numlines = log.index('end - 1 line').split('.')[0]
    log['state'] = 'normal'
    if numlines==24:
        log.delete(1.0, 2.0)
    if log.index('end-1c')!='1.0':
        log.insert('end', '\n')
    log.insert('end', msg)
    log['state'] = 'disabled'

Had not looked at tkinter as, up til now, :) everyone was pinting me towards wxPython...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.