123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533 |
- import os
- import datetime
- import gi
- gi.require_version('Gtk', '3.0')
- from gi.repository import Gtk
- from gi.repository import Gdk
- import cairo
- import datetime
- import threading
- 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_storyDeletionLayer
- from studio import studio_storyLayer
- from studio import studio_settingsLayer
- from studio import studio_assetLayer
- from studio import studio_analyticsLayer
- from studio import studio_scriptLayer
- from studio import studio_multiuserLayer
- from troubleshooter import error_notify
- from UI import UI_testing
- from UI import UI_color
- from UI import UI_elements
- from network import network_renders
- from network import network_multiuser
- from network import multiuser_terminal
- def previous(win):
- win.previous = {}
- for i in win.current:
- if type(win.current[i]) == list or type(win.current[i]) is dict:
- win.previous[i] = win.current[i].copy()
- else:
- win.previous[i] = win.current[i]
- def run(project, win):
-
-
-
-
-
- try:
- win.destroy()
- except:
- pass
-
-
-
- fn = project
- try: os.mkdir(fn)
- except: pass
- try: os.mkdir(fn+"/rnd")
- except: pass
- try: os.mkdir(fn+"/dev")
- except: pass
- try: os.mkdir(fn+"/ast")
- except: pass
- try: os.mkdir(fn+"/pln")
- except: pass
- try: os.mkdir(fn+"/mus")
- except: pass
- try: os.mkdir(fn+"/set")
- except: pass
-
- for f in ["chr","loc","veh","obj"]:
- try: os.mkdir(fn+"/ast/"+f)
- except: pass
- try: os.mkdir(fn+"/dev/"+f)
- except: pass
-
-
-
-
-
- win = Gtk.Window()
- win.set_default_size(1200,720)
- win.set_position(Gtk.WindowPosition.CENTER)
- win.maximize()
- win.connect("destroy", Gtk.main_quit)
- win.set_title("VCStudio")
- win.set_default_icon_from_file("tinyicon.png")
-
-
- win.connect("button-press-event", mouse_button_press, win)
- win.connect("button-release-event", mouse_button_release, win)
- win.connect("key-press-event", key_press, win)
- win.connect("key-release-event", key_release, win)
-
-
-
-
-
-
- scroll = Gtk.ScrolledWindow()
- scroll.connect("scroll-event", scrolling, win)
-
-
- win.animations = {}
- win.previous = {}
- win.current = {}
- win.images = {}
- win.imageload = 0
- win.text = {}
- win.textactive = ""
- win.scroll = {}
- win.FPS = 0
- win.url = "story_editor"
- win.cur = ""
- win.update = {"versions":{}}
- win.project = project
- win.out_dots = {}
- win.assets = {}
- win.szone = [[100,100],[100,100]]
- win.surround = {
- "frame":0,
- "rects":[]
- }
- win.calllayer = False
- win.layercashe = {}
- win.checklists = {}
- win.blink = False
- win.renders = {}
- win.undo_history = []
- win.undo_index = 0
- win.multiuser = {
- "server":False,
- "userid":"",
- "last_request": "",
- "curs":{},
- "request":[["story"]],
- "users":{},
- "messages":[],
- "unread":0 ,
- "terminal":[],
- "asset_list_check":False,
- "story_check":False,
- "analytics_check":False
- }
-
- if pm_project.is_legacy(project):
- win.story = story.get_legacy(project)
- win.analytics = analytics.get_legacy(project)
- else:
- win.story = story.load(project)
- win.analytics = analytics.load(project)
-
-
- win.set_title("VCStudio : "+win.analytics["name"])
-
-
- win.color = UI_color.get_table()
- win.settings = settings.load_all()
-
-
- win.current["frame"] = 0
- win.current["testing"] = False
- win.current["LMB"] = False
- win.current["MMB"] = False
- win.current["RMB"] = False
- win.current["keys"] = []
- win.current["key_letter"] = ""
- win.current["scroll"] = [0,0]
- win.current["project"] = ""
- win.current["tool"] = "selection"
- win.current["draw_dot"] = "end"
- win.current["calls"] = {}
- win.current["script_find"] = [0,0]
- win.current["camera_arrived"] = False
-
-
- if "pointers" not in win.story:
- win.story["pointers"] = {}
-
- new_date_format = "%Y/%m/%d"
- today = datetime.datetime.strftime(datetime.datetime.today(), new_date_format)
- win.current["date"] = today
-
- previous(win)
-
-
- win.version = 0.0
- try:
- vfile = open("settings/update.data")
- vfile = vfile.read()
- vfile = vfile.split("\n")
-
- for line in vfile:
- if line.startswith("VERSION "):
- win.version = float(line.replace("VERSION ", ""))
- break
- except:
- win.version = 0.0
-
-
- win.sFPS = datetime.datetime.now()
-
-
- pmdraw = Gtk.DrawingArea()
- pmdraw.set_size_request(1040, 720)
- scroll.set_size_request(1040, 720)
- win.add(scroll)
- scroll.add_with_viewport(pmdraw)
- pmdraw.connect("draw", pmdrawing, win)
-
-
- multiuser = threading.Thread(target=network_multiuser.client, args=(win,))
- multiuser.setDaemon(True)
- multiuser.start()
-
-
- multiuser_term = threading.Thread(target=multiuser_terminal.listen, args=(win,))
- multiuser_term.setDaemon(True)
- multiuser_term.start()
-
-
- win.show_all()
- Gtk.main()
- def pmdrawing(pmdrawing, main_layer, win):
-
-
-
-
-
- try:
-
-
- win.fFPS = datetime.datetime.now()
- win.tFPS = win.fFPS - win.sFPS
- if win.current["frame"] % 5 == 0:
- win.blink = not win.blink
- if win.current["frame"] % 10 == 0:
- win.FPS = int ( 1.0 / ( win.tFPS.microseconds /1000000))
- if "Auto_De-Blur" not in win.settings:
- win.settings["Auto_De-Blur"] = True
-
- if win.FPS < 10 and win.settings["Auto_De-Blur"]:
- win.settings["Blur"] = False
- win.sFPS = datetime.datetime.now()
-
-
- win.current["frame"] += 1
- if win.current["frame"] == 10:
- win.cur = "/set"
- win.url = "analytics"
-
- if not "scale" in win.settings:
- settings.write("scale", 1)
- win.settings = settings.load_all()
-
-
- win.current['mx'] = int(round(win.get_pointer()[0] / win.settings["scale"]))
- win.current['my'] = int(round(win.get_pointer()[1] / win.settings["scale"]))
- win.current['w'] = int(round(win.get_size()[0] / win.settings["scale"] ))
- win.current['h'] = int(round(win.get_size()[1] / win.settings["scale"] ))
- if 65451 in win.current["keys"]:
- settings.write("scale", win.settings["scale"]+0.2)
- win.settings = settings.load_all()
- win.current["keys"] = []
-
- elif 65453 in win.current["keys"]:
- settings.write("scale", win.settings["scale"]-0.2)
- win.settings = settings.load_all()
- win.current["keys"] = []
- win.cursors = {
- "arrow":Gdk.Cursor.new(Gdk.CursorType.ARROW),
- "watch":Gdk.Cursor.new(Gdk.CursorType.WATCH),
- "text" :Gdk.Cursor.new(Gdk.CursorType.XTERM),
- "hand" :Gdk.Cursor.new(Gdk.CursorType.HAND1),
- "cross":Gdk.Cursor.new(Gdk.CursorType.CROSS)
- }
- win.current["cursor"] = win.cursors["arrow"]
-
- if 65507 in win.current["keys"] and win.current["LMB"]:
-
- dx = win.current["LMB"][0] - win.current["mx"]
- dx = max(dx, dx*-1)
- dy = win.current["LMB"][1] - win.current["my"]
- dy = max(dy, dy*-1)
-
- if dx > dy:
- win.current["my"] = win.current["LMB"][1]
- else:
- win.current["mx"] = win.current["LMB"][0]
-
- if win.previous["LMB"] and len(win.previous["LMB"]) > 2 and win.current["LMB"]:
- win.current["LMB"] = win.previous["LMB"]
-
- UI_color.set(main_layer, win, "background")
- main_layer.rectangle(
- 0,
- 0,
- win.current['w']*win.settings["scale"],
- win.current['h']*win.settings["scale"])
- main_layer.fill()
-
-
-
- win.tooltip_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, win.current['w'],
- win.current['h'])
- win.tooltip = cairo.Context(win.tooltip_surface)
- win.tooltip.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
-
- Layers = []
- if win.url == "story_editor":
- Layers.append([studio_storyLayer.layer(win),"story_editor"])
- if "story_editor" in win.layercashe:
- del win.layercashe["story_editor"]
- else:
- if "story_editor" not in win.layercashe:
- win.layercashe["story_editor" ] = studio_storyLayer.layer(win)
- Layers.append([win.layercashe["story_editor" ],"story_editor"])
- if win.url == "story_deletion_dialog":
- Layers.append([studio_storyDeletionLayer.layer(win),"story_deletion_dialog"])
- elif win.url == "settings_layer":
- Layers.append([studio_settingsLayer.layer(win),"settings_layer"])
- elif win.url == "analytics":
- Layers.append([studio_analyticsLayer.layer(win),"analytics"])
- elif win.url == "assets":
- Layers.append([studio_assetLayer.layer(win),"assets"])
- elif win.url == "script":
- Layers.append([studio_scriptLayer.layer(win), "script"])
- elif win.url == "multiuser":
- Layers.append([studio_multiuserLayer.layer(win), "multiuser"])
-
- win.calllayer = False
- remlater = []
- for call in list(win.current["calls"].keys()):
- if win.current["calls"][call]["var"] == None:
- Layers.append([win.current["calls"][call]["draw"](win, call)])
- win.url = win.current["calls"][call]["url"]
- win.calllayer = True
- else:
- win.url = win.current["calls"][call]["back"]
- win.current["calls"][call]["call"](win, win.current["calls"][call]["var"])
- win.textactive = ""
- remlater.append(call)
- for call in remlater:
-
- try:
- del win.current["calls"][call]
- except:
- pass
- Layers.append([UI_testing.layer(win)])
- Layers.append([win.tooltip_surface])
- if win.settings["scale"] != 1:
- main_layer.scale(win.settings["scale"],
- win.settings["scale"])
-
- for layer in Layers:
- if len(layer) > 1:
- layer, url = layer
- blur = UI_elements.animate(url+"_blur", win, 50)
- if (win.url != url or win.calllayer):
- if win.current["tool"] not in ["schedule", "grab"]:
- blur = UI_elements.animate(url+"_blur", win, blur, 50, 2, True)
- else:
- blur = UI_elements.animate(url+"_blur", win, 50, 50, 0, True)
- else:
- if win.current["tool"] not in ["schedule", "grab"]:
- blur = UI_elements.animate(url+"_blur", win, blur, 0, 2, True)
- else:
- blur = UI_elements.animate(url+"_blur", win, 0, 0, 0, True)
- layer = UI_elements.blur(layer, win, blur)
- else:
- layer = layer[0]
- main_layer.set_source_surface(layer, 0 , 0)
- main_layer.paint()
- win.get_root_window().set_cursor(win.current["cursor"])
-
- if 65307 in win.current["keys"] and win.url != "install_updates":
- win.url = "story_editor"
- win.story["selected"] = []
- win.current["tool"] = "selection"
- win.current["keys"] = []
- win.textactive = ""
-
-
- network_renders.read_renders(win)
-
-
- if not win.is_active():
- win.current["keys"] = []
- elif "is_active" in win.previous and not win.previous["is_active"]:
- win.multiuser["last_request"] = ""
- UI_elements.reload_images(win)
- win.current["is_active"] = win.is_active()
-
-
-
- previous(win)
-
- win.current["scroll"] = [0,0]
-
- pmdrawing.queue_draw()
- except:
- Gtk.main_quit()
- error_notify.show()
-
- def mouse_button_press(widget, event, win):
-
-
-
-
-
-
-
- for i, button in enumerate(["LMB", "MMB", "RMB"]):
- if i+1 == int(event.get_button()[1]):
- win.current[button] = [event.x, event.y]
-
-
-
-
-
- def mouse_button_release(widget, event, win):
-
-
-
- for i, button in enumerate(["LMB", "MMB", "RMB"]):
- if i+1 == int(event.get_button()[1]):
- win.current[button] = False
- def key_press(widget, event, win):
- if event.keyval not in win.current["keys"]:
- win.current["keys"].append(event.keyval)
- win.current["key_letter"] = event.string
-
- def key_release(widget, event, win):
- try:
- win.current["keys"].remove(event.keyval)
- except:
- win.current["keys"] = []
-
-
-
- if not win.current["keys"]:
- win.current["key_letter"] = ""
-
- def scrolling(widget, event, win):
- e, x, y = event.get_scroll_deltas()
- win.current["scroll"] = [x,y]
-
|