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.7KB

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