Dear all,
I wrote 2 scripts and at a certain point of the first I would like to run the second, and when the second is done, to go back to the first and continue with it.
How can I do it?
I put at the desired point of the firstscript.py

from secondscript impot *

and it works. The second script is something like

open a wx window
do something according to what the user chooses in a dropdown menu
write the result to a txt file
sys.close()

and in the firstscript.py I have to read from the txt file and go on.
Everything goes fine till the end of secondscript, but at that point it doesn't go on with the first.

I hope I manage to explain it in the proper way.
Thanks,
G.

Recommended Answers

All 4 Replies

You should put the action in function of secondscript and call it after importing it. Import runs the main script once, it has no effect if module is already loaded.

The point is that the second script is a wx window with class and def already defined.

Ok, to make it easier for me, I inserted the second script in the first but again, when it finishes, it stacks and it doesn't continue with what is after.

I will try to copy here a selection of the code to understand better my error

import wx
import shutil,sys,os,subprocess
from PIL import Image
import PIL.PngImagePlugin
import PIL.JpegImagePlugin
import PIL.TiffImagePlugin

if not os.path.exists(temp_folder):
        os.makedirs(temp_folder)

	
application = wx.PySimpleApp()

info0 = wx.MessageDialog(None, 'The script will now drive you through the bla bla bla', '.: Title :.', wx.OK)
info0.ShowModal()
info0.Destroy()

progressMax = 10
dialog1 = wx.ProgressDialog(".: title :.", "Progress...", progressMax,style=wx.PD_AUTO_HIDE|wx.PD_ELAPSED_TIME|wx.PD_APP_MODAL)
keepGoing = True
count = 0

bla bla bla

count = count + 1
keepGoing = dialog1.Update(count, "Progress...(7%)")


# here I copied the content of the second script

class choice ( wx.Frame ):
	
	def __init__( self, parent ):
		wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"Image rotation", pos =wx.DefaultPosition, size = wx.Size( 409,371 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
		
		self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
		self.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_WINDOW ) )
...
...

def OnAccept( self, event ):
		global selected2
		limit=3960
		
		imt2 = Image.open(selected2)
		try:
			original_dpi2=imt2.info["dpi"]
		except KeyError:
			original_dpi2=72,72
		if sel==2:
			do something
		else:
			self.Close(True)

class start(wx.App):
    def OnInit(self):
        self.m_frame = choice(None)
        self.m_frame.Show()
        self.SetTopWindow(self.m_frame)
        return True

app = start(0)
app.MainLoop()


count = count+1
keepGoing = dialog1.Update(count, "Progress...(8%)")

...
...

After I close the window, it doesn't update the dialog1 and it doesn't go on.
Where is the error?

Ok, I found my error.
I gave the same name to the main and the secondary app
app = start(0)
app.MainLoop()

So when I was closing the app, I was killing also the first one. I just rename it to app1
... ...

Thanks anyway for reading ;)

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.