# Path: plasticity/run_sim.py
# def Plot(sim):
#     gray=pylab.cm.gray
#     pylab.ion()
#     
#     try:
#         if not sim['params']['display']:
#             return
#     except TypeError:  # sent a string
#         sim=zpickle.load(sim)
# 
#         
#     try:
#         if sim['params']['display_module']:
#             pass
#     except:
#         sim['params']['display_module']=False
#         
#     if sim['params']['display_module']:
#         try:
#             module=__import__(sim['params']['display_module'],fromlist=['UserPlot'])
#         except ImportError:
#             sim['params']['display']=False
#             print("Error","Error in Import: %s.  Turning display off.  %s" % (
#                                 sim['params']['display_module'],
#                                 sys.exc_info()))
#             return
#         
#         try:
#             module.UserPlot(None,sim)
#             pylab.draw()
#             return
#         except ValueError:
#             sim['params']['display']=False
#             print("Error in display.  Turning display off")
#             return
#     
#     try:
#     
#         im=weights2image(sim['params'],sim['weights'])
#         ax=pylab.subplot(221)
#         pylab.pcolor(im,cmap=gray)
#         ax.set_axis_bgcolor('k')
#         pylab.axis('equal')
#         
#         num_moments=sim['moments_mat'].shape[0]
# 
#         
#         ax=pylab.subplot(222)
#         ax.hold(False)
#         if num_moments==1:
#             num_neurons=sim['moments_mat'].shape[1]
#             for k in range(num_neurons):
#                 pylab.plot(sim['t_mat'],sim['moments_mat'][0,k,:],'-o')
#                 ax.hold(True)
#         elif num_moments==2:
#             num_neurons=sim['moments_mat'].shape[1]
#             for k in range(num_neurons):
#                 pylab.plot(sim['t_mat'],sim['moments_mat'][0,k,:],'b-o')
#                 ax2=pylab.twinx(ax)
#                 pylab.plot(sim['t_mat'],sim['moments_mat'][1,k,:],'g-o')
#                 ax2.yaxis.tick_right()
# 
#         else:
#             num_neurons=sim['moments_mat'].shape[1]
#             for k in range(num_neurons):
#                 for i in range(num_moments):
#                     pylab.plot(sim['t_mat'],sim['moments_mat'][i,k,:],'-o')
#                     ax.hold(True)
#         
#         
#     
#         pylab.subplot(223)
#         pylab.hold(False)
#         response_mat=sim['response_mat']
#         response_var_list=sim['response_var_list']
#         
#         
#         styles=['b-','g-','r-','k-']
#         ls=len(styles)
#         for i,r in enumerate(response_var_list[-1]):
#             x=r[1]
#             y=r[2]
#         
#             pylab.plot(x,y,styles[i % ls]+"o")
#             pylab.hold(True)
#     
#         pylab.subplot(224)
#         pylab.hold(False)
#         for i,r in enumerate(response_mat):
#             pylab.plot(r,styles[i % ls])
#             pylab.hold(True)
#     
#     
#         pylab.draw()
# 
# 
#     except ValueError:
#         sim['params']['display']=False
#         print("Error in display.  Turning display off")
#         return


from .dialogs.waxy import *
from .run_sim import Plot
import os,sys
import glob
    
    
    def WatchForEnter(self,event):
        
        event.Skip()
        if event.GetKeyCode()==13:  # enter
            self.UpdateWildcard()
        
    def UpdateWildcard(self,event=None):
        wildcard=self.textbox.Value
        
        if '*' not in wildcard:
            wildcard+='*'
        
        files=glob.glob(wildcard)
        
        self.listbox.Fill(files)
        
        
    def Click(self,event):
    
        
        file=event.GetString()
        
        if file:
            
            self.SetCursor('arrowwait')
            self.UpdateWindowUI()
            self.Refresh()
            

# Path: plasticity/run_sim.py
# def Plot(sim):
#     gray=pylab.cm.gray
#     pylab.ion()
#     
#     try:
#         if not sim['params']['display']:
#             return
#     except TypeError:  # sent a string
#         sim=zpickle.load(sim)
# 
#         
#     try:
#         if sim['params']['display_module']:
#             pass
#     except:
#         sim['params']['display_module']=False
#         
#     if sim['params']['display_module']:
#         try:
#             module=__import__(sim['params']['display_module'],fromlist=['UserPlot'])
#         except ImportError:
#             sim['params']['display']=False
#             print("Error","Error in Import: %s.  Turning display off.  %s" % (
#                                 sim['params']['display_module'],
#                                 sys.exc_info()))
#             return
#         
#         try:
#             module.UserPlot(None,sim)
#             pylab.draw()
#             return
#         except ValueError:
#             sim['params']['display']=False
#             print("Error in display.  Turning display off")
#             return
#     
#     try:
#     
#         im=weights2image(sim['params'],sim['weights'])
#         ax=pylab.subplot(221)
#         pylab.pcolor(im,cmap=gray)
#         ax.set_axis_bgcolor('k')
#         pylab.axis('equal')
#         
#         num_moments=sim['moments_mat'].shape[0]
# 
#         
#         ax=pylab.subplot(222)
#         ax.hold(False)
#         if num_moments==1:
#             num_neurons=sim['moments_mat'].shape[1]
#             for k in range(num_neurons):
#                 pylab.plot(sim['t_mat'],sim['moments_mat'][0,k,:],'-o')
#                 ax.hold(True)
#         elif num_moments==2:
#             num_neurons=sim['moments_mat'].shape[1]
#             for k in range(num_neurons):
#                 pylab.plot(sim['t_mat'],sim['moments_mat'][0,k,:],'b-o')
#                 ax2=pylab.twinx(ax)
#                 pylab.plot(sim['t_mat'],sim['moments_mat'][1,k,:],'g-o')
#                 ax2.yaxis.tick_right()
# 
#         else:
#             num_neurons=sim['moments_mat'].shape[1]
#             for k in range(num_neurons):
#                 for i in range(num_moments):
#                     pylab.plot(sim['t_mat'],sim['moments_mat'][i,k,:],'-o')
#                     ax.hold(True)
#         
#         
#     
#         pylab.subplot(223)
#         pylab.hold(False)
#         response_mat=sim['response_mat']
#         response_var_list=sim['response_var_list']
#         
#         
#         styles=['b-','g-','r-','k-']
#         ls=len(styles)
#         for i,r in enumerate(response_var_list[-1]):
#             x=r[1]
#             y=r[2]
#         
#             pylab.plot(x,y,styles[i % ls]+"o")
#             pylab.hold(True)
#     
#         pylab.subplot(224)
#         pylab.hold(False)
#         for i,r in enumerate(response_mat):
#             pylab.plot(r,styles[i % ls])
#             pylab.hold(True)
#     
#     
#         pylab.draw()
# 
# 
#     except ValueError:
#         sim['params']['display']=False
#         print("Error in display.  Turning display off")
#         return


# Path: plasticity/plot_sims.py
from .dialogs.waxy import *
from .run_sim import Plot
import os,sys
import glob

    
    
    def WatchForEnter(self,event):
        
        event.Skip()
        if event.GetKeyCode()==13:  # enter
            self.UpdateWildcard()
        
    def UpdateWildcard(self,event=None):
        wildcard=self.textbox.Value
        
        if '*' not in wildcard:
            wildcard+='*'
        
        files=glob.glob(wildcard)
        
        self.listbox.Fill(files)
        
        
    def Click(self,event):
    
        
        file=event.GetString()
        
        if file:
            
            self.SetCursor('arrowwait')
            self.UpdateWindowUI()
            self.Refresh()
            

            Plot(file)