def runLauncher(mytools, wtitle='TaklowKernewek GUI'): # put up a simple launcher bar for later use root = tk.Tk() root.title(wtitle) row1 = tk.Frame(root) row2 = tk.Frame(root) for (name, commandLine) in mytools[:5]: b = tk.Button(row1, text=name, fg='black', bg='beige', border=2, command=PortableLauncher(name, commandLine)) b.pack(side=tk.LEFT, expand=tk.YES, fill=tk.BOTH) row1.pack(side=tk.TOP, expand=tk.YES, fill=tk.BOTH) for (name, commandLine) in mytools[5:]: b = tk.Button(row2, text=name, fg='black', bg='beige', border=2, command=PortableLauncher(name, commandLine)) b.pack(side=tk.LEFT, expand=tk.YES, fill=tk.BOTH) row2.pack(side=tk.TOP, expand=tk.YES, fill=tk.BOTH) root.mainloop()
def runImmediate(mytools): print('Starting Python/Tk gadgets...') for (name, commandLine) in mytools: PortableLauncher(name, commandLine)() print('One moment please ...') if sys.platform[:3] == 'win': for i in range(10): time.sleep(1) print('.' * 5 * (i + 1))
def runImmediate(mytools): # launch gadget programs immediately print 'Starting Python/Tk gadgets...' # msgs to temp stdout screen for (name, commandLine) in mytools: PortableLauncher(name, commandLine)() # call now to start now print 'One moment please...' # \b means a backspace if sys.platform[:3] == 'win': # on Windows keep stdio console window up for 5 seconds for i in range(5): time.sleep(1) print('\b' + '.' * 10),
def runImmediate(mytools): """ 立即启动小工具程序 """ print('Starting Python/Tk gadgets...') # 消息输出到标准输出 for (name, commandLine) in mytools: PortableLauncher(name, commandLine)() # 现在调用,即刻启动 print('One moment please...') if sys.platform[:3] == 'win': # 保留控制台10秒 for i in range(10): time.sleep(1) print('.' * 5 * (i + 1))
def runImmediate(mytools): """ launch gadget programs immediately """ print('Starting Python/Tk gadgets...') # msgs to stdout (poss temp) for (name, commandLine) in mytools: PortableLauncher(name, commandLine)() # call now to start now print('One moment please...') if sys.platform[:3] == 'win': # windows: keep console 10 secs for i in range(10): time.sleep(1) print('.' * 5 * (i + 1))
def runLauncher(mytools): root = MainWindow('PyGadgets PP4E') for (name, commandLine) in mytools: b = Button(root, text=name, fg='black', bg='beige', border=2, command=PortableLauncher(name, commandLine)) b.pack(side=LEFT, expand=YES, fill=BOTH) root.mainloop()
def runImmediate(mytools): # launch programs immediately print('Yma ow talleth Python/Tk GUI rag taklowkernewek' ) # msgs to temp stdout screen for (name, commandLine) in mytools: PortableLauncher(name, commandLine)() # call now to start now print('Unn pols mar pleg...') # \b means a backspace if sys.platform[:3] == 'win': # on Windows keep stdio console window up for 5 seconds for i in range(5): time.sleep(1) print(('\b' + '.' * 10), end=' ')
def runLauncher(mytools): # put up a simple launcher bar for later use root = Tk() root.title('PyGadgets PP3E') for (name, commandLine) in mytools: b = Button(root, text=name, fg='black', bg='beige', border=2, command=PortableLauncher(name, commandLine)) b.pack(side=LEFT, expand=YES, fill=BOTH) root.mainloop()
def runLauncher(mytools): """ pop up a simple launcher bar for later use """ root = MainWindow('PyGadgets PP4E') # or root = Tk() if prefer for (name, commandLine) in mytools: b = Button(root, text=name, fg='black', bg='beige', border=2, command=PortableLauncher(name, commandLine)) b.pack(side=LEFT, expand=YES, fill=BOTH) root.mainloop()
def runLauncher(mytools): """ 弹出一个简单的启动器栏备用 """ root = MainWindow('PyGadgets Programming Python') # 也可使用root=Tk() for (name, commandLine) in mytools: b = Button(root, text=name, fb='black', bg='beige', border=2, command=PortableLauncher(name, commandLine)) b.pack(side=LEFT, expand=YES, fill=BOTH) root.mainloop()
# GUI server side: read and display non-GUI script's output import sys, os from socket import * from tkinter import Tk from launchmodes import PortableLauncher from guiStreams import GuiOutput myport = 50008 sockobj = socket(AF_INET, SOCK_STREAM) sockobj.bind(('', myport)) sockobj.listen(5) print('starting') PortableLauncher('nongui', 'socket-nongui.py -gui')() print('accepting') conn, addr = sockobj.accept() conn.setblocking(False) print('accepted') def checkdata(): try: message = conn.recv(1024) # output.write(message + '\n') print(message, file=output) except error: print('no data') root.after(1000, checkdata)
""" 4 демонстрационных класса, выполняемых как независимые процессы: команды; если теперь одно окно будет завершено щелчком на кнопке Quit, остальные продолжат работу; в данном случае не существует простого способа вызвать все методы report (впрочем, для организации взаимодействий между процессами можно было бы воспользоваться сокетами и каналами), а кроме того, некоторые способы запуска могут сбрасывать поток stdout дочерних программ и разрывать связь между родителем и потомком; """ from tkinter import * from launchmodes import PortableLauncher demoModules = ['demoDlg', 'demoCheck', 'demoRadio', 'demoScale'] for demo in demoModules: PortableLauncher(demo, demo + '.py')() root = Tk() root.title('Processes') Label(root, text='Multiple program demo: command lines', bg='white').pack() root.mainloop()
def spawn(self, pycmdline, wait=0): if not wait: PortableLauncher(pycmdline, pycmdline)() # run Python progam else: System(pycmdline, pycmdline)() # wait for it to exit
def spawn(self, pycmdline, wait=False): if not wait: # запустить новый процесс PortableLauncher(pycmdline, pycmdline)() # запустить программу else: System(pycmdline, pycmdline)() # ждать ее завершения
# GUI server side: read and display non-GUI script's output import sys, os from socket import * # including socket.error from tkinter import Tk from launchmodes import PortableLauncher from gui_streams import GuiOutput myport = 50008 sockobj = socket(AF_INET, SOCK_STREAM) # GUI is server, script is client sockobj.bind(('', myport)) # config server before client sockobj.listen(5) print('starting') PortableLauncher('nongui', 'socket_non_gui.py -gui')() # spawn non-GUI script print('accepting') conn, addr = sockobj.accept() # wait for client to connect conn.setblocking(False) # use nonblocking socket (False=0) print('accepted') def checkdata(): try: message = conn.recv(1024) # don't block for input #output.write(message + '\n') # could do sys.stdou=output too print(message, file=output) # if ready, show text in GUI window except error: # raises socket.error if not ready print('no data') # print to sys.stdout root.after(1000, checkdata) # check once per second
def spawn(self, pycmdline, wait=False): if not wait: # start new process PortableLauncher(pycmdline, pycmdline)() # run Python progam else: System(pycmdline, pycmdline)() # wait for it to exit
""" 4 demo classes run as independent program processes: command lines; if one window is quit now, the others will live on; there is no simple way to run all report calls here (though sockets and pipes could be used for IPC), and some launch schemes may drop child program stdout and disconnect parent/child; """ from tkinter import * from launchmodes import PortableLauncher demoModules = ['demoDlg', 'demoRadio', 'demoCheck', 'demoScale'] for demo in demoModules: # see Parallel System Tools PortableLauncher(demo, demo + '.py')() # start as top-level programs root = Tk() root.title('Processes') Label(root, text='Multiple program demo: command lines', bg='white').pack() root.mainloop()
def spawn(self, pycmdline, wait=False): if not wait: # 启动新的进程 PortableLauncher(pycmdline, pycmdline)() # 运行python程序 else: System(pycmdline, pycmdline)() # 等待程序退出
def spawn(self, pycmdline, wait=False): if not wait: PortableLauncher(pycmdline, pycmdline)() else: System(pycmdline, pycmdline)()
""" 4 демонстрационных класса, выполняемых как независимые процессы: команды; если теперь одно окно будет завершено щелчком на кнопке Quit, остальные продолжат работу; в данном случае не существует простого способа вызвать все методы report (впрочем, для организации взаимодействий между процессами можно было бы воспользоваться сокетами и каналами), а кроме того, некоторые способы запуска могут сбрасывать поток stdout дочерних программ и разрывать связь между родителем и потомком; """ from tkinter import * from launchmodes import PortableLauncher demoModules = ['demoDlg', 'demoRadio', 'demoCheck', 'demoScale'] for demo in demoModules: # смотрите главу 5 PortableLauncher(demo, demo + '.py')() # запуск в виде программ верхнего # уровня root = Tk() root.title('Processes') Label(root, text='Multiple program demo: command lines', bg='white').pack() root.mainloop()