a nice editor in 100 lines
class writerKl(object):
def __init__(self):
import tkinter
fromtkinter import messagebox
fromtkinter import filedialog
fromtkinter import Tk
fromtkinter import Menu
fromtkinter import END
self.fileName = None
self.saved= True
self.app = tkinter.Tk()
self.app.title("FenInst is another instance of the writerKl class")
self.menuBar = tkinter.Menu(self.app)
self.fileMenu = tkinter.Menu(self.menuBar, tearoff=0)
self.fileMenu.add_command(label="New", command=self.newFile)
self.fileMenu.add_command(label="Open",command=self.openFile)
self.fileMenu.add_command(label="Save",command=self.saveFile)
self.fileMenu.add_command(label="Save As", command=self.saveFileAs)
self.fileMenu.add_separator() ; self.About = "A selfish tkinter
text editor in 100 lines of python3 code.\n\n In fact this very ''About
window'' also was modded using the selfish editor himself.\n\n Open the source
''writer.py'' to find out why this editor is seen as so 105x self-obsessed."
self.fileMenu.add_command(label= "About", command=lambda:
tkinter.messagebox.showinfo("About", self.About))
self.fileMenu.add_separator()
self.fileMenu.add_command(label="Exit", command=self.onExit)
self.menuBar.add_cascade( label="File", menu =self.fileMenu)
self.app.config(menu=self.menuBar)
self.app.bind('', self.newFile ) # key Bindings
self.app.bind('', self.openFile)
self.app.bind('', self.saveFile)
self.app.bind('', self.setsavedFalse )
self.app.protocol("WM_DELETE_WINDOW", self.onExit)# save before
exit?
self.textf = tkinter.Text(self.app) #
initializing text container
self.textf.pack(expand=True, fill='both') # deploying
text container
self.textf.focus()
self.app.mainloop()
def newFile(self):
import tkinter
if not self.saved:
save = self.promptToSave()
if save: self.saveFile()
elif self.save is None:return
self.fileName = None
self.textf.delete(0.0, tkinter.END)
self.saved = True
def openFile(self):
import tkinter
if not self.saved:
self.save = self.promptToSave()
if self.save:
self.saveFile()
elif self.save is None:
return
try:
self.f = tkinter.filedialog.askopenfile( filetypes=[ ('all files',
'*') , ('py files', '.py') ] )
if self.f:
self.fileName = self.f.name
self.t = self.f.read()
self.textf.delete(0.0, tkinter.END)
self.textf.insert(tkinter.END, self.t)
self.saved = True
except: tkinter.messagebox.showerror("Error", "Unable to open
file.")
def saveFile(self):
import tkinter
self.t = self.textf.get(0.0, tkinter.END)
if self.fileName:
self.f = open(self.fileName, "w")
self.f.write(self.t)
self.f.close()
self.saved = True
else:self.saveFileAs()
def saveFileAs(self):
import tkinter
self.f = tkinter.filedialog.asksaveasfile(defaultextension=".txt",
filetypes=[ ('all files', '*'),('py files', '.py') ])
self.t = self.textf.get(0.0, tkinter.END)
if self.f:
try:
self.f.write(self.t)
self.f.close( )
self.saved = True
self.fileName=self.f.name
except: tkinter.messagebox.showwarning("Error", "Unable to save
file.")
def onExit(self):
import tkinter
if notself.saved:
self.save = self.promptToSave()
if self.save: self.saveFile()
elif self.save is None:return
self.app.destroy()
def setsavedFalse(self, key):
import tkinter
if (key.keysym.isalpha() or key.keysym.isdigit() or key.keysym in
["Return", "Tab", "Backspace", "Delete"]): self.saved = False # any key that
changes text
def promptToSave(self):
import tkinter
return tkinter.messagebox.askyesnocancel( "Save file?", "Do you
want to save the current file?")
if __name__ == '__main__' :
import tkinter
FenInst =writerKl()
--
https://mail.python.org/mailman/listinfo/python-list
Re: Anaconda Navigator : Add App
that is a very slow manager. too slow. -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter,show pictures from the list of files in catalog-problem
nothing works in ure soft everything breaks -- https://mail.python.org/mailman/listinfo/python-list
Re: Python: asyncio and Tkinter
this is kinda interesting. seems there is no easy way though -- https://mail.python.org/mailman/listinfo/python-list
tkinter MP working like a charm
from tkinter import *#I cant see
anything wrong with this , it works like a charm
from tkinter import messagebox #is there a
serious concern doing things his way ?
import asyncio , threading , random #goal is multi
tasking with the GUI not freezing before loop completed
#which is being
achieved here !
def _asyncio_thread(async_loop):
async_loop.run_until_complete(do_urls())
def do_work(async_loop):
""" Button-Event-Handler starting stuff """
threading.Thread(target=_asyncio_thread, args=(async_loop,)).start()
async def one_url(url):
""" One task. """
sec = random.randint(1, 8)
await asyncio.sleep(sec )
return 'url: {} --- sec: {}'.format(url, sec)
async def do_urls():
""" Creating and starting 10 tasks. """
tasks = [one_url(url) for url in range(10)]
completed, pending = await asyncio.wait(tasks)
results = [task.result() for task in completed]
print('\n'.join(results))
def do_nofreeze():
messagebox.showinfo(message='see, Tkinter is still responsive')
def submain(async_loop):
root = Tk()
b1 = Button(master=root, text='do work', command= lambda:do_work(
async_loop)).pack()
b2 = Button(master=root, text='Frozen?', command=do_nofreeze
).pack()
root.mainloop()
if __name__ == '__main__':
async_loop = asyncio.get_event_loop()# all in this loop
submain(async_loop)
--
https://mail.python.org/mailman/listinfo/python-list
Re: tkinter MP working like a charm
OK, I never figured out that "import *" business... I was originally referring to the handling of multi-tasking via the root.mainloop() if __name__ == '__main__': async_loop = asyncio.get_event_loop()# all in this loop submain(async_loop) business , which some found a bit outlandish. I cannot see why, though. -- https://mail.python.org/mailman/listinfo/python-list
Re: a nice editor in 100 lines
[email protected]: > Le dimanche 31 décembre 2017 10:33:03 UTC+1, [email protected] a écrit : >> Le samedi 30 décembre 2017 23:02:41 UTC+1, Wu Xi a écrit : > Addendum > > This one is also not working. > > https://www.reddit.com/r/Python/comments/7murk2/a_python_ide_made_with_tkinter_it_should_be nice find! works smoothly here, except running the opened file kinda not path finding... gotta be easy to fix. -- https://mail.python.org/mailman/listinfo/python-list
Re: a nice editor in 100 lines
https://github.com/morten1982/crossviper > > nice find! > > > works smoothly here, except running the opened file kinda not path finding... > gotta be easy to fix. > take that back in xterm mode , path is no problem. nice IDE ! -- https://mail.python.org/mailman/listinfo/python-list
Mr. Conway in 50 lines of code
import time , itertools
__doc__=" Mr Conway_s Game Of Life simulation in python 2 and 3 "
width = 55 ; height = 55# size of life habitat , e.g. a simulated
meteorite, bolide , etc.
vmap = [['D' for w in range(width)] for h in range(height)] # D =
Dead at first
def neighbours(point):
x,y = point
yield x + 1 , y
yield x - 1 , y
yield x , y + 1
yield x , y - 1 #this is proof that life can emerge
inside of computers and cellular automatons,
yield x + 1 , y + 1 #and evolve through memory, attack
other cells and morph into toads, pulsars, etc..
yield x + 1 , y - 1
yield x - 1 , y + 1 #spray your memory with space alien
patterns and life evolution will start in your machine !
yield x - 1 , y - 1
def ageing(habitat):
newstate = set()
recalc = habitat | set(itertools.chain(*map(neighbours, habitat)))
for point in recalc:
count = sum((neigh in habitat) for neigh in neighbours( point))
if count == 3 or (count == 2 and point in habitat): #
standard rule def. - a life cell having less than 2 alive neighbours will die
newstate.add(point)
return newstate
glider = set([ (40,40) , (41,40) , (42,40) , (40,41) , (41,42) ])#
patterns of life: gliders, boats, guns, imps, toads, pulsars and so on
previous = set([ ( 0, 0) , ( 1, 0) , ( 2, 0) , ( 0, 1) , ( 1, 2) ])#
offset on screen / place during last step in life
for lifetime in range(300): #
number of simulated lifetime steps (e.g. 300 / 0.1 sleep = 30 seconds) before
death occurs
try:
time.sleep( 0.1 ) # slow
it down
previous = glider ; glider = ageing(glider)
for tup in glider :
el=tup ; xx=el[0] % width; yy =el[1] % height ;
vmap[xx][yy]='L' # Live cell has emerged
for tup in previous :
el=tup ; xx=el[0] % width; yy =el[1] % height
if tup not in glider : vmap[xx][yy]='D'
# Dead cell
# put more life patterns in this lifespan loop and let them evolutionize!
vtxt = [''.join('*' if cell=='L' else ' ' for cell in row) for row in vmap]
print('\033[H\033[J')
# clear screen
print('\n'.join(reversed(vtxt)))
except: pass
print("Simulated lifetime of the glider is over. May there live soon a new
glider in the life habitat of your screen.")
--
https://mail.python.org/mailman/listinfo/python-list
Re: Copy-on-write friendly Python garbage collection
[email protected]: > An interesting write up on something that is incorporated into Python 3.7 > https://engineering.instagram.com/copy-on-write-friendly-python-garbage-collection-ad6ed5233ddf kewl py 3.7 does not fully make install here, but it built and works, as far as I can tell -- https://mail.python.org/mailman/listinfo/python-list
Re: Copy-on-write friendly Python garbage collection
they said they run the largest deployment of Django world-wide. be it as it may... many still consider the web guys to be the "funny people". Why did they not switch over to Erlang ? -- https://mail.python.org/mailman/listinfo/python-list
Re: tkinter MP working like a charm (Posting On Python-List Prohibited)
Lawrence D’Oliveiro: > On Sunday, December 31, 2017 at 10:23:32 PM UTC+13, Wu Xi wrote: >> >> I was originally referring to the handling of multi-tasking... which >> some found a bit outlandish. >> >> I cannot see why, though. > > I just can’t help thinking that you are using two threads to handle what can > be done with one. > my question is: is the event loop business done OK in the sample programme ? -- https://mail.python.org/mailman/listinfo/python-list
Re: Python: asyncio and Tkinter (Posting On Python-List Prohibited)
Lawrence D’Oliveiro: > On Sunday, December 31, 2017 at 12:47:21 PM UTC+13, Wu Xi wrote: >> this is kinda interesting. seems there is no easy way though > > If I could do it for GTK/GLib <https://github.com/ldo/glibcoro>, I don’t see > why Tk should be hard. ;) well, hard or no, but glibcoro is a no workie here. 2-3 chaos, as intended by Guido. -- https://mail.python.org/mailman/listinfo/python-list
you shortened it, but you broke it too... ;-)
import time , itertools
__doc__=" Mr Conway_s Game Of Life simulation in python 2 and 3 "
width = 100 ; height = 50# size of life habitat , e.g. a simulated
meteorite, bolide , etc.
vmap = [['D' for w in range(width)] for h in range(height)] # D =
Dead at first
def neighbours(point):
x,y = point
yield x + 1 , y
yield x - 1 , y
yield x , y + 1
yield x , y - 1 #this is proof that life can emerge
inside of computers and cellular automatons,
yield x + 1 , y + 1 #and evolve through memory, attack
other cells and morph into toads, pulsars, etc..
yield x + 1 , y - 1
yield x - 1 , y + 1 #spray your memory with space alien
patterns and life evolution will start in your machine !
yield x - 1 , y - 1
'''
for i in range(-1, 2) :
for j in range(-1, 2) :
if i != j :
yield x + i, y + j
'''
# yield from [(x+i, x+j) for i in [-1,1] for j in [-1,1]]
def ageing(habitat):
newstate = set()
recalc = habitat | set(itertools.chain(*map(neighbours, habitat)))
for point in recalc:
count = sum((neigh in habitat) for neigh in neighbours( point))
if count == 3 or (count == 2 and point in habitat): #
standard rule def. - a life cell having less than 2 alive neighbours will die
newstate.add(point)
return newstate
glider = set([ (40,40) , (41,40) , (42,40) , (40,41) , (41,42) ])#
patterns of life: gliders, boats, guns, imps, toads, pulsars and so on
previous = set([ ( 0, 0) , ( 1, 0) , ( 2, 0) , ( 0, 1) , ( 1, 2) ])#
offset on screen / place during last step in life
for lifetime in range(300): #
number of simulated lifetime steps (e.g. 300 / 0.1 sleep = 30 seconds) before
death occurs
try:
time.sleep( 0.1 ) # slow
it down
previous = glider ; glider = ageing(glider)
for tup in glider :
el=tup ; xx=el[0] % width; yy =el[1] % height ;
vmap[xx][yy]='L' # Live cell has emerged
for tup in previous :
el=tup ; xx=el[0] % width; yy =el[1] % height
if tup not in glider : vmap[xx][yy]='D'
# Dead cell
# put more life patterns in this lifespan loop and let them evolutionize!
vtxt = [''.join('*' if cell=='L' else ' ' for cell in row) for row in vmap]
print('\033[H\033[J')
# clear screen
print('\n'.join(reversed(vtxt)))
except: pass
print("Simulated lifetime of the glider is over. May there live soon a new
glider in the life habitat of your screen.")
--
https://mail.python.org/mailman/listinfo/python-list
OK, now one main block only , but loop.run_forever() ? idk...
from tkinter import *#I cant see
anything wrong with the async_loop business here. It works like a charm.
from tkinter import messagebox #is there a
serious concern doing things his way ?
import asyncio , threading , random #goal is multi
tasking with the GUI not freezing before loop completed
#which is being
achieved here !works in py 3.7 of 2018
def _asyncio_thread(async_loop):
async_loop.run_until_complete(do_urls())
def do_work(async_loop):
""" Button-Event-Handler starting stuff """
threading.Thread(target=_asyncio_thread, args=(async_loop,)).start()
async def one_url(url):
""" One task. """
global root
sec = random.randint(1, 8)
root.update() # more often
await asyncio.sleep(sec )
return 'url: {} --- sec: {}'.format(url, sec)
async def do_urls():
""" Creating and starting 10 tasks. """
tasks = [one_url(url) for url in range(10)]
completed, pending = await asyncio.wait(tasks)
results = [task.result() for task in completed]
print('\n'.join(results))
def do_notfreeze(): messagebox.showinfo(message='see, Tkinter is still
responsive')
if __name__ == '__main__':
global root
async_loop = asyncio.get_event_loop()# all in this loop
root = Tk()
Button(master=root, text='do work', command= lambda:do_work(
async_loop )).pack()
Button(master=root, text='Frozen?', command= do_notfreeze
).pack()
root.update()
#async_loop.run_forever() # < uncomment, then it won"t
work anymore
root.mainloop() # how to replace ?
# To do everything in the main thread,
# one can replace 'root.mainloop' with loop.run_forever (in the main thread)
# and repeated root.update calls.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Copy-on-write friendly Python garbage collection
[email protected]: > An interesting write up on something that is incorporated into Python 3.7 > https://engineering.instagram.com/copy-on-write-friendly-python-garbage-collection-ad6ed5233ddf Appearantly, Erlang is the way to go, when it comes to web frameworks. -- https://mail.python.org/mailman/listinfo/python-list
Re: Copy-on-write friendly Python garbage collection
[email protected]: > On Sunday, December 31, 2017 at 6:19:13 PM UTC, Wu Xi wrote: >> breamoreboy: >>> An interesting write up on something that is incorporated into Python 3.7 >>> https://engineering.instagram.com/copy-on-write-friendly-python-garbage-collection-ad6ed5233ddf >> >> Appearantly, Erlang is the way to go, when it comes to web frameworks. > > What has that got to do with the subject of this thread? Well, a little implicitly. Pointing out Erlang superiority in a pythonic newsgroup is, of course, heresy. -- https://mail.python.org/mailman/listinfo/python-list
Re: tkinter MP working like a charm - almost...
from tkinter import * ; from tkinter import messagebox
import asyncio , random
async def one_url(url):
""" This is a multi threaded tkinter demo where tasks run in the background
and aim to not freeze the tk GUI, py v3.7"""
sec = random.randint(1, 8)
await asyncio.sleep(sec )
return 'url: {} took {} seconds'.format(url, sec)
async def do_urls():
""" Creating and starting 10 tasks. """
tasks = [one_url(url) for url inrange(10)]
completed, pending = await asyncio.wait(tasks)
results = [task.result() for task incompleted]
print('\n'.join(results))
def do_nofreeze(): messagebox.showinfo(message='see, Tkinter is still
responsive.')
def widgets(master): Button(master, text='GUI Frozen?',
command=do_nofreeze).pack()
def tk_update(interval):
""" A production version of this should make it possible to cancel.
However, when loop stops, updates will stop. T. Reedy"""
loop.call_later( interval, root.update )
root.update()
if __name__ == '__main__':
root = Tk()
widgets(root)
loop = asyncio.get_event_loop()
tk_update(.05)
loop.run_until_complete(do_urls())
# wow! no call to root.mainloop()
anymore. somehow like in IDLE - but it freezes now :-(
--
https://mail.python.org/mailman/listinfo/python-list
Re: Mr. Conway in 50 lines of code (Posting On Python-List Prohibited)
the short versions are not equivalent, proggy won't work with them > def neighbours(point): > x,y = point > > yield x + 1 , y > yield x - 1 , y > yield x , y + 1 > yield x , y - 1 #this is proof that life can emerge > inside of computers and cellular automatons, > > yield x + 1 , y + 1 #and evolve through memory, attack > other cells and morph into toads, pulsars, etc.. > yield x + 1 , y - 1 > yield x - 1 , y + 1 #spray your memory with space alien > patterns and life evolution will start in your machine ! > yield x - 1 , y - 1 > > ''' > for i in range(-1, 2) : > for j in range(-1, 2) : > if i != j : > yield x + i, y + j > > ''' > # yield from [(x+i, x+j) for i in [-1,1] for j in [-1,1]] -- https://mail.python.org/mailman/listinfo/python-list
Re: tkinter MP working like a charm
Abdur-Rahmaan Janhangeer: > it seems that the original poster's mail went missing > > leugenpresse means lying press btw > > weird > > i doubt the author wanted to prank us by announcing i did this and that. > > Abdur-Rahmaan Janhangeer, > Mauritius > abdurrahmaanjanhangeer.wordpress.com > > On 31 Dec 2017 5:00 am, "Wu Xi" wrote: > >> from tkinter import *#I cant see Lügen Presse = lying press , fake news makers - indeed. Using a real news reader, changing the post's topic still keeps the posting chain intact. I hope ypu don't use soft not giving you that post concatenation feature. -- https://mail.python.org/mailman/listinfo/python-list
... (Posting On Python-List Prohibited)
>> (Posting On Python-List Prohibited) >> why ? > I'm posting to the usenet group comp.lang.python (an off-topic reply to an > off-topic remark, but it happens). > I've no idea what the prohibited part is about, if that's what you're posting > about. But there have been dozens of other messages with the same subject. that's right. on https://mail.python.org/pipermail/python-list/2018-January/subject.html#start which feeds intocomp.lang.python, a lot of messages are missing. Appearantly there is some oppression scheme going on. -- https://mail.python.org/mailman/listinfo/python-list
Re: ... (Posting On Python-List Prohibited)
> Blocking of spamming and trolling prevents oppression of people who want to > use the list, funded by PSF, for its purpose, discussion of Python. why are PSF funds privileged over anybody else's fund, which has zero privilege? -- https://mail.python.org/mailman/listinfo/python-list
web fw performance with Erlang
>> Well, a little implicitly. Pointing out Erlang superiority in a pythonic >> newsgroup is, of course, heresy. > > Python is fourth in the latest TIOBE index, Erlang doesn't even make the top > 20, so in what way is it superior? > > Python doesn't need Pinky and the Brain in its quest to take over the world. Erlang is so fast, they had to ban erlang from competing here: https://www.techempower.com/benchmarks/#section=data-r14&hw=ph&test=fortune worst loser is the python framework of course -- https://mail.python.org/mailman/listinfo/python-list
