33GTK Spreadsheet
44===============
55
6- Example of embedding matplotlib in an application and interacting with
7- a treeview to store data. Double click on an entry to update plot
8- data
9-
6+ Example of embedding Matplotlib in an application and interacting with a
7+ treeview to store data. Double click on an entry to update plot data.
108"""
9+
1110import gi
1211gi .require_version ('Gtk' , '3.0' )
1312gi .require_version ('Gdk' , '3.0' )
1413from gi .repository import Gtk , Gdk
1514
16- from matplotlib .backends .backend_gtk3agg import FigureCanvas
17- # from matplotlib.backends.backend_gtk3cairo import FigureCanvas
15+ from matplotlib .backends .backend_gtk3agg import FigureCanvas # or gtk3cairo.
1816
1917from numpy .random import random
2018from matplotlib .figure import Figure
2119
2220
2321class DataManager (Gtk .Window ):
24- numRows , numCols = 20 , 10
22+ num_rows , num_cols = 20 , 10
2523
26- data = random ((numRows , numCols ))
24+ data = random ((num_rows , num_cols ))
2725
2826 def __init__ (self ):
29- Gtk . Window . __init__ (self )
27+ super (). __init__ ()
3028 self .set_default_size (600 , 600 )
3129 self .connect ('destroy' , lambda win : Gtk .main_quit ())
3230
3331 self .set_title ('GtkListStore demo' )
3432 self .set_border_width (8 )
3533
36- vbox = Gtk .VBox (False , 8 )
34+ vbox = Gtk .VBox (homogeneous = False , spacing = 8 )
3735 self .add (vbox )
3836
39- label = Gtk .Label ('Double click a row to plot the data' )
37+ label = Gtk .Label (label = 'Double click a row to plot the data' )
4038
4139 vbox .pack_start (label , False , False , 0 )
4240
4341 sw = Gtk .ScrolledWindow ()
4442 sw .set_shadow_type (Gtk .ShadowType .ETCHED_IN )
45- sw .set_policy (Gtk .PolicyType .NEVER ,
46- Gtk .PolicyType .AUTOMATIC )
43+ sw .set_policy (Gtk .PolicyType .NEVER , Gtk .PolicyType .AUTOMATIC )
4744 vbox .pack_start (sw , True , True , 0 )
4845
4946 model = self .create_model ()
5047
51- self .treeview = Gtk .TreeView (model )
52- self .treeview .set_rules_hint (True )
48+ self .treeview = Gtk .TreeView (model = model )
5349
54- # matplotlib stuff
50+ # Matplotlib stuff
5551 fig = Figure (figsize = (6 , 4 ))
5652
5753 self .canvas = FigureCanvas (fig ) # a Gtk.DrawingArea
@@ -75,14 +71,13 @@ def plot_row(self, treeview, path, view_column):
7571 self .canvas .draw ()
7672
7773 def add_columns (self ):
78- for i in range (self .numCols ):
74+ for i in range (self .num_cols ):
7975 column = Gtk .TreeViewColumn (str (i ), Gtk .CellRendererText (), text = i )
8076 self .treeview .append_column (column )
8177
8278 def create_model (self ):
83- types = [float ]* self .numCols
79+ types = [float ] * self .num_cols
8480 store = Gtk .ListStore (* types )
85-
8681 for row in self .data :
8782 store .append (tuple (row ))
8883 return store
0 commit comments