]> git.donarmstrong.com Git - lilypond.git/commitdiff
* ikebana.py (NotationApplication.create_window): add zoom.
authorhanwen <hanwen>
Thu, 21 Jul 2005 23:14:18 +0000 (23:14 +0000)
committerhanwen <hanwen>
Thu, 21 Jul 2005 23:14:18 +0000 (23:14 +0000)
* notationcanvas.py (Notation_toolbar.__init__): multiple rows.

ChangeLog
ikebana.py
notation.py
notationcanvas.py

index e6a21fd68f1644870fc80c4cd175ad3181d947af..dc02454925bde7cdfb005aebb6c11d8f20065d18 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-07-22  Han-Wen Nienhuys  <hanwen@xs4all.nl>
+
+       * ikebana.py (NotationApplication.create_window): add zoom.
+
+       * notationcanvas.py (Notation_toolbar.__init__): multiple rows.
+
 2005-07-20  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
        * notationcanvas.py (Notation_toolbar.__init__): new class
index bc16b712f6919e9d4ccf179f30cfcb1d5096014e..ea4efbeb323529707d1e5bb433b099225631c778 100644 (file)
@@ -47,6 +47,10 @@ class NotationApplication:
         
         win.add (vbox)
         toolbar.show ()
+
+        toolbar.add_button ('zoom out', 'minus', lambda: canvas.zoom (-1), 0)
+        toolbar.add_button ('zoom in', 'Shift+plus', lambda: canvas.zoom (1), 0)
+        
         win.show()
         
         return win
index a010b57d4274afd4da78d4d3bb4cc27e9d0d7b17..1efad94862cc50c3d9788ca76becb9340c99c896 100644 (file)
@@ -22,6 +22,9 @@ clefsetting = """
        (make-property-set 'middleCPosition 0) 'Staff)
 """
 
+server = 'maagd'
+# server = 'localhost'
+
 lilypond_input_log_file = open ("input.log", 'w')
 
 def talk_to_lilypond (expression_str):
@@ -31,7 +34,7 @@ def talk_to_lilypond (expression_str):
         lilypond_input_log_file.flush ()
     
     sock = socket.socket (socket.AF_INET)
-    address = ("localhost", 2904)
+    address = (server, 2904)
     sock.connect (address)
     sock.send (expression_str, socket.MSG_WAITALL)
 
index 77c8242babfdacd2f7d334dbeea45667f7e28884..36adcb39bd230a2cae16e7da4690fec12ccc3ca8 100644 (file)
@@ -1,17 +1,28 @@
 import gtk
 import gnomecanvas
 import music
+import math
 
-
-class Notation_toolbar (gtk.HBox):
+class Notation_toolbar (gtk.VBox):
        def __init__ (self, notation, check_refresh_callback):
-               gtk.HBox.__init__ (self)
+               gtk.VBox.__init__ (self)
                self.button_dict = {}
                self.key_dict = {}
                self.notation = notation
+               self.rows = {}
                self.add_buttons ()
                self.check_refresh_callback = check_refresh_callback
                
+       def get_row (self, row):
+               if not self.rows.has_key (row):
+                       r = gtk.HBox()
+                       self.pack_start (r, expand = False)
+                       r.show ()
+                       self.rows[row] = r
+                       return r
+               
+               return self.rows[row]
+               
        def click_callback (self, widget):
                if not self.button_dict.has_key (widget):
                        print 'no such widget?'
@@ -38,9 +49,11 @@ class Notation_toolbar (gtk.HBox):
                button.do_activate (button)
                return True
        
-       def add_button (self, text, key, callback):
+       def add_button (self, text, key, callback, row_id):
                b = gtk.Button (text)
-               self.pack_start (b, expand=True)
+               row = self.get_row (row_id)
+               row.pack_start (b, expand=True)
+               
                b.connect ('clicked', self.click_callback)
                b.set_focus_on_click (False)
                self.key_dict[key] = b
@@ -48,69 +61,69 @@ class Notation_toolbar (gtk.HBox):
                b.show ()
 
        def add_buttons (self):
-               for (key_name, text, func) in \
-                       [('Left', '<-',
-                         lambda: self.notation.cursor_move (-1)),
+               for (key_name, text, func, row) in \
+                       [('p', 'LilyPond',
+                         lambda: self.notation.print_score(), 0),
+                        ('q', 'quit',
+                         lambda: gtk.main_quit(), 0),
+                        ('Left', '<-',
+                         lambda: self.notation.cursor_move (-1), 0),
                         ('Right', '->',
-                         lambda: self.notation.cursor_move (1)),
-                        ('space', 'next',
-                         lambda: self.notation.add_note ()),
+                         lambda: self.notation.cursor_move (1), 0),
+                        ('space', 'new',
+                         lambda: self.notation.add_note (), 0),
                         ('BackSpace', 'backspace',
-                         lambda: self.notation.backspace ()),
+                         lambda: self.notation.backspace (), 0),
                         ('Shift+Up', '#',
-                         lambda: self.notation.change_alteration (2)),
+                         lambda: self.notation.change_alteration (2), 1),
                         ('Shift+Down', 'b',
-                         lambda: self.notation.change_alteration (-2)),
+                         lambda: self.notation.change_alteration (-2), 1),
                         ('Up', 'up',
-                         lambda: self.notation.change_step (1)),
+                         lambda: self.notation.change_step (1), 1),
                         ('Down', 'down',
-                         lambda: self.notation.change_step (-1)),
+                         lambda: self.notation.change_step (-1), 1),
                         ('apostrophe', 'oct up',
-                         lambda: self.notation.change_octave (1)),
+                         lambda: self.notation.change_octave (1), 1),
                         ('comma', 'oct down',
-                         lambda: self.notation.change_octave (-1)),
+                         lambda: self.notation.change_octave (-1), 1),
                         ('period', '.',
-                         lambda: self.notation.change_dots ()),
+                         lambda: self.notation.change_dots (), 1),
                         ('slash', 'shorter',
-                         lambda: self.notation.change_duration_log (1)),
+                         lambda: self.notation.change_duration_log (1), 1),
                         ('Shift+asterisk', 'longer',
-                         lambda: self.notation.change_duration_log (-1)),
-                        ('p', 'LilyPond',
-                         lambda: self.notation.print_score()),
-                        ('q', 'quit',
-                         lambda: gtk.main_quit()),
+                         lambda: self.notation.change_duration_log (-1), 1),
                         ('r', 'rest',
-                         lambda: self.notation.ensure_rest ()),
+                         lambda: self.notation.ensure_rest (), 1),
                         ('Shift+C', '+C',
-                         lambda: self.notation.add_step (0)),
+                         lambda: self.notation.add_step (0), 2),
                         ('Shift+D', '+D',
-                         lambda: self.notation.add_step (1)),
+                         lambda: self.notation.add_step (1), 2),
                         ('Shift+E', '+E',
-                         lambda: self.notation.add_step (2)),
+                         lambda: self.notation.add_step (2), 2),
                         ('Shift+F', '+F',
-                         lambda: self.notation.add_step (3)),
+                         lambda: self.notation.add_step (3), 2),
                         ('Shift+G', '+G',
-                         lambda: self.notation.add_step (4)),
+                         lambda: self.notation.add_step (4), 2),
                         ('Shift+A', '+A',
-                         lambda: self.notation.add_step (5)),
+                         lambda: self.notation.add_step (5), 2),
                         ('Shift+B', '+B',
-                         lambda: self.notation.add_step (6)),
+                         lambda: self.notation.add_step (6), 2),
                         ('c', 'C',
-                         lambda: self.notation.set_step (0)),
+                         lambda: self.notation.set_step (0), 3),
                         ('d', 'D',
-                         lambda: self.notation.set_step (1)),
+                         lambda: self.notation.set_step (1), 3),
                         ('e', 'E',
-                         lambda: self.notation.set_step (2)),
+                         lambda: self.notation.set_step (2), 3),
                         ('f', 'F',
-                         lambda: self.notation.set_step (3)),
+                         lambda: self.notation.set_step (3), 3),
                         ('g', 'G',
-                         lambda: self.notation.set_step (4)),
+                         lambda: self.notation.set_step (4), 3),
                         ('a', 'A',
-                         lambda: self.notation.set_step (5)),
+                         lambda: self.notation.set_step (5), 3),
                         ('b', 'B',
-                         lambda: self.notation.set_step (6))]:
+                         lambda: self.notation.set_step (6), 3)]:
                        
-                       self.add_button (text, key_name, func)
+                       self.add_button (text, key_name, func, row)
 
 
 class Notation_canvas (gnomecanvas.Canvas):
@@ -120,14 +133,16 @@ class Notation_canvas (gnomecanvas.Canvas):
                gnomecanvas.Canvas.__init__ (self,
                                             #aa=True
                                             )
-               (w,h) = (800,400)
+               (w,h) = (400,200)
                self.set_size_request (w, h) 
                self.set_scroll_region (0, 0, w, h)
                root = self.root ()
-               root.affine_relative ((1,0,0,-1,0,0))
+               root.affine_relative ((1,0,0,-1,0, 5))
                self.pixel_scale = 10
                self.set_pixels_per_unit (self.pixel_scale)
-               i = root.add (gnomecanvas.CanvasRect, x2 = w, y2 = -h,
+               i = root.add (gnomecanvas.CanvasRect,
+                             y1 = 5,
+                             x2 = w, y2 = -h + 5,
                              fill_color = 'white', outline_color = 'white')
                i.notation_item = None
                self.notation_canvas_controller = canvas_controller
@@ -187,6 +202,11 @@ class Notation_canvas (gnomecanvas.Canvas):
                if c_items:
                        self.set_cursor (c_items[0].notation_item)
 
+       def zoom (self, delta):
+               fact = pow (1.25, delta)
+               self.pixel_scale *= fact
+               self.set_pixels_per_unit (self.pixel_scale)
+               
 class Notation_canvas_controller:
        """The connection between canvas and the abstract notation graphics."""
 
@@ -206,3 +226,5 @@ class Notation_canvas_controller:
                        self.update_canvas ()
                elif self.notation.cursor_touched:
                        self.update_cursor ()
+
+