pm_mainLayer.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. # THIS FILE IS A PART OF VCStudio
  2. # PYTHON 3
  3. import os
  4. # GTK module ( Graphical interface
  5. import gi
  6. gi.require_version('Gtk', '3.0')
  7. from gi.repository import Gtk
  8. from gi.repository import GLib
  9. from gi.repository import Gdk
  10. import cairo
  11. # Own modules
  12. from settings import settings
  13. from settings import talk
  14. from project_manager import pm_project
  15. from studio import analytics
  16. from studio import story
  17. from studio import studio_gtk
  18. from studio import studio_dialogs
  19. #UI modules
  20. from UI import UI_elements
  21. from UI import UI_color
  22. def layer(win):
  23. # Making the layer
  24. surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, win.current['w'],
  25. win.current['h'])
  26. layer = cairo.Context(surface)
  27. #text setting
  28. layer.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
  29. UI_color.set(layer, win, "darker_parts")
  30. UI_elements.roundrect(layer, win,
  31. 50,
  32. 5,
  33. win.current["w"] - 55,
  34. win.current["h"] - 30,
  35. 30)
  36. # Little verion thing in the bottom corner
  37. UI_color.set(layer, win, "testing_banner")
  38. layer.set_font_size(15)
  39. layer.move_to(win.current["w"]-80, win.current["h"] - 7)
  40. layer.show_text(str(win.version))
  41. # Side bar. First 3. New project / Search Projects / Configure Project.
  42. # New Project
  43. def do():
  44. print("New Project")
  45. win.url = "new_project"
  46. UI_elements.roundrect(layer, win,
  47. 5,
  48. 5,
  49. 40,
  50. 40,
  51. 10,
  52. do,
  53. "new_file",
  54. talk.text("createnewproject_tooltip"),
  55. url="project_manager")
  56. # Search for projects
  57. def do():
  58. win.url = "scan_projects"
  59. UI_elements.roundrect(layer, win,
  60. 5,
  61. 55,
  62. 40,
  63. 40,
  64. 10,
  65. do,
  66. "search_file",
  67. talk.text("scanforprojects_tooltip"),
  68. url="project_manager")
  69. # Configure
  70. if win.current["project"] and pm_project.is_legacy(win.current["project"]):
  71. def do():
  72. print("configure")
  73. #GLib.timeout_add(1, studio_gtk.run, win )
  74. analytics.save(win.current["project"], win.projects[win.current["project"]])
  75. story.save(win.current["project"], story.get_legacy(win.current["project"]))
  76. # Makinf the set folder
  77. try:
  78. os.mkdir(win.current["project"]+"/set/")
  79. except:
  80. pass
  81. # Copy the project.data to set
  82. try:
  83. f = open(win.current["project"]+"/project.progress")
  84. t = open(win.current["project"]+"/set/project.progress", "w")
  85. t.write(f.read())
  86. t.close()
  87. except:
  88. pass
  89. UI_elements.roundrect(layer, win,
  90. 5,
  91. 110,
  92. 40,
  93. 40,
  94. 10,
  95. do,
  96. "configure_file",
  97. talk.text("convertoldproject_tooltip"),
  98. url="project_manager")
  99. # Side bar. Last 3. Internet things / Updater / Settings
  100. # Internet things
  101. def do():
  102. # I used to have a specific UI instance for the help layer here. But
  103. # it proved to be too hard to maintain. So I'm changing it to a different
  104. # dialog. I'm not going to delete the help layer it self. For curious
  105. # poeple.
  106. # win.url = "help_layer"
  107. # The following commands are the replacement. So if you want to see how
  108. # it used to look. Comment those. So not to launch both in the same time.
  109. def after(win, var):
  110. pass
  111. studio_dialogs.help(win, "help", after, SEARCH=talk.text("documentation_project_manager"))
  112. UI_elements.roundrect(layer, win,
  113. 5,
  114. win.current["h"]-95, #-150 ( Update removed )
  115. 40,
  116. 40,
  117. 10,
  118. do,
  119. "question",
  120. talk.text("pm_internet_tooltip"),
  121. url="project_manager")
  122. # Update
  123. #def do():
  124. # win.url = "update_layer"
  125. #
  126. #UI_elements.roundrect(layer, win,
  127. # 5,
  128. # win.current["h"]-95,
  129. # 40,
  130. # 40,
  131. # 10,
  132. # do,
  133. # "update",
  134. # talk.text("Update"),
  135. # url="project_manager")
  136. # I gonna draw a little thingy for if a new update is available
  137. try:
  138. if win.update["count"]:
  139. count = str(win.update["count"])
  140. UI_color.set(layer, win, "node_background")
  141. UI_elements.roundrect(layer, win,
  142. 30,
  143. win.current["h"]-100,
  144. len(count)*12+6,
  145. 25,
  146. 5)
  147. layer.fill()
  148. UI_color.set(layer, win, "text_normal")
  149. layer.set_font_size(20)
  150. layer.move_to(33,win.current["h"]-80)
  151. layer.show_text(count)
  152. except:
  153. pass
  154. # Settings
  155. def do():
  156. win.url = "settings_layer"
  157. UI_elements.roundrect(layer, win,
  158. 5,
  159. win.current["h"]-45,
  160. 40,
  161. 40,
  162. 10,
  163. do,
  164. "settings",
  165. talk.text("Settings"),
  166. url="project_manager")
  167. # Now let's make previews of projects. I think each one will be it's own
  168. # layer thingy. Just so I could draw things inside them.
  169. # Clipping so it wont draw beyon the frame
  170. UI_elements.roundrect(layer, win,
  171. 50,
  172. 5,
  173. win.current["w"] - 55,
  174. win.current["h"] - 30,
  175. 30,
  176. fill=False)
  177. layer.clip()
  178. # Setting up scroll for Projects
  179. if "pm_scroll" not in win.current:
  180. win.current["pm_scroll"] = 0.0
  181. # Setting up tilling
  182. tileY = 0
  183. tileX = 0
  184. if "pm_main" not in win.scroll:
  185. win.scroll["pm_main"] = 0
  186. for num, project in enumerate(pm_project.get_list()):
  187. if tileX > (win.current["w"]-55)-391:
  188. tileY += 330
  189. tileX = 0
  190. project_node(layer, win, 60+tileX, 15+tileY+ win.scroll["pm_main"], project)
  191. tileX += 360
  192. UI_elements.scroll_area(layer, win, "pm_main",
  193. 50,
  194. 5,
  195. win.current["w"] - 55,
  196. win.current["h"] - 30,
  197. tileY+340,
  198. bar=True,
  199. mmb=True,
  200. url="project_manager"
  201. )
  202. return surface
  203. def project_node(layer, win, x, y, project):
  204. # This function will draw a project to a given place.
  205. node_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, win.current['w'],
  206. win.current['h'])
  207. node = cairo.Context(node_surface)
  208. node.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
  209. # Before we gonna do clip. Let's put here the logic of the node.
  210. def do():
  211. print(project)
  212. win.current["project"] = project
  213. Legacytip = ""
  214. nameonly = project[project.rfind("/")+1:]
  215. timefraction = 0.0
  216. projectfraction = 0.0
  217. if pm_project.is_legacy(project):
  218. Legacytip = "\nLegacy (Blender-Organizer)"
  219. # Getting info about the project. For now only Legacy. Since nothing is
  220. # written for the new stuff.
  221. try:
  222. if project not in win.projects:
  223. win.projects[project] = analytics.get_legacy(project)
  224. nameonly = win.projects[project]["name"]
  225. timefraction = win.projects[project]["timepassed"]
  226. projectfraction = win.projects[project]["fraction"]
  227. except:
  228. pass
  229. else:
  230. try:
  231. if project not in win.projects:
  232. win.projects[project] = analytics.load(project)
  233. nameonly = win.projects[project]["name"]
  234. timefraction = win.projects[project]["timepassed"]
  235. projectfraction = win.projects[project]["fraction"]
  236. except:
  237. pass
  238. node.set_line_width(10)
  239. UI_elements.roundrect(node, win,
  240. x-5,
  241. y-5,
  242. 350+10,
  243. 320+10,
  244. 20+5,
  245. button=do,
  246. fill=False,
  247. tip=project+Legacytip,
  248. url="project_manager")
  249. node.stroke()
  250. # If project is selected
  251. if win.current["project"] == project and win.previous["project"] == project:
  252. UI_color.set(node, win, "button_active")
  253. UI_elements.roundrect(node, win,
  254. x-5,
  255. y-5,
  256. 350+10,
  257. 320+10,
  258. 20+5,
  259. button=False,
  260. fill=False
  261. )
  262. node.stroke()
  263. def do():
  264. pm_project.load(project, win)
  265. #Gtk.main_quit() # Here I might do some kind a setting later
  266. UI_elements.roundrect(node, win,
  267. x-5,
  268. y-5,
  269. 350+10,
  270. 320+10,
  271. 20+5,
  272. button=do,
  273. fill=False,
  274. url="project_manager"
  275. )
  276. # Enter keys
  277. if win.url == "project_manager":
  278. if 65293 in win.current["keys"] or 65421 in win.current["keys"]:
  279. do()
  280. win.current["keys"].remove(65293)
  281. win.current["keys"].remove(65421)
  282. # This next roundrect will both be the backdrop of the node and both will
  283. # clip the node content. All folowing graphics will be drawn clipped to the
  284. # current roundrect.
  285. UI_color.set(node, win, "node_background")
  286. UI_elements.roundrect(node, win,
  287. x,
  288. y,
  289. 350,
  290. 320,
  291. 20)
  292. # Clip
  293. UI_elements.roundrect(node, win,
  294. x,
  295. y,
  296. 350,
  297. 320,
  298. 20,
  299. fill=False)
  300. node.clip()
  301. if os.path.exists(project+"/set/banner.png"):
  302. UI_elements.image(node, win, project+"/set/banner.png",
  303. x,y,350,320)
  304. elif os.path.exists(project+"/py_data/banner.png"):
  305. UI_elements.image(node, win, project+"/py_data/banner.png",
  306. x,y,350,320)
  307. else:
  308. UI_elements.image(node, win, "icon.png",
  309. x,y,350,320)
  310. # Top Banner thingy
  311. if pm_project.is_legacy(project):
  312. UI_color.set(node, win, "node_badfile")
  313. else:
  314. UI_color.set(node, win, "node_blendfile")
  315. node.rectangle(x,y,350,40)
  316. node.fill()
  317. # Name of the project
  318. UI_color.set(node, win, "text_normal")
  319. node.set_font_size(20)
  320. node.move_to(x+175-len(nameonly)*12/2,y+25)
  321. node.show_text(nameonly)
  322. # Bottom widget part
  323. UI_color.set(node, win, "node_background")
  324. node.rectangle(x,y+250,350,100)
  325. node.fill()
  326. # Finally the progress bar HELL YEAH. (I had to write 3 hard parsing
  327. # algorythms only to read percentage from the project)
  328. #Background
  329. UI_color.set(node, win, "progress_background")
  330. UI_elements.roundrect(node, win,
  331. x+20,
  332. y+280,
  333. 310,
  334. 10,
  335. 10)
  336. #Time-passed
  337. UI_color.set(node, win, "progress_time")
  338. UI_elements.roundrect(node, win,
  339. x+20,
  340. y+280,
  341. 310*timefraction,
  342. 10,
  343. 10)
  344. #Done
  345. UI_color.set(node, win, "progress_active")
  346. UI_elements.roundrect(node, win,
  347. x+20,
  348. y+280,
  349. 310*projectfraction,
  350. 10,
  351. 10)
  352. # Drawing the Node on the main layer.
  353. layer.set_source_surface(node_surface, 0,0)
  354. layer.paint()