12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235 |
- import os
- import math
- import urllib3
- import hashlib
- import threading
- import gi
- gi.require_version('Gtk', '3.0')
- from gi.repository import Gtk
- from gi.repository import Gdk
- from gi.repository import GLib
- from gi.repository import GdkPixbuf
- import cairo
- from settings import settings
- from settings import talk
- from settings import fileformats
- from UI import UI_color
- def roundrect(layer, win, x, y, width, height, r, button=False, icon=False,
- tip="", fill=True, url="", clip=False, offset=[0,0], text=False):
-
-
-
-
-
- if button:
-
-
- if url and url != win.url:
-
-
- if icon:
- image(layer, win, "settings/themes/"\
- +win.settings["Theme"]+"/icons/"+icon+".png", x, y)
-
- return
-
-
- if win.current["testing"]:
- UI_color.set(layer, win, "testing_banner")
- layer.rectangle(x,y,width,height)
- layer.stroke()
-
-
- if win.current['mx'] in range(int(x+offset[0]), int(x+width+offset[0])) \
- and win.current['my'] in range(int(y+offset[1]), int(y+height+offset[1])) :
- do = True
-
- if clip:
- if win.current['mx'] in range(int(clip[0]), int(clip[0]+clip[2])) \
- and win.current['my'] in range(int(clip[1]), int(clip[1]+clip[3])) :
- do = True
- else:
- do = False
-
- else:
- do = False
-
-
-
- if do:
-
-
- if text:
- win.current["cursor"] = win.cursors["text"]
- else:
- win.current["cursor"] = win.cursors["hand"]
-
-
- if win.current["LMB"]:
- UI_color.set(layer, win, "button_clicked")
- else:
- UI_color.set(layer, win, "button_active")
-
- if win.previous["LMB"] and not win.current["LMB"]:
- win.current["cursor"] = win.cursors["watch"]
- button()
-
-
- if tip:
- tooltip(win, tip)
-
-
- else:
- do = True
-
- if do:
-
-
-
- if width < r*2:
- width = r*2
- if height < r*2:
- height = r*2
-
-
-
-
-
- if "Roundness" not in win.settings:
- win.settings["Roundness"] = 1.0
- settings.write("Roundness", 1.0)
-
- r = r*win.settings["Roundness"]
-
-
- layer.move_to(x,y+r)
- layer.arc(x+r, y+r, r, math.pi, 3*math.pi/2)
- layer.arc(x+width-r, y+r, r, 3*math.pi/2, 0)
- layer.arc(x+width-r, y+height-r, r, 0, math.pi/2)
- layer.arc(x+r, y+height-r, r, math.pi/2, math.pi)
- layer.close_path()
- if fill:
- layer.fill()
-
-
-
- if icon:
- image(layer, win, "settings/themes/"\
- +win.settings["Theme"]+"/icons/"+icon+".png", x, y)
-
- def animate(name, win, v1=0, v2=None, time=10, force=False):
-
-
-
-
-
-
-
- if v2 == None:
- v2 = v1
-
-
- if name not in win.animations or force:
- win.animations[name] = [
- v1,
- v2,
- time,
- win.current["frame"]
- ]
-
-
- v1 = win.animations[name][0]
- v2 = win.animations[name][1]
- time = win.animations[name][2]
- start = win.animations[name][3]
- frame = win.current["frame"]
-
- if time == 0:
- return v2
-
-
- if start + time < frame:
- return v2
-
-
-
- if v1 == v2:
- return v2
-
- if v1 < v2:
- vN = v1 + ((v2 - v1)/time*(frame-start))
- else:
- vN = v1 - ((v1 - v2)/time*(frame-start))
-
- return vN
-
- def blur(surface, win, amount):
-
-
-
-
-
-
- if amount < 3:
- return surface
-
-
- if not "Blur" in win.settings:
- settings.write("Blur", True)
- win.settings = settings.load_all()
-
-
- if win.settings["Blur"]:
-
- surface1 = cairo.ImageSurface(cairo.FORMAT_ARGB32, win.current['w'],
- win.current['h'])
-
- slacedownlayer = cairo.Context(surface1)
- slacedownlayer.scale(1/amount,
- 1/amount)
-
- slacedownlayer.set_source_surface(surface, 0 , 0)
- slacedownlayer.paint()
-
-
- surface2 = cairo.ImageSurface(cairo.FORMAT_ARGB32, win.current['w'],
- win.current['h'])
- slaceuplayer = cairo.Context(surface2)
-
- slaceuplayer.scale(amount,
- amount)
-
-
- slaceuplayer.set_source_surface(surface1, 0 , 0)
-
-
- if not "PixelBlur" in win.settings:
- settings.write("PixelBlur", False)
- win.settings = settings.load_all()
- if win.settings["PixelBlur"]:
- p = slaceuplayer.get_source()
- p.set_filter(cairo.FILTER_NEAREST)
- slaceuplayer.paint()
-
- return surface2
- else:
- return surface
- def hash_file(f):
-
-
-
- try:
- BLOCKSIZE = 65536
- hasher = hashlib.md5()
- with open(f, 'rb') as afile:
- buf = afile.read(BLOCKSIZE)
- while len(buf) > 0:
- hasher.update(buf)
- buf = afile.read(BLOCKSIZE)
- return str(hasher.hexdigest())
- except:
- return "FOLDER"
- def loadimage(layer, win ,path, x, y, width, height, fit, cell=0):
-
-
-
-
-
-
-
-
-
-
- if "auto_download_images" not in win.settings:
- win.settings["auto_download_images"] = False
- settings.write("auto_download_images", win.settings["auto_download_images"])
-
- filename = "/tmp/"+path.replace("/","_")
-
- found = False
- for f in fileformats.images:
- if filename.endswith(f):
- found = True
- if not found:
- filename = filename+".png"
- tmppath = ""
- if path.startswith("http") and not os.path.exists(filename):
-
- if win.images[cell][path]["image"] != "downloading":
-
-
-
-
- win.images[cell][path]["loading"] = False
- win.images[cell][path]["image"] = "download_button"
- return
- else:
-
-
-
- win.images[cell][path]["image"] = None
-
- http = urllib3.PoolManager()
- r = http.request('GET', path, preload_content=False)
- with open(filename, 'wb') as out:
- while True:
- data = r.read(1024)
- if not data:
- break
- out.write(data)
- r.release_conn()
-
- elif path.startswith("http"):
- tmppath = path
- path = filename
-
-
-
-
-
-
-
-
-
-
-
-
-
- foundformat = False
-
-
- for f in fileformats.images:
- if path.endswith(f):
-
- foundformat = True
-
-
-
-
-
-
-
- try:
- load1 = GdkPixbuf.Pixbuf.new_from_file(path)
- except:
-
- try:
- load1 = GdkPixbuf.Pixbuf.new_from_file("settings/themes/"+win.settings["Theme"]+"/icons/image.png")
- except:
- load1 = GdkPixbuf.Pixbuf.new_from_file("settings/themes/Default/icons/image.png")
-
-
- for f in fileformats.videos:
- if path.endswith(f):
-
- foundformat = True
-
-
-
-
-
- try:
-
-
-
-
- part = path.replace("/", "_").replace(" ", "_")
-
-
- os.system("totem-video-thumbnailer -s "+str(width)+" "+path\
- +" /tmp/vcstudio_thumbnail"+part+".png")
-
-
- load1 = GdkPixbuf.Pixbuf.new_from_file("/tmp/vcstudio_thumbnail"+part+".png")
-
-
- try:
- os.remove("/tmp/vcstudio_thumbnail"+part+".png")
- except:
- pass
-
- except:
- try:
- load1 = GdkPixbuf.Pixbuf.new_from_file("settings/themes/"+win.settings["Theme"]+"/icons/video.png")
- except:
- load1 = GdkPixbuf.Pixbuf.new_from_file("settings/themes/Default/icons/video.png")
-
-
- for f in ["blend", "blend1"]:
- if path.endswith(f):
-
- foundformat = True
-
-
-
-
-
-
-
-
-
-
-
-
- try:
-
-
-
-
- part = path.replace("/", "_").replace(" ", "_")
-
-
- os.system("python3 "+os.getcwd()+"/UI/blender-thumbnailer.py "\
- +path+" /tmp/vcstudio_thumbnail"+part+".png")
-
-
- load1 = GdkPixbuf.Pixbuf.new_from_file("/tmp/vcstudio_thumbnail"+part+".png")
-
-
- try:
- os.remove("/tmp/vcstudio_thumbnail"+part+".png")
- except:
- pass
-
- except:
-
- try:
- load1 = GdkPixbuf.Pixbuf.new_from_file("settings/themes/"+win.settings["Theme"]+"/icons/blender.png")
- except:
- load1 = GdkPixbuf.Pixbuf.new_from_file("settings/themes/Default/icons/blender.png")
-
- if not foundformat:
-
-
- try:
- load1 = GdkPixbuf.Pixbuf.new_from_file("settings/themes/"+win.settings["Theme"]+"/icons/file.png")
- except:
- load1 = GdkPixbuf.Pixbuf.new_from_file("settings/themes/Default/icons/file.png")
-
-
-
- Px = load1.get_width()
- Py = load1.get_height()
- load2 = cairo.ImageSurface(cairo.FORMAT_ARGB32, Px, Py)
- imagedraw = cairo.Context(load2)
- Gdk.cairo_set_source_pixbuf( imagedraw, load1, 0, 0)
- imagedraw.paint()
-
-
-
-
- if width or height:
-
- dx = 0
- dy = 0
-
-
- imagesurface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
- imagedraw = cairo.Context(imagesurface)
-
-
-
- if fit == 'crop':
- if height > load2.get_height()\
- or width > load2.get_width():
-
- dx = (width/2) -(load2.get_width() /2)
- dy = (height/2)-(load2.get_height()/2)
-
- else:
- factor = 1
- if (load2.get_height()*(width/load2.get_width()))\
- < height:
- factor = height / load2.get_height()
- else:
- factor = width / load2.get_width()
-
- imagedraw.scale(factor, factor)
- dx = (width/2)/factor -(load2.get_width() /2)
- dy = (height/2)/factor -(load2.get_height()/2)
-
-
-
-
- elif fit == "fit_width" and load2.get_width() > width:
- factor = width / load2.get_width()
- dx = 0
- dy = 0
- imagesurface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(width), int(load2.get_height()*factor))
- imagedraw = cairo.Context(imagesurface)
- imagedraw.scale(factor, factor)
- elif fit == "fit_width":
- dx = 0
- dy = 0
- imagesurface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(load2.get_width()), int(load2.get_height()))
- imagedraw = cairo.Context(imagesurface)
-
-
-
-
-
- imagedraw.set_source_surface(load2, dx, dy)
- imagedraw.paint()
- else:
- imagesurface = load2
-
-
- if tmppath:
- path = tmppath
- win.images[cell][path]["loading"] = False
- win.images[cell][path]["image"] = imagesurface
- win.images[cell][path]["hash"] = hash_file(path)
-
- win.imageload -= 1
- def reload_images(win):
-
-
-
-
-
-
-
- for cell in list(win.images.keys()):
- for image in list(win.images[cell].keys()):
- if hash_file(image) != win.images[cell][image]["hash"]:
- win.images[cell][image]["loading"] = True
-
- pass
- def image(layer, win ,path, x, y, width=0, height=0, fit="crop", cell=0, offset=[0,0]):
-
-
-
-
-
-
-
-
-
-
-
-
-
- if cell not in win.images:
- win.images[cell] = {}
-
- if int(x) not in range(int(0-width ), int(win.current["w"])) or \
- int(y) not in range(int(0-height-win.current["h"]), int(win.current["h"])) :
- return
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if win.settings["Theme"] in path and not os.path.exists(path):
- path = path.replace(win.settings["Theme"], "Default")
-
- if path not in win.images[cell] or win.images[cell][path]["loading"]:
-
-
-
-
- win.images[cell][path] = {
- "loading": True,
- "image" : None,
- "hash" : ""
- }
-
-
-
-
- MAXLOAD = 10
-
- if win.imageload < MAXLOAD:
- win.imageload += 1
-
-
-
-
-
-
-
- t = threading.Thread(target=loadimage, args=(layer, win ,path, x, y, width, height, fit, cell))
- t.start()
-
-
- else:
- if win.images[cell][path]["image"] and win.images[cell][path]["image"] != "download_button":
- imagesurface = win.images[cell][path]["image"]
-
-
-
-
- try:
- if "icons" in win.color and "settings/themes/" in path:
- UI_color.set(layer, win, "icons")
- layer.rectangle(x,y,0,0)
- layer.fill()
- layer.mask_surface(imagesurface, x, y)
- UI_color.set(layer, win, "icons")
- layer.fill()
- else:
- layer.set_source_surface(imagesurface, x, y)
- layer.paint()
- except:
- pass
-
-
-
- if win.current["testing"]:
- UI_color.set(layer, win, "testing_image")
- layer.rectangle(x,y,imagesurface.get_width(),imagesurface.get_height())
- layer.stroke()
-
- elif win.images[cell][path]["image"] == "download_button":
-
-
-
- def do():
- win.images[cell][path]["image"] = "downloading"
- loadimage(layer, win ,path, x, y, width, height, fit, cell)
- win.images[cell][path]["loading"] = True
-
-
- win.current["LMB"] = False
- win.previous["LMB"] = False
-
- if win.settings["auto_download_images"]:
- t = threading.Thread(target=do)
- t.start()
- else:
-
- roundrect(layer, win, x,y,40,40,10,
- icon="image_link",
- button=do,
- offset=offset,
- tip=path)
-
- def tooltip(win, text):
-
- layer = win.tooltip
-
-
-
-
- text = str(text)
-
-
- lines = 0
- maxletters = 0
-
- for line in text.split("\n"):
- lines += 1
-
- if len(line) > maxletters:
- maxletters = len(line)
-
-
-
-
-
-
- sx = win.current["mx"]
- sy = win.current["my"]
-
- if sx+(maxletters*9)+40 > win.current["w"]:
- sx = win.current["w"] - ((maxletters*9)+40)
- if sy+(lines*20)+10 > win.current["h"]:
- sy = win.current["h"] - ((lines*20)+10)
-
-
- UI_color.set(layer, win, "node_background")
- roundrect(layer, win,
- sx,
- sy,
- (maxletters*9)+40,
- (lines*20)+10,
- 10)
-
-
-
- layer.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL,
- cairo.FONT_WEIGHT_NORMAL)
- layer.set_font_size(15)
- UI_color.set(layer, win, "text_normal")
-
- for num, line in enumerate(text.split("\n")):
- layer.move_to(sx+20,
- sy+20+(20*num) )
- layer.show_text(line)
-
- def scroll_area(layer, win, name, x, y, width, height, maxlength,
- bar=False,sideways=False, mmb=False, mmb_only=False,
- url="", strenght=50, bar_always=False):
-
-
-
-
-
- if maxlength == 0:
- maxlength = 1
-
- x = int(x)
- y = int(y)
- width = int(width)
- height = int(height)
-
-
- if name not in win.scroll:
- win.scroll[name] = 0
- return
-
-
-
-
-
- amount = 0.0
- if win.current['mx'] in range(x, x+width) \
- and win.current['my'] in range(y, y+height) :
- if not mmb_only:
-
- amount = win.current["scroll"][1]*strenght
-
-
- if mmb_only:
- mmb = True
-
-
- if mmb:
- if win.current["MMB"]:
- if not sideways:
- amount = 0 - ( win.current["my"] - win.previous["my"] )
- else:
- amount = 0 - ( win.current["mx"] - win.previous["mx"] )
-
-
-
-
-
- def logic():
- if url and url != win.url:
- return
-
- win.scroll[name] -= amount
-
- if not sideways:
-
- if win.scroll[name] < (1-maxlength+height):
- win.scroll[name] = (1-maxlength+height)
-
- if win.scroll[name] > 0:
- win.scroll[name] = 0
- else:
-
- if win.scroll[name] < (1-maxlength+width):
- win.scroll[name] = (1-maxlength+width)
-
- if win.scroll[name] > 0:
- win.scroll[name] = 0
- logic()
-
-
-
-
- if bar:
-
-
-
-
- if not sideways:
-
-
-
-
- tobreak = False
- fraction = height / maxlength
- if fraction > 1:
- tobreak = True
- fraction = 1
-
-
-
-
-
- if not tobreak or bar_always:
-
-
-
-
- offset = (height-60)*( (1-win.scroll[name]) / maxlength )
-
-
-
- UI_color.set(layer, win, "background")
- roundrect(layer, win,
- (x+width)-20,
- y+30,
- 10,
- height-60,
- 5
- )
-
-
-
- UI_color.set(layer, win, "button_active")
-
-
-
-
- Lx = (x+width)-20
- LSx = 10
- Ly = y+30+offset
- LSy = (height-60)*fraction
-
-
-
-
- if win.current['mx'] in range(int(Lx), int(Lx+LSx)) \
- and win.current['my'] in range(int(Ly), int(Lx+LSy)) :
- UI_color.set(layer, win, "button_clicked")
-
-
-
-
-
-
-
-
- if win.current["LMB"]:
- if int(win.current['LMB'][0]) in range(int(Lx), int(Lx+LSx)) \
- and int(win.current['LMB'][1]) in range(int(y), int(y+(height-60))) :
-
- UI_color.set(layer, win, "button_clicked")
-
-
- amount = ( win.current["my"] - win.previous["my"] ) / \
- (height-60) * maxlength
- logic()
-
-
-
-
- roundrect(layer, win,
- Lx,
- Ly,
- LSx,
- LSy,
- 5
- )
- else:
-
-
-
-
- tobreak = False
- fraction = width / maxlength
- if fraction > 1:
- tobreak = True
- fraction = 1
-
-
-
-
-
- if not tobreak or bar_always:
-
-
-
-
- offset = (width-60)*( (1-win.scroll[name]) / maxlength )
-
-
-
- UI_color.set(layer, win, "background")
- roundrect(layer, win,
- x+30,
- (y+height)-20,
- width-60,
- 10,
- 5
- )
-
-
-
- UI_color.set(layer, win, "button_active")
-
-
-
-
- Lx = (y+height)-20
- LSx = 10
- Ly = x+30+offset
- LSy = (width-60)*fraction
-
-
-
-
- if win.current['my'] in range(int(Lx), int(Lx+LSx)) \
- and win.current['mx'] in range(int(Ly), int(Lx+LSy)) :
- UI_color.set(layer, win, "button_clicked")
-
-
-
-
-
-
-
-
- if win.current["LMB"]:
- if int(win.current['LMB'][1]) in range(int(Lx), int(Lx+LSx)) \
- and int(win.current['LMB'][0]) in range(int(x), int(x+(width-60))) :
-
- UI_color.set(layer, win, "button_clicked")
-
-
- amount = ( win.current["mx"] - win.previous["mx"] ) / \
- (width-60) * maxlength
- logic()
-
-
-
-
- roundrect(layer, win,
- Ly,
- Lx,
- LSy,
- LSx,
- 5
- )
- def text(outlayer, win, name, x, y, width, height, set_text="", parse=False, fill=True,
- editable=True, multiline=False , linebreak=False, centered=False, tip="",
- offset=[0,0]):
-
-
-
-
-
-
-
- surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(width), int(height))
- layer = cairo.Context(surface)
- layer.select_font_face("Monospace", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
- layer.set_font_size(20)
-
-
-
-
-
- if name not in win.text:
-
-
- scrollname = name
- while scrollname in win.scroll:
- scrollname = scrollname+"_text"
-
- win.text[name] = {
- "text" :set_text,
- "cursor":[len(str(set_text)),len(str(set_text))],
- "insert":False,
- "scroll":scrollname
- }
-
-
- if fill:
- UI_color.set(layer, win, "darker_parts")
- roundrect(layer, win,
- 0,
- 0,
- width,
- height,
- 10)
- layer.fill()
-
-
-
- roundrect(layer, win,
- 0,
- 0,
- width,
- height,
- 10,
- fill=False)
- layer.clip()
-
-
-
-
-
-
- offsetX = 0
- cursor2location = win.text[name]["cursor"][1]*12 + offsetX
- while cursor2location > width - 5:
- offsetX -= 1
- cursor2location = win.text[name]["cursor"][1]*12 + offsetX
-
-
-
-
- if editable:
- UI_color.set(layer, win, "node_blendfile")
- if win.text[name]["cursor"][0] == win.text[name]["cursor"][1]:
- if win.blink:
- layer.rectangle(
- win.text[name]["cursor"][0]*12+5 +offsetX,
- 5,
- (win.text[name]["cursor"][1]*12)-(win.text[name]["cursor"][0]*12)+2,
- 30
- )
- else:
- roundrect(layer, win,
- win.text[name]["cursor"][0]*12+5 +offsetX,
- 5,
- (win.text[name]["cursor"][1]*12)-(win.text[name]["cursor"][0]*12)+2,
- 30,
- 5,
- fill=False
- )
- if win.textactive == name:
- layer.fill()
- elif win.text[name]["cursor"][0] != win.text[name]["cursor"][1]:
- layer.stroke()
-
-
-
-
-
-
- if win.current["LMB"]:
- if int(win.current["mx"]-offset[0]) in range(int(x), int(x+width))\
- and int(win.current["my"]-offset[1]) in range(int(y), int(y+height)):
- win.text[name]["cursor"][0] = int((win.current["LMB"][0]-x-offsetX-offset[0])/12)
- win.text[name]["cursor"][1] = int((win.current["mx"]-x-offsetX-offset[0])/12)
-
-
- if win.text[name]["cursor"][0] > win.text[name]["cursor"][1]:
- win.text[name]["cursor"] = [
- win.text[name]["cursor"][1],
- win.text[name]["cursor"][0]]
-
-
- if win.text[name]["cursor"][0] < 0:
- win.text[name]["cursor"][0] = 0
- if win.text[name]["cursor"][1] < 0:
- win.text[name]["cursor"][1] = 0
- if win.text[name]["cursor"][0] > len(str(win.text[name]["text"])):
- win.text[name]["cursor"][0] = len(str(win.text[name]["text"]))
- if win.text[name]["cursor"][1] > len(str(win.text[name]["text"])):
- win.text[name]["cursor"][1] = len(str(win.text[name]["text"]))
-
-
-
-
-
- UI_color.set(layer, win, "text_normal")
- layer.move_to(5+offsetX, height/2+5)
- if centered:
- layer.move_to(width/2-len(str(win.text[name]["text"]))*12/2, height/2+5)
- layer.show_text(str(win.text[name]["text"]))
-
-
- if win.current["keys"] and editable and name == win.textactive:
-
-
- if not multiline:
- if 65293 in win.current["keys"] or 65421 in win.current["keys"]\
- or 65289 in win.current["keys"]:
- win.current["key_letter"] = ""
-
-
- prevlen = len(win.text[name]["text"])
- clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
- regularclean = True
- ORD = 0
- try:
- ORD = ord(win.current["key_letter"])
- except:
- pass
- backremove = False
-
-
-
-
- if 65288 in win.current["keys"]:
- if win.text[name]["cursor"][0] != 0 and win.text[name]["cursor"][0]\
- == win.text[name]["cursor"][1]:
-
- win.text[name]["text"] = win.text[name]["text"]\
- [:win.text[name]["cursor"][0]-1]+\
- win.text[name]["text"]\
- [win.text[name]["cursor"][1]:]
-
- elif win.text[name]["cursor"][1] != 0 and win.text[name]["cursor"][0]\
- != win.text[name]["cursor"][1]:
-
- win.text[name]["text"] = win.text[name]["text"]\
- [:win.text[name]["cursor"][0]]+\
- win.text[name]["text"]\
- [win.text[name]["cursor"][1]:]
- backremove = True
-
-
- elif ORD == 3:
- clipboard.set_text( win.text[name]["text"]\
- [win.text[name]["cursor"][0]:win.text[name]["cursor"][1]], -1)
-
-
- elif ORD == 22:
-
- cliptext = str(clipboard.wait_for_text())
-
- win.text[name]["text"] = win.text[name]["text"]\
- [:win.text[name]["cursor"][0]]\
- + cliptext +\
- win.text[name]["text"]\
- [win.text[name]["cursor"][1]:]
- win.text[name]["cursor"][0] = win.text[name]["cursor"][1]
-
-
- elif ORD == 1:
- win.text[name]["cursor"][0] = 0
- win.text[name]["cursor"][1] = len(win.text[name]["text"])
-
-
- elif 65507 in win.current["keys"]:
- pass
-
-
- elif 65506 in win.current["keys"]:
-
- if 65363 in win.current["keys"]:
- win.text[name]["cursor"][1] = win.text[name]["cursor"][1] + 1
-
-
-
- elif 65361 in win.current["keys"]:
- if win.text[name]["cursor"][1] > win.text[name]["cursor"][0]:
- win.text[name]["cursor"][1] = win.text[name]["cursor"][1] - 1
-
-
-
- elif 65363 in win.current["keys"]:
- win.text[name]["cursor"][0] = win.text[name]["cursor"][0] + 1
- win.text[name]["cursor"][1] = win.text[name]["cursor"][0]
- win.current["keys"].remove(65363)
-
-
- elif 65361 in win.current["keys"]:
- win.text[name]["cursor"][0] = win.text[name]["cursor"][0] - 1
- win.text[name]["cursor"][1] = win.text[name]["cursor"][0]
- win.current["keys"].remove(65361)
-
-
- elif 65307 in win.current["keys"]:
- win.textactive = ""
- win.current["keys"].remove(65307)
-
- else:
- win.text[name]["text"] = win.text[name]["text"]\
- [:win.text[name]["cursor"][0]]\
- + win.current["key_letter"]+\
- win.text[name]["text"]\
- [win.text[name]["cursor"][1]:]
-
-
-
- nowlen = len(win.text[name]["text"])
- if win.text[name]["cursor"][0] == win.text[name]["cursor"][1]:
- win.text[name]["cursor"][0] = win.text[name]["cursor"][0] + (nowlen - prevlen)
- win.text[name]["cursor"][1] = win.text[name]["cursor"][0]
-
- elif backremove:
- win.text[name]["cursor"][1] = win.text[name]["cursor"][0]
-
-
- if nowlen != prevlen and regularclean:
-
- win.current["keys"] = []
-
-
-
-
-
- outlayer.set_source_surface(surface, x, y)
- outlayer.paint()
-
-
- if editable:
- def do():
- win.textactive = name
- roundrect(outlayer, win,
- x,
- y,
- width,
- height,
- 10,
- fill=False,
- button=do,
- tip=tip,
- offset=offset,
- text=True)
- outlayer.stroke()
-
- if win.textactive == name:
- UI_color.set(outlayer, win, "button_active")
- roundrect(outlayer, win,
- x,
- y,
- width,
- height,
- 10,
- fill=False)
- outlayer.stroke()
|