pm_installUpdatesLayer.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # THIS FILE IS A PART OF VCStudio
  2. # PYTHON 3
  3. # This a console project manager.
  4. import os
  5. import sys
  6. import urllib3
  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 project_manager import pm_project
  18. #UI modules
  19. from UI import UI_elements
  20. from UI import UI_color
  21. def layer(win):
  22. # Making the layer
  23. surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, win.current['w'],
  24. win.current['h'])
  25. layer = cairo.Context(surface)
  26. #text setting
  27. layer.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
  28. UI_color.set(layer, win, "dark_overdrop")
  29. layer.rectangle(
  30. 0,
  31. 0,
  32. win.current["w"],
  33. win.current["h"],
  34. )
  35. layer.fill()
  36. # So it's going to be like a little window in the center of the VCStudio
  37. # with a simple UI. Probably like 2 things. Folder and a projectname.
  38. UI_color.set(layer, win, "node_background")
  39. UI_elements.roundrect(layer, win,
  40. win.current["w"]/2-250,
  41. win.current["h"]/2-50,
  42. 500,
  43. 200,
  44. 10)
  45. # Title of the operation. Incase the user forgot.
  46. UI_elements.text(layer, win, "installing_project_title",
  47. win.current["w"]/2-250,
  48. win.current["h"]/2-15,
  49. 500,
  50. 30,
  51. 10,
  52. fill=False,
  53. centered=True,
  54. editable=False)
  55. win.text["installing_project_title"]["text"] = talk.text("update_installing")
  56. frame = win.current["frame"] - win.update["frame"] - 50
  57. files = win.update["get_files"]
  58. if win.settings["Update_all"]:
  59. files = win.update["get_all_files"]
  60. UI_color.set(layer, win, "progress_background")
  61. UI_elements.roundrect(layer, win,
  62. win.current["w"]/2-200,
  63. win.current["h"]/2+70,
  64. 400,
  65. 20,
  66. 10)
  67. if frame in range(-1, len(files)):
  68. filename = files[frame]
  69. try:
  70. UI_color.set(layer, win, "text_normal")
  71. layer.set_font_size(15)
  72. layer.move_to(win.current["w"]/2-(len(files[frame+1])*9)/2,
  73. win.current["h"]/2+50)
  74. layer.show_text(files[frame+1])
  75. except:
  76. pass
  77. path = "https://notabug.org/troler/foo/raw/master/"
  78. url = path+filename
  79. http = urllib3.PoolManager()
  80. r = http.request('GET', url, preload_content=False)
  81. try:
  82. os.makedirs(filename[:filename.rfind("/")])
  83. except:
  84. pass
  85. with open(filename, 'wb') as out:
  86. while True:
  87. data = r.read(1024)
  88. if not data:
  89. break
  90. out.write(data)
  91. r.release_conn()
  92. fraction = ((frame + 1) / len(files))
  93. if fraction > 1:
  94. fraction = 1
  95. UI_color.set(layer, win, "progress_active")
  96. UI_elements.roundrect(layer, win,
  97. win.current["w"]/2-200,
  98. win.current["h"]/2+70,
  99. (400)*fraction,
  100. 20,
  101. 10)
  102. if frame > len(files)+30:
  103. os.execl(sys.executable, sys.executable, *sys.argv)
  104. return surface