/
CM Manager.py
164 lines (124 loc) · 5.32 KB
/
CM Manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
"""
Carousel Maze Manager - a program for analysis of data from behavioral neuroscience tasks
Copyright 2013 Štěpán Bahník
This file is part of Carousel Maze Manager.
Carousel Maze Manager is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Carousel Maze Manager is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Carousel Maze Manager. If not, see <http://www.gnu.org/licenses/>.
"""
from tkinter import *
from tkinter import ttk
from urllib.request import urlopen
from time import localtime, strftime
import traceback
import os.path
import os
import sys
sys.path.append(os.path.join(os.getcwd(), "Stuff", "Modules"))
from controller import Controller
from explorer import Explorer
from processor import Processor
from menu import MenuCM
from filestorage import FileStorage
from optionget import optionGet
from options import optionWrite
from dialogbox import DialogBox
from version import version
from window import placeWindow
class GUI(Tk):
"represents GUI"
def __init__(self):
super().__init__()
self.title("CM Manager " + ".".join(version()))
self.option_add("*tearOff", FALSE)
self.resizable(FALSE, FALSE)
'''
used when size of the window is changed for placeWindow arguments
self.after(50, lambda: print(self.winfo_width()))
self.after(50, lambda: print(self.winfo_height()))
'''
placeWindow(self, 1010, 786)
# notebook
self.selectFunction = ttk.Notebook(self)
self.selectFunction.grid()
# FileStorage is associated with the Notebook
self.selectFunction.fileStorage = FileStorage()
self.processor = Processor(self.selectFunction)
self.explorer = Explorer(self.selectFunction)
self.controller = Controller(self.selectFunction)
notepageWidth = 20
self.selectFunction.add(self.processor, text = "{:^{}}".format("Process", notepageWidth))
self.selectFunction.add(self.explorer, text = "{:^{}}".format("Explore", notepageWidth))
self.selectFunction.add(self.controller, text = "{:^{}}".format("Control", notepageWidth))
self.selectFunction.bind("<<NotebookTabChanged>>", lambda e: self.checkProcessing(e))
# menu
self["menu"] = MenuCM(self)
# checks for new messages and versions on the web
if optionGet("CheckMessages", True, "bool"):
self.onStart()
self.mainloop()
def onStart(self):
"checks web for new version and post"
try:
self.checkNewVersion()
except Exception:
pass
try:
self.checkNewPost()
except Exception:
pass
def checkNewVersion(self):
"checks whether there is a new version available"
newVersion = self.returnSiteContent("http://www.cmmanagerweb.appspot.com/version").\
split(".")
versionSeen = optionGet("DontShowVersion", version(), "list")
for i in range(3):
if int(newVersion[i]) > int(versionSeen[i]):
DialogBox(self, title = "New version available", message =
self.returnSiteContent(
"http://www.cmmanagerweb.appspot.com/version/message"),
dontShowOption = "DontShowVersion", optionValue = newVersion)
break
def checkNewPost(self):
"checks whether there is some post with new information on the web"
currentPost = optionGet("WebPostNumber", 0, "int")
webPostNumber = int(self.returnSiteContent("http://www.cmmanagerweb.appspot.com/post"))
if webPostNumber > currentPost:
DialogBox(self, "New information", self.returnSiteContent(
"http://www.cmmanagerweb.appspot.com/post/message"))
optionWrite("WebPostNumber", webPostNumber)
def returnSiteContent(self, link):
"return text obtained from web site"
site = urlopen(link)
text = site.read()
site.close()
text = str(text)[2:-1]
return text
def checkProcessing(self, event):
"""checks whether it is possible for processor and controller to process files and change
states of buttons accordingly"""
self.processor.checkProcessing()
self.controller.checkProcessing()
self.explorer.checkProcessing()
def main():
if optionGet("Developer", False, 'bool'):
GUI()
else:
try:
filepath = os.path.join(os.getcwd(), "Stuff", "Bugs")
writeTime = localtime()
filename = os.path.join(filepath, strftime("%y_%m_%d_%H%M%S", writeTime) +
"_bugs" + ".txt")
with open(filename, mode = "w") as bugfile:
sys.stderr = bugfile
GUI()
finally:
bugfile.close()
if __name__ == "__main__": main()