summaryrefslogtreecommitdiff
path: root/lidt/__init__.py
blob: 5966a987c4fc812990745ebc9762ac81ae7edcd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# 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 os
import sys

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

#from . import lidt
import lidt
#from . import plotout
import plotout

L = None
builder = None

label_list = [
    "actarea",
    "spotzise",
    "numspots",
    "disttestsitess",
    "disttestsitesshex",
    "numpulsperstep",
    "numsitespulsstep",
    "numofsiteseng",
    "numengavsample",
    "numofneededsites",
    "numofneededsitesbool"
    ]

def updategtk():
    if builder is None:
        return
    #print("render")
    for edt in label_list:
        #print(edt)
        edtobj = builder.get_object(edt)
        edtobj.set_text(str(eval("L." + edt)))

class Handler:
    def __init__(self, lidt):
        self.lidt = lidt

    def onDeleteWindow(self, *args):
        Gtk.main_quit(*args)

    def onRootChange(self, editable):
        #print("signal " + Gtk.Buildable.get_name(editable))
        try:
            eval("self.lidt.set_" + Gtk.Buildable.get_name(editable) + "(float(editable.get_text()))")
            self.lidt.calc()
        except ValueError:
            print("Invalid input!")

    def render_click(widg, _):
        plotout.grid_render(window, L.disttestsitess, L.beamdia)


def main():
    global L
    L = lidt.Lidt(updategtk)

    glade_file = os.path.join(os.path.dirname(__file__), "form.glade")

    global builder
    builder = Gtk.Builder()
    builder.add_from_file(glade_file)
    builder.connect_signals(Handler(L))

    updategtk()

    global window
    window = builder.get_object("window")
    window.show_all()

    Gtk.main()


if __name__ == "__main__":
    main()