Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Francis <francis@sugarlabs.org>2012-07-18 19:27:37 (GMT)
committer Daniel Francis <francis@sugarlabs.org>2012-07-18 19:27:37 (GMT)
commit7cc97f241446f467b9b87eac23efe0deb2edfa58 (patch)
tree93e7d1355637dad2e5e9b09de240fd8b0adf921c
parentb68b7589594b91a17e0d7734e9baa727c4cfa724 (diff)
Code organized
-rw-r--r--canvas.py19
-rw-r--r--staff.py39
-rw-r--r--track.py52
3 files changed, 99 insertions, 11 deletions
diff --git a/canvas.py b/canvas.py
index d86d2c5..d439ae1 100644
--- a/canvas.py
+++ b/canvas.py
@@ -20,27 +20,24 @@
import gtk
+from track import Track
+
class StaffCanvas(gtk.DrawingArea):
width = None
+ tracks = []
def __init__(self):
gtk.DrawingArea.__init__(self)
self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#FFF'))
self.connect('expose-event', self._expose_event_cb)
+ self.tracks.append(Track())
def _expose_event_cb(self, widget, event):
window = widget.get_window()
context = window.cairo_create()
- self.width = event.area[2]
+ width = event.area[2]
height = event.area[3]
- self.draw_staff(context, 50, self.width * 0.1, self.width * 0.05,
- height * 0.025)
-
- def draw_staff(self, context, y, lmarg, rmarg, spacing):
- line_y = y
- for i in range(5):
- context.move_to(lmarg, line_y)
- context.line_to(self.width - rmarg, line_y)
- line_y += spacing
- context.stroke()
+ for track in self.tracks:
+ track.linespacing = height * 0.025
+ track.draw(context, width)
diff --git a/staff.py b/staff.py
new file mode 100644
index 0000000..7986921
--- /dev/null
+++ b/staff.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2012 S. Daniel Francis <francis@sugarlabs.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+
+class Staff:
+ y = 0
+ lmarg = 0
+ rmarg = 0
+ spacing = 0
+
+ def __init__(self):
+ pass
+
+ def draw(self, context, width):
+ context.set_source_rgb(0, 0, 0)
+ context.set_line_width(2)
+ line_y = self.y
+ for i in range(5):
+ context.move_to(self.lmarg, line_y)
+ context.line_to(width - self.rmarg, line_y)
+ line_y += self.spacing
+ context.stroke()
diff --git a/track.py b/track.py
new file mode 100644
index 0000000..837e929
--- /dev/null
+++ b/track.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2012 S. Daniel Francis <francis@sugarlabs.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+from staff import Staff
+
+
+class Track:
+
+ def __init__(self):
+ self._y = 0
+ self._linespacing = 10
+ self.staff = Staff()
+
+ def draw(self, context, width):
+ self.staff.lmarg = width * 0.1
+ self.staff.rmarg = width * 0.05
+ self.staff.spacing = self.linespacing
+ self.staff.y = self.linespacing * 3
+ self.staff.draw(context, width)
+
+ def set_y(self, y):
+ self._y = y
+
+ def get_y(self):
+ return self.y
+
+ y = property(get_y, set_y)
+
+ def set_linespacing(self, value):
+ self._linespacing = value
+
+ def get_linespacing(self):
+ return self._linespacing
+
+ linespacing = property(get_linespacing, set_linespacing)