meine main.py sieht so aus.
Ich muss noch ein paar Details hinzufügen, bis Stackoverflow mich fragen lässt. Aber ich denke, der Code spricht für sich.
Code: Select all
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.widget import Widget
from kivy.graphics import Line, Color
from kivy.properties import ListProperty
import os
class CamMeasureWidget(BoxLayout):
def load_file(self):
"""Test: Datei laden und visualisieren"""
try:
with open("daten.bin", "rb") as f:
data = f.read()
self.ids.plot.data = list(data)
print(f"{len(data)} Bytes geladen.")
except Exception as e:
print("Fehler beim Laden:", e)
class BytePlot(Widget):
data = ListProperty([]) # Liste von Bytes
def __init__(self, **kwargs):
super().__init__(**kwargs)
with self.canvas:
Color(0, 1, 0, 1)
Line(circle=(self.width / 2, self.height / 2, 25), width=2)
Line(rectangle=(0, 0, self.width, self.height), width=5)
def on_data(self, instance, value):
"""Neuzeichnen wenn Daten geändert werden."""
self.draw_data()
def draw_data(self):
self.canvas.clear()
if not self.data:
return
with self.canvas:
Color(0, 1, 0) # grün
width = self.width
height = self.height
n = len(self.data)
if n == 0:
return
# Abstand zwischen Linien
x_step = width / n
for i, b in enumerate(self.data):
x = i * x_step
line_height = (b / 255) * height
Line(points=[x, 0, x, line_height], width=1)
class CamMeasureApp(App):
def build(self):
return CamMeasureWidget()
if __name__ == '__main__':
CamMeasureApp().run()
Code: Select all
#:kivy 1.0.9
:
# BoxLayout:
orientation: "vertical"
spacing: 10
padding: 10
BytePlot:
id: plot
Button:
text: "Start (Datei laden)"
on_release: root.load_file()
Button:
text: "Stopp"
on_release: print("Stopp gedrückt")
Was stimmt hier nicht?
Screenshot
Grüße aus Bayern
Mobile version