studio_vseLayer.py 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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. # Exit button
  57. def do():
  58. win.current["calls"][call]["var"] = False
  59. UI_elements.roundrect(layer, win,
  60. win.current["w"]/2+210,
  61. win.current["h"]-140,
  62. 40,
  63. 40,
  64. 10,
  65. button=do,
  66. icon="cancel",
  67. tip=talk.text("cancel"))
  68. x = win.current["w"]/2-250 + 10
  69. y = 170
  70. width = 500 - 20
  71. height = win.current["h"]-270
  72. # Search
  73. UI_elements.image(layer, win, "settings/themes/"\
  74. +win.settings["Theme"]+"/icons/search.png",
  75. x+width/4,
  76. y-50,
  77. 40,
  78. 40)
  79. UI_elements.text(layer, win, "in_vses",
  80. x+width/4+50,
  81. y-50,
  82. width/2-50,
  83. 40)
  84. # Clip
  85. UI_elements.roundrect(layer, win,
  86. x,
  87. y,
  88. width,
  89. height-60,
  90. 10,
  91. fill=False)
  92. layer.clip()
  93. clip = [
  94. x,
  95. y,
  96. width,
  97. height-60]
  98. # Little testing thing. Make it True to see where it's clipping.
  99. if False:
  100. # Background
  101. UI_color.set(layer, win, "dark_overdrop")
  102. layer.rectangle(x,y,width, height)
  103. layer.fill()
  104. # Setting up the scroll
  105. if "vse" not in win.scroll:
  106. win.scroll["vse"] = 0
  107. current_Y = 0
  108. # There is not going to be any launch buttons. Basically you click on a
  109. # file in the list and it's launched. ( Or out_putted into parent function )
  110. # And since the contents of those blend files are not model based. Let's not
  111. # draw tiles of squares, but rather a simple list would be fine.
  112. # I think something like
  113. #####################################################
  114. # #
  115. # [____SEARCH____] #
  116. # #
  117. # [] NAME_OF_FILE.BLEND #
  118. # [] NAME_OF_FILE.BLEND #
  119. # [] NAME_OF_FILE.BLEND #
  120. # [] NAME_OF_FILE.BLEND #
  121. # [] NAME_OF_FILE.BLEND #
  122. # [] NAME_OF_FILE.BLEND #
  123. # [] NAME_OF_FILE.BLEND #
  124. # [] NAME_OF_FILE.BLEND #
  125. # #
  126. # #
  127. # #
  128. # #
  129. # #
  130. # #
  131. # #
  132. # #
  133. # #
  134. # X #
  135. #####################################################
  136. # Of course It's going to look better in the end. I'm not great with ASCII
  137. # art. And of course to add a blend file you will look for it in a search
  138. # and it will give you to make one or copy one. Like usual.
  139. blends = []
  140. for blend in os.listdir(win.project+"/rnd"):
  141. if blend.endswith(".blend"):
  142. blends.append(blend)
  143. # I just did this because there could not be a file to begin with. And I
  144. # want to make one if such doesn't exists.
  145. if not blends:
  146. newname = "sequence.blend"
  147. oscalls.copy_file(
  148. win,
  149. os.getcwd()+"/new_file/seq.blend",
  150. "/rnd/",
  151. newname)
  152. # Okay since now we have our file let's list them. Or it. Yeah.
  153. newcreate = win.text["in_vses"]["text"].replace("/","_").replace(" ", "_")\
  154. .replace('"',"_").replace("(","_").replace(")","_").replace("'","_")\
  155. .replace("[","_").replace("]","_").replace("{","_").replace("}","_")
  156. for blend in blends:
  157. # Search
  158. if newcreate and newcreate.lower() not in blend.lower():
  159. continue
  160. # LAUNCH BUTTON
  161. def do():
  162. win.current["calls"][call]["var"] = "/rnd/"+blend
  163. UI_elements.roundrect(layer, win,
  164. x,
  165. y+current_Y + win.scroll["vse"],
  166. width,
  167. 40,
  168. 10,
  169. button=do)
  170. # ICON
  171. UI_elements.image(layer, win, "settings/themes/"\
  172. +win.settings["Theme"]+"/icons/vse.png",
  173. x+5,
  174. y+current_Y + win.scroll["vse"],
  175. 40,
  176. 40)
  177. # NAME
  178. UI_color.set(layer, win, "text_normal")
  179. layer.set_font_size(20)
  180. layer.move_to(x+50,
  181. y+current_Y + win.scroll["vse"]+30)
  182. layer.show_text(blend)
  183. current_Y = current_Y + 50
  184. # Now let's make the 2 adding buttons and to hell with it.
  185. if newcreate and newcreate not in blends:
  186. if not newcreate.endswith(".blend"):
  187. newcreate = newcreate + ".blend"
  188. # NEW FILE
  189. def do():
  190. oscalls.copy_file(
  191. win,
  192. os.getcwd()+"/new_file/seq.blend",
  193. "/rnd/",
  194. newcreate)
  195. win.text["in_vses"]["text"] = ""
  196. UI_elements.roundrect(layer, win,
  197. x,
  198. y+current_Y + win.scroll["vse"],
  199. width,
  200. 40,
  201. 10,
  202. button=do)
  203. UI_color.set(layer, win, "progress_background")
  204. UI_elements.roundrect(layer, win,
  205. x,
  206. y+current_Y + win.scroll["vse"],
  207. width,
  208. 40,
  209. 10,
  210. fill=False)
  211. layer.stroke()
  212. # ICON
  213. UI_elements.image(layer, win, "settings/themes/"\
  214. +win.settings["Theme"]+"/icons/new_file.png",
  215. x+5,
  216. y+current_Y + win.scroll["vse"],
  217. 40,
  218. 40)
  219. # NAME
  220. UI_color.set(layer, win, "text_normal")
  221. layer.set_font_size(20)
  222. layer.move_to(x+50,
  223. y+current_Y + win.scroll["vse"]+30)
  224. layer.show_text(newcreate)
  225. current_Y = current_Y + 50
  226. # COPY FILE
  227. def do():
  228. def after(win, var):
  229. if var and var.endswith(".blend"):
  230. oscalls.copy_file(
  231. win,
  232. var,
  233. "/rnd/",
  234. newcreate)
  235. win.text["in_vses"]["text"] = ""
  236. studio_dialogs.file_select(win, "seq_blends", after, force=True,
  237. IMAGE=False, BLEND=True, VIDEO=False, FILE=False, CHR=False, VEH=False,
  238. LOC=False, OBJ=False, RND=True, FOLDER=False)
  239. UI_elements.roundrect(layer, win,
  240. x,
  241. y+current_Y + win.scroll["vse"],
  242. width,
  243. 40,
  244. 10,
  245. button=do)
  246. UI_color.set(layer, win, "progress_background")
  247. UI_elements.roundrect(layer, win,
  248. x,
  249. y+current_Y + win.scroll["vse"],
  250. width,
  251. 40,
  252. 10,
  253. fill=False)
  254. layer.stroke()
  255. # ICON
  256. UI_elements.image(layer, win, "settings/themes/"\
  257. +win.settings["Theme"]+"/icons/copy_file.png",
  258. x+5,
  259. y+current_Y + win.scroll["vse"],
  260. 40,
  261. 40)
  262. # NAME
  263. UI_color.set(layer, win, "text_normal")
  264. layer.set_font_size(20)
  265. layer.move_to(x+50,
  266. y+current_Y + win.scroll["vse"]+30)
  267. layer.show_text(newcreate)
  268. current_Y = current_Y + 50
  269. ###########################
  270. UI_elements.scroll_area(layer, win, "vse",
  271. x,
  272. y,
  273. width,
  274. height-60,
  275. current_Y,
  276. bar=True,
  277. mmb=True,
  278. url="vse"
  279. )
  280. return surface