studio_settingsLayer.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. # THIS FILE IS A PART OF VCStudio
  2. # PYTHON 3
  3. import os
  4. import datetime
  5. # GTK module ( Graphical interface
  6. import gi
  7. gi.require_version('Gtk', '3.0')
  8. from gi.repository import Gtk
  9. from gi.repository import GLib
  10. from gi.repository import Gdk
  11. import cairo
  12. # Own modules
  13. from settings import settings
  14. from settings import talk
  15. from settings import fileformats
  16. from project_manager import pm_project
  17. #UI modules
  18. from UI import UI_elements
  19. from UI import UI_color
  20. # Studio
  21. from studio import studio_dialogs
  22. from studio import analytics
  23. def layer(win):
  24. # Making the layer
  25. surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, win.current['w'],
  26. win.current['h'])
  27. layer = cairo.Context(surface)
  28. #text setting
  29. layer.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
  30. UI_color.set(layer, win, "dark_overdrop")
  31. layer.rectangle(
  32. 0,
  33. 0,
  34. win.current["w"],
  35. win.current["h"],
  36. )
  37. layer.fill()
  38. UI_color.set(layer, win, "node_background")
  39. UI_elements.roundrect(layer, win,
  40. win.current["w"]/2-250,
  41. 100,
  42. 500,
  43. win.current["h"]-200,
  44. 10)
  45. # Exit button
  46. def do():
  47. win.url = "story_editor"
  48. win.textactive = ""
  49. UI_elements.roundrect(layer, win,
  50. win.current["w"]/2+210,
  51. win.current["h"]-140,
  52. 40,
  53. 40,
  54. 10,
  55. button=do,
  56. icon="cancel",
  57. tip=talk.text("cancel"))
  58. # Clipping everything
  59. UI_elements.roundrect(layer, win,
  60. win.current["w"]/2-250,
  61. 100,
  62. 500,
  63. win.current["h"]-260,
  64. 10,
  65. fill=False)
  66. layer.clip()
  67. clip = [
  68. win.current["w"]/2-250,
  69. 100,
  70. 500,
  71. win.current["h"]-260]
  72. # Setting up the scroll
  73. if "studio_settings" not in win.scroll:
  74. win.scroll["studio_settings"] = 0
  75. current_Y = 0 # The max scroll value
  76. # Projectname
  77. UI_elements.image(layer, win, "settings/themes/"\
  78. +win.settings["Theme"]+"/icons/analytics.png",
  79. win.current["w"]/2-240,
  80. 110 + current_Y + win.scroll["studio_settings"],
  81. 40,
  82. 40)
  83. UI_elements.text(layer, win, "Project_Name_setting",
  84. win.current["w"]/2-190,
  85. 110 + current_Y + win.scroll["studio_settings"],
  86. 420,
  87. 40,
  88. set_text=win.analytics["name"],
  89. tip=talk.text("project_name"))
  90. if win.text["Project_Name_setting"]["text"] != win.analytics["name"]:
  91. def do():
  92. win.analytics["name"] = win.text["Project_Name_setting"]["text"]
  93. UI_elements.roundrect(layer, win,
  94. win.current["w"]/2-240+430,
  95. 110 + current_Y + win.scroll["studio_settings"],
  96. 40,
  97. 40,
  98. 10,
  99. button=do,
  100. icon="ok",
  101. tip=talk.text("checked"))
  102. current_Y += 50
  103. # Director
  104. UI_elements.image(layer, win, "settings/themes/"\
  105. +win.settings["Theme"]+"/icons/analytics.png",
  106. win.current["w"]/2-240,
  107. 110 + current_Y + win.scroll["studio_settings"],
  108. 40,
  109. 40)
  110. UI_elements.text(layer, win, "Project_Director_setting",
  111. win.current["w"]/2-190,
  112. 110 + current_Y + win.scroll["studio_settings"],
  113. 420,
  114. 40,
  115. set_text=win.analytics["director"],
  116. tip=talk.text("project_director"))
  117. if win.text["Project_Director_setting"]["text"] != win.analytics["director"]:
  118. def do():
  119. win.analytics["director"] = win.text["Project_Director_setting"]["text"]
  120. UI_elements.roundrect(layer, win,
  121. win.current["w"]/2-240+430,
  122. 110 + current_Y + win.scroll["studio_settings"],
  123. 40,
  124. 40,
  125. 10,
  126. button=do,
  127. icon="ok",
  128. tip=talk.text("checked"))
  129. current_Y += 50
  130. # Project Comment
  131. UI_elements.image(layer, win, "settings/themes/"\
  132. +win.settings["Theme"]+"/icons/analytics.png",
  133. win.current["w"]/2-240,
  134. 110 + current_Y + win.scroll["studio_settings"],
  135. 40,
  136. 40)
  137. UI_elements.text(layer, win, "Project_status_setting",
  138. win.current["w"]/2-190,
  139. 110 + current_Y + win.scroll["studio_settings"],
  140. 420,
  141. 40,
  142. set_text=win.analytics["status"],
  143. tip=talk.text("project_status"))
  144. if win.text["Project_status_setting"]["text"] != win.analytics["status"]:
  145. def do():
  146. win.analytics["status"] = win.text["Project_status_setting"]["text"]
  147. UI_elements.roundrect(layer, win,
  148. win.current["w"]/2-240+430,
  149. 110 + current_Y + win.scroll["studio_settings"],
  150. 40,
  151. 40,
  152. 10,
  153. button=do,
  154. icon="ok",
  155. tip=talk.text("checked"))
  156. current_Y += 50
  157. # Banner / Background image settings.
  158. if os.path.exists(win.project+"/set/banner.png"):
  159. UI_elements.image(layer, win, win.project+"/set/banner.png",
  160. win.current["w"]/2-240,
  161. 110 + current_Y + win.scroll["studio_settings"],
  162. 480,
  163. 200,
  164. cell="settings_background")
  165. elif os.path.exists(win.project+"/py_data/banner.png"):
  166. UI_elements.image(layer, win, win.project+"/py_data/banner.png",
  167. win.current["w"]/2-240,
  168. 110 + current_Y + win.scroll["studio_settings"],
  169. 480,
  170. 200,
  171. cell="settings_background")
  172. else:
  173. UI_elements.image(layer, win, "icon.png",
  174. win.current["w"]/2-240,
  175. 110 + current_Y + win.scroll["studio_settings"],
  176. 480,
  177. 200,
  178. cell="settings_background")
  179. def do():
  180. def after(win, var):
  181. try:
  182. if var:
  183. # Let's check that the selected if an image.
  184. for f in fileformats.images:
  185. if var.endswith(f):
  186. # Now let's copy the picture from whereever it is to be the new
  187. # banner. For this first of all I need to check whether it exists
  188. # inside the project.
  189. if os.path.exists(win.project+"/"+var):
  190. fr = win.project+"/"+var
  191. else:
  192. fr = var
  193. with open(fr, "rb") as in_file, open(win.project+"/set/banner.png", "wb") as out_file:
  194. out_file.write(in_file.read())
  195. # Refrashing images
  196. win.images = {}
  197. break
  198. except:
  199. raise()
  200. studio_dialogs.file_select(win, "banner_editing", after, force=True)
  201. UI_elements.roundrect(layer, win,
  202. win.current["w"]/2-250,
  203. 100 + current_Y + win.scroll["studio_settings"],
  204. 500,
  205. 220,
  206. 10,
  207. button=do,
  208. fill=False,
  209. tip=talk.text("project_banner"))
  210. layer.stroke()
  211. current_Y += 220
  212. # Start date and Deadline
  213. UI_elements.image(layer, win, "settings/themes/"\
  214. +win.settings["Theme"]+"/icons/schedule.png",
  215. win.current["w"]/2-240,
  216. 110 + current_Y + win.scroll["studio_settings"],
  217. 40,
  218. 40)
  219. UI_elements.text(layer, win, "Project_startdate_setting",
  220. win.current["w"]/2-190,
  221. 110 + current_Y + win.scroll["studio_settings"],
  222. 200,
  223. 40,
  224. set_text=win.analytics["startdate"],
  225. tip=talk.text("project_startdate"))
  226. if win.text["Project_startdate_setting"]["text"] != win.analytics["startdate"]\
  227. and analytics.ifdate(win.text["Project_startdate_setting"]["text"]):
  228. def do():
  229. win.analytics["startdate"] = win.text["Project_startdate_setting"]["text"]
  230. # Refrashing the analytics
  231. analytics.save(win.project, win.analytics)
  232. win.analytics = analytics.load(win.project)
  233. UI_elements.roundrect(layer, win,
  234. win.current["w"]/2-240+210,
  235. 110 + current_Y + win.scroll["studio_settings"],
  236. 40,
  237. 40,
  238. 10,
  239. button=do,
  240. icon="ok",
  241. tip=talk.text("checked"))
  242. UI_elements.text(layer, win, "Project_deadline_setting",
  243. win.current["w"]/2-190+210,
  244. 110 + current_Y + win.scroll["studio_settings"],
  245. 200,
  246. 40,
  247. set_text=win.analytics["deadline"],
  248. tip=talk.text("project_deadline"))
  249. if win.text["Project_deadline_setting"]["text"] != win.analytics["deadline"]\
  250. and analytics.ifdate(win.text["Project_deadline_setting"]["text"]):
  251. def do():
  252. win.analytics["deadline"] = win.text["Project_deadline_setting"]["text"]
  253. # Refrashing the analytics
  254. analytics.save(win.project, win.analytics)
  255. win.analytics = analytics.load(win.project)
  256. UI_elements.roundrect(layer, win,
  257. win.current["w"]/2-240+420,
  258. 110 + current_Y + win.scroll["studio_settings"],
  259. 40,
  260. 40,
  261. 10,
  262. button=do,
  263. icon="ok",
  264. tip=talk.text("checked"))
  265. current_Y += 100
  266. # Username
  267. UI_elements.image(layer, win, "settings/themes/"\
  268. +win.settings["Theme"]+"/icons/user.png",
  269. win.current["w"]/2-240,
  270. 110 + current_Y + win.scroll["studio_settings"],
  271. 40,
  272. 40)
  273. UI_elements.text(layer, win, "Username_setting",
  274. win.current["w"]/2-190,
  275. 110 + current_Y + win.scroll["studio_settings"],
  276. 420,
  277. 40,
  278. set_text=win.settings["Username"],
  279. tip=talk.text("username"))
  280. if win.text["Username_setting"]["text"] != win.settings["Username"]:
  281. def do():
  282. win.settings["Username"] = win.text["Username_setting"]["text"]
  283. settings.write("Username", win.settings["Username"])
  284. UI_elements.roundrect(layer, win,
  285. win.current["w"]/2-240+430,
  286. 110 + current_Y + win.scroll["studio_settings"],
  287. 40,
  288. 40,
  289. 10,
  290. button=do,
  291. icon="ok",
  292. tip=talk.text("checked"))
  293. current_Y += 50
  294. # Preparing lists.
  295. if "settings_lists" not in win.current:
  296. win.current["settings_lists"] = {}
  297. win.current["settings_lists"]["languages"] = settings.list_languages()
  298. win.current["settings_lists"]["languages_open"] = False
  299. win.current["settings_lists"]["themes"] = os.listdir(os.getcwd()+"/settings/themes")
  300. win.current["settings_lists"]["themes_open"] = False
  301. # Languages
  302. def do():
  303. win.current["settings_lists"]["languages_open"] = \
  304. not win.current["settings_lists"]["languages_open"]
  305. UI_elements.roundrect(layer, win,
  306. win.current["w"]/2-240,
  307. 110 + current_Y + win.scroll["studio_settings"],
  308. 450,
  309. 40,
  310. 10,
  311. button=do,
  312. icon="font",
  313. tip=talk.text("change_language"))
  314. UI_color.set(layer, win, "text_normal")
  315. layer.set_font_size(20)
  316. layer.move_to(win.current["w"]/2-180,
  317. current_Y + win.scroll["studio_settings"] + 135)
  318. layer.show_text(win.settings["Language"])
  319. current_Y += 50
  320. if win.current["settings_lists"]["languages_open"]:
  321. for lang in win.current["settings_lists"]["languages"]:
  322. if lang != win.settings["Language"]:
  323. UI_color.set(layer, win, "button_active")
  324. layer.move_to(win.current["w"]/2-227, 102 + current_Y + win.scroll["studio_settings"])
  325. layer.line_to(win.current["w"]/2-227, 152 + current_Y + win.scroll["studio_settings"])
  326. layer.stroke()
  327. def do():
  328. win.settings["Language"] = lang
  329. settings.write("Language", lang)
  330. win.current["settings_lists"]["languages_open"] = False
  331. UI_elements.roundrect(layer, win,
  332. win.current["w"]/2-220,
  333. 110 + current_Y + win.scroll["studio_settings"],
  334. 430,
  335. 40,
  336. 10,
  337. button=do,
  338. icon="font",
  339. tip=talk.text("set_language")+lang)
  340. UI_color.set(layer, win, "text_normal")
  341. layer.set_font_size(20)
  342. layer.move_to(win.current["w"]/2-150,
  343. current_Y + win.scroll["studio_settings"] + 135)
  344. layer.show_text(lang)
  345. current_Y += 50
  346. # Themes. Finally we have some themes to choose from. And a good place to
  347. # change them so the user would not need to do it manually. I think it's
  348. # important.
  349. # So there is a folder in the VCStudio installation called. settings/themes
  350. # which contains all of the themes. So let's look through it.
  351. # Themes
  352. def do():
  353. win.current["settings_lists"]["themes_open"] = \
  354. not win.current["settings_lists"]["themes_open"]
  355. UI_elements.roundrect(layer, win,
  356. win.current["w"]/2-240,
  357. 110 + current_Y + win.scroll["studio_settings"],
  358. 450,
  359. 40,
  360. 10,
  361. button=do,
  362. icon="theme",
  363. tip=talk.text("change_theme"))
  364. UI_color.set(layer, win, "text_normal")
  365. layer.set_font_size(20)
  366. layer.move_to(win.current["w"]/2-180,
  367. current_Y + win.scroll["studio_settings"] + 135)
  368. layer.show_text(win.settings["Theme"])
  369. current_Y += 50
  370. if win.current["settings_lists"]["themes_open"]:
  371. for lang in win.current["settings_lists"]["themes"]:
  372. if lang != win.settings["Theme"]:
  373. UI_color.set(layer, win, "button_active")
  374. layer.move_to(win.current["w"]/2-227, 102 + current_Y + win.scroll["studio_settings"])
  375. layer.line_to(win.current["w"]/2-227, 152 + current_Y + win.scroll["studio_settings"])
  376. layer.stroke()
  377. def do():
  378. win.settings["Theme"] = lang
  379. settings.write("Theme", lang)
  380. win.current["settings_lists"]["themes_open"] = False
  381. win.color = UI_color.get_table()
  382. UI_elements.roundrect(layer, win,
  383. win.current["w"]/2-220,
  384. 110 + current_Y + win.scroll["studio_settings"],
  385. 430,
  386. 40,
  387. 10,
  388. button=do,
  389. icon="theme",
  390. tip=talk.text("set_theme")+lang)
  391. UI_color.set(layer, win, "text_normal")
  392. layer.set_font_size(20)
  393. layer.move_to(win.current["w"]/2-150,
  394. current_Y + win.scroll["studio_settings"] + 135)
  395. layer.show_text(lang)
  396. current_Y += 50
  397. # BLUR
  398. blur_ok = "unchecked"
  399. if win.settings["Blur"]:
  400. blur_ok = "checked"
  401. def do():
  402. win.settings["Blur"] = not win.settings["Blur"]
  403. settings.write("Blur", win.settings["Blur"])
  404. UI_elements.roundrect(layer, win,
  405. win.current["w"]/2-240,
  406. 110 + current_Y + win.scroll["studio_settings"],
  407. 450,
  408. 40,
  409. 10,
  410. button=do,
  411. icon=blur_ok,
  412. tip=talk.text("Blur"))
  413. UI_color.set(layer, win, "text_normal")
  414. layer.set_font_size(20)
  415. layer.move_to(win.current["w"]/2-180,
  416. current_Y + win.scroll["studio_settings"] + 135)
  417. layer.show_text(talk.text("Blur"))
  418. current_Y += 50
  419. if win.settings["Blur"]:
  420. ablur_ok = "unchecked"
  421. if win.settings["Auto_De-Blur"]:
  422. ablur_ok = "checked"
  423. def do():
  424. win.settings["Auto_De-Blur"] = not win.settings["Auto_De-Blur"]
  425. settings.write("Auto_De-Blur", win.settings["Auto_De-Blur"])
  426. UI_elements.roundrect(layer, win,
  427. win.current["w"]/2-240,
  428. 110 + current_Y + win.scroll["studio_settings"],
  429. 450,
  430. 40,
  431. 10,
  432. button=do,
  433. icon=ablur_ok,
  434. tip=talk.text("Auto_De-Blur"))
  435. UI_color.set(layer, win, "text_normal")
  436. layer.set_font_size(20)
  437. layer.move_to(win.current["w"]/2-180,
  438. current_Y + win.scroll["studio_settings"] + 135)
  439. layer.show_text(talk.text("Auto_De-Blur"))
  440. current_Y += 50
  441. # ROUNDNESS
  442. # The roundness setting is a setting that will define how round the UI will
  443. # look. Potentially it can grow beyond 1.0, but will introduce weird rendering
  444. # artifacts. If you wan to do that be free to edit the Setting file manually.
  445. # I'm going to use the Scroller for this setting. But first we need an icon. And
  446. # I think the opengl icon is quite good for this.
  447. UI_elements.image(layer, win, "settings/themes/"\
  448. +win.settings["Theme"]+"/icons/opengl.png",
  449. win.current["w"]/2-240,
  450. 110 + current_Y + win.scroll["studio_settings"],
  451. 40,
  452. 40)
  453. # Then i'm going to hack my way to it. I'm going to use a scroll for a scrooled
  454. # window as the slider. Creativity.
  455. maxround = 1000 # I need it do be a higher number then from 0 to 1 since we want
  456. # to imulate the scroll
  457. if "roundness_setting" not in win.scroll:
  458. win.scroll["roundness_setting"] = 0 - win.settings["Roundness"] * 549
  459. if (0 - win.settings["Roundness"] * 549) != win.scroll["roundness_setting"]:
  460. win.settings["Roundness"] = (win.scroll["roundness_setting"] / 549)*-1
  461. settings.write("Roundness", win.settings["Roundness"])
  462. UI_elements.scroll_area(layer, win, "roundness_setting",
  463. int(win.current["w"]/2-200),
  464. 110 + current_Y + win.scroll["studio_settings"]+33,
  465. 450,
  466. 0,
  467. maxround,
  468. bar=True,
  469. sideways=True,
  470. url="settings_layer"
  471. )
  472. current_Y += 50
  473. UI_elements.scroll_area(layer, win, "studio_settings",
  474. int(win.current["w"]/2-250),
  475. 100,
  476. 500,
  477. win.current["h"]-260,
  478. current_Y,
  479. bar=True,
  480. mmb=True,
  481. url="settings_layer"
  482. )
  483. return surface