summaryrefslogtreecommitdiff
path: root/lidt/plotout.py
diff options
context:
space:
mode:
Diffstat (limited to 'lidt/plotout.py')
-rw-r--r--lidt/plotout.py121
1 files changed, 121 insertions, 0 deletions
diff --git a/lidt/plotout.py b/lidt/plotout.py
new file mode 100644
index 0000000..cb3b838
--- /dev/null
+++ b/lidt/plotout.py
@@ -0,0 +1,121 @@
+# LIDT
+# Copyright (C) 2016 Karel Kočí
+#
+# 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, see <http://www.gnu.org/licenses/>.
+
+import math
+import gi
+gi.require_version('Gtk', '3.0')
+from gi.repository import Gtk, Gdk
+
+grid = None
+grid_bot = None
+step = 50
+dia = 300
+selectx = None
+selecty = None
+grid_h = 1
+
+def __grid_draw(wd, cr):
+ w = wd.get_allocated_width()
+ h = wd.get_allocated_height()
+ if w < h:
+ s = w
+ else:
+ s = h
+ cr.set_source_rgb(0, 0, 0)
+ h = s / 2 # half of the size of drawing area
+ global grid_h
+ grid_h = h
+ st = (h / dia) * step
+
+ cr.rectangle(0, 0, s, s)
+ cr.fill()
+
+ cr.move_to(0, h)
+ cr.arc(h, h, h, 0, 2 * math.pi)
+ cr.set_source_rgb(1, 1, 1)
+ cr.fill()
+
+ cr.set_source_rgb(0, 0, 0)
+ i = 0
+ while i < h:
+ cr.move_to(h + i, 0)
+ cr.line_to(h + i, s)
+ cr.move_to(h - i, 0)
+ cr.line_to(h - i, s)
+ cr.move_to(0, h + i)
+ cr.line_to(s, h + i)
+ cr.move_to(0, h - i)
+ cr.line_to(s, h - i)
+ i = i + st
+ cr.set_line_width(1)
+ cr.stroke()
+
+ if selectx is not None:
+ slx = (h / dia) * selectx
+ sly = (h / dia) * selecty
+ cr.move_to(h +slx - 5, h + sly)
+ cr.arc(h + slx, h + sly, 5, 0, 2 * math.pi)
+ cr.set_source_rgb(0, 1, 0)
+ cr.fill()
+
+def __grid_button(widg, button):
+ global selectx
+ global selecty
+ selectx = (button.x - grid_h) * (dia / grid_h)
+ selecty = (button.y - grid_h) * (dia / grid_h)
+ selectx = round(selectx / step) * step
+ selecty = round(selecty / step) * step
+ grid_bot.set_text(str(selectx) + ':' + str(selecty))
+ grid.queue_draw()
+
+def test():
+ grid_render(None, 1, 1)
+ grid.connect("delete-event", Gtk.main_quit)
+ Gtk.main()
+
+
+def grid_render(win, st, di):
+ global grid
+ if not grid is None:
+ grid.destroy()
+ global step
+ step = st
+ global dia
+ dia = di
+ global selectx
+ selectx = None
+ global selecty
+ selecty = None
+ grid = Gtk.Window()
+ grid.set_title("LIDT: Grid")
+ grid.set_attached_to(win)
+ grid.set_destroy_with_parent(True)
+
+ box = Gtk.Box(orientation = Gtk.Orientation.VERTICAL)
+ grid.add(box)
+
+ drawarea = Gtk.DrawingArea()
+ drawarea.set_size_request(512, 512)
+ drawarea.set_events(drawarea.get_events() | Gdk.EventMask.BUTTON_PRESS_MASK)
+ drawarea.connect('draw', __grid_draw)
+ drawarea.connect('button-press-event', __grid_button)
+ box.pack_start(drawarea, True, True, 0)
+
+ global grid_bot
+ grid_bot = Gtk.Label('')
+ box.pack_start(grid_bot, False, False, 0)
+
+ grid.show_all()