ns2 0.2.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. ns2/__init__.py +0 -0
  2. ns2/core.py +0 -0
  3. ns2/dbus/__init__.py +0 -0
  4. ns2/dbus/dbus.py +13 -0
  5. ns2/lib/__init__.py +0 -0
  6. ns2/lib/accounts.py +130 -0
  7. ns2/lib/commands.py +32 -0
  8. ns2/lib/firewalld.py +167 -0
  9. ns2/lib/introspection/org.fedoraproject.FirewallD1.config.xml +3 -0
  10. ns2/lib/introspection/org.fedoraproject.FirewallD1.xml +763 -0
  11. ns2/lib/introspection/org.freedesktop.NetworkManager.AccessPoint.xml +106 -0
  12. ns2/lib/introspection/org.freedesktop.NetworkManager.AgentManager.xml +43 -0
  13. ns2/lib/introspection/org.freedesktop.NetworkManager.Checkpoint.xml +36 -0
  14. ns2/lib/introspection/org.freedesktop.NetworkManager.Connection.Active.xml +185 -0
  15. ns2/lib/introspection/org.freedesktop.NetworkManager.DHCP4Config.xml +21 -0
  16. ns2/lib/introspection/org.freedesktop.NetworkManager.DHCP6Config.xml +20 -0
  17. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Adsl.xml +21 -0
  18. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Bluetooth.xml +36 -0
  19. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Bond.xml +40 -0
  20. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Bridge.xml +41 -0
  21. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Dummy.xml +20 -0
  22. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Generic.xml +27 -0
  23. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Hsr.xml +51 -0
  24. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.IPTunnel.xml +107 -0
  25. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Infiniband.xml +31 -0
  26. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Ipvlan.xml +38 -0
  27. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Loopback.xml +8 -0
  28. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Lowpan.xml +27 -0
  29. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Macsec.xml +109 -0
  30. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Macvlan.xml +39 -0
  31. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Modem.xml +62 -0
  32. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.OlpcMesh.xml +34 -0
  33. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.OvsBridge.xml +21 -0
  34. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.OvsInterface.xml +11 -0
  35. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.OvsPort.xml +21 -0
  36. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Ppp.xml +11 -0
  37. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Statistics.xml +35 -0
  38. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Team.xml +48 -0
  39. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Tun.xml +65 -0
  40. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Veth.xml +18 -0
  41. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Vlan.xml +45 -0
  42. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Vrf.xml +18 -0
  43. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Vxlan.xml +139 -0
  44. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.WiMax.xml +109 -0
  45. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.WifiP2P.xml +76 -0
  46. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.WireGuard.xml +38 -0
  47. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Wired.xml +53 -0
  48. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Wireless.xml +131 -0
  49. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.Wpan.xml +20 -0
  50. ns2/lib/introspection/org.freedesktop.NetworkManager.Device.xml +407 -0
  51. ns2/lib/introspection/org.freedesktop.NetworkManager.DnsManager.xml +40 -0
  52. ns2/lib/introspection/org.freedesktop.NetworkManager.IP4Config.xml +125 -0
  53. ns2/lib/introspection/org.freedesktop.NetworkManager.IP6Config.xml +95 -0
  54. ns2/lib/introspection/org.freedesktop.NetworkManager.PPP.xml +34 -0
  55. ns2/lib/introspection/org.freedesktop.NetworkManager.SecretAgent.xml +94 -0
  56. ns2/lib/introspection/org.freedesktop.NetworkManager.Settings.Connection.xml +224 -0
  57. ns2/lib/introspection/org.freedesktop.NetworkManager.Settings.xml +233 -0
  58. ns2/lib/introspection/org.freedesktop.NetworkManager.VPN.Connection.xml +42 -0
  59. ns2/lib/introspection/org.freedesktop.NetworkManager.VPN.Plugin.xml +204 -0
  60. ns2/lib/introspection/org.freedesktop.NetworkManager.WiMax.Nsp.xml +35 -0
  61. ns2/lib/introspection/org.freedesktop.NetworkManager.WifiP2PPeer.xml +91 -0
  62. ns2/lib/introspection/org.freedesktop.NetworkManager.xml +598 -0
  63. ns2/lib/lib.py +0 -0
  64. ns2/lib/network_delay.py +92 -0
  65. ns2/lib/networking.py +528 -0
  66. ns2/lib/ntl.py +188 -0
  67. ns2/lib/pam_client.py +37 -0
  68. ns2/lib/ping_data_collector.py +37 -0
  69. ns2/lib/snmp.py +511 -0
  70. ns2/lib/socket.py +132 -0
  71. ns2/lib/socket_client.py +62 -0
  72. ns2/lib/systemd.py +151 -0
  73. ns2/lib/test.py +374 -0
  74. ns2/lib/udp_client.py +227 -0
  75. ns2/lib/udp_server.py +167 -0
  76. ns2/snmp/__init__.py +0 -0
  77. ns2/snmp/ns_dbus_service.py +38 -0
  78. ns2/snmp/pam_interface.py +19 -0
  79. ns2/snmp/snmp_interface.py +66 -0
  80. ns2/ui/__init__.py +0 -0
  81. ns2/ui/assets/NOVUS_LOGO.svg +105 -0
  82. ns2/ui/assets/favicon.png +0 -0
  83. ns2/ui/firewalld_page.py +375 -0
  84. ns2/ui/fpga_page.py +24 -0
  85. ns2/ui/login.py +65 -0
  86. ns2/ui/main.py +200 -0
  87. ns2/ui/networking_page.py +406 -0
  88. ns2/ui/ntp.py +105 -0
  89. ns2/ui/root.py +31 -0
  90. ns2/ui/snmp_page.py +353 -0
  91. ns2/ui/terminal.py +65 -0
  92. ns2/ui/tests_page.py +116 -0
  93. ns2/ui/theme.py +25 -0
  94. ns2/utils.py +5 -0
  95. ns2-0.2.6.dist-info/METADATA +78 -0
  96. ns2-0.2.6.dist-info/RECORD +98 -0
  97. ns2-0.2.6.dist-info/WHEEL +4 -0
  98. ns2-0.2.6.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,406 @@
1
+ from nicegui import ui, app, binding
2
+ from ns.lib.networking import *
3
+ from ns.lib.firewalld import *
4
+ from dbus_next.signature import Variant
5
+ from dbus_next.errors import DBusError
6
+ from dbus_next.aio.proxy_object import ProxyInterface
7
+ from ns.dbus import dbus
8
+
9
+ from ns.ui.firewalld_page import firewall_status
10
+
11
+
12
+
13
+
14
+ async def network_page():
15
+
16
+ with ui.column().classes("w-full"):
17
+ with ui.card().classes("w-full").props('flat'):
18
+ await firewall_status(True)
19
+
20
+ interfaces = await GetInterfacesAndAddresses(dbus.AppBus)
21
+
22
+ interface_table = ui.table(
23
+ title="Interfaces",
24
+ rows=interfaces,
25
+ # rows=[{'d':'v'}],
26
+ column_defaults={
27
+ "align": "left",
28
+ "headerClasses": "uppercase text-primary",
29
+ },
30
+ ).classes("w-full").props('flat')
31
+
32
+ interface_table.add_slot(
33
+ "body-cell-name",
34
+ """
35
+ <q-td :props="props">
36
+ <a :href="'/networking/' + props.row.name"
37
+ class="text-accent cursor-pointer hover:underline"
38
+ >
39
+ {{ props.value }}
40
+ </a>
41
+ </q-td>
42
+ """,
43
+ )
44
+ interface_table.add_slot(
45
+ "body-cell-addresses",
46
+ """
47
+ <q-td :props="props" class="font-bold text-sm">
48
+ {{ props.value }}
49
+ </q-td>
50
+ """,
51
+ )
52
+
53
+ #with ui.card():
54
+
55
+
56
+
57
+
58
+ @ui.refreshable
59
+ async def interface_card(nm : ProxyInterface, device: ProxyInterface, interface):
60
+
61
+ with ui.card().props('flat'):
62
+ with ui.row():
63
+ ui.link("Networking", "/networking").classes('text-accent')
64
+ ui.label(">")
65
+ ui.label(interface.Name)
66
+ ui.label(interface.Active)
67
+
68
+ with ui.row().classes("w-full items-center justify-between"):
69
+ ui.label().classes("text-h6").bind_text(interface, "Name")
70
+ ui.label().classes("text-h6").bind_text(interface, "HardwareAddress")
71
+ async def connection_sw_cb(e):
72
+ action = "enable" if e.sender.value else "disable"
73
+ with ui.dialog() as dialog, ui.card():
74
+ ui.label(f"Are you sure you want to {action} this connection?")
75
+ with ui.row():
76
+ ui.button(
77
+ "Cancel", on_click=lambda: dialog.submit("Cancel")
78
+ ).props("flat color=accent align=left")
79
+ ui.button(
80
+ f"{action}", on_click=lambda: dialog.submit(action)
81
+ ).props("flat color=accent align=left")
82
+ result = await dialog
83
+ if result == "enable":
84
+ await nm.call_activate_connection("/", interface._dev_path, "/")
85
+ elif result == "disable":
86
+ await nm.call_deactivate_connection(interface._act_con_path)
87
+ else:
88
+ print('canceled')
89
+
90
+ ui.switch("Connected").on("click", lambda e: connection_sw_cb(e)).props(
91
+ "flat color=accent"
92
+ ).bind_value_from(interface, "Active")
93
+ ui.separator()
94
+
95
+ ui.spinner(size='lg').bind_visibility_from(interface, "Active", backward=lambda e: (not e))
96
+
97
+ with ui.column().classes("flex-1 gap-4"):
98
+ with ui.row().classes("flex-1 gap-16"):
99
+ ui.label("Status").classes("font-bold w-8")
100
+ ui.label().bind_text_from(interface, "Status")
101
+ with ui.row().classes("flex-1 gap-16"):
102
+ ui.label("State").classes("font-bold w-8")
103
+ ui.label().bind_text_from(interface, "StateString")
104
+ with ui.row().classes("flex-1 gap-16"):
105
+ ui.label("Carrier").classes("font-bold w-8")
106
+ ui.label().bind_text_from(interface, "Carrier")
107
+ with ui.row().classes("flex-1 gap-16"):
108
+ ui.label("General").classes("font-bold w-8")
109
+ async def auto_connect_cb(e):
110
+ return
111
+ device = GetDevice(dbus.Bus, interface._dev_path)
112
+ settings = await GetSettings(device)
113
+ settings["connection"]["autoconnect"] = Variant(
114
+ "b", e.value
115
+ )
116
+ # await connection.call_update2(settings, 0x1, {})
117
+ # await device.call_reapply(settings, 0, 0)
118
+ ui.checkbox(
119
+ "Connect automatically", on_change=auto_connect_cb
120
+ ).props("flat color=accent dense").bind_value(
121
+ interface, "AutoConnect"
122
+ )
123
+
124
+
125
+ with ui.row().classes("flex-1 gap-16"):
126
+ ui.label("IPv4").classes("font-bold w-8")
127
+ ui.label().bind_text_from(interface, "Ip4")
128
+ ui.label("Edit").classes(
129
+ "text-accent cursor-pointer hover:underline"
130
+ ).on("click", lambda: edit_ip_connection('ipv4', device))
131
+
132
+
133
+ with ui.row().classes("flex-1 gap-16"):
134
+ ui.label("IPv6").classes("font-bold w-8")
135
+ ui.label().bind_text_from(interface, "Ip6")
136
+ ui.label("Edit").classes(
137
+ "text-accent cursor-pointer hover:underline"
138
+ ).on("click", lambda: edit_ip_connection('ipv6', device))
139
+
140
+
141
+
142
+ async def interface_page(interface_name: str):
143
+ nm = GetNetworkManager(dbus.AppBus)
144
+
145
+ dev_path = await nm.call_get_device_by_ip_iface(interface_name)
146
+
147
+ device = GetDevice(dbus.AppBus, dev_path)
148
+
149
+ interface = await GetInterfaceData(dbus.AppBus, nm, interface_name)
150
+
151
+ await interface_card(nm, device, interface)
152
+
153
+ async def state_changed_cb(u1, u2, u3):
154
+
155
+ print(u1, u2, u3)
156
+ # Re-fetch the interface data to get the new state
157
+ updated_interface = await GetInterfaceData(nm, interface_name)
158
+
159
+ # Update the existing interface object's properties
160
+ # This will trigger the UI bindings to update automatically
161
+ interface.Status = updated_interface.Status
162
+ interface.StateString = updated_interface.StateString
163
+ interface.StateNumber = updated_interface.StateNumber
164
+ interface.Carrier = updated_interface.Carrier
165
+ interface.Active = updated_interface.Active
166
+ interface.Ip4 = updated_interface.Ip4
167
+ interface.Ip6 = updated_interface.Ip6
168
+ # Add any other properties that might change
169
+
170
+ device.on_state_changed(state_changed_cb)
171
+
172
+
173
+
174
+
175
+ async def edit_ip_connection(version: str, device: ProxyInterface):
176
+
177
+ settings = await GetSettings(dbus.AppBus, device)
178
+
179
+ ip = GetIp(version, settings)
180
+
181
+ connection = await GetConnectionFromDevice(dbus.AppBus, device)
182
+
183
+ def add_ip_address(a: str = None, p: str = None, g: str = None):
184
+ ip.AddressData.append(IpAddress(a, p))
185
+ ip_address_list.refresh()
186
+
187
+ def remove_ip_address(addr):
188
+ ip.AddressData.remove(addr)
189
+ ip_address_list.refresh()
190
+
191
+ def add_dns_server(server: str = None):
192
+ ip.DnsData.append(DnsServer(server))
193
+ dns_server_list.refresh()
194
+
195
+ def remove_dns_server(dns):
196
+ ip.DnsData.remove(dns)
197
+ dns_server_list.refresh()
198
+
199
+ def add_dns_search(search: str = None):
200
+ ip.DnsSearch.append(DnsServer(search))
201
+ dns_search_list.refresh()
202
+
203
+ def remove_dns_search(search):
204
+ ip.DnsSearch.remove(search)
205
+ dns_search_list.refresh()
206
+
207
+ def add_route(
208
+ Address: str = None, Prefix: str = None, NextHop: str = None, Metric: str = None
209
+ ):
210
+ ip.RouteData.append(IpRoute(Address, Prefix, NextHop, Metric))
211
+ route_list.refresh()
212
+
213
+ def remove_route(route):
214
+ ip.RouteData.remove(route)
215
+ route_list.refresh()
216
+
217
+ @ui.refreshable
218
+ async def ip_address_list():
219
+ for addr in ip.AddressData:
220
+ with ui.row():
221
+ ui.input(label="Address").props("dense").classes("flex-1").bind_value(
222
+ addr, "Address"
223
+ )
224
+ ui.input(label="Prefix or netmask").props("dense").classes(
225
+ "flex-1"
226
+ ).bind_value(addr, "Prefix")
227
+ ui.input(label="Gateway").props("dense").classes("flex-1").bind_value(
228
+ ip, "Gateway"
229
+ )
230
+ ui.button(
231
+ icon="delete", on_click=lambda a=addr: remove_ip_address(a)
232
+ ).props("flat color=accent").props("dense")
233
+
234
+ @ui.refreshable
235
+ async def dns_server_list():
236
+ for dns in ip.DnsData:
237
+ with ui.row():
238
+ ui.input(label="Server").props("dense").classes("flex-1").bind_value(
239
+ dns, "Server"
240
+ )
241
+ ui.button(
242
+ icon="delete", on_click=lambda d=dns: remove_dns_server(d)
243
+ ).props("flat color=accent").props("dense")
244
+
245
+ @ui.refreshable
246
+ async def dns_search_list():
247
+ for search in ip.DnsSearch:
248
+ with ui.row():
249
+ ui.input(label="Server").props("dense").classes("flex-1").bind_value(
250
+ search, "Server"
251
+ )
252
+ ui.button(
253
+ icon="delete", on_click=lambda d=search: remove_dns_search(d)
254
+ ).props("flat color=accent").props("dense")
255
+
256
+ @ui.refreshable
257
+ async def route_list():
258
+ for route in ip.RouteData:
259
+ with ui.row():
260
+ ui.input(label="Server").props("dense").classes("flex-1").bind_value(
261
+ route, "Dest"
262
+ )
263
+ ui.input(label="Prefix or netmask").props("dense").classes(
264
+ "flex-1"
265
+ ).bind_value(route, "Prefix")
266
+ ui.input(label="Next Hop").props("dense").classes("flex-1").bind_value(
267
+ route, "NextHop"
268
+ )
269
+ ui.input(label="Metric").props("dense").classes("flex-1").bind_value(
270
+ route, "Metric"
271
+ )
272
+
273
+ ui.button(
274
+ icon="delete", on_click=lambda d=route: remove_route(d)
275
+ ).props("flat color=accent").props("dense")
276
+
277
+ ###
278
+ with ui.dialog() as dialog:
279
+ with ui.card().classes("w-full self-start max-h-[90vh] overflow-y-auto"):
280
+ ui.label("IPv4 settings").classes("text-h5")
281
+ with ui.column().classes("w-full"):
282
+
283
+ ### ADDRESSES
284
+ with ui.row().classes("w-full justify-between"):
285
+ ui.label("Addresses")
286
+ with ui.row():
287
+
288
+ def on_method_change(e):
289
+ # SetIp4Method(settings, e.value)
290
+ return
291
+
292
+ ui.select(
293
+ options=["disabled", "auto", "manual"],
294
+ on_change=on_method_change,
295
+ ).props("dense").classes("w-24").bind_value(ip, "Method")
296
+
297
+ ip_address_button = ui.button(
298
+ icon="add", on_click=add_ip_address
299
+ ).props("flat color=accent dense")
300
+
301
+ with ui.column().classes("items-center justify-between gap-4 w-full"):
302
+ await ip_address_list()
303
+ print()
304
+ ###
305
+
306
+ ### DNS SERVER
307
+ ui.separator()
308
+ with ui.row().classes("w-full justify-between"):
309
+ ui.label("DNS Servers")
310
+ with ui.row():
311
+
312
+ dns_server_switch = (
313
+ ui.switch("Automatic")
314
+ .props("flat color=accent dense")
315
+ .classes("w-24")
316
+ .bind_value(
317
+ ip,
318
+ "IgnoreAutoDns",
319
+ forward=lambda x: not x,
320
+ backward=lambda x: not x,
321
+ )
322
+ )
323
+ dns_server_button = ui.button(
324
+ icon="add",
325
+ on_click=add_dns_server,
326
+ ).props("flat color=accent dense")
327
+ with ui.column().classes("items-center justify-between gap-4 w-full"):
328
+ await dns_server_list()
329
+ ###
330
+
331
+ ### DNS SEARCH
332
+ ui.separator()
333
+ with ui.row().classes("w-full justify-between"):
334
+ ui.label("DNS Searches")
335
+ with ui.row():
336
+ dns_search_button = (
337
+ ui.button(
338
+ icon="add",
339
+ on_click=add_dns_search,
340
+ )
341
+ .props("flat color=accent")
342
+ .props("dense")
343
+ )
344
+ with ui.column().classes("items-center justify-between gap-4 w-full"):
345
+ await dns_search_list()
346
+ ###
347
+
348
+ ### ROUTES
349
+ ui.separator()
350
+ with ui.row().classes("w-full justify-between"):
351
+ ui.label("Routes")
352
+ with ui.row():
353
+ route_switch = (
354
+ ui.switch("Automatic")
355
+ .props("flat color=accent")
356
+ .props("dense")
357
+ .classes("w-24")
358
+ .bind_value(
359
+ ip,
360
+ "IgnoreAutoRoutes",
361
+ forward=lambda x: not x,
362
+ backward=lambda x: not x,
363
+ )
364
+ )
365
+ route_button = (
366
+ ui.button(icon="add", on_click=add_route)
367
+ .props("flat color=accent")
368
+ .props("dense")
369
+ )
370
+ with ui.column().classes("items-center justify-between gap-4 w-full"):
371
+ await route_list()
372
+ ###
373
+
374
+ with ui.row().classes("items-center justify-between gap-4 w-full"):
375
+
376
+ async def on_save_cb():
377
+ try:
378
+
379
+ _settings = SetIp(ip, version, settings)
380
+
381
+ _settings = ApplyModes(version, _settings)
382
+
383
+ await connection.call_update2(_settings, 0x1, {})
384
+
385
+ await device.call_reapply(_settings, 0, 0)
386
+
387
+ dialog.close()
388
+
389
+ except DBusError as e:
390
+ ui.notify(e, type="negative")
391
+ # dialog.close()
392
+
393
+ except Exception as e:
394
+ print(e)
395
+ ui.notify("Please correct the errors", type="negative")
396
+
397
+ def on_cancel_cb():
398
+ dialog.close()
399
+
400
+ save_button = ui.button("save", on_click=on_save_cb).props(
401
+ "flat color=accent align=left"
402
+ )
403
+ cancel_button = ui.button("cancel", on_click=on_cancel_cb).props(
404
+ "flat color=accent align=left"
405
+ )
406
+ await dialog
ns2/ui/ntp.py ADDED
@@ -0,0 +1,105 @@
1
+ from ns.lib.socket import *
2
+ from nicegui import ui, events
3
+
4
+ import plotly.graph_objects as go
5
+ from ns.dbus import dbus
6
+
7
+
8
+ from ns.lib.ntl import NtpServerProperties
9
+
10
+
11
+
12
+
13
+ async def writeNtlConfig(content: str):
14
+ content.splitlines()
15
+ for line in content.splitlines():
16
+ if line.startswith("$WC"):
17
+ await write_socket(line)
18
+
19
+ def parse_lines_for_num(lines :list[str]) -> list:
20
+ frequencies = []
21
+
22
+ line: str
23
+ for line in lines:
24
+ if line.startswith("$GPNVS,9,"):
25
+ fields = line.split(',')
26
+ freq = fields[2].strip('+')
27
+ frequencies.append(float(freq))
28
+
29
+ return frequencies
30
+
31
+
32
+
33
+
34
+
35
+ async def ntp_page():
36
+ with ui.column() as pageContainer:
37
+ ui.label("NTP").classes("text-h5")
38
+ with ui.row():
39
+ term = ui.xterm({'convertEol': True})
40
+
41
+
42
+ socket_receive.subscribe(lambda _data: term.write(_data))
43
+
44
+
45
+ #term.on_data(lambda e: term.write(e.data.replace('\r', '\n\r').replace('\x7f', '\x1b[0D\x1b[0K')))
46
+
47
+ with ui.card():
48
+ async def handle_upload(e: events.UploadEventArguments):
49
+ ui.notify(f'Uploaded {e.file.name}')
50
+ await WriteConfig(await e.file.text())
51
+
52
+ ui.upload(label="FPGA Config Upload", on_upload=handle_upload).props("flat color=accent")
53
+
54
+
55
+
56
+
57
+ def build_plot():
58
+ # initial read
59
+ with open('data.txt', 'r') as f:
60
+ lines = f.readlines()
61
+ y = parse_lines_for_num(lines)
62
+
63
+ fig = go.Figure(go.Scatter(x=list(range(len(y))),y=y))
64
+ fig.update_layout(margin=dict(l=0, r=0, t=0, b=0))
65
+
66
+ plot = ui.plotly(fig).classes('w-full h-40')
67
+ return plot, fig
68
+
69
+ plot, fig = build_plot()
70
+
71
+ def refresh_plot():
72
+ # re-read file and update trace data
73
+ with open('data.txt', 'r') as f:
74
+ lines = f.readlines()
75
+ y = parse_lines_for_num(lines)
76
+
77
+ # update the existing figure instead of creating a new one
78
+ fig.data[0].y = y
79
+ plot.update()
80
+
81
+ # call this whenever you get new data
82
+ #socket_received.subscribe(lambda _data: refresh_plot())
83
+
84
+ ui.timer(1, refresh_plot)
85
+
86
+ @ui.refreshable
87
+ async def ntp_card():
88
+ with ui.card():
89
+ ui.button("read ntp stuff", on_click=ntp_card.refresh).props("flat color=accent align=left")
90
+
91
+ ntpProps = await ReadNtlProperties(22, NtpServerProperties)
92
+
93
+
94
+ ui.json_editor({'content': {'json': ntpProps}},
95
+ on_select=lambda e: ui.notify(f'Select: {e}'),
96
+ on_change=lambda e: ui.notify(f'Change: {e}'))
97
+
98
+
99
+ await ntp_card()
100
+
101
+
102
+
103
+
104
+
105
+
ns2/ui/root.py ADDED
@@ -0,0 +1,31 @@
1
+ from nicegui import ui, app
2
+
3
+ def clear_user():
4
+ print("hello")
5
+ app.storage.user.clear()
6
+
7
+
8
+
9
+
10
+ async def root_page():
11
+
12
+ ui.label("Overview - root page").classes("text-h5")
13
+
14
+
15
+
16
+ #v2s, v3s = GetUsers()
17
+ #print(v2s, v3s)
18
+ #ui.button("clear", on_click= clear_user)
19
+
20
+ #values = []
21
+ #async def update_value():
22
+ # print("test")
23
+ # values.append(await get_pps_ave_diff())
24
+ #
25
+ #ui.timer(1, update_value)
26
+ #
27
+ #ui.echart({
28
+ #'xAxis': {'type': 'category'},
29
+ #'yAxis': {'axisLabel': {':formatter': 'value => "$" + value'}},
30
+ #'series': [{'type': 'line', 'data': values}],
31
+ #})