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

  • Home
  • SEARCH
  • 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 7000075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:37:27+00:00 2026-05-27T20:37:27+00:00

The sampled code below is for the GUI I am currently making. I have

  • 0

The sampled code below is for the GUI I am currently making. I have two problems. The first problem is when I redirect the python output using the RedirectText class, the output is printed on the TextCtrl box (‘tc2’) only when the loop is finished, for that particular iteration. How do I get the text to print as it goes through the loop and not when its finished?

My second problem is i’m using a compiled fortran file EHSS_updated_atoms.out the output from this file prints to the terminal and not to the text control box. How do I get the the output from the compiled fortran file to the text control box? as it is printed to the terminal.

import wx
class RedirectText(object):
    def __init__(self,aWxTextCtrl):
        self.out=aWxTextCtrl

    def write(self,string):
        self.out.WriteText(string)



def __init__(self, *args, **kwargs):
    super(Example, self).__init__(*args, **kwargs) 

    self.InitUI()
    self.Centre()
    self.Show() 
    self.SetSize((800, 600))
    self.SetTitle('Hello')

def InitUI(self):
    import sys

    vbox = wx.BoxSizer(wx.VERTICAL)
    hbox5 = wx.BoxSizer(wx.HORIZONTAL)
    btn1 = wx.Button(panel, label='Run prog')
    hbox5.Add(btn1)
    btn2 = wx.Button(panel, label='Stop prog')
    hbox5.Add(btn2, flag=wx.LEFT|wx.BOTTOM, border=5)
    vbox.Add(hbox5, flag=wx.ALIGN_CENTER|wx.RIGHT, border=10)
    self.Bind(wx.EVT_BUTTON, self.prog, btn1)
    #self.Bind(wx.EVT_BUTTON, self.cancel_prog, btn2)


    hbox3 = wx.BoxSizer(wx.HORIZONTAL)
    tc2 = wx.TextCtrl(panel, style=(wx.TE_MULTILINE|wx.TE_READONLY))
    hbox3.Add(tc2, proportion=1, flag=wx.EXPAND)
    vbox.Add(hbox3, proportion=1, flag=wx.LEFT|wx.RIGHT|wx.EXPAND,border=10)
    redir=RedirectText(tc2)
    sys.stdout=redir
    sys.stderr=redir


    panel.SetSizer(vbox)

def prog(self, evt):
    import os
    import shutil
    import subprocess
    from mobcal_prep import mobcal

    extension = '.pdb'
    list_of_files = [file for file in os.listdir('%s' % _selectedDir) if file.lower().endswith(extension)]

    prep = mobcal()

    for pdb in list_of_files:
        print '### Running PDB: %s ###' % pdb
        prep.new_mobcal_format(pdb)
        subprocess.call(['./EHSS_updated_atoms.out', pdb[:-4]+'_new_mobcal.mfj',pdb[:-4]+'_new_mobcal.out'])
        prep.caluclate_average('%s_new_mobcal.out' % pdb[:-4], pdb)
        subprocess.call(['rm', pdb[:-4]+'_new_mobcal.out'])
  • 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-27T20:37:28+00:00Added an answer on May 27, 2026 at 8:37 pm

    When dealing with graphical interfaces, have into account that the program is basically running into a loop (the “main loop”), which among other things triggers events, etc. That’s the main thread of the program. If you do anything inside that thread (like calling EHSS_updated_atoms.out) that blocks the main loop for a while, there will be no changes on your interface until that is finished.

    You can make this work by, for example, running the prog function in a separate thread. Check this forum post for a small example piece of code on how to do it. Note the hint to use wx.Yield() or wx.SafeYield() to make the interface more responsive.

    Edit: forgot about the redirection.

    You don’t need to redirect the whole sys.stdout and sys.stderr. subprocess.call admits two arguments just for that, so if you pass redir to the prog function, you can do:

    call(.........., stdout = redir, stderr = redir)

    Edit:

    For the redirection, try this instead:

    p subprocess.Popen(['./EHSS_updated_atoms.out', pdb[:-4]+'_new_mobcal.mfj',pdb[:-4]+'_new_mobcal.out'],
                       stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    for line in p.stdout:
        redir.write(line)
    p.wait()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with DBMS_DATA_MINING.CREATE_MODEL on version 11.2. On 10g this code below
I have this sample code ( below ), example1() method works with no problem,
I have no problem to run the sample code below in a iPhone simulator,
Below, I have written simple code that re-creates problems that have emerged as my
I have a plot (sample code pasted below) that I am trying to add
I've put together a small code-sample below (Currently in C# 3.5 but would also
I have this snippet from apple sample code LazyTableImages . In the code below
I want to add a value to a checkboxlist using javascript /jquery.The code below
I am trying to create a CSV file using the C# code below: string
I have simple problem as I am not much familiar with Java GUI. I

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.