123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446 |
- # THIS FILE IS A PART OF VCStudio
- # PYTHON 3
- import os
- # GTK module ( Graphical interface
- 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
- # Own modules
- from settings import settings
- from settings import talk
- from project_manager import pm_project
- from studio import analytics
- from studio import story
- from studio import studio_gtk
- from studio import studio_dialogs
- #UI modules
- from UI import UI_elements
- from UI import UI_color
- def layer(win):
-
- # Making the layer
- surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, win.current['w'],
- win.current['h'])
- layer = cairo.Context(surface)
-
-
- #text setting
- layer.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
-
- UI_color.set(layer, win, "darker_parts")
- UI_elements.roundrect(layer, win,
- 50,
- 5,
- win.current["w"] - 55,
- win.current["h"] - 30,
- 30)
-
- # Little verion thing in the bottom corner
- UI_color.set(layer, win, "testing_banner")
- layer.set_font_size(15)
- layer.move_to(win.current["w"]-80, win.current["h"] - 7)
- layer.show_text(str(win.version))
-
-
- # Side bar. First 3. New project / Search Projects / Configure Project.
-
- # New Project
- def do():
- print("New Project")
- win.url = "new_project"
-
- UI_elements.roundrect(layer, win,
- 5,
- 5,
- 40,
- 40,
- 10,
- do,
- "new_file",
- talk.text("createnewproject_tooltip"),
- url="project_manager")
-
-
-
- # Search for projects
- def do():
-
- win.url = "scan_projects"
-
- UI_elements.roundrect(layer, win,
- 5,
- 55,
- 40,
- 40,
- 10,
- do,
- "search_file",
- talk.text("scanforprojects_tooltip"),
- url="project_manager")
-
-
- # Configure
- if win.current["project"] and pm_project.is_legacy(win.current["project"]):
-
- def do():
- print("configure")
- #GLib.timeout_add(1, studio_gtk.run, win )
- analytics.save(win.current["project"], win.projects[win.current["project"]])
- story.save(win.current["project"], story.get_legacy(win.current["project"]))
-
- # Makinf the set folder
- try:
- os.mkdir(win.current["project"]+"/set/")
- except:
- pass
-
- # Copy the project.data to set
- try:
- f = open(win.current["project"]+"/project.progress")
- t = open(win.current["project"]+"/set/project.progress", "w")
- t.write(f.read())
- t.close()
- except:
- pass
-
- UI_elements.roundrect(layer, win,
- 5,
- 110,
- 40,
- 40,
- 10,
- do,
- "configure_file",
- talk.text("convertoldproject_tooltip"),
- url="project_manager")
-
-
- # Side bar. Last 3. Internet things / Updater / Settings
-
- # Internet things
- def do():
-
- # I used to have a specific UI instance for the help layer here. But
- # it proved to be too hard to maintain. So I'm changing it to a different
- # dialog. I'm not going to delete the help layer it self. For curious
- # poeple.
-
- # win.url = "help_layer"
-
- # The following commands are the replacement. So if you want to see how
- # it used to look. Comment those. So not to launch both in the same time.
-
- def after(win, var):
- pass
-
- studio_dialogs.help(win, "help", after, SEARCH=talk.text("documentation_project_manager"))
-
- UI_elements.roundrect(layer, win,
- 5,
- win.current["h"]-150,
- 40,
- 40,
- 10,
- do,
- "question",
- talk.text("pm_internet_tooltip"),
- url="project_manager")
-
- # Update
- def do():
- win.url = "update_layer"
-
- UI_elements.roundrect(layer, win,
- 5,
- win.current["h"]-95,
- 40,
- 40,
- 10,
- do,
- "update",
- talk.text("Update"),
- url="project_manager")
-
- # I gonna draw a little thingy for if a new update is available
- try:
- if win.update["count"]:
- count = str(win.update["count"])
-
- UI_color.set(layer, win, "node_background")
- UI_elements.roundrect(layer, win,
- 30,
- win.current["h"]-100,
- len(count)*12+6,
- 25,
- 5)
- layer.fill()
- UI_color.set(layer, win, "text_normal")
- layer.set_font_size(20)
- layer.move_to(33,win.current["h"]-80)
- layer.show_text(count)
-
- except:
- pass
-
- # Settings
- def do():
- win.url = "settings_layer"
-
- UI_elements.roundrect(layer, win,
- 5,
- win.current["h"]-45,
- 40,
- 40,
- 10,
- do,
- "settings",
- talk.text("Settings"),
- url="project_manager")
-
- # Now let's make previews of projects. I think each one will be it's own
- # layer thingy. Just so I could draw things inside them.
-
- # Clipping so it wont draw beyon the frame
- UI_elements.roundrect(layer, win,
- 50,
- 5,
- win.current["w"] - 55,
- win.current["h"] - 30,
- 30,
- fill=False)
- layer.clip()
-
- # Setting up scroll for Projects
- if "pm_scroll" not in win.current:
- win.current["pm_scroll"] = 0.0
-
- # Setting up tilling
- tileY = 0
- tileX = 0
-
- if "pm_main" not in win.scroll:
- win.scroll["pm_main"] = 0
-
- for num, project in enumerate(pm_project.get_list()):
-
-
- if tileX > (win.current["w"]-55)-391:
- tileY += 330
- tileX = 0
-
- project_node(layer, win, 60+tileX, 15+tileY+ win.scroll["pm_main"], project)
-
- tileX += 360
-
- UI_elements.scroll_area(layer, win, "pm_main",
- 50,
- 5,
- win.current["w"] - 55,
- win.current["h"] - 30,
- tileY+340,
- bar=True,
- mmb=True,
- url="project_manager"
- )
-
-
-
- return surface
-
- def project_node(layer, win, x, y, project):
-
- # This function will draw a project to a given place.
- node_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, win.current['w'],
- win.current['h'])
- node = cairo.Context(node_surface)
- node.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
-
-
-
-
-
- # Before we gonna do clip. Let's put here the logic of the node.
- def do():
- print(project)
- win.current["project"] = project
-
- Legacytip = ""
- nameonly = project[project.rfind("/")+1:]
- timefraction = 0.0
- projectfraction = 0.0
-
- if pm_project.is_legacy(project):
- Legacytip = "\nLegacy (Blender-Organizer)"
-
- # Getting info about the project. For now only Legacy. Since nothing is
- # written for the new stuff.
-
- try:
- if project not in win.projects:
- win.projects[project] = analytics.get_legacy(project)
-
- nameonly = win.projects[project]["name"]
- timefraction = win.projects[project]["timepassed"]
- projectfraction = win.projects[project]["fraction"]
- except:
- pass
-
- else:
- try:
- if project not in win.projects:
- win.projects[project] = analytics.load(project)
-
- nameonly = win.projects[project]["name"]
- timefraction = win.projects[project]["timepassed"]
- projectfraction = win.projects[project]["fraction"]
- except:
- pass
-
-
- node.set_line_width(10)
- UI_elements.roundrect(node, win,
- x-5,
- y-5,
- 350+10,
- 320+10,
- 20+5,
- button=do,
- fill=False,
- tip=project+Legacytip,
- url="project_manager")
- node.stroke()
-
- # If project is selected
- if win.current["project"] == project and win.previous["project"] == project:
- UI_color.set(node, win, "button_active")
- UI_elements.roundrect(node, win,
- x-5,
- y-5,
- 350+10,
- 320+10,
- 20+5,
- button=False,
- fill=False
- )
- node.stroke()
-
- def do():
- pm_project.load(project, win)
- #Gtk.main_quit() # Here I might do some kind a setting later
-
- UI_elements.roundrect(node, win,
- x-5,
- y-5,
- 350+10,
- 320+10,
- 20+5,
- button=do,
- fill=False,
- url="project_manager"
- )
-
- # Enter keys
- if win.url == "project_manager":
- if 65293 in win.current["keys"] or 65421 in win.current["keys"]:
- do()
- win.current["keys"].remove(65293)
- win.current["keys"].remove(65421)
-
- # This next roundrect will both be the backdrop of the node and both will
- # clip the node content. All folowing graphics will be drawn clipped to the
- # current roundrect.
-
-
- UI_color.set(node, win, "node_background")
- UI_elements.roundrect(node, win,
- x,
- y,
- 350,
- 320,
- 20)
-
- # Clip
- UI_elements.roundrect(node, win,
- x,
- y,
- 350,
- 320,
- 20,
- fill=False)
- node.clip()
-
- if os.path.exists(project+"/set/banner.png"):
- UI_elements.image(node, win, project+"/set/banner.png",
- x,y,350,320)
- elif os.path.exists(project+"/py_data/banner.png"):
- UI_elements.image(node, win, project+"/py_data/banner.png",
- x,y,350,320)
- else:
- UI_elements.image(node, win, "icon.png",
- x,y,350,320)
-
- # Top Banner thingy
- if pm_project.is_legacy(project):
- UI_color.set(node, win, "node_badfile")
- else:
- UI_color.set(node, win, "node_blendfile")
-
- node.rectangle(x,y,350,40)
- node.fill()
-
- # Name of the project
-
- UI_color.set(node, win, "text_normal")
- node.set_font_size(20)
- node.move_to(x+175-len(nameonly)*12/2,y+25)
- node.show_text(nameonly)
-
- # Bottom widget part
- UI_color.set(node, win, "node_background")
- node.rectangle(x,y+250,350,100)
- node.fill()
-
- # Finally the progress bar HELL YEAH. (I had to write 3 hard parsing
- # algorythms only to read percentage from the project)
-
- #Background
- UI_color.set(node, win, "progress_background")
- UI_elements.roundrect(node, win,
- x+20,
- y+280,
- 310,
- 10,
- 10)
-
- #Time-passed
- UI_color.set(node, win, "progress_time")
- UI_elements.roundrect(node, win,
- x+20,
- y+280,
- 310*timefraction,
- 10,
- 10)
-
- #Done
- UI_color.set(node, win, "progress_active")
- UI_elements.roundrect(node, win,
- x+20,
- y+280,
- 310*projectfraction,
- 10,
- 10)
-
- # Drawing the Node on the main layer.
- layer.set_source_surface(node_surface, 0,0)
- layer.paint()
|