<commit_before>#!/usr/bin/env python
import os
from spa_sequence.spa_sequence import net, pThal

import pygtk
pygtk.require('2.0')
import gtk
import cairo
import math

import view.components.spectrogram as spectrogram
#import view.components.input_panel as Input_Panel
from view.components.input_panel import Input_Panel
from view.components.controller_panel import Controller_Panel
from view.components.menu_bar import Menu_Bar
import simulator
import simulator.watchers
from old_plots.xy_plot import XY_Plot
from old_plots.voltage_grid import Voltage_Grid_Plot

from matplotlib.backends.backend_gtkcairo import FigureCanvasGTKCairo as FigureCanvas

class MainFrame:
    def __init__(self):
        
        self.vbox = gtk.VBox(False, 0)
        self.playing = False
        self.press = None
        self.resize = False
        self.resize_info = None

        self.sim = simulator.Simulator(net, net.dt)
        self.sim.add_watcher(simulator.watchers.LFPSpectrogramWatcher())
        self.sim.add_watcher(simulator.watchers.XYWatcher())
        self.sim.add_watcher(simulator.watchers.Voltage_Grid_Watcher())
        self.sim.watcher_manager.add_object("pThal", pThal)
        self.spectrogram = None
        
        self.all_plots = []
        self.all_canvas = []

        net.run(0.001) #run for one timestep
        self.sim.tick()
        self.sim.tick()

        for name, type, data in [("pThal", "LFP Spectrogram", None)]:
            if name in self.sim.watcher_manager.objects.keys():
                for (t, view_class, args) in self.sim.watcher_manager.list_watcher_views(name):
                    if t == type:
                        component = view_class(self.sim, name, **args)
                        # we know we only have the spectrogram in our example
                        self.spectrogram = component
                    elif (t == "XY"):
                        self.xy_plot = view_class(self.sim, name, **args)
                    elif (t == "Voltage Grid"):
                        self.voltage_grid = view_class(self.sim, name, **args)
                        

        #TODO(amtinits): this should go in a super-class for all plots
        def button_press(widget, event, canvas):
            if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
                export_pdf_item = gtk.MenuItem("Export to PDF")
                export_pdf_item.connect("activate", self.on_export_pdf, canvas)
                export_pdf_item.show()
                context_menu = gtk.Menu()
                context_menu.append(export_pdf_item)
                context_menu.popup(None, None, None, event.button, event.time)
                return True
            return False

        self.spec_canvas = FigureCanvas(self.spectrogram.get_figure())
        self.spec_canvas.connect("event", button_press, self.spec_canvas)
        self.all_plots.append(self.spectrogram)
        self.all_canvas.append(self.spec_canvas)

        self.xy_canvas = FigureCanvas(self.xy_plot.get_figure())
        self.xy_canvas.connect("event", button_press, self.xy_canvas)
        self.all_plots.append(self.xy_plot)
        self.all_canvas.append(self.xy_canvas)

        self.vg_canvas = FigureCanvas(self.voltage_grid.get_figure())
        self.vg_canvas.connect("event", button_press, self.vg_canvas)
        self.all_plots.append(self.voltage_grid)
        self.all_canvas.append(self.vg_canvas)
        
        map(lambda x:x.mpl_connect('figure_enter_event', self.enter_figure), self.all_canvas)
        map(lambda x:x.mpl_connect('figure_leave_event', self.leave_figure), self.all_canvas)
        map(lambda x:x.mpl_connect('button_press_event', self.mouse_on_press), self.all_canvas)
        map(lambda x:x.mpl_connect('button_release_event', self.mouse_on_release), self.all_canvas)
        map(lambda x:x.mpl_connect('motion_notify_event', self.mouse_on_motion), self.all_canvas)

        # create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_size_request(200, 100)
        self.window.set_title("Nengo Python Visualizer")
        self.window.connect("delete_event", lambda w,e: gtk.main_quit())
        
        self.input_panel = Input_Panel(self)
        self.controller_panel = Controller_Panel(self)
        self.menu_bar = Menu_Bar(self)
        
        self.canvas_layout = gtk.Layout(None, None)
        self.canvas_layout.set_size(600, 600)

        figure = self.spectrogram.get_figure()

        # Used to control framerate for redrawing graph components
        self.sim_rate = 6 # rate at which we call sim.tick()
        self.framerate = 2
        self.next_gcomponent_redraw = 0
        
        self.canvas = FigureCanvas(figure)  # a gtk.DrawingArea
        self.timer = self.canvas.new_timer(interval=1000/self.sim_rate)
        self.timer.add_callback(self.tick)
        
        self.vbox.pack_start(self.menu_bar, False, False, 0)
        self.vbox.pack_start(self.controller_panel, False, False, 0)
        self.vbox.pack_start(self.canvas_layout, True, True, 0)
        self.window.add(self.vbox)
        
        self.menu_bar.show()
        self.controller_panel.show()
        self.spec_canvas.show()
        self.canvas_layout.show()<commit_msg>Make canvas background white<commit_after>#!/usr/bin/env python
import os
from spa_sequence.spa_sequence import net, pThal

import pygtk
pygtk.require('2.0')
import gtk
import cairo
import math

import view.components.spectrogram as spectrogram
#import view.components.input_panel as Input_Panel
from view.components.input_panel import Input_Panel
from view.components.controller_panel import Controller_Panel
from view.components.menu_bar import Menu_Bar
import simulator
import simulator.watchers
from old_plots.xy_plot import XY_Plot
from old_plots.voltage_grid import Voltage_Grid_Plot

from matplotlib.backends.backend_gtkcairo import FigureCanvasGTKCairo as FigureCanvas

class MainFrame:
    def __init__(self):
        
        self.vbox = gtk.VBox(False, 0)
        self.playing = False
        self.press = None
        self.resize = False
        self.resize_info = None

        self.sim = simulator.Simulator(net, net.dt)
        self.sim.add_watcher(simulator.watchers.LFPSpectrogramWatcher())
        self.sim.add_watcher(simulator.watchers.XYWatcher())
        self.sim.add_watcher(simulator.watchers.Voltage_Grid_Watcher())
        self.sim.watcher_manager.add_object("pThal", pThal)
        self.spectrogram = None
        
        self.all_plots = []
        self.all_canvas = []

        net.run(0.001) #run for one timestep
        self.sim.tick()
        self.sim.tick()

        for name, type, data in [("pThal", "LFP Spectrogram", None)]:
            if name in self.sim.watcher_manager.objects.keys():
                for (t, view_class, args) in self.sim.watcher_manager.list_watcher_views(name):
                    if t == type:
                        component = view_class(self.sim, name, **args)
                        # we know we only have the spectrogram in our example
                        self.spectrogram = component
                    elif (t == "XY"):
                        self.xy_plot = view_class(self.sim, name, **args)
                    elif (t == "Voltage Grid"):
                        self.voltage_grid = view_class(self.sim, name, **args)
                        

        #TODO(amtinits): this should go in a super-class for all plots
        def button_press(widget, event, canvas):
            if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
                export_pdf_item = gtk.MenuItem("Export to PDF")
                export_pdf_item.connect("activate", self.on_export_pdf, canvas)
                export_pdf_item.show()
                context_menu = gtk.Menu()
                context_menu.append(export_pdf_item)
                context_menu.popup(None, None, None, event.button, event.time)
                return True
            return False

        self.spec_canvas = FigureCanvas(self.spectrogram.get_figure())
        self.spec_canvas.connect("event", button_press, self.spec_canvas)
        self.all_plots.append(self.spectrogram)
        self.all_canvas.append(self.spec_canvas)

        self.xy_canvas = FigureCanvas(self.xy_plot.get_figure())
        self.xy_canvas.connect("event", button_press, self.xy_canvas)
        self.all_plots.append(self.xy_plot)
        self.all_canvas.append(self.xy_canvas)

        self.vg_canvas = FigureCanvas(self.voltage_grid.get_figure())
        self.vg_canvas.connect("event", button_press, self.vg_canvas)
        self.all_plots.append(self.voltage_grid)
        self.all_canvas.append(self.vg_canvas)
        
        map(lambda x:x.mpl_connect('figure_enter_event', self.enter_figure), self.all_canvas)
        map(lambda x:x.mpl_connect('figure_leave_event', self.leave_figure), self.all_canvas)
        map(lambda x:x.mpl_connect('button_press_event', self.mouse_on_press), self.all_canvas)
        map(lambda x:x.mpl_connect('button_release_event', self.mouse_on_release), self.all_canvas)
        map(lambda x:x.mpl_connect('motion_notify_event', self.mouse_on_motion), self.all_canvas)

        # create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_size_request(200, 100)
        self.window.set_title("Nengo Python Visualizer")
        self.window.connect("delete_event", lambda w,e: gtk.main_quit())
        
        self.input_panel = Input_Panel(self)
        self.controller_panel = Controller_Panel(self)
        self.menu_bar = Menu_Bar(self)
        
        self.canvas_layout = gtk.Layout(None, None)
        self.canvas_layout.set_size(600, 600)
        self.canvas_layout.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff"))

        figure = self.spectrogram.get_figure()

        # Used to control framerate for redrawing graph components
        self.sim_rate = 6 # rate at which we call sim.tick()
        self.framerate = 2
        self.next_gcomponent_redraw = 0
        
        self.canvas = FigureCanvas(figure)  # a gtk.DrawingArea
        self.timer = self.canvas.new_timer(interval=1000/self.sim_rate)
        self.timer.add_callback(self.tick)
        
        self.vbox.pack_start(self.menu_bar, False, False, 0)
        self.vbox.pack_start(self.controller_panel, False, False, 0)
        self.vbox.pack_start(self.canvas_layout, True, True, 0)
        self.window.add(self.vbox)
        
        self.menu_bar.show()
        self.controller_panel.show()
        self.spec_canvas.show()
        self.canvas_layout.show()
{'fraction_non_alphanumeric': 0.09860086972962753, 'fraction_numerical': 0.005672149744753261, 'mean_word_length': 2.558358560376724, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1017244', 'n_tokens_mistral': 3373, 'n_tokens_neox': 3199, 'n_words': 596}