pm_updateLayer.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. ####################################
  2. # #
  3. # COPYRIGHT NOTICE #
  4. # #
  5. # This file is a part of Victori- #
  6. # ous Children Studio Organizer. #
  7. # Or simply VCStudio. Copyright #
  8. # of J.Y.Amihud. But don't be sad #
  9. # because I released the entire #
  10. # project under a GNU GPL license. #
  11. # You may use Version 3 or later. #
  12. # See www.gnu.org/licenses if your #
  13. # copy has no License file. Please #
  14. # note. Ones I used the GPL v2 for #
  15. # it. It's no longer the case. #
  16. # #
  17. ####################################
  18. import os
  19. import urllib3
  20. # GTK module ( Graphical interface
  21. import gi
  22. gi.require_version('Gtk', '3.0')
  23. from gi.repository import Gtk
  24. from gi.repository import GLib
  25. from gi.repository import Gdk
  26. import cairo
  27. # Own modules
  28. from settings import settings
  29. from settings import talk
  30. from settings import oscalls
  31. from project_manager import pm_project
  32. from project_manager import update_reader
  33. #UI modules
  34. from UI import UI_elements
  35. from UI import UI_color
  36. from UI import UI_Markdown
  37. def layer(win):
  38. # Sometimes the user didn't want the software to check for updates automatically.
  39. # In this case we want to check for updates when he click on the update button.
  40. if not win.settings["check-for-updates"]:
  41. GLib.timeout_add(1 , update_reader.get_update_info, win)
  42. # Making the layer
  43. surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, win.current['w'],
  44. win.current['h'])
  45. layer = cairo.Context(surface)
  46. #text setting
  47. layer.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
  48. UI_color.set(layer, win, "dark_overdrop")
  49. layer.rectangle(
  50. 0,
  51. 0,
  52. win.current["w"],
  53. win.current["h"],
  54. )
  55. layer.fill()
  56. # This is the Markdown UI object.
  57. UI_Markdown.draw(layer, win, "update_markdown",
  58. 20,
  59. 100,
  60. win.current["w"]-40,
  61. win.current["h"]-200)
  62. UI_color.set(layer, win, "node_background")
  63. UI_elements.roundrect(layer, win,
  64. 50,
  65. win.current["h"]-80,
  66. win.current["w"]-100,
  67. 50,
  68. 10)
  69. # Exit button
  70. def do():
  71. win.url = "project_manager"
  72. win.textactive = ""
  73. UI_elements.roundrect(layer, win,
  74. 55,
  75. win.current["h"]-75,
  76. 40,
  77. 40,
  78. 10,
  79. button=do,
  80. icon="cancel",
  81. tip=talk.text("cancel"))
  82. # Setting to get all files. Sometimes you need a way to restore the entire
  83. # program. Or sometimes I make mistakes. And want give myself and others a
  84. # simple way to refresh the system. So here I gonna make a button that will
  85. # tell the updater to ignore the update version and download the whole
  86. # package. All 300 something files. ( It's 2021/01 at the time. )
  87. # Also not so long ago I made Version naming mistakes. So some kind of way
  88. # to download versions should exist. Here we go.
  89. if "Update_all" not in win.settings:
  90. win.settings["Update_all"] = False
  91. settings.write("Update_all", False)
  92. if win.settings["Update_all"]:
  93. ic = "checked"
  94. else:
  95. ic = "unchecked"
  96. def do():
  97. win.settings["Update_all"] = not win.settings["Update_all"]
  98. settings.write("Update_all", win.settings["Update_all"])
  99. UI_elements.roundrect(layer, win,
  100. 110,
  101. win.current["h"]-75,
  102. 250,
  103. 40,
  104. 10,
  105. button=do,
  106. icon=ic,
  107. tip=talk.text("update_all_tooltip"))
  108. UI_color.set(layer, win, "text_normal")
  109. layer.set_font_size(15)
  110. layer.move_to(
  111. 150,
  112. win.current["h"]-50)
  113. layer.show_text(talk.text("update_all")+" "+str(len(win.update["get_all_files"]))+" "+talk.text("files"))
  114. # Install Updates button
  115. try:
  116. if win.update["count"] or win.settings["Update_all"]:
  117. def do():
  118. win.url = "install_updates"
  119. win.update["frame"] = win.current["frame"]
  120. UI_elements.roundrect(layer, win,
  121. win.current["w"]-100,
  122. win.current["h"]-75,
  123. 40,
  124. 40,
  125. 10,
  126. button=do,
  127. icon="ok",
  128. tip=talk.text("update_install"))
  129. except:
  130. pass
  131. # At the top of the Update window there is a selector bar to
  132. # select various versions. They will load the page into the
  133. # little browser below.
  134. # For this wee need to clip it.
  135. # Clipping everything
  136. UI_elements.roundrect(layer, win,
  137. 50,
  138. 20,
  139. win.current["w"]-100,
  140. 80,
  141. 10,
  142. fill=False)
  143. layer.clip()
  144. clip = [
  145. 50,
  146. 20,
  147. win.current["w"]-100,
  148. 80]
  149. # Setting up the scroll
  150. if "pm_update" not in win.scroll:
  151. win.scroll["pm_update"] = 0
  152. current_X = 0 # The max scroll value
  153. for version in win.update["versions"]:
  154. is_open = win.update["versions"][version]["open"]
  155. files = win.update["versions"][version]["files"]
  156. link = win.update["versions"][version]["link"]
  157. if version == win.version:
  158. UI_color.set(layer, win, "node_imagefile")
  159. sufix = talk.text("update_current")
  160. elif version < win.version:
  161. UI_color.set(layer, win, "node_badfile")
  162. sufix = talk.text("update_previous")
  163. elif version > win.version:
  164. UI_color.set(layer, win, "node_blendfile")
  165. sufix = talk.text("update_available")
  166. UI_elements.roundrect(layer, win,
  167. current_X + 50 + win.scroll["pm_update"],
  168. 20,
  169. 300,
  170. 40,
  171. 10)
  172. UI_color.set(layer, win, "text_normal")
  173. layer.set_font_size(20)
  174. layer.move_to(current_X + 60 + win.scroll["pm_update"],
  175. 45)
  176. layer.show_text(str(version)+" "+sufix)
  177. def do():
  178. # We gonna attempt at previewing the update information in the window
  179. # and only if it's not going to work, we gonna launch the browser with
  180. # the link. Or do some weird. Like giving a generated page about the
  181. # stuff.
  182. openlink = "wiki/updates/"+str(version)+".md"
  183. if not os.path.exists(os.getcwd()+"/"+openlink):
  184. # In case the folder is not there yet
  185. try:
  186. os.mkdir("wiki/updates")
  187. except:
  188. pass
  189. # Now we are getting the file
  190. try:
  191. http = urllib3.PoolManager()
  192. resp = http.request('GET', "https://notabug.org/jyamihud/VCStudio/raw/master/"+openlink)
  193. # Sometimes we might get a 404 error page
  194. if not resp.data.decode("utf-8").startswith("<!DOCTYPE html>"):
  195. s = open(openlink, "wb")
  196. s.write(resp.data)
  197. s.close()
  198. else:
  199. 1/0 # Else we want to execute the exception
  200. except:
  201. # We gonna make a simple 404 page
  202. # And load it
  203. openlink = "/tmp/404-error-"+str(version)+".md"
  204. s = open(openlink, "w")
  205. s.write("# Version "+str(version)+" No page :(\n\n")
  206. s.write("You can try")
  207. s.write("![](../../settings/themes/OldSchool/icons/lbry.png)")
  208. s.write("[the LBRY link]("+link.replace("(","%28").replace(")","%29")+").\n\n")
  209. s.write("![](../../settings/themes/OldSchool/icons/question.png) [What is LBRY?](../../wiki/extra/LBRY.md)")
  210. s.close()
  211. win.current["mdfs"]["update_markdown"] = openlink # Loading MD file into viever
  212. win.current["update_markdown_files"] = files # Files, for list of updates
  213. UI_elements.roundrect(layer, win,
  214. current_X + 50 + win.scroll["pm_update"],
  215. 20,
  216. 300,
  217. 40,
  218. 10,
  219. button=do,
  220. tip=talk.text("update_read_version_notes"),
  221. fill=False,
  222. clip=clip)
  223. layer.stroke()
  224. # Loading markdown page at start of the update window
  225. if not win.current["mdfs"]["update_markdown"]:
  226. do()
  227. current_X = current_X + 310
  228. # And finally the scroller for the top bar.
  229. UI_elements.scroll_area(layer, win, "pm_update",
  230. 50,
  231. 20,
  232. win.current["w"]-100,
  233. 80,
  234. current_X,
  235. bar=True,
  236. mmb=True,
  237. sideways=True,
  238. url="update_layer"
  239. )
  240. return surface