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"]-150,
  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. UI_elements.roundrect(layer, win,
  126. 5,
  127. win.current["h"]-95,
  128. 40,
  129. 40,
  130. 10,
  131. do,
  132. "update",
  133. talk.text("Update"),
  134. url="project_manager")
  135. # I gonna draw a little thingy for if a new update is available
  136. try:
  137. if win.update["count"]:
  138. count = str(win.update["count"])
  139. UI_color.set(layer, win, "node_background")
  140. UI_elements.roundrect(layer, win,
  141. 30,
  142. win.current["h"]-100,
  143. len(count)*12+6,
  144. 25,
  145. 5)
  146. layer.fill()
  147. UI_color.set(layer, win, "text_normal")
  148. layer.set_font_size(20)
  149. layer.move_to(33,win.current["h"]-80)
  150. layer.show_text(count)
  151. except:
  152. pass
  153. # Settings
  154. def do():
  155. win.url = "settings_layer"
  156. UI_elements.roundrect(layer, win,
  157. 5,
  158. win.current["h"]-45,
  159. 40,
  160. 40,
  161. 10,
  162. do,
  163. "settings",
  164. talk.text("Settings"),
  165. url="project_manager")
  166. # Now let's make previews of projects. I think each one will be it's own
  167. # layer thingy. Just so I could draw things inside them.
  168. # Clipping so it wont draw beyon the frame
  169. UI_elements.roundrect(layer, win,
  170. 50,
  171. 5,
  172. win.current["w"] - 55,
  173. win.current["h"] - 30,
  174. 30,
  175. fill=False)
  176. layer.clip()
  177. # Setting up scroll for Projects
  178. if "pm_scroll" not in win.current:
  179. win.current["pm_scroll"] = 0.0
  180. # Setting up tilling
  181. tileY = 0
  182. tileX = 0
  183. if "pm_main" not in win.scroll:
  184. win.scroll["pm_main"] = 0
  185. for num, project in enumerate(pm_project.get_list()):
  186. if tileX > (win.current["w"]-55)-391:
  187. tileY += 330
  188. tileX = 0
  189. project_node(layer, win, 60+tileX, 15+tileY+ win.scroll["pm_main"], project)
  190. tileX += 360
  191. UI_elements.scroll_area(layer, win, "pm_main",
  192. 50,
  193. 5,
  194. win.current["w"] - 55,
  195. win.current["h"] - 30,
  196. tileY+340,
  197. bar=True,
  198. mmb=True,
  199. url="project_manager"
  200. )
  201. return surface
  202. def project_node(layer, win, x, y, project):
  203. # This function will draw a project to a given place.
  204. node_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, win.current['w'],
  205. win.current['h'])
  206. node = cairo.Context(node_surface)
  207. node.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
  208. # Before we gonna do clip. Let's put here the logic of the node.
  209. def do():
  210. print(project)
  211. win.current["project"] = project
  212. Legacytip = ""
  213. nameonly = project[project.rfind("/")+1:]
  214. timefraction = 0.0
  215. projectfraction = 0.0
  216. if pm_project.is_legacy(project):
  217. Legacytip = "\nLegacy (Blender-Organizer)"
  218. # Getting info about the project. For now only Legacy. Since nothing is
  219. # written for the new stuff.
  220. try:
  221. if project not in win.projects:
  222. win.projects[project] = analytics.get_legacy(project)
  223. nameonly = win.projects[project]["name"]
  224. timefraction = win.projects[project]["timepassed"]
  225. projectfraction = win.projects[project]["fraction"]
  226. except:
  227. pass
  228. else:
  229. try:
  230. if project not in win.projects:
  231. win.projects[project] = analytics.load(project)
  232. nameonly = win.projects[project]["name"]
  233. timefraction = win.projects[project]["timepassed"]
  234. projectfraction = win.projects[project]["fraction"]
  235. except:
  236. pass
  237. node.set_line_width(10)
  238. UI_elements.roundrect(node, win,
  239. x-5,
  240. y-5,
  241. 350+10,
  242. 320+10,
  243. 20+5,
  244. button=do,
  245. fill=False,
  246. tip=project+Legacytip,
  247. url="project_manager")
  248. node.stroke()
  249. # If project is selected
  250. if win.current["project"] == project and win.previous["project"] == project:
  251. UI_color.set(node, win, "button_active")
  252. UI_elements.roundrect(node, win,
  253. x-5,
  254. y-5,
  255. 350+10,
  256. 320+10,
  257. 20+5,
  258. button=False,
  259. fill=False
  260. )
  261. node.stroke()
  262. def do():
  263. pm_project.load(project, win)
  264. #Gtk.main_quit() # Here I might do some kind a setting later
  265. UI_elements.roundrect(node, win,
  266. x-5,
  267. y-5,
  268. 350+10,
  269. 320+10,
  270. 20+5,
  271. button=do,
  272. fill=False,
  273. url="project_manager"
  274. )
  275. # Enter keys
  276. if win.url == "project_manager":
  277. if 65293 in win.current["keys"] or 65421 in win.current["keys"]:
  278. do()
  279. win.current["keys"].remove(65293)
  280. win.current["keys"].remove(65421)
  281. # This next roundrect will both be the backdrop of the node and both will
  282. # clip the node content. All folowing graphics will be drawn clipped to the
  283. # current roundrect.
  284. UI_color.set(node, win, "node_background")
  285. UI_elements.roundrect(node, win,
  286. x,
  287. y,
  288. 350,
  289. 320,
  290. 20)
  291. # Clip
  292. UI_elements.roundrect(node, win,
  293. x,
  294. y,
  295. 350,
  296. 320,
  297. 20,
  298. fill=False)
  299. node.clip()
  300. if os.path.exists(project+"/set/banner.png"):
  301. UI_elements.image(node, win, project+"/set/banner.png",
  302. x,y,350,320)
  303. elif os.path.exists(project+"/py_data/banner.png"):
  304. UI_elements.image(node, win, project+"/py_data/banner.png",
  305. x,y,350,320)
  306. else:
  307. UI_elements.image(node, win, "icon.png",
  308. x,y,350,320)
  309. # Top Banner thingy
  310. if pm_project.is_legacy(project):
  311. UI_color.set(node, win, "node_badfile")
  312. else:
  313. UI_color.set(node, win, "node_blendfile")
  314. node.rectangle(x,y,350,40)
  315. node.fill()
  316. # Name of the project
  317. UI_color.set(node, win, "text_normal")
  318. node.set_font_size(20)
  319. node.move_to(x+175-len(nameonly)*12/2,y+25)
  320. node.show_text(nameonly)
  321. # Bottom widget part
  322. UI_color.set(node, win, "node_background")
  323. node.rectangle(x,y+250,350,100)
  324. node.fill()
  325. # Finally the progress bar HELL YEAH. (I had to write 3 hard parsing
  326. # algorythms only to read percentage from the project)
  327. #Background
  328. UI_color.set(node, win, "progress_background")
  329. UI_elements.roundrect(node, win,
  330. x+20,
  331. y+280,
  332. 310,
  333. 10,
  334. 10)
  335. #Time-passed
  336. UI_color.set(node, win, "progress_time")
  337. UI_elements.roundrect(node, win,
  338. x+20,
  339. y+280,
  340. 310*timefraction,
  341. 10,
  342. 10)
  343. #Done
  344. UI_color.set(node, win, "progress_active")
  345. UI_elements.roundrect(node, win,
  346. x+20,
  347. y+280,
  348. 310*projectfraction,
  349. 10,
  350. 10)
  351. # Drawing the Node on the main layer.
  352. layer.set_source_surface(node_surface, 0,0)
  353. layer.paint()