<commit_before>from plot_funcs import *
from canvas_slider import *
from network_classes import *

import matplotlib
matplotlib.use('TkAgg')

from numpy import arange, sin, pi
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg#, NavigationToolbar2TkAgg
from matplotlib.figure import Figure

import Tkinter as Tk
             
class SchematicFrame(Tk.Frame):
    def im_reorder(self,event,old,new):
        self.canvas1.move(self.item_arr[new], (old-new)*self.im_x_size, 0)

        self.item_arr[old], self.item_arr[new] = self.item_arr[new], self.item_arr[old]
        self.net.element_array[old], self.net.element_array[new] = self.net.element_array[new], self.net.element_array[old]
        
        self.image_selection=new
        self.draw_plot()

    def down_click(self,event):
        self.image_selection=int(event.x/self.im_x_size)
#        if self.image_selection>len(self.item_arr):
#            self.image_selection=self.item_arr[-1]
        self.canvas1.delete(self.box)
        self.draw_box(self.canvas1,self.image_selection)#event.x/self.im_x_size)    
        #self.canvas1.tag_raise(self.box)

    def follow_mouse(self,event):
        new_x, new_y = event.x, event.y
        old_x, old_y = self.canvas1.coords(self.item_arr[self.image_selection])

        num_items=len(self.item_arr)        
        position_num=int(new_x/self.im_x_size)

        #Move image to follow mouse
        if ((new_x>0)&(new_x<self.im_x_size*num_items)):
            self.canvas1.move(self.item_arr[self.image_selection], new_x-old_x, new_y-old_y)
            self.drag=True
        else:
            pass
            #reposition image -- but now this will fail

        #Dynamically move icons while dragging
        if ((position_num<num_items)&(new_x>0.0)&(old_x<num_items*self.im_x_size)): #Only if move if within region of circuit
            if int(new_x/self.im_x_size) != int(old_x/self.im_x_size):
                self.im_reorder(event,int(old_x/self.im_x_size),int(new_x/self.im_x_size))
                item_n=int(new_x/self.im_x_size)

    def draw_box(self,canvas,n):
        w=2        
        self.box = canvas.create_rectangle((n)*self.im_x_size+w, 2*w ,(n+1)*self.im_x_size-w/2, self.im_y_size-w/2,
                                           width=w,dash='.')
        canvas.tag_raise(self.box)

    def reposition_image(self,event):
        new_x, new_y = event.x, event.y
        
        position_num=int(new_x/self.im_x_size)
        if (self.drag==True&(position_num<=len(self.item_arr))&(new_x>0.0)):
            self.canvas1.move(self.item_arr[int(new_x/self.im_x_size)],
                              -new_x%self.im_x_size-0.5*self.im_x_size,
                              -new_y+0.5*self.im_y_size)
        self.drag=False

    def draw_schematic(self):
        capse = "icons/Cseries2.gif"
        capsh = "icons/Cshunt2.gif"
        self.CapIconSe = Tk.PhotoImage(file=capse)
        self.CapIconSh = Tk.PhotoImage(file=capsh)

        indse = "icons/Lseries2.gif"
        indsh = "icons/Lshunt2.gif"
        self.IndIconSe = Tk.PhotoImage(file=indse)
        self.IndIconSh = Tk.PhotoImage(file=indsh)

        self.Match=[]
        for elem in self.net.element_array:
            if elem.name == 'cap':
                if elem.orientation==1:
                    self.Match.append({'type':self.CapIconSh})
                elif elem.orientation==0:
                    self.Match.append({'type':self.CapIconSe})
            elif elem.name =='ind':
                if elem.orientation==1:
                    self.Match.append({'type':self.IndIconSh})
                elif elem.orientation==0:
                    self.Match.append({'type':self.IndIconSe})

        for elem in self.item_arr:
            self.canvas1.delete(elem)
            self.item_arr=[]

        x = (self.im_x_size)/2.0
        y = (self.im_y_size)/2.0
        for n,elem in enumerate(self.Match):
            self.item_arr.append(self.canvas1.create_image(x+100*n, y, image=elem['type']))

    def update_icons(self):
        pass 

    def __init__(self,parent,network,draw_plot):
        Tk.Frame.__init__(self,parent)
        self.parent=parent
        
        self.net=network
        self.draw_plot=draw_plot
        self.Match=[]
        
        self.im_y_size=150
        self.im_x_size=100

        self.box=None
        self.drag=False
        self.image_selection=0

        self.item_arr=[] #contains canvas item index

        self.canvas1 = Tk.Canvas(parent,width=850, height=150)#,scrollregion=(0,0,1000,150)
        self.canvas1.grid(row=3,column=0,columnspan=3,sticky=Tk.W)
        self.canvas1.configure(background='white')

        #print self.item_arr
        self.update_icons()
        self.draw_schematic()
        self.draw_box(self.canvas1,0)

        self.canvas1.bind('<Button-1>', self.down_click)
        ##canvas1.bind('<Button-3>', right_click)
        self.canvas1.bind('<B1-Motion>', self.follow_mouse)
        self.canvas1.bind('<ButtonRelease-1>', self.reposition_image)


class MainWindow(Tk.Frame):
    def __init__(self,parent):
        Tk.Frame.__init__(self,parent)
        fig = Figure(figsize=(7, 7), dpi=100)
        fig.subplots_adjust(left=0.01, bottom=0.01, right=0.99, top=0.99)
        self.mainplot = fig.add_subplot(111,aspect=1)

        self.curves=[]
        self.dots=[]

        print "Git Test"
        
        PlotSmith(self.mainplot)

        parent.bind('<Up>',self.test)
        
        #fig.draw(0)
        
        self.settings={'centerfreq':2.0e9,
                       'lowerfreq':1.5e9,
                       'upperfreq':2.5e9,
                       'SmithImpedance':50.0,
                       'InputImpedance':50+0*1j,
                       'LoadImpedance':50+0*1j}

        #PALETTE FRAME
        Palette = Tk.Frame(root)
        Palette.grid(row=1,column=0,sticky=Tk.N)
        button1=Tk.Button(Palette,text="SeriesC", command=self.add_series_c)
        button1.grid(row=0,column=0)
        button1=Tk.Button(Palette,text="ShuntC", command=self.add_shunt_c)
        button1.grid(row=0,column=1)
        button1=Tk.Button(Palette,text="SeriesL", command=self.add_series_l)
        button1.grid(row=1,column=0)
        button1=Tk.Button(Palette,text="ShuntL", command=self.add_shunt_l)
        button1.grid(row=1,column=1)

        a=Tk.Canvas(Palette,width=50)
        a.grid(row=2,column=0,columnspan=2,sticky=Tk.N+Tk.W)
        b=SliderFrame(a)
        #b.grid(row=2,column=0)
        <commit_msg>Corrected import filename errors Added slider functionality<commit_after>from plot_funcs import *
from canvas_slider import *
from network_classes import *

import matplotlib
matplotlib.use('TkAgg')

from numpy import arange, sin, pi
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg#, NavigationToolbar2TkAgg
from matplotlib.figure import Figure

import Tkinter as Tk
             
class SchematicFrame(Tk.Frame):
    def im_reorder(self,event,old,new):
        self.canvas1.move(self.item_arr[new], (old-new)*self.im_x_size, 0)

        self.item_arr[old], self.item_arr[new] = self.item_arr[new], self.item_arr[old]
        self.net.element_array[old], self.net.element_array[new] = self.net.element_array[new], self.net.element_array[old]
        
        self.image_selection=new
        self.draw_plot()

    def down_click(self,event):
        self.image_selection=int(event.x/self.im_x_size)
#        if self.image_selection>len(self.item_arr):
#            self.image_selection=self.item_arr[-1]
        self.canvas1.delete(self.box)
        self.draw_box(self.canvas1,self.image_selection)#event.x/self.im_x_size)    
        #self.canvas1.tag_raise(self.box)

    def follow_mouse(self,event):
        new_x, new_y = event.x, event.y
        old_x, old_y = self.canvas1.coords(self.item_arr[self.image_selection])

        num_items=len(self.item_arr)        
        position_num=int(new_x/self.im_x_size)

        #Move image to follow mouse
        if ((new_x>0)&(new_x<self.im_x_size*num_items)):
            self.canvas1.move(self.item_arr[self.image_selection], new_x-old_x, new_y-old_y)
            self.drag=True
        else:
            pass
            #reposition image -- but now this will fail

        #Dynamically move icons while dragging
        if ((position_num<num_items)&(new_x>0.0)&(old_x<num_items*self.im_x_size)): #Only if move if within region of circuit
            if int(new_x/self.im_x_size) != int(old_x/self.im_x_size):
                self.im_reorder(event,int(old_x/self.im_x_size),int(new_x/self.im_x_size))
                item_n=int(new_x/self.im_x_size)

    def draw_box(self,canvas,n):
        w=2        
        self.box = canvas.create_rectangle((n)*self.im_x_size+w, 2*w ,(n+1)*self.im_x_size-w/2, self.im_y_size-w/2,
                                           width=w,dash='.')
        canvas.tag_raise(self.box)

    def reposition_image(self,event):
        new_x, new_y = event.x, event.y
        
        position_num=int(new_x/self.im_x_size)
        if (self.drag==True&(position_num<=len(self.item_arr))&(new_x>0.0)):
            self.canvas1.move(self.item_arr[int(new_x/self.im_x_size)],
                              -new_x%self.im_x_size-0.5*self.im_x_size,
                              -new_y+0.5*self.im_y_size)
        self.drag=False

    def draw_schematic(self):
        capse = "icons/Cseries2.gif"
        capsh = "icons/Cshunt2.gif"
        self.CapIconSe = Tk.PhotoImage(file=capse)
        self.CapIconSh = Tk.PhotoImage(file=capsh)

        indse = "icons/Lseries2.gif"
        indsh = "icons/Lshunt2.gif"
        self.IndIconSe = Tk.PhotoImage(file=indse)
        self.IndIconSh = Tk.PhotoImage(file=indsh)

        self.Match=[]
        for elem in self.net.element_array:
            if elem.name == 'cap':
                if elem.orientation==1:
                    self.Match.append({'type':self.CapIconSh})
                elif elem.orientation==0:
                    self.Match.append({'type':self.CapIconSe})
            elif elem.name =='ind':
                if elem.orientation==1:
                    self.Match.append({'type':self.IndIconSh})
                elif elem.orientation==0:
                    self.Match.append({'type':self.IndIconSe})

        for elem in self.item_arr:
            self.canvas1.delete(elem)
            self.item_arr=[]

        x = (self.im_x_size)/2.0
        y = (self.im_y_size)/2.0
        for n,elem in enumerate(self.Match):
            self.item_arr.append(self.canvas1.create_image(x+100*n, y, image=elem['type']))

    def update_icons(self):
        pass 

    def __init__(self,parent,network,draw_plot):
        Tk.Frame.__init__(self,parent)
        self.parent=parent
        
        self.net=network
        self.draw_plot=draw_plot
        self.Match=[]
        
        self.im_y_size=150
        self.im_x_size=100

        self.box=None
        self.drag=False
        self.image_selection=0

        self.item_arr=[] #contains canvas item index

        self.canvas1 = Tk.Canvas(parent,width=850, height=150)#,scrollregion=(0,0,1000,150)
        self.canvas1.grid(row=3,column=0,columnspan=3,sticky=Tk.W)
        self.canvas1.configure(background='white')

        #print self.item_arr
        self.update_icons()
        self.draw_schematic()
        self.draw_box(self.canvas1,0)

        self.canvas1.bind('<Button-1>', self.down_click)
        ##canvas1.bind('<Button-3>', right_click)
        self.canvas1.bind('<B1-Motion>', self.follow_mouse)
        self.canvas1.bind('<ButtonRelease-1>', self.reposition_image)


class MainWindow(Tk.Frame):
    def __init__(self,parent):
        Tk.Frame.__init__(self,parent)
        fig = Figure(figsize=(7, 7), dpi=100)
        fig.subplots_adjust(left=0.01, bottom=0.01, right=0.99, top=0.99)
        self.mainplot = fig.add_subplot(111,aspect=1)

        self.curves=[]
        self.dots=[]

        PlotSmith(self.mainplot)

        parent.bind('<Up>',self.test)
        
        #fig.draw(0)
        
        self.settings={'centerfreq':2.0e9,
                       'lowerfreq':1.5e9,
                       'upperfreq':2.5e9,
                       'SmithImpedance':50.0,
                       'InputImpedance':50+0*1j,
                       'LoadImpedance':50+0*1j}

        #PALETTE FRAME
        Palette = Tk.Frame(root)
        Palette.grid(row=1,column=0,sticky=Tk.N)
        button1=Tk.Button(Palette,text="SeriesC", command=self.add_series_c)
        button1.grid(row=0,column=0)
        button1=Tk.Button(Palette,text="ShuntC", command=self.add_shunt_c)
        button1.grid(row=0,column=1)
        button1=Tk.Button(Palette,text="SeriesL", command=self.add_series_l)
        button1.grid(row=1,column=0)
        button1=Tk.Button(Palette,text="ShuntL", command=self.add_shunt_l)
        button1.grid(row=1,column=1)

        a=Tk.Canvas(Palette,width=50)
        a.grid(row=2,column=0,columnspan=2,sticky=Tk.N+Tk.W)
        b=SliderFrame(a)
        #b.grid(row=2,column=0)
        
{'fraction_non_alphanumeric': 0.13046153846153846, 'fraction_numerical': 0.02246153846153846, 'mean_word_length': 2.317427915284511, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3781222', 'n_tokens_mistral': 4707, 'n_tokens_neox': 4534, 'n_words': 557}