studio_vseLayer.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. # THIS FILE IS A PART OF VCStudio
  2. # PYTHON 3
  3. import os
  4. import datetime
  5. import json
  6. from subprocess import *
  7. # GTK module ( Graphical interface
  8. import gi
  9. gi.require_version('Gtk', '3.0')
  10. from gi.repository import Gtk
  11. from gi.repository import GLib
  12. from gi.repository import Gdk
  13. import cairo
  14. # Own modules
  15. from settings import settings
  16. from settings import talk
  17. from settings import fileformats
  18. from settings import oscalls
  19. from project_manager import pm_project
  20. #UI modules
  21. from UI import UI_elements
  22. from UI import UI_color
  23. from UI import UI_math
  24. # Studio
  25. from studio import studio_dialogs
  26. from studio import analytics
  27. from studio import story
  28. def layer(win, call):
  29. ##########################################################################
  30. # This file will select a VSE blend file. And create ones when needed.
  31. # I'm making it as a dialog (see: studio/studio_dialogs.py ) because I
  32. # want to be able to use this UI in various places in VCStudio.
  33. # The launching of the file will be done by a host Layer.
  34. ##########################################################################
  35. # Making the layer
  36. surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, win.current['w'],
  37. win.current['h'])
  38. layer = cairo.Context(surface)
  39. #text setting
  40. layer.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
  41. UI_color.set(layer, win, "dark_overdrop")
  42. layer.rectangle(
  43. 0,
  44. 0,
  45. win.current["w"],
  46. win.current["h"],
  47. )
  48. layer.fill()
  49. UI_color.set(layer, win, "node_background")
  50. UI_elements.roundrect(layer, win,
  51. win.current["w"]/2-250,
  52. 100,
  53. 500,
  54. win.current["h"]-200,
  55. 10)
  56. # Remote server download button
  57. if win.analytics["from-remote-server"]:
  58. if "remote-folder-data" not in win.current:
  59. win.current["remote-folder-data"] = {}
  60. if win.cur not in win.current["remote-folder-data"]:
  61. win.current["remote-folder-data"][win.cur] = {"missing":{},
  62. "changed":{}}
  63. def do():
  64. def after(win, var):
  65. UI_elements.reload_images(win)
  66. win.current["remote-folder-data"]["prompt"] = "vse"
  67. studio_dialogs.http_client_update_prompt(win, "http-client-prompt", after)
  68. UI_elements.roundrect(layer, win,
  69. win.current["w"]/2+210-50,
  70. win.current["h"]-140,
  71. 40,
  72. 40,
  73. 10,
  74. do,
  75. "download",
  76. tip=talk.text("RemoteAssetUpdates"))
  77. if win.current["remote-folder-data"]["vse"]["missing"] or win.current["remote-folder-data"]["vse"]["changed"]:
  78. count = str(len(win.current["remote-folder-data"]["vse"]["missing"])+len(win.current["remote-folder-data"]["vse"]["changed"]))
  79. UI_color.set(layer, win, "progress_active")
  80. UI_elements.roundrect(layer, win,
  81. win.current["w"]/2+210-50+25,
  82. win.current["h"]-140,
  83. len(count)*12+6,
  84. 25,
  85. 5)
  86. layer.fill()
  87. UI_color.set(layer, win, "text_normal")
  88. layer.set_font_size(20)
  89. layer.move_to(win.current["w"]/2+210-50+28,
  90. win.current["h"]-140+20,)
  91. layer.show_text(count)
  92. # Exit button
  93. def do():
  94. win.current["calls"][call]["var"] = False
  95. UI_elements.roundrect(layer, win,
  96. win.current["w"]/2+210,
  97. win.current["h"]-140,
  98. 40,
  99. 40,
  100. 10,
  101. button=do,
  102. icon="cancel",
  103. tip=talk.text("cancel"))
  104. x = win.current["w"]/2-250 + 10
  105. y = 170
  106. width = 500 - 20
  107. height = win.current["h"]-270
  108. # Search
  109. UI_elements.image(layer, win, "settings/themes/"\
  110. +win.settings["Theme"]+"/icons/search.png",
  111. x+width/4,
  112. y-50,
  113. 40,
  114. 40)
  115. UI_elements.text(layer, win, "in_vses",
  116. x+width/4+50,
  117. y-50,
  118. width/2-50,
  119. 40)
  120. # Clip
  121. UI_elements.roundrect(layer, win,
  122. x,
  123. y,
  124. width,
  125. height-60,
  126. 10,
  127. fill=False)
  128. layer.clip()
  129. clip = [
  130. x,
  131. y,
  132. width,
  133. height-60]
  134. # Little testing thing. Make it True to see where it's clipping.
  135. if False:
  136. # Background
  137. UI_color.set(layer, win, "dark_overdrop")
  138. layer.rectangle(x,y,width, height)
  139. layer.fill()
  140. # Setting up the scroll
  141. if "vse" not in win.scroll:
  142. win.scroll["vse"] = 0
  143. current_Y = 0
  144. # There is not going to be any launch buttons. Basically you click on a
  145. # file in the list and it's launched. ( Or out_putted into parent function )
  146. # And since the contents of those blend files are not model based. Let's not
  147. # draw tiles of squares, but rather a simple list would be fine.
  148. # I think something like
  149. #####################################################
  150. # #
  151. # [____SEARCH____] #
  152. # #
  153. # [] NAME_OF_FILE.BLEND #
  154. # [] NAME_OF_FILE.BLEND #
  155. # [] NAME_OF_FILE.BLEND #
  156. # [] NAME_OF_FILE.BLEND #
  157. # [] NAME_OF_FILE.BLEND #
  158. # [] NAME_OF_FILE.BLEND #
  159. # [] NAME_OF_FILE.BLEND #
  160. # [] NAME_OF_FILE.BLEND #
  161. # #
  162. # #
  163. # #
  164. # #
  165. # #
  166. # #
  167. # #
  168. # #
  169. # #
  170. # X #
  171. #####################################################
  172. # Of course It's going to look better in the end. I'm not great with ASCII
  173. # art. And of course to add a blend file you will look for it in a search
  174. # and it will give you to make one or copy one. Like usual.
  175. blends = []
  176. for blend in os.listdir(win.project+"/rnd"):
  177. if blend.endswith(".blend"):
  178. blends.append(blend)
  179. # I just did this because there could not be a file to begin with. And I
  180. # want to make one if such doesn't exists.
  181. if not blends:
  182. newname = "sequence.blend"
  183. oscalls.copy_file(
  184. win,
  185. os.getcwd()+"/new_file/seq.blend",
  186. "/rnd/",
  187. newname)
  188. # Okay since now we have our file let's list them. Or it. Yeah.
  189. newcreate = win.text["in_vses"]["text"].replace("/","_").replace(" ", "_")\
  190. .replace('"',"_").replace("(","_").replace(")","_").replace("'","_")\
  191. .replace("[","_").replace("]","_").replace("{","_").replace("}","_")
  192. for blend in blends:
  193. # Search
  194. if newcreate and newcreate.lower() not in blend.lower():
  195. continue
  196. # LAUNCH BUTTON
  197. def do():
  198. win.current["calls"][call]["var"] = "/rnd/"+blend
  199. UI_elements.roundrect(layer, win,
  200. x,
  201. y+current_Y + win.scroll["vse"],
  202. width,
  203. 40,
  204. 10,
  205. button=do)
  206. # ICON
  207. UI_elements.image(layer, win, "settings/themes/"\
  208. +win.settings["Theme"]+"/icons/vse.png",
  209. x+5,
  210. y+current_Y + win.scroll["vse"],
  211. 40,
  212. 40)
  213. # NAME
  214. UI_color.set(layer, win, "text_normal")
  215. layer.set_font_size(20)
  216. layer.move_to(x+50,
  217. y+current_Y + win.scroll["vse"]+30)
  218. layer.show_text(blend)
  219. current_Y = current_Y + 50
  220. # Now let's make the 2 adding buttons and to hell with it.
  221. if newcreate and newcreate not in blends:
  222. if not newcreate.endswith(".blend"):
  223. newcreate = newcreate + ".blend"
  224. # NEW FILE
  225. def do():
  226. oscalls.copy_file(
  227. win,
  228. os.getcwd()+"/new_file/seq.blend",
  229. "/rnd/",
  230. newcreate)
  231. win.text["in_vses"]["text"] = ""
  232. UI_elements.roundrect(layer, win,
  233. x,
  234. y+current_Y + win.scroll["vse"],
  235. width,
  236. 40,
  237. 10,
  238. button=do)
  239. UI_color.set(layer, win, "progress_background")
  240. UI_elements.roundrect(layer, win,
  241. x,
  242. y+current_Y + win.scroll["vse"],
  243. width,
  244. 40,
  245. 10,
  246. fill=False)
  247. layer.stroke()
  248. # ICON
  249. UI_elements.image(layer, win, "settings/themes/"\
  250. +win.settings["Theme"]+"/icons/new_file.png",
  251. x+5,
  252. y+current_Y + win.scroll["vse"],
  253. 40,
  254. 40)
  255. # NAME
  256. UI_color.set(layer, win, "text_normal")
  257. layer.set_font_size(20)
  258. layer.move_to(x+50,
  259. y+current_Y + win.scroll["vse"]+30)
  260. layer.show_text(newcreate)
  261. current_Y = current_Y + 50
  262. # COPY FILE
  263. def do():
  264. def after(win, var):
  265. if var and var.endswith(".blend"):
  266. oscalls.copy_file(
  267. win,
  268. var,
  269. "/rnd/",
  270. newcreate)
  271. win.text["in_vses"]["text"] = ""
  272. studio_dialogs.file_select(win, "seq_blends", after, force=True,
  273. IMAGE=False, BLEND=True, VIDEO=False, FILE=False, CHR=False, VEH=False,
  274. LOC=False, OBJ=False, RND=True, FOLDER=False)
  275. UI_elements.roundrect(layer, win,
  276. x,
  277. y+current_Y + win.scroll["vse"],
  278. width,
  279. 40,
  280. 10,
  281. button=do)
  282. UI_color.set(layer, win, "progress_background")
  283. UI_elements.roundrect(layer, win,
  284. x,
  285. y+current_Y + win.scroll["vse"],
  286. width,
  287. 40,
  288. 10,
  289. fill=False)
  290. layer.stroke()
  291. # ICON
  292. UI_elements.image(layer, win, "settings/themes/"\
  293. +win.settings["Theme"]+"/icons/copy_file.png",
  294. x+5,
  295. y+current_Y + win.scroll["vse"],
  296. 40,
  297. 40)
  298. # NAME
  299. UI_color.set(layer, win, "text_normal")
  300. layer.set_font_size(20)
  301. layer.move_to(x+50,
  302. y+current_Y + win.scroll["vse"]+30)
  303. layer.show_text(newcreate)
  304. current_Y = current_Y + 50
  305. ###########################
  306. UI_elements.scroll_area(layer, win, "vse",
  307. x,
  308. y,
  309. width,
  310. height-60,
  311. current_Y,
  312. bar=True,
  313. mmb=True,
  314. url="vse"
  315. )
  316. return surface