I am new to python and also to kivy so i cant really get what is the problem.
I tried the new thread outside the root gui class. I tried it outside the root class. Everytime the same.
Maybe the problem is that i dont really understand the deep working of GUIs. How Imagine it is that GUI is the main thread, so if I open Graph, GUI must stops ltill the graph is closed... That works. So I dont really understand why it crashes when I create paralel thread that process the Graph.
class STORAGEofVARIABLES():
COLORS={'red':'r','yellow':'y','blue':'b','green':'g','magenta':'m','black':'k','cyan':'c'}
pass
STORAGE=STORAGEofVARIABLES()
class gui(BoxLayout):
PlotActive=0
COLORS={'red':'r','yellow':'y','blue':'b','green':'g','magenta':'m','black':'k','cyan':'c'}
##VALUES
def __init__(self, *args, **kwargs):
super(gui, self).__init__(*args, **kwargs)
#Clock.schedule_interval(self.Thr, 1.5)
def Thr(self):
print('------')
print('Number of Active Threads:' + str(threading.active_count()))
print('Current working Thread: '+str(threading.current_thread().name))
print('------')
def save_values(self):
OsaX = self.ids.OsaX
OsaY = self.ids.OsaY
Hodnota=self.ids.slajd
Code=self.ids.codas
COLORKA=self.ids.spin
MARKER=self.ids.MarkSpinner
GRID=self.ids.grid
TLEGEND=self.ids.tlegenda
LEGEND=self.ids.legenda
TITLEGRAPH=self.ids.Titlegraph
STORAGE.Y_LABEL = OsaY.text
STORAGE.X_LABEL = OsaX.text
STORAGE.TITLE_LABEL = TITLEGRAPH.text
STORAGE.CODE = Code.text
STORAGE.SLIDER_VALUE = Hodnota.value
STORAGE.GRID = GRID.active
STORAGE.TLEGEND = TLEGEND.text
STORAGE.LEGEND = LEGEND.active
STORAGE.COLORKA = COLORKA.text
STORAGE.MARKER=MARKER.text
STORAGE.PlotActive = threading.active_count()
STORAGE.MARKER=MARKER.text
Thread() # Start the thread
def Thread():
t = threading.Thread(target=BasicGraph)
t.daemon = True
t.start()
def BasicGraph():
x, y = [], []
loc = {}
try:
exec(STORAGE.CODE, {}, loc)
x = loc['x']
y = loc['y']
except:
print("Chyba v kodu")
plt.plot(x, y, label=STORAGE.TLEGEND, marker=STORAGE.MARKER, linewidth=STORAGE.SLIDER_VALUE,
color=STORAGE.COLORS[STORAGE.COLORKA])
if STORAGE.LEGEND == True:
plt.legend()
if STORAGE.GRID == True:
plt.grid(color=STORAGE.COLORS[STORAGE.COLORKA])
plt.title(STORAGE.TITLE_LABEL)
plt.xlabel(STORAGE.X_LABEL)
plt.ylabel(STORAGE.Y_LABEL)
print(STORAGE.PlotActive) # HOW MANY THREADS ACTIVE
if STORAGE.PlotActive == 1:
plt.show()
else:
plt.draw()
class MainWindowApp(App):
pass
if __name__=='__main__':
MainWindowApp().run()