You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UIViewTKinter.py 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. try:
  2. from Tkinter import *
  3. import tkFileDialog as fd
  4. except ImportError:
  5. from tkinter import *
  6. from tkinter import filedialog as fd
  7. #from tkinter import font
  8. from UIController import *
  9. class View(Tk):
  10. def __init__(self, c, *args, **kwargs):
  11. Tk.__init__(self, *args, **kwargs)
  12. self.controller = c
  13. self.title("Visuelles Spelling")
  14. self.h = 800
  15. self.w = 1000
  16. self.geometry('{}x{}'.format(self.w,self.h))
  17. self.faktor = [(0.0675),(0.7325), (0.2)]
  18. #self.resizable(height=False, width= False)
  19. self.layout = {
  20. "background": "#00001E",
  21. "backgroundBtn": "#1C86EE",
  22. "fontColor": "#FFFFFF",
  23. "backgroundBar": "#00002E",
  24. "font": ('Calibri', 25, 'bold'),
  25. "fontSmall": ('Calibri', 10, 'bold'),
  26. "fontInfo": ('Calibri', 25)
  27. }
  28. self.createTopFrame()
  29. self.createMainFrame()
  30. self.createBottomFrame()
  31. self.bind("<Configure>", self.adjustSize)
  32. self.protocol("WM_DELETE_WINDOW", self.onClosing)
  33. def changeFrame(self, pageName):
  34. frame = self.frames[pageName]
  35. frame.tkraise()
  36. def adjustSize(self, event):
  37. if(str(event.widget) =="."):
  38. self.h = event.height
  39. self.w = event.width
  40. self.topFrame.configure(height=(self.h*self.faktor[0]), width=self.w)
  41. self.mainFrame.configure(height=(self.h*self.faktor[1]), width=self.w)
  42. self.bottomFrame.configure(height=(self.h*self.faktor[2]), width=self.w)
  43. self.container.configure(height=(self.h*self.faktor[1]), width=self.w)
  44. for f in self.frames:
  45. self.frames[f].configure(height=(self.h*self.faktor[1]), width=self.w)
  46. self.frames[f].adjustSize(height=(self.h*self.faktor[1]), width=self.w)
  47. def onClosing(self):
  48. print("closing")
  49. self.controller.commandStop()
  50. print("destroy")
  51. self.destroy()
  52. def createTopFrame(self):
  53. self.topFrame = Frame(self, bg=self.layout["backgroundBar"], height=50, width=500)
  54. self.changeBtn = Button(self.topFrame, text="Wechsel zu taktilen BCI", command=lambda: self.controller.actionPerformed("wechsel"), height=2, width = 25, font=self.layout["fontSmall"], bg=self.layout["backgroundBtn"], fg=self.layout["fontColor"])
  55. self.saveBtn = Button(self.topFrame, text="Auswaehlen der Datei", command=lambda: self.controller.actionPerformed("speicherort"), height=2, width = 25, font=self.layout["fontSmall"], bg=self.layout["backgroundBtn"], fg=self.layout["fontColor"])
  56. #self.setBtn = Button(self.topFrame, text="Auswaehlen der Datei", command=lambda: self.controller.actionPerformed("setFile"), height=2, width = 25, font=self.layout["fontSmall"], bg=self.layout["backgroundBtn"], fg=self.layout["fontColor"])
  57. self.toplabel = Label(self.topFrame, text="visuelles BCI", font=self.layout["font"], bg=self.layout["backgroundBar"], fg=self.layout["fontColor"], )
  58. self.topFrame.grid(column=0, row=0)
  59. self.topFrame.grid_propagate(0)
  60. self.topFrame.pack_propagate(0)
  61. self.changeBtn.grid(column=0, row=0, padx=10,pady=5)
  62. self.saveBtn.grid(column=1, row=0, padx=10, pady=5)
  63. #self.setBtn.grid(column=2, row=0, padx=10, pady=5)
  64. self.toplabel.grid(column=2, row=0, padx=100, pady=2)
  65. def createMainFrame(self):
  66. self.mainFrame = Frame(self, bg=self.layout["background"], height=250, width=500)
  67. self.mainFrame.grid(column=0, row=1)
  68. self.mainFrame.pack_propagate(0)
  69. self.container = Frame(self.mainFrame, bg=self.layout["background"], height=250, width=500)
  70. self.container.pack(side="top", fill="both", expand = True)
  71. self.container.pack_propagate(0)
  72. self.container.grid_propagate(0)
  73. self.frames = {}
  74. for F in (StartPage, WorkingPageTaktil, WorkingPageVisuell):
  75. page_name = F.__name__
  76. frame = F(parent=self.container, controller=self.controller, layout=self.layout)
  77. self.frames[page_name] = frame
  78. frame.grid(row=0, column=0, sticky="nsew")
  79. self.changeFrame("StartPage")
  80. def createBottomFrame(self):
  81. self.bottomFrame = Frame(self, bg=self.layout["backgroundBar"], height=100, width=500)
  82. self.bottomlabel = Label(self.bottomFrame, text="Hier stehen Infos\nGanz viele", justify='left', font=self.layout["fontInfo"], bg=self.layout["backgroundBar"], fg=self.layout["fontColor"])
  83. self.bottomFrame.grid(column=0, row=2)
  84. self.bottomFrame.pack_propagate(0)
  85. self.bottomFrame.grid_propagate(0)
  86. self.bottomlabel.grid(padx=5,pady=5)
  87. def setInfoText(self, text):
  88. self.bottomlabel['text'] = text
  89. def setTitleText(self,text):
  90. self.title(text)
  91. self.toplabel["text"] = text
  92. def setChangeBtnText(self,text):
  93. self.changeBtn["text"] = text
  94. def openfiledialog(self):
  95. path = "Projekte/OpenViBE_visual_BCI-master/openvibe_visual_bci/datasets"
  96. file = fd.askopenfilename(initialdir=path)
  97. return file
  98. def savefiledialog(self):
  99. path = "Projekte/OpenViBE_visual_BCI-master/openvibe_visual_bci/datasets"
  100. file = fd.asksaveasfilename(initialdir=path)
  101. return file
  102. class StartPage(Frame):
  103. def __init__(self, parent, controller, layout):
  104. self.layout = layout
  105. Frame.__init__(self, parent, height=250, width=500, bg=self.layout["background"])
  106. self.grid_propagate(0)
  107. self.pack_propagate(0)
  108. self.controller = controller
  109. self.container = Frame(self, bg=self.layout["background"], height=250, width=500)
  110. self.btnFrame = Frame(self.container, bg=self.layout["background"], height=250, width=250)
  111. self.container.columnconfigure(0, weight=1) # Set weight to row and
  112. self.container.rowconfigure(0, weight=1) # column where the widget is
  113. self.container.grid_propagate(0)
  114. self.container.pack_propagate(0)
  115. self.container.pack()
  116. self.btnFrame.grid()
  117. testBtn = Button(self.btnFrame, text="copySpelling", command=lambda: self.controller.actionPerformed("test"), height=6, width = 20, font=self.layout["font"], bg=self.layout["backgroundBtn"], fg=self.layout["fontColor"])
  118. testBtn.grid(row=0,column=0, padx=25,pady=25)
  119. freeSpellingBtn = Button(self.btnFrame, text="freeSpelling", command=lambda: self.controller.actionPerformed("freeSpelling"), height=6, width = 20, font=self.layout["font"], bg=self.layout["backgroundBtn"], fg=self.layout["fontColor"])
  120. freeSpellingBtn.grid(row=0, column=1, padx=25,pady=25)
  121. def adjustSize(self, height, width):
  122. self.container.configure(height=height, width= width)
  123. self.btnFrame.configure(height=(height*4)/5, width= width/2)
  124. class WorkingPageTaktil(Frame):
  125. def __init__(self, parent, controller, layout):
  126. self.layout = layout
  127. Frame.__init__(self, parent, height=250, width=500, bg=self.layout["background"])
  128. self.controller = controller
  129. self.columnconfigure(0, weight=1) # Set weight to row and
  130. self.rowconfigure(0, weight=1) # column where the widget is
  131. stopBtn = Button(self, text="stop", command=lambda: self.controller.actionPerformed("stop"), height=4, width = 15, font=self.layout["font"], bg=self.layout["backgroundBtn"], fg=self.layout["fontColor"])
  132. stopBtn.grid()
  133. def adjustSize(self, height, width):
  134. pass
  135. class WorkingPageVisuell(Frame):
  136. def __init__(self, parent, controller, layout):
  137. self.layout = layout
  138. Frame.__init__(self, parent, height=250, width=500, bg=self.layout["background"])
  139. self.controller = controller
  140. self.grid_propagate(0)
  141. self.pack_propagate(0)
  142. self.windowFrame = Frame(self, height=200, width=500, bg=self.layout["background"])
  143. self.windowFrame.grid(column=0, row=0)
  144. self.buttonFrame = Frame(self, height=200, width=500, bg=self.layout["background"])
  145. self.buttonFrame.grid(column=0, row=1)
  146. self.buttonFrame.columnconfigure(0, weight=1) # Set weight to row and
  147. self.buttonFrame.rowconfigure(0, weight=1) # column where the widget is
  148. stopBtn = Button(self.buttonFrame, text="stop", command=lambda: self.controller.actionPerformed("stop"), height=1, width = 15, font=self.layout["font"], bg=self.layout["backgroundBtn"], fg=self.layout["fontColor"])
  149. stopBtn.grid()
  150. def adjustSize(self, height, width):
  151. self.windowFrame.configure(height=(height*4)/5, width= width)
  152. self.buttonFrame.configure(height=(height)/10, width= width)