File: gtk3

package info (click to toggle)
libhinawa 4.0.2-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 540 kB
  • sloc: ansic: 1,901; python: 690; javascript: 5; makefile: 5
file content (91 lines) | stat: -rwxr-xr-x 2,640 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python3

from pathlib import Path
from sys import argv, exit
from signal import SIGINT
from struct import unpack
import common

import gi
gi.require_versions({'GLib': '2.0', 'Hinawa': '4.0', 'Gtk': '3.0'})
from gi.repository import GLib, Hinawa, Gtk


def main() -> int:
    if len(argv) < 2:
        msg = ('One argument is required for path to special file of Linux FireWire character '
               'device')
        common.print_help_with_msg(Path(__file__).name, msg)
        return 1
    cmd, literal = argv[:2]

    try:
        path = common.detect_fw_cdev(literal)
    except Exception as e:
        common.print_help_with_msg(cmd, str(e))
        return 1

    try:
        node = Hinawa.FwNode.new()
        _ = node.open(str(path), 0)
        common.print_fw_node_information(node)
    except Exception as e:
        msg = str(e)
        common.print_help_with_msg(cmd, msg)
        return 1

    with common.listen_node_event(node, path):
        sample = Sample(node)
        sample.show_all()
        node.connect('disconnected', lambda n, s: Gtk.main_quit(), sample)
        Gtk.main()

    return 0


class Sample(Gtk.Window):
    def __init__(self, node):
        Gtk.Window.__init__(self, title="Hinawa-4.0 gir sample")

        self.node = node
        self.req = Hinawa.FwReq.new()

        grid = Gtk.Grid(row_spacing=10, row_homogeneous=True,
                        column_spacing=10, column_homogeneous=True,
                        margin_start=20, margin_end=20, margin_top=20,
                        margin_bottom=20)
        self.add(grid)

        button = Gtk.Button(label="Read")
        button.connect("clicked", self.run_transaction)
        grid.attach(button, 0, 0, 1, 1)

        button = Gtk.Button(label="_Close", use_underline=True)
        button.connect("clicked", lambda s: Gtk.main_quit())
        grid.attach(button, 1, 0, 1, 1)

        self.entry = Gtk.Entry()
        self.entry.set_text("0xfffff0000980")
        grid.attach(self.entry, 0, 1, 1, 1)

        self.label = Gtk.Label(label="result")
        self.label.set_text("0x00000000")
        grid.attach(self.label, 1, 1, 1, 1)

        # handle unix signal
        GLib.unix_signal_add(GLib.PRIORITY_HIGH, SIGINT, lambda s: Gtk.main_quit(), self)

    def run_transaction(self, button):
        addr = int(self.entry.get_text(), 16)
        frames = [0] * 4
        try:
            quadlet = common.read_quadlet(self.node, self.req, addr)
        except Exception as e:
            print(e)

        label = '0x{:08x}'.format(quadlet)
        self.label.set_text(label)


if __name__ == '__main__':
    exit(main())