import wx
import os
import sys
import wx.lib.plot as plot
import datetime
import urllib
import threading
pathstr = '/media/meant2b/My Passport/C Drive/Convert/GFSMaps/'
class Frame(wx.Frame):
def __init__(self, parent, id, title):
style = wx.DEFAULT_FRAME_STYLE ^ (wx.RESIZE_BORDER)
wx.Frame.__init__(self, parent, id, title=title, size = (1024, 768), style=style)
self.Center()
self.panel = wx.Panel(self)
self.panel.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
self.panel.SetFocus()
self.panel.SetBackgroundColour('White')
self.bitmap = None
self.PhotoMaxSize_1 = (881)
self.CreateMenuBar()
self.model = 0
self.map = 0
self.dMinus = 0
self.Model = ['00', '06', '12', '18']
self.MDay = ['000','003','006','009','012','015','018','021','024','027','030','033','036','039','042','045','048','051','054','057','060','063','066','069','072','075','078','081','084','087','090','093','096','099','102','105','108','111','114','117','120','123','126','129','132','135','138','141','144','147','150','153','156','159','162','165','168','171','174','177','180','183','186','189','192','204','216','228','240','252','264','276','288','300','312','324','336','348','360','372','384']
self.MapType = 0
def gif1(self, event):
pathstr = '/'
for self.dMinus in range(4, -1, -1):
self.MoveCalendar() #sets date
for Counter1 in range(0, 4):
for Counter2 in range(0, 81):
if os.path.isfile(pathstr + self.strDate + self.Model[Counter1] + self.MDay[Counter2] + '.gif') == True:
continue
url = 'http://mag.ncep.noaa.gov/GemPakTier/MagGemPakImages/gfs/' + self.strDate + '/' + self.Model[Counter1] + '/gfs_namer_' + self.MDay[Counter2] + '_1000_500_thick.gif'
urllib.urlretrieve(url,str(pathstr + self.strDate + self.Model[Counter1] + self.MDay[Counter2] + '.gif'))
statinfo = os.stat(str(pathstr + self.strDate + self.Model[Counter1] + self.MDay[Counter2] + '.gif'))
if statinfo.st_size<21000L:
os.remove(str(pathstr + self.strDate + self.Model[Counter1] + self.MDay[Counter2] + '.gif'))
counter2 = 80
for Counter1 in range (3, -1, -1):
url = 'http://mag.ncep.noaa.gov/GemPakTier/MagGemPakImages/gfs/' + self.Model[Counter1] + '/gfs_namer_384_850_temp_mslp_precip.gif'
urllib.urlretrieve(url,pathstr + '850Temp384.gif')
statinfo = os.stat(pathstr + '850Temp384.gif')
if statinfo.st_size<21000:
os.remove(pathstr + '850Temp384.gif')
continue
else:
for Counter2 in range(0, 81):
url = 'http://mag.ncep.noaa.gov/GemPakTier/MagGemPakImages/gfs/' + self.Model[Counter1] + '/gfs_namer_' + self.MDay[Counter2] + '_850_temp_mslp_precip.gif'
urllib.urlretrieve(url,pathstr + '850Temp' + self.MDay[Counter2] + '.gif')
statinfo = os.stat(pathstr + '850Temp' + self.MDay[Counter2] + '.gif')
if statinfo.st_size<21000:
os.remove(pathstr + '850Temp' + self.MDay[Counter2] + '.gif')
print('SHOW ME')
self.VGFS(event)
def gif2(self, event):
url = 'http://www.cpc.ncep.noaa.gov/products/precip/CWlink/daily_ao_index/ao.sprd2.gif'
urllib.urlretrieve(url,pathstr + '/AO.gif')
url = 'http://www.cpc.ncep.noaa.gov/products/precip/CWlink/pna/nao.sprd2.gif'
urllib.urlretrieve(url,pathstr + '/NAO.gif')
url = 'http://www.cpc.ncep.noaa.gov/products/precip/CWlink/pna/pna.sprd2.gif'
urllib.urlretrieve(url,pathstr + '/PNA.gif')
url = 'http://www.esrl.noaa.gov/psd/enso/mei/ts.gif'
urllib.urlretrieve(url,pathstr + '/MEI.gif')
'''
And numerous more gifs/pngs as well
'''
def All(self, event):
dl0 = threading.Thread(target = self.GFS(event))
print('MESHOW')
dl0.start()
dl1 = threading.Thread(target = self.Oscillators(event))
print('MEGO')
dl1.start()
class App(wx.App):
def OnInit(self):
self.frame = Frame(parent = None, id =-1)
self.frame.Show()
self.SetTopWindow(self.frame)
return True
if __name__=='__main__':
app = App()
app.MainLoop()
I'm skipping tons of code. When I run the above in wxpython it runs fine EXCEPT, it runs the code sequentially not all at the same time. Each thread is downloading numerous gif & png files...enough that I want to split up the action to save some time. It's making the call to each 'thread' but it's waiting for dl0 to finish before it runs dl1. I can tell by looking at the directory where the files are being stored. How do I change this around to get it so it will call both threads 'at the same time?'
I will add this in as well as I don't know if this might be something different in threading in wxpython vs. tkinter. In tkinter to get this to work I never had to add in Thread.init(self)(this won't let me do the __ for some reason) like I see being done in wxpython coding I've seen.
Pretty much I'm just trying to take two separate running correctly programs and combine them together into one right now. I am changing from tkinter to wxpython as well.