Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2013-01-12 18:28:12 (GMT)
committer Walter Bender <walter.bender@gmail.com>2013-01-12 18:28:12 (GMT)
commitd7707e9fe31569ba5c3bcf7310ca693e1d278efe (patch)
tree45bd3302a9741b41a6028f7799c9a1f04645ec50
parenta31ed5b08df44d6ea6b5d6248dc3d8d641a18460 (diff)
allow units < 8mm in custom toolbar #4376
-rw-r--r--RulerActivity.py21
-rw-r--r--show_rulers.py19
2 files changed, 21 insertions, 19 deletions
diff --git a/RulerActivity.py b/RulerActivity.py
index 48cf868..8ef8c05 100644
--- a/RulerActivity.py
+++ b/RulerActivity.py
@@ -53,7 +53,8 @@ import show_grids
import show_checkers
import show_angles
-from sugar3.graphics import style
+MMPERINCH = 25.4
+
class MyCanvas(Gtk.DrawingArea):
''' Create a GTK+ widget on which we will draw using Cairo '''
@@ -263,15 +264,17 @@ class RulerActivity(activity.Activity):
def custom_unit_change_cb(self, widget):
try:
new = float(widget.get_text())
- if new > 7: # less than 7 results in overlapping.
- self._canvas.add_a_ruler(self._r)
- self._r.custom_unit_in_mm = new
- self._r.draw_custom_ruler(self._r.custom_unit_in_mm)
- self.metadata['custom_unit'] = new
except ValueError:
- if widget.get_text() != '':
- widget.set_text('25.4')
- self.metadata['custom_unit'] = 25.4
+ new = MMPERINCH
+ new = abs(new)
+ if new == 0:
+ new = MMPERINCH
+ if widget.get_text != '':
+ widget.set_text(str(new))
+ self._canvas.add_a_ruler(self._r)
+ self._r.custom_unit_in_mm = new
+ self._r.draw_custom_ruler(self._r.custom_unit_in_mm)
+ self.metadata['custom_unit'] = new
def _grids_cb(self, button=None):
if self._ready:
diff --git a/show_rulers.py b/show_rulers.py
index 30f8e46..b776c0d 100644
--- a/show_rulers.py
+++ b/show_rulers.py
@@ -126,16 +126,15 @@ class ScreenOfRulers():
range(0, (width + 1) * 100, int(units_per_mm * 100))]
coord_list = [mm(self.dpi, xm / 100) for xm in range(
0, (width + 1) * 100, int(units_per_mm * 100))]
- for a in range(0, len(coord_list)):
- xm = pt_list[a]
- x = coord_list[a]
- n = xm
- self.c.move_to(x, mm(self.dpi, -4))
- write(self.c, "%d" % n, self.font_bold, mm(self.dpi, 2.5),
- centered=True)
-
- self.c.move_to(mm(self.dpi, 1.5), mm(self.dpi, -4))
- write(self.c, "unit", self.font_bold, mm(self.dpi, 2))
+
+ if units_per_mm > 7: # Avoid overlapping labels
+ for a in range(0, len(coord_list)):
+ xm = pt_list[a]
+ x = coord_list[a]
+ n = xm
+ self.c.move_to(x, mm(self.dpi, -4))
+ write(self.c, "%d" % n, self.font_bold, mm(self.dpi, 2.5),
+ centered=True)
self.c.restore()