1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042 |
- import os
- import urllib3
- import gi
- gi.require_version('Gtk', '3.0')
- from gi.repository import Gtk
- from gi.repository import GLib
- from gi.repository import Gdk
- import cairo
- from settings import settings
- from settings import talk
- from settings import oscalls
- from project_manager import pm_project
- from UI import UI_elements
- from UI import UI_color
- def Open(win, filename, name):
-
-
-
-
- try:
-
-
- if filename.startswith("lbry://"):
-
-
-
-
-
-
-
- print("LBRY links: "+filename)
- filename = filename.replace("lbry://", "https://spee.ch/")
- print("REQUESTING: "+filename)
- http = urllib3.PoolManager()
- resp = http.request('GET', filename)
- print("FILE RECIEVED!")
- md = resp.data.decode('utf-8')
- print("FILE CONVERTED")
-
- elif not filename.endswith(".md"):
- 1/0
- else:
-
-
- l = win.settings["Language"]
- if os.path.exists(os.getcwd()+"/"+filename[:-3]+"_"+l+".md"):
- filename = filename[:-3]+"_"+l+".md"
- md = open(filename)
- md = md.read()
- except:
-
-
- md = ""
- oscalls.Open(filename)
- win.current["mdfs"][name] = win.current["mdfs"]["failsafe"]
-
-
-
- md = md.replace("- [ ]", "")
- md = md.replace("- [X]", "")
- md = md.replace("- [x]", "")
- md = md.replace("- ", "• ")
-
-
-
- md = md.replace("../", "")
-
- md = md.split("\n")
-
-
-
-
- tree = []
- indent = 1
- c = []
-
- for line in md:
-
- ty = "text"
- te = line
-
-
-
-
-
- if line.startswith("#"):
-
-
-
-
-
-
-
-
- ty = line.count("#")
-
- elif line.startswith("> "):
-
-
-
- ty = "quote"
-
- tree.append([ty, te+"\n"])
-
-
-
-
-
-
-
-
- newtree = []
-
- for block in tree:
-
- part = ""
- skip = 0
-
- for n, l in enumerate(block[-1]):
-
- if skip > n:
- continue
-
- part = part + l
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if part.endswith("[!["):
-
-
- newtree.append([block[0], part[:-3]])
- tooltip = ""
- imageurl = ""
- url = ""
- t = False
- iu = False
- skip = n
- for le in block[-1][n:]:
- skip = skip + 1
- if le == "]":
- t = True
- elif le == ")" and t and not iu:
- iu = True
- elif le == ")" and t and iu:
- break
- elif not t:
- tooltip = tooltip +le
- elif t and not iu:
- imageurl = imageurl + le
- else:
- url = url+le
- tooltip = tooltip[tooltip.find("[")+1:]
- imageurl = imageurl[imageurl.find("(")+1:]
- url = url[url.find("(")+1:]
-
- apnd = ["image_link", tooltip, imageurl, url]
-
- newtree.append(apnd)
- part = ""
-
-
- elif part.endswith("!["):
-
-
- newtree.append([block[0], part[:-2]])
-
- tooltip = ""
- url = ""
- t = False
- skip = n
- for le in block[-1][n:]:
- skip = skip + 1
- if le == "]":
- t = True
- elif le == ")" and t:
- break
- elif not t:
- tooltip = tooltip +le
- else:
- url = url+le
- tooltip = tooltip[tooltip.find("[")+1:]
- url = url[url.find("(")+1:]
- apnd = ["image", tooltip, url]
- newtree.append(apnd)
-
- part = ""
-
-
- elif part.endswith("[") and not block[-1][n:].startswith('[!['):
-
-
- newtree.append([block[0], part[:-1]])
-
-
- tooltip = ""
- url = ""
- t = False
- skip = n
- for le in block[-1][n:]:
- skip = skip + 1
- if le == "]":
- t = True
- elif le == ")" and t:
- break
- elif not t:
- tooltip = tooltip +le
- else:
- url = url+le
- tooltip = tooltip[tooltip.find("[")+1:]
- url = url[url.find("(")+1:]
-
- apnd = ["link", tooltip, url]
- newtree.append(apnd)
-
- part = ""
-
-
-
-
-
-
-
-
-
-
-
-
-
- elif part.endswith("**") and not block[-1][n+2:].startswith('*'):
-
-
-
- newtree.append([block[0], part[:-2]])
- if block[0] == "text":
- block[0] = "text_b"
- else:
- block[0] = "text"
- part = ""
-
- elif part.endswith("*") and not block[-1][n+1:].startswith('*'):
-
-
-
- newtree.append([block[0], part[:-1]])
- if block[0] == "text":
- block[0] = "text_i"
- else:
- block[0] = "text"
- part = ""
- elif part.endswith("`"):
-
-
-
- newtree.append([block[0], part[:-1]])
- if block[0] == "text":
- block[0] = "text_c"
- else:
- block[0] = "text"
- part = ""
-
- newtree.append([block[0], part])
-
-
-
- tree = newtree
-
- return(tree)
- def search_convert(s):
-
-
-
-
-
-
-
- l = " ./\|[]{}()?!@#$%^&*`~:;'\"=,<>"
- s = s.lower().replace(" ","-")
- r = ""
- for i in s:
- if i not in l:
- r = r + i
- return r
- def draw(outlayer, win, name, x, y, width, height):
-
-
-
-
- if "mdfs" not in win.current:
- win.current["mdfs"] = {}
- win.current["mdfs"]["failsafe"] = ""
-
- if name not in win.current["mdfs"]:
- win.current["mdfs"][name] = ""
-
- filename = win.current["mdfs"][name]
- filename = filename.replace("../", "")
- win.current["mdfs"][name] = filename
-
- if "#" in filename and not "@" in filename:
- filename, search = filename.split("#")
- win.current["mdfs"][name] = filename
- else:
- search = ""
-
-
-
-
- if "mds" not in win.current:
- win.current["mds"] = {}
-
- if filename not in win.current["mds"]:
- win.current["mds"][filename] = Open(win, filename, name)
-
- md = win.current["mds"][filename]
-
-
-
-
-
-
-
-
-
-
-
- UI_color.set(outlayer, win, "node_background")
- UI_elements.roundrect(outlayer, win,
- x,
- y,
- width,
- height,
- 10)
- outlayer.fill()
-
-
-
-
- try:
- UI_elements.text(outlayer, win, "markdown_name",
- x+10,
- y+5,
- int(width/2)-120,
- 40,
- set_text=filename,
- fill=False)
-
- if win.text["markdown_name"]["text"] != filename \
- and win.textactive != "markdown_name":
- win.text["markdown_name"]["text"] = filename
-
-
- elif win.text["markdown_name"]["text"] != filename:
- def do():
- win.current["mdfs"]["failsafe"] = filename
- win.current["mdfs"][name] = win.text["markdown_name"]["text"]
-
- UI_elements.roundrect(outlayer, win,
- x+int(width/2)-150,
- y+5,
- 40,
- 40,
- 10,
- button=do,
- icon="ok",
- tip=talk.text("checked"))
-
- except:
- pass
-
-
-
- if width > 350:
- download_ok = "unchecked"
- if win.settings["auto_download_images"]:
- download_ok = "checked"
- def do():
- win.settings["auto_download_images"] = not win.settings["auto_download_images"]
- settings.write("auto_download_images", win.settings["auto_download_images"])
- UI_elements.roundrect(outlayer, win,
- x+int(width/2)-100,
- y+5,
- int(width/2)-150,
- 40,
- 10,
- button=do,
- icon=download_ok,
- tip=talk.text("auto_download_images"))
- UI_color.set(outlayer, win, "text_normal")
- outlayer.set_font_size(20)
- outlayer.move_to(x+int(width/2)-50,
- y+30)
- outlayer.show_text(talk.text("auto_download_images")[:int((int(width/2)-150)/9)])
-
-
-
- if width > 150 and not filename.startswith("lbry://"):
-
- def do():
- oscalls.Open(filename)
- UI_elements.roundrect(outlayer, win,
- x+int(width)-100,
- y+5,
- 40,
- 40,
- 10,
- button=do,
- icon="edit",
- tip=talk.text("edit_markdown"))
-
- def do():
- oscalls.Open("https://notabug.org/jyamihud/VCStudio/src/master/"+filename)
- UI_elements.roundrect(outlayer, win,
- x+int(width)-50,
- y+5,
- 40,
- 40,
- 10,
- button=do,
- icon="notabug",
- tip=talk.text("notabug_markdown"))
- elif width > 100:
-
- def do():
- oscalls.Open(filename.replace("lbry://", "https://odysee.com/"))
- UI_elements.roundrect(outlayer, win,
- x+int(width)-50,
- y+5,
- 40,
- 40,
- 10,
- button=do,
- icon="lbry",
- tip="Odysee.com (LBRY)")
-
-
-
-
-
-
-
-
-
-
- textsurface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(width), int(height))
- layer = cairo.Context(textsurface)
- layer.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
- layer_i = cairo.Context(textsurface)
- layer_i.select_font_face("Monospace", cairo.FONT_SLANT_ITALIC, cairo.FONT_WEIGHT_NORMAL)
- layer_b = cairo.Context(textsurface)
- layer_b.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
- layer_bi = cairo.Context(textsurface)
- layer_bi.select_font_face("Monospace", cairo.FONT_SLANT_ITALIC, cairo.FONT_WEIGHT_BOLD)
-
-
-
- UI_elements.roundrect(layer, win, 0,50,width, height-50, 10,fill=False)
- layer.clip()
- UI_elements.roundrect(layer_b, win, 0,50,width, height-50, 10,fill=False)
- layer_b.clip()
- UI_elements.roundrect(layer_bi, win, 0,50,width, height-50, 10,fill=False)
- layer_bi.clip()
- UI_elements.roundrect(layer_i, win, 0,50,width, height-50, 10,fill=False)
- layer_i.clip()
-
-
-
-
-
- if "markdown" not in win.scroll:
- win.scroll["markdown"] = 0
-
- current_Y = 70
- tyleX = 10
- newX = 10
- newY = 0
-
- for block in md:
-
-
-
- if type(block[0]) == int:
- current_Y = current_Y + newY + 100
-
- UI_color.set(layer_b, win, "text_normal")
- layer_b.set_font_size(30-(block[0]*4))
- layer_b.move_to(
- 10,
- current_Y + win.scroll["markdown"]
- )
- layer_b.show_text(block[1].replace("\n", "").replace("#", " "))
-
- current_Y = current_Y + 40
- if search and search in search_convert(block[1].replace("\n", "").replace("#", "")):
- win.scroll["markdown"] = 0 - current_Y + 140
- search = ""
-
- newX = 10
- newY = 0
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- elif "image" in block[0]:
-
-
-
-
-
-
-
-
- if "settings/themes/" in block[2] and "/icons/" in block[2]:
- iconname = block[2][block[2].rfind('/')+1:]
- block[2] = "settings/themes/"+win.settings["Theme"]+"/icons/"+iconname
- UI_elements. image(layer, win, "settings/themes/"\
- +win.settings["Theme"]+"/icons/"+iconname,
- tyleX,
- current_Y + win.scroll["markdown"]-30)
- tyleX = tyleX + 40
-
-
-
-
-
- else:
- if newY:
- current_Y = current_Y + newY + 40
- tyleX = 10
- newX = 10
- newY = 0
-
- UI_elements. image(layer, win, block[2],
- tyleX,
- current_Y + win.scroll["markdown"]-15,
- cell="markdown",offset=[x,y],width=width-40,fit="fit_width")
- try:
- imH = win.images["markdown"][block[2]]['image'].get_height()
- imW = win.images["markdown"][block[2]]['image'].get_width()
- except:
- imH = 40
- imW = 40
- bx = tyleX
- by = current_Y
-
- if imW < width/2:
- tyleX = tyleX + imW
- newX = imW + 40
- newY = imH - 20
- else:
- tyleX = 10
- current_Y = current_Y + imH
-
- if "link" in block[0]:
-
-
-
-
- def do():
- if block[3].endswith(".md"):
- win.current["mdfs"]["failsafe"] = filename
- win.current["mdfs"][name] = block[3]
- win.current["current_help_selected"] = ""
- win.scroll["markdown"] = 0
- else:
- oscalls.Open(block[3])
- try:
- downloadbutton = win.images["markdown"][block[2]]["image"] == "download_button"
- except:
- downloadbutton = False
-
- if not win.settings["auto_download_images"]\
- and block[2].startswith("http")\
- and downloadbutton:
-
-
- UI_elements.roundrect(layer, win, tyleX,
- current_Y + win.scroll["markdown"]-15,40,40,10,
- icon="internet",
- button=do,
- offset=[x,y],
- tip=block[3])
-
- tyleX = tyleX + 60
- else:
-
-
- UI_elements.roundrect(layer, win, bx,
- by + win.scroll["markdown"]-15,imW, imH,10,
- button=do,
- offset=[x,y],
- tip=block[3],
- fill=False)
- layer.stroke()
-
-
-
- elif block[0] in ["text", "text_i", "text_b", "text_ib", "text_c", "link"]:
- for word in block[1].split(" "):
-
- if tyleX + len(word)*12+12 > width :
- tyleX = newX
- newY = max(0, newY-30)
- if newY == 0:
- newX = 10
- current_Y = current_Y + 30
-
-
-
- if "text" in block[0]:
- UI_color.set(layer, win, "text_normal")
- UI_color.set(layer_i, win, "text_normal")
- UI_color.set(layer_b, win, "text_normal")
- UI_color.set(layer_bi, win, "text_normal")
-
-
-
-
- else:
-
-
-
- if "markdown_mouse_link" not in win.current:
- win.current["markdown_mouse_link"] = ""
- if win.current["mx"] in range(int(x+tyleX-6), int(x+tyleX-6+len(word)*12+12))\
- and win.current["my"] in range(int(y+current_Y + win.scroll["markdown"]-20),
- int(y+current_Y + win.scroll["markdown"]+5)):
- win.current["markdown_mouse_link"] = block[2]
- UI_elements.tooltip(win,block[2])
-
-
- if not win.current["LMB"] and win.previous["LMB"]:
- if block[2].startswith("#"):
- win.current["mdfs"][name] = win.current["mdfs"][name] + block[2]
- win.current["current_help_selected"] = ""
- else:
- win.current["mdfs"]["failsafe"] = filename
- win.current["mdfs"][name] = block[2]
- win.current["current_help_selected"] = ""
- win.scroll["markdown"] = 0
-
- elif win.current["mx"] not in range(win.previous["mx"]-5, win.previous["mx"]+5):
- win.current["markdown_mouse_link"] = ""
-
-
-
- if win.current["markdown_mouse_link"] == block[2]:
- UI_color.set(layer, win, "text_normal")
- UI_elements.roundrect(layer, win,
- tyleX-6,
- current_Y + win.scroll["markdown"],
- len(word)*12+12,
- 4,
- 2)
- UI_color.set(layer, win, "text_link")
-
-
-
- if "_i" in block[0]:
- layer_i.set_font_size(20)
- layer_i.move_to(
- tyleX,
- current_Y + win.scroll["markdown"]
- )
- layer_i.show_text(word.replace("\n", ""))
-
-
- elif "_b" in block[0]:
- layer_b.set_font_size(20)
- layer_b.move_to(
- tyleX,
- current_Y + win.scroll["markdown"]
- )
- layer_b.show_text(word.replace("\n", ""))
-
-
- else:
- if "_c" in block[0]:
- UI_color.set(layer, win, "node_background")
- UI_elements.roundrect(layer, win,
- tyleX-6,
- current_Y + win.scroll["markdown"]-20,
- len(word)*12+12,
- 25,
- 5)
- UI_color.set(layer, win, "text_normal")
- layer.set_font_size(20)
- layer.move_to(
- tyleX,
- current_Y + win.scroll["markdown"]
- )
- layer.show_text(word.replace("\n", ""))
-
-
- if "\n" in word:
- tyleX = newX
- newY = max(0, newY-30)
- if newY == 0:
- newX = 10
- current_Y = current_Y + 30
- else:
-
- tyleX = tyleX + len(word)*12+12
-
-
-
-
-
-
-
-
-
-
-
-
-
- if "update_markdown_files" in win.current:
- files = win.current["update_markdown_files"]
- tyleX = 50
- for file in files:
- if int(current_Y + win.scroll["markdown"] + 100) in range(0-100, win.current["h"]):
-
- nodesurface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 170, 250)
- node = cairo.Context(nodesurface)
- node.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
- UI_elements.roundrect(node, win,
- 0,
- 0,
- 170,
- 250,
- 10,
- fill=False)
- node.clip()
-
- UI_color.set(node, win, "dark_overdrop")
- node.rectangle(0,0,170, 250)
- node.fill()
-
- UI_color.set(node, win, "node_asset")
- node.rectangle(0,0,170, 20)
- node.fill()
-
- layer.set_source_surface(nodesurface,
- tyleX-10,
- current_Y + win.scroll["markdown"] + 120)
- layer.paint()
-
- UI_elements.image(layer, win, file,
- tyleX,
- current_Y + win.scroll["markdown"] + 140,
- 150,
- 150,
- cell="update_previews")
-
- UI_color.set(layer, win, "text_normal")
- layer.set_font_size(12)
- layer.move_to(tyleX,
- current_Y + win.scroll["markdown"] + 135)
- layer.show_text(file[file.rfind("/")+1:][:22])
-
- def do():
- win.current["mdfs"]["failsafe"] = filename
- win.current["mdfs"][name] = file
- win.current["update_markdown_files"] = []
- layer.set_line_width(4)
- UI_elements.roundrect(layer, win,
- tyleX-10,
- current_Y + win.scroll["markdown"] + 120,
- 170,
- 200,
- 10,
- button=do,
- tip=file,
- fill=False,
- offset=[x,y])
- layer.stroke()
- layer.set_line_width(2)
-
- ntbg = "https://notabug.org/jyamihud/VCStudio/src/master/"
-
- def do():
- oscalls.Open(ntbg+file)
- UI_elements.roundrect(layer, win,
- tyleX+35,
- current_Y + win.scroll["markdown"] + 120+205,
- 40,
- 40,
- 10,
- button=do,
- tip=ntbg+file,
- icon="notabug",
- offset=[x,y])
- ntbg = "https://notabug.org/jyamihud/VCStudio/commits/master/"
-
- def do():
- oscalls.Open(ntbg+file)
- UI_elements.roundrect(layer, win,
- tyleX+75,
- current_Y + win.scroll["markdown"] + 120+205,
- 40,
- 40,
- 10,
- button=do,
- tip=ntbg+file,
- icon="history",
- offset=[x,y])
-
- tyleX = tyleX + 200
- if tyleX > width-210:
- tyleX = 50
- current_Y = current_Y + 270
- current_Y = current_Y + 400
-
-
- UI_elements.scroll_area(outlayer, win, "markdown",
- x+0,
- y+0,
- width+30,
- height-0,
- current_Y,
- bar=True,
- mmb=True,
- bar_always=True)
-
-
-
- outlayer.set_source_surface(textsurface, x, y)
- outlayer.paint()
-
-
-
-
|