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

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