initial checkin
--HG-- branch : sandbox
This commit is contained in:
55
src/prgag/fibui_place.py
Normal file
55
src/prgag/fibui_place.py
Normal file
@@ -0,0 +1,55 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: cp1252 -*-
|
||||
# Copyright (c) 2015 Andreas
|
||||
# See LICENSE for details.
|
||||
|
||||
""" gui.fibui2 """
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from Tkinter import *
|
||||
import ttk
|
||||
|
||||
|
||||
class Application(Frame):
|
||||
def createWidgets(self, master=None):
|
||||
# Set background of toplevel window to match
|
||||
# current style
|
||||
style = ttk.Style()
|
||||
theme = style.theme_use()
|
||||
default = style.lookup(theme, 'background')
|
||||
master.configure(background=default)
|
||||
|
||||
self.eingabe = Entry(master)
|
||||
self.eingabe.place(relx=0.04, rely=0.04, relheight=0.08, relwidth=0.55)
|
||||
self.eingabe.configure(background="white")
|
||||
|
||||
self.knopf = Button(master)
|
||||
self.knopf.place(relx=0.7, rely=0.04)
|
||||
self.knopf.configure(pady="0")
|
||||
self.knopf.configure(text="Fibo")
|
||||
self.knopf.configure(command=self.fibo)
|
||||
|
||||
self.ausgabe = Text(master)
|
||||
self.ausgabe.place(relx=0.04, rely=0.21, relheight=0.7, relwidth=0.85)
|
||||
self.ausgabe.configure(background="white")
|
||||
self.ausgabe.configure(height="164")
|
||||
self.ausgabe.configure(width="194")
|
||||
self.ausgabe.configure(wrap="none")
|
||||
|
||||
def fibo(self):
|
||||
nstring = self.eingabe.get()
|
||||
n= int(nstring)
|
||||
self.ausgabe.insert(END, "{}\n".format(n))
|
||||
|
||||
def __init__(self, master=None):
|
||||
Frame.__init__(self, master)
|
||||
self.createWidgets(master)
|
||||
|
||||
|
||||
root = Tk()
|
||||
app = Application(master=root)
|
||||
app.mainloop()
|
||||
# root.destroy()
|
||||
41
src/prgag/fibwebui1.py
Normal file
41
src/prgag/fibwebui1.py
Normal file
@@ -0,0 +1,41 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: cp1252 -*-
|
||||
# Copyright (c) 2015 Andreas
|
||||
# See LICENSE for details.
|
||||
|
||||
""" prgag.fibusrv """
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
import SocketServer
|
||||
|
||||
|
||||
class MyTCPHandler(SocketServer.BaseRequestHandler):
|
||||
"""
|
||||
The RequestHandler class for our server.
|
||||
|
||||
It is instantiated once per connection to the server, and must
|
||||
override the handle() method to implement communication to the
|
||||
client.
|
||||
"""
|
||||
|
||||
def handle(self):
|
||||
# self.request is the TCP socket connected to the client
|
||||
self.data = self.request.recv(1024).strip()
|
||||
print("---")
|
||||
print("{} wrote:".format(self.client_address[0]))
|
||||
print(self.data)
|
||||
print("---")
|
||||
# just send back the same data, but upper-cased
|
||||
self.request.sendall(self.data.upper())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
HOST, PORT = "localhost", 8080
|
||||
# Create the server, binding to localhost on port 9999
|
||||
server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
|
||||
# Activate the server; this will keep running until you
|
||||
# interrupt the program with Ctrl-C
|
||||
server.serve_forever()
|
||||
61
src/prgag/fibwebui2.py
Normal file
61
src/prgag/fibwebui2.py
Normal file
@@ -0,0 +1,61 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: cp1252 -*-
|
||||
# Copyright (c) 2015 Andreas
|
||||
# See LICENSE for details.
|
||||
|
||||
""" prgag.fibusrv """
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
import SocketServer
|
||||
|
||||
RESPONSE = """
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: text/html
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta content="text/html; charset=ISO-8859-1"
|
||||
http-equiv="content-type">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<form name="fibo">
|
||||
<input type="text" name="Limit" value="100">
|
||||
<input type="submit" value="Fibo"></input><br>
|
||||
<br>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
|
||||
class MyTCPHandler(SocketServer.BaseRequestHandler):
|
||||
"""
|
||||
The RequestHandler class for our server.
|
||||
|
||||
It is instantiated once per connection to the server, and must
|
||||
override the handle() method to implement communication to the
|
||||
client.
|
||||
"""
|
||||
|
||||
def handle(self):
|
||||
# self.request is the TCP socket connected to the client
|
||||
self.data = self.request.recv(1024).strip()
|
||||
print("{} wrote:".format(self.client_address[0]))
|
||||
print(self.data)
|
||||
print("---")
|
||||
# just send back the same data, but upper-cased
|
||||
# self.request.sendall(self.data.upper())
|
||||
self.request.sendall(RESPONSE)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
HOST, PORT = "localhost", 8080
|
||||
# Create the server, binding to localhost on port 9999
|
||||
server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
|
||||
# Activate the server; this will keep running until you
|
||||
# interrupt the program with Ctrl-C
|
||||
server.serve_forever()
|
||||
86
src/prgag/fibwebui3.py
Normal file
86
src/prgag/fibwebui3.py
Normal file
@@ -0,0 +1,86 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: cp1252 -*-
|
||||
# Copyright (c) 2015 Andreas
|
||||
# See LICENSE for details.
|
||||
|
||||
""" prgag.fibusrv """
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
import SocketServer
|
||||
|
||||
EINGABE = """
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: text/html
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta content="text/html; charset=ISO-8859-1"
|
||||
http-equiv="content-type">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<form name="fibo">
|
||||
<input type="text" name="Limit" value="100">
|
||||
<input type="submit" value="Fibo"></input><br>
|
||||
<br>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
AUSGABE = """
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: text/html
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta content="text/html; charset=ISO-8859-1"
|
||||
http-equiv="content-type">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
{}
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
|
||||
class MyTCPHandler(SocketServer.BaseRequestHandler):
|
||||
"""
|
||||
The RequestHandler class for our server.
|
||||
|
||||
It is instantiated once per connection to the server, and must
|
||||
override the handle() method to implement communication to the
|
||||
client.
|
||||
"""
|
||||
|
||||
def handle(self):
|
||||
# self.request is the TCP socket connected to the client
|
||||
self.data = self.request.recv(1024).strip()
|
||||
print("{} wrote:".format(self.client_address[0]))
|
||||
# print(self.data)
|
||||
print("---")
|
||||
mode = "Anfang"
|
||||
for line in self.data.split("\n"):
|
||||
print(line)
|
||||
if line.find(r"GET /?Limit=") >= 0:
|
||||
mode = "Fibo"
|
||||
n = int(line[12])
|
||||
ergebnis = "2 3 4"
|
||||
if mode == "Fibo":
|
||||
self.request.sendall(AUSGABE.format(ergebnis))
|
||||
else:
|
||||
self.request.sendall(EINGABE)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
HOST, PORT = "localhost", 8080
|
||||
# Create the server, binding to localhost on port 9999
|
||||
server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
|
||||
# Activate the server; this will keep running until you
|
||||
# interrupt the program with Ctrl-C
|
||||
server.serve_forever()
|
||||
Reference in New Issue
Block a user