#! /usr/bin/python # -*- coding: utf-8 -*- """ This file is part of LibreLight. LibreLight is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2 of the License. LibreLight is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with LibreLight. If not, see . (c) 2012 micha@uxsrv.de """ import random rnd_id = str(random.randint(1000,9000)) rnd_id += " beta 22.10 " import subprocess import string _gcmd=['git', 'rev-parse', '--short', 'HEAD'] try: r = subprocess.check_output(_gcmd) rnd_id += r.decode('ascii').strip() except Exception as e: rnd_id += " no git" #rnd_id += " ".join(_gcmd) +str(e) try: xtitle = __file__ except: xtitle = "__file__" if "/" in xtitle: xtitle = xtitle.split("/")[-1] import sys sys.stdout.write("\x1b]2;"+str(xtitle)+" "+str(rnd_id)+"\x07") # terminal title import json import time import sys import os import _thread as thread import traceback import tkinter import tkinter as tk from tkinter import font space_font = None import tkinter.simpledialog _global_short_key = 1 class Dialog(): def __init__(self): self.d = tkinter.simpledialog self._exit = None def askstring(self,title="title",prompt="prompt:",initialvalue=""): title = "#"+title return self.askstring_old(title=title,prompt=prompt,initialvalue=initialvalue) return self.askstring_new(title=title,prompt=prompt,initialvalue=initialvalue) def askstring_old(self,title="title",prompt="prompt:",initialvalue=""): print(self.d) print(dir(self.d)) txt = self.d.askstring(title=title,prompt=prompt,initialvalue=initialvalue) return txt def close(self): print("dialog.close()") self.tk.destroy() return self._exit def event(self,event,**args): global _global_short_key #print() print("dialog:",self,"-event-",event,args) #print("###-",self.e_txt,dir(self.e_txt)) if "num" in dir(event): _global_short_key = 0 #self.e["bg"] = "red" self.el.config({"background": "grey"}) #print(dir(self.e)) if "keysym" in dir(event): t=self.e_txt.get()[:-1] if event.keysym == "Return": _global_short_key = 1 #self.e["bg"] = "blue" self.el.config({"background": "yellow"}) self.el.focus_set() self.close() print("dialog: get()",_global_short_key,t) if _global_short_key == 0: if event.keysym == "BackSpace": if len(t) > 1: t = t[:-1] #self.e_txt.set(t[:-1]) else: t = "" #self.e_txt.set("") elif event.keysym == "Escape": t = "" #self.e_txt.set("") elif event.keysym == "space": t = t+ " " #self.e_txt.set(t+" ") elif len(event.keysym) == 1: t += event.keysym #self.e_txt.set(t+event.keysym) self.e_txt.set(t+"<") #time.sleep(0.2) #_global_short_key = 1 def askstring_new(self,title="title",prompt="prompt:",initialvalue=""): self._exit = None try: #self.tk.quit() print(dir(self.tk)) self.close() except Exception as e:print(e) #self.tk = tkinter.Tk() self.tk = tkinter.Toplevel() self.tk.geometry("200x120") self.tk.title(""+str(title) )#+" "+":"+str(rnd_id)) self.tk.attributes('-topmost',True) self.tk.protocol("WM_DELETE_WINDOW", self.close) #self.tk.state(newstate='iconic') self.f = tk.Frame(self.tk) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0) self.f.pack(side="top") self.elx = tk.Label(self.f,text="") self.elx.pack(side="left") self.f = tk.Frame(self.tk) #, highlightbackground = "lightgrey", highlightthickness = 1, bd=0) self.f.pack(side="top") self.el = tk.Label(self.f,text=prompt) self.el.pack(side="top") self.e_txt = tk.StringVar() self.e = tk.Entry(self.f,state="readonly",textvariable=self.e_txt) self.e_txt.set(initialvalue+"<") self.e.bind("",self.event) self.e.bind("