Updater 2.0

This commit is contained in:
Jeison Yehuda Amihud (Blender Dumbass) 2021-06-15 17:07:52 +00:00
parent b98b3670b4
commit d9f973be15

View file

@ -1,7 +1,23 @@
# THIS FILE IS A PART OF VCStudio
# PYTHON 3
####################################
# #
# COPYRIGHT NOTICE #
# #
# This file is a part of Victori- #
# ous Children Studio Organizer. #
# Or simply VCStudio. Copyright #
# of J.Y.Amihud. But don't be sad #
# because I released the entire #
# project under a GNU GPL license. #
# You may use Version 3 or later. #
# See www.gnu.org/licenses if your #
# copy has no License file. Please #
# note. Ones I used the GPL v2 for #
# it. It's no longer the case. #
# #
####################################
import os
import urllib3
# GTK module ( Graphical interface
import gi
@ -21,6 +37,7 @@ from project_manager import update_reader
#UI modules
from UI import UI_elements
from UI import UI_color
from UI import UI_Markdown
def layer(win):
@ -49,34 +66,37 @@ def layer(win):
)
layer.fill()
# So it's going to be like a little window in the center of the VCStudio
# with a simple UI. Probably like 2 things. Folder and a projectname.
# This is the Markdown UI object.
UI_Markdown.draw(layer, win, "update_markdown",
20,
100,
win.current["w"]-40,
win.current["h"]-200)
UI_color.set(layer, win, "node_background")
UI_elements.roundrect(layer, win,
win.current["w"]/2-250,
100,
500,
win.current["h"]-200,
50,
win.current["h"]-80,
win.current["w"]-100,
50,
10)
# Exit button
def do():
win.url = "project_manager"
win.textactive = ""
UI_elements.roundrect(layer, win,
win.current["w"]/2+210,
win.current["h"]-140,
55,
win.current["h"]-75,
40,
40,
10,
button=do,
icon="cancel",
tip=talk.text("cancel"))
# Setting to get all files. Sometimes you need a way to restore the entire
# program. Or sometimes I make mistakes. And want give myself and others a
# simple way to refresh the system. So here I gonna make a button that will
@ -101,25 +121,22 @@ def layer(win):
UI_elements.roundrect(layer, win,
win.current["w"]/2-250,
win.current["h"]-140,
420,
110,
win.current["h"]-75,
250,
40,
10,
button=do,
icon=ic,
tip=talk.text("update_all_tooltip"))
UI_color.set(layer, win, "text_normal")
layer.set_font_size(15)
layer.move_to(
win.current["w"]/2-200,
win.current["h"]-115)
150,
win.current["h"]-50)
layer.show_text(talk.text("update_all")+" "+str(len(win.update["get_all_files"]))+" "+talk.text("files"))
# Install Updates button
try:
if win.update["count"] or win.settings["Update_all"]:
@ -129,8 +146,8 @@ def layer(win):
UI_elements.roundrect(layer, win,
win.current["w"]/2+170,
win.current["h"]-140,
win.current["w"]-100,
win.current["h"]-75,
40,
40,
10,
@ -138,35 +155,43 @@ def layer(win):
icon="ok",
tip=talk.text("update_install"))
except:
pass
pass
# At the top of the Update window there is a selector bar to
# select various versions. They will load the page into the
# little browser below.
# For this wee need to clip it.
# Clipping everything
UI_elements.roundrect(layer, win,
win.current["w"]/2-250,
100,
500,
win.current["h"]-260,
50,
20,
win.current["w"]-100,
80,
10,
fill=False)
layer.clip()
clip = [
win.current["w"]/2-250,
100,
500,
win.current["h"]-260]
50,
20,
win.current["w"]-100,
80]
# Setting up the scroll
if "pm_update" not in win.scroll:
win.scroll["pm_update"] = 0
current_Y = 0 # The max scroll value
current_X = 0 # The max scroll value
for version in win.update["versions"]:
is_open = win.update["versions"][version]["open"]
files = win.update["versions"][version]["files"]
link = win.update["versions"][version]["link"]
if version == win.version:
UI_color.set(layer, win, "node_imagefile")
@ -179,26 +204,73 @@ def layer(win):
sufix = talk.text("update_available")
UI_elements.roundrect(layer, win,
win.current["w"]/2-240,
110 + current_Y + win.scroll["pm_update"],
450,
current_X + 50 + win.scroll["pm_update"],
20,
300,
40,
10)
UI_color.set(layer, win, "text_normal")
layer.set_font_size(20)
layer.move_to(win.current["w"]/2-180,
current_Y + win.scroll["pm_update"] + 140)
layer.move_to(current_X + 60 + win.scroll["pm_update"],
45)
layer.show_text(str(version)+" "+sufix)
def do():
oscalls.Open(link)
# We gonna attempt at previewing the update information in the window
# and only if it's not going to work, we gonna launch the browser with
# the link. Or do some weird. Like giving a generated page about the
# stuff.
openlink = "wiki/updates/"+str(version)+".md"
if not os.path.exists(os.getcwd()+"/"+openlink):
# In case the folder is not there yet
try:
os.mkdir("wiki/updates")
except:
pass
# Now we are getting the file
try:
http = urllib3.PoolManager()
resp = http.request('GET', "https://notabug.org/jyamihud/VCStudio/raw/master/"+openlink)
# Sometimes we might get a 404 error page
if not resp.data.decode("utf-8").startswith("<!DOCTYPE html>"):
s = open(openlink, "wb")
s.write(resp.data)
s.close()
else:
1/0 # Else we want to execute the exception
except:
# We gonna make a simple 404 page
# And load it
openlink = "/tmp/404-error-"+str(version)+".md"
s = open(openlink, "w")
s.write("# Version "+str(version)+" No page :(\n\n")
s.write("You can try")
s.write("![](../../settings/themes/OldSchool/icons/lbry.png)")
s.write("[the LBRY link]("+link.replace("(","%28").replace(")","%29")+").\n\n")
s.write("![](../../settings/themes/OldSchool/icons/question.png) [What is LBRY?](../../wiki/extra/LBRY.md)")
s.close()
win.current["mdfs"]["update_markdown"] = openlink # Loading MD file into viever
win.current["update_markdown_files"] = files # Files, for list of updates
UI_elements.roundrect(layer, win,
win.current["w"]/2-200,
110 + current_Y + win.scroll["pm_update"],
410,
current_X + 50 + win.scroll["pm_update"],
20,
300,
40,
10,
button=do,
@ -206,76 +278,25 @@ def layer(win):
fill=False,
clip=clip)
layer.stroke()
# Loading markdown page at start of the update window
if not win.current["mdfs"]["update_markdown"]:
do()
# Open and Close button. A little side triangle thingy.
if is_open:
icon = "open"
expandcall = talk.text("Compress")
else:
icon = "closed"
expandcall = talk.text("Expand")
def do():
win.update["versions"][version]["open"] = not is_open
UI_elements.roundrect(layer, win,
win.current["w"]/2-240,
110 + current_Y + win.scroll["pm_update"],
40,
40,
10,
button=do,
icon=icon,
tip=expandcall,
clip=clip)
current_Y = current_Y + 50
if is_open:
for filename in files:
UI_color.set(layer, win, "button_active")
layer.move_to(win.current["w"]/2-227, 102 + current_Y + win.scroll["pm_update"])
layer.line_to(win.current["w"]/2-227, 152 + current_Y + win.scroll["pm_update"])
layer.stroke()
gitlink = "https://notabug.org/jyamihud/VCStudio/commits/master/"
def do():
oscalls.Open(gitlink+filename)
UI_elements.roundrect(layer, win,
win.current["w"]/2-220,
110 + current_Y + win.scroll["pm_update"],
430,
40,
10,
button=do,
tip=talk.text("update_see_history")+"\n"+gitlink+filename,
icon="notabug",
clip=clip)
layer.stroke()
UI_color.set(layer, win, "text_normal")
layer.set_font_size(15)
layer.move_to(win.current["w"]/2-170,
current_Y + win.scroll["pm_update"] + 140)
layer.show_text(str(filename))
current_Y = current_Y + 50
current_X = current_X + 310
# And finally the scroller for the top bar.
UI_elements.scroll_area(layer, win, "pm_update",
int(win.current["w"]/2-250),
100,
500,
win.current["h"]-260,
current_Y,
50,
20,
win.current["w"]-100,
80,
current_X,
bar=True,
mmb=True,
sideways=True,
url="update_layer"
)
return surface