Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
61e8c85bbe | ||
![]() |
dac83ccbf9 | ||
![]() |
4d2b58b744 | ||
6db74b04f5 | |||
060c235e3f | |||
![]() |
ea14cde427 | ||
![]() |
fec0969d7f | ||
![]() |
af36c44e66 | ||
b913b2cb01 | |||
![]() |
37cbae2683 |
@@ -32,4 +32,5 @@ CC-BY-SA Olli Graf
|
||||
|25 | reguläre Ausdrücke|
|
||||
|26 | lambda Funktionen|
|
||||
|27 | logging.config|
|
||||
|28 | Decorators|
|
||||
|
||||
|
52
date_diff.py
Normal file
52
date_diff.py
Normal file
@@ -0,0 +1,52 @@
|
||||
#! python
|
||||
import sys
|
||||
from datetime import datetime
|
||||
|
||||
def date_diff_in_days(date1, date2):
|
||||
try:
|
||||
# Konvertiere die übergebenen Datumsangaben in datetime-Objekte
|
||||
if date1 == '$today':
|
||||
print('date1 ist heutiges Datum')
|
||||
date1_obj = datetime.today()
|
||||
date1_obj = date1_obj.replace(hour=0,minute=0,second=0,microsecond=0)
|
||||
else:
|
||||
print(f'konvertiere erstes Datum {date1}')
|
||||
date1_obj = datetime.strptime(date1, "%d.%m.%Y")
|
||||
|
||||
if date2 == '$today':
|
||||
print('date2 ist heutiges Datum')
|
||||
date2_obj = datetime.today()
|
||||
date2_obj = date2_obj.replace(hour=0,minute=0,second=0,microsecond=0)
|
||||
else:
|
||||
print(f'konvertiere zweites Datum {date2}')
|
||||
date2_obj = datetime.strptime(date2, "%d.%m.%Y")
|
||||
|
||||
print(f'konvertiere zweites Datum {date2}')
|
||||
|
||||
|
||||
# Berechne die Differenz zwischen den beiden Datumsangaben
|
||||
print(f'erstes Datum: {date1_obj}, zweites Datum: {date2_obj}')
|
||||
diff = abs(date1_obj - date2_obj).days
|
||||
return diff
|
||||
except ValueError as e:
|
||||
print("Fehler beim Parsen der Datumsangaben:", e)
|
||||
return None
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Überprüfe, ob genau zwei Datumsangaben als Parameter übergeben wurden
|
||||
print(f'Params: {sys.argv}')
|
||||
print(f'Anzahl Param: {len(sys.argv)}')
|
||||
if len(sys.argv) != 3:
|
||||
print("Bitte geben Sie zwei Datumsangaben im Format YYYY-MM-DD als Kommandozeilenparameter ein.")
|
||||
else:
|
||||
date1 = sys.argv[1]
|
||||
date2 = sys.argv[2]
|
||||
|
||||
# Berechne die Differenz in Tagen zwischen den beiden Datumsangaben
|
||||
difference = date_diff_in_days(date1, date2)
|
||||
if difference is not None:
|
||||
if sys.argv[1] == '$today':
|
||||
date1= 'heutigen Tag'
|
||||
if sys.argv[2] == '$today':
|
||||
date2= 'heutigen Tag'
|
||||
print(f"Zwischen dem {date1} und dem {date2} liegen {difference} Tage.")
|
9
docker/docker-compose.yml
Normal file
9
docker/docker-compose.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
version: "2.1"
|
||||
services:
|
||||
fibserver:
|
||||
image: hans:5000/fibserver:1
|
||||
container_name: fibserver
|
||||
ports:
|
||||
- 8085:8085
|
||||
restart: unless-stopped
|
1
getattr/.gitignore
vendored
Normal file
1
getattr/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
__pycache__
|
19
getattr/Kreis_getattr.py
Normal file
19
getattr/Kreis_getattr.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from math import pi as pi
|
||||
|
||||
|
||||
class Kreis_getattr:
|
||||
def __init__(self, radius):
|
||||
self.radius = radius
|
||||
self.operators ={
|
||||
'durchmesser': lambda x: self.radius * 2,
|
||||
'umfang': lambda x: self.durchmesser * pi,
|
||||
'flaeche': lambda x: self.radius**2 *pi
|
||||
}
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name not in self.operators:
|
||||
raise TypeError(f'unbekannte Operation {name}')
|
||||
|
||||
return self.operators[name](0)
|
||||
|
||||
|
1
teil28/.gitignore
vendored
Normal file
1
teil28/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
__pycache__
|
25
teil28/classdecor.py
Normal file
25
teil28/classdecor.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Datei: classdecor.py
|
||||
|
||||
|
||||
def addrepr(cls):
|
||||
# Universelle __repr__ Methode
|
||||
def __repr__(self):
|
||||
return f"{cls.__name__}({self.__dict__})"
|
||||
cls.__repr__ = __repr__
|
||||
|
||||
return cls
|
||||
|
||||
@addrepr
|
||||
class Fahrzeug():
|
||||
def __init__(self,farbe,typ):
|
||||
self.typ = typ
|
||||
self.farbe = farbe
|
||||
|
||||
|
||||
f1 = Fahrzeug('grau','VW')
|
||||
f2 = Fahrzeug('rot','Ferrari')
|
||||
|
||||
print(f'{f1}')
|
||||
print(f'{f2}')
|
||||
|
||||
|
13
teil28/counter.py
Normal file
13
teil28/counter.py
Normal file
@@ -0,0 +1,13 @@
|
||||
#Datei: counter.py
|
||||
|
||||
def counter(func):
|
||||
func.count = 0
|
||||
def wrapper(*args, **kwargs):
|
||||
func.count = func.count +1
|
||||
print(f'{func.__name__} wurde {func.count}-mal aufgerufen.')
|
||||
result = func(*args,**kwargs)
|
||||
|
||||
return result
|
||||
wrapper.count = 0
|
||||
return wrapper
|
||||
|
16
teil28/fib.py
Normal file
16
teil28/fib.py
Normal file
@@ -0,0 +1,16 @@
|
||||
#Datei: fib.py
|
||||
|
||||
import functools
|
||||
import sys
|
||||
from counter import counter
|
||||
|
||||
#@functools.cache
|
||||
@counter
|
||||
def fib(n):
|
||||
if n in [0,1]:
|
||||
return n
|
||||
else:
|
||||
return fib(n-1) + fib(n-2)
|
||||
|
||||
|
||||
|
16
teil28/func_param.py
Normal file
16
teil28/func_param.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# Datei: func_param.py
|
||||
|
||||
def add(x, y):
|
||||
return x + y
|
||||
|
||||
def mul(x,y):
|
||||
return x * y
|
||||
|
||||
def calculate(func, x, y):
|
||||
return func(x, y)
|
||||
|
||||
result = calculate(add, 4, 6) # Aufruf von calculate mit add Funktion als Parameter
|
||||
print(result) # Ausgabe ist 10
|
||||
|
||||
result = calculate(mul, 4, 6) # Aufruf von calculate mit add Funktion als Parameter
|
||||
print(result) # Ausgabe ist 24
|
12
teil28/nested_function.py
Normal file
12
teil28/nested_function.py
Normal file
@@ -0,0 +1,12 @@
|
||||
#Datei: nested_function.py
|
||||
|
||||
def print_message(message):
|
||||
print('Umgebende Funktion')
|
||||
def inner_function():
|
||||
print('Eingebettete Funktion')
|
||||
print(message)
|
||||
|
||||
inner_function()
|
||||
|
||||
print_message("Irgendein Text")
|
||||
|
20
teil28/pass_func.py
Normal file
20
teil28/pass_func.py
Normal file
@@ -0,0 +1,20 @@
|
||||
def make_pretty(func):
|
||||
# define the inner function
|
||||
def inner():
|
||||
# add some additional behavior to decorated function
|
||||
print("Dies ist die innere Funktion.")
|
||||
|
||||
# call original function
|
||||
func()
|
||||
# return the inner function
|
||||
return inner
|
||||
|
||||
# define ordinary function
|
||||
def ordinary():
|
||||
print("Dies ist die ordinary() Funktion.")
|
||||
|
||||
# decorate the ordinary function
|
||||
decorated_func = make_pretty(ordinary)
|
||||
|
||||
# call the decorated function
|
||||
decorated_func()
|
17
teil28/reverse.py
Normal file
17
teil28/reverse.py
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
|
||||
def reverse_decorator(func):
|
||||
|
||||
def wrapper(text):
|
||||
make_reverse = "".join(reversed(text))
|
||||
return func(make_reverse)
|
||||
|
||||
return wrapper
|
||||
|
||||
@reverse_decorator
|
||||
def format_message(text):
|
||||
return f'Text: {text}'
|
||||
|
||||
print(format_message('Hallo'))
|
||||
|
||||
|
21
teil28/simpledecorator.py
Normal file
21
teil28/simpledecorator.py
Normal file
@@ -0,0 +1,21 @@
|
||||
def make_pretty(func):
|
||||
# define the inner function
|
||||
def inner():
|
||||
# add some additional behavior to decorated function
|
||||
print("I got decorated")
|
||||
|
||||
# call original function
|
||||
func()
|
||||
# return the inner function
|
||||
return inner
|
||||
|
||||
# define ordinary function
|
||||
@make_pretty
|
||||
def ordinary():
|
||||
print("I am ordinary")
|
||||
|
||||
# decorate the ordinary function
|
||||
decorated_func = make_pretty(ordinary)
|
||||
|
||||
# call the decorated function
|
||||
ordinary()
|
20
teil28/static.py
Normal file
20
teil28/static.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# Datei static.py
|
||||
|
||||
class Math():
|
||||
|
||||
@staticmethod
|
||||
def add(x,y):
|
||||
return x+y
|
||||
|
||||
@staticmethod
|
||||
def sub(x,y):
|
||||
return x-y
|
||||
|
||||
@staticmethod
|
||||
def mul(x,y):
|
||||
return x*y
|
||||
|
||||
|
||||
print(f'Add: {Math.add(3,2)}')
|
||||
print(f'Sub: {Math.sub(3,2)}')
|
||||
print(f'Mul: {Math.mul(3,2)}')
|
28
teil28/timer.py
Normal file
28
teil28/timer.py
Normal file
@@ -0,0 +1,28 @@
|
||||
#Datei: timer.py
|
||||
|
||||
from fib import fib
|
||||
from counter import counter
|
||||
import time
|
||||
import sys
|
||||
|
||||
def timer(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
start_time = time.time()
|
||||
|
||||
result = func(*args,**kwargs)
|
||||
|
||||
end_time = time.time()
|
||||
print(f'Methode {func.__name__} - Laufzeit {end_time - start_time:.4f}s')
|
||||
return result
|
||||
return wrapper
|
||||
|
||||
@timer
|
||||
def summe(n):
|
||||
return f"Summe: {sum(range(n))}"
|
||||
|
||||
@timer
|
||||
def calc_fib(n):
|
||||
return fib(n)
|
||||
|
||||
print(summe(1000000))
|
||||
print(calc_fib(int(sys.argv[1])))
|
4
teil29/.gitignore
vendored
Normal file
4
teil29/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
# created by virtualenv automatically
|
||||
bin
|
||||
lib
|
||||
|
30
teil29/handleButton.py
Executable file
30
teil29/handleButton.py
Executable file
@@ -0,0 +1,30 @@
|
||||
#! /usr/bin/python
|
||||
#Datei: handleButton.py
|
||||
|
||||
import sys
|
||||
from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.setWindowTitle("Button Signal")
|
||||
|
||||
button = QPushButton("Bitte klicken")
|
||||
button.setCheckable(True)
|
||||
button.clicked.connect(self.handle_button_click)
|
||||
|
||||
# Set the central widget of the Window.
|
||||
self.setCentralWidget(button)
|
||||
|
||||
def handle_button_click(self):
|
||||
print("Button geklickt")
|
||||
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
window = MainWindow()
|
||||
window.show()
|
||||
|
||||
app.exec()
|
36
teil29/lineedit.py
Executable file
36
teil29/lineedit.py
Executable file
@@ -0,0 +1,36 @@
|
||||
#! /usr/bin/python
|
||||
#Datei: lineEdit.py
|
||||
|
||||
from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel, QLineEdit, QVBoxLayout, QWidget
|
||||
import sys
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.setWindowTitle("Eingabe mit LineEdit")
|
||||
|
||||
self.label = QLabel()
|
||||
|
||||
self.input = QLineEdit()
|
||||
self.input.textChanged.connect(self.label.setText)
|
||||
|
||||
layout = QVBoxLayout()
|
||||
layout.addWidget(self.input)
|
||||
layout.addWidget(self.label)
|
||||
|
||||
container = QWidget()
|
||||
container.setLayout(layout)
|
||||
|
||||
# Set the central widget of the Window.
|
||||
self.setCentralWidget(container)
|
||||
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
window = MainWindow()
|
||||
window.show()
|
||||
|
||||
app.exec()
|
||||
|
78
teil29/login.py
Executable file
78
teil29/login.py
Executable file
@@ -0,0 +1,78 @@
|
||||
#! /usr/bin/python
|
||||
#Datei: lineEdit.py
|
||||
|
||||
from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel, QLineEdit, QPushButton, QGridLayout, QWidget
|
||||
from PyQt6.QtGui import QPixmap
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.setWindowTitle("Login")
|
||||
|
||||
layout = QGridLayout()
|
||||
layout.setContentsMargins(20, 20, 20, 20)
|
||||
layout.setSpacing(10)
|
||||
|
||||
self.user_logo_pixmap =QPixmap('./user.jpg')
|
||||
self.user_logo_label = QLabel()
|
||||
self.user_logo_label.setPixmap(self.user_logo_pixmap)
|
||||
|
||||
layout.addWidget(self.user_logo_label,1,1)
|
||||
|
||||
|
||||
|
||||
self.user_label = QLabel('Username:')
|
||||
self.password_label = QLabel('Passwort:')
|
||||
self.username_input = QLineEdit()
|
||||
self.password_input = QLineEdit()
|
||||
self.password_input.setEchoMode(QLineEdit.EchoMode.Password)
|
||||
|
||||
layout.addWidget(self.user_label,2,0)
|
||||
layout.addWidget(self.username_input,2,1,1,2)
|
||||
|
||||
layout.addWidget(self.password_label,3,0)
|
||||
layout.addWidget(self.password_input,3,1,1,2)
|
||||
|
||||
#Buttons
|
||||
self.register_button = QPushButton("Register")
|
||||
layout.addWidget(self.register_button, 4, 1)
|
||||
|
||||
self.login_button = QPushButton("Login")
|
||||
self.login_button.clicked.connect(self.handle_login_button)
|
||||
self.register_button.clicked.connect(self.handle_register_button)
|
||||
|
||||
layout.addWidget(self.login_button, 4, 2)
|
||||
|
||||
# Password vergessen
|
||||
self.forgot_pw_button = QPushButton('Passwort vergessen')
|
||||
self.forgot_pw_button.setStyleSheet('QPushButton {background-color: #A3C1DA; color: blue;}')
|
||||
layout.addWidget(self.forgot_pw_button,5,2)
|
||||
container = QWidget()
|
||||
container.setLayout(layout)
|
||||
|
||||
# Set the central widget of the Window.
|
||||
self.setCentralWidget(container)
|
||||
|
||||
def handle_register_button(self):
|
||||
print('Register Button')
|
||||
|
||||
def handle_login_button(self):
|
||||
print(f'Login mit {self.username_input.text()} and {self.password_input.text()}')
|
||||
|
||||
def handle_forgot_pw_button(self):
|
||||
print('Forgot PW')
|
||||
|
||||
|
||||
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
window = MainWindow()
|
||||
window.show()
|
||||
|
||||
app.exec()
|
||||
|
26
teil29/mainwindow.py
Executable file
26
teil29/mainwindow.py
Executable file
@@ -0,0 +1,26 @@
|
||||
#! /usr/bin/python
|
||||
#Datei: mainwindows.py
|
||||
import sys
|
||||
|
||||
from PyQt6.QtCore import QSize, Qt
|
||||
from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton
|
||||
|
||||
|
||||
# Subclass QMainWindow to customize your application's main window
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.setWindowTitle("My App")
|
||||
button = QPushButton("Bitte klicken")
|
||||
|
||||
# Set the central widget of the Window.
|
||||
self.setCentralWidget(button)
|
||||
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
window = MainWindow()
|
||||
window.show()
|
||||
|
||||
app.exec()
|
12
teil29/pushbutton.py
Executable file
12
teil29/pushbutton.py
Executable file
@@ -0,0 +1,12 @@
|
||||
#! /usr/bin/python
|
||||
#Datei: pushbutton.py
|
||||
|
||||
import sys
|
||||
from PyQt6.QtWidgets import QApplication, QPushButton
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
window = QPushButton("Bitte klicken")
|
||||
window.show()
|
||||
|
||||
app.exec()
|
8
teil29/pyvenv.cfg
Normal file
8
teil29/pyvenv.cfg
Normal file
@@ -0,0 +1,8 @@
|
||||
home = /usr/bin
|
||||
implementation = CPython
|
||||
version_info = 3.11.2.final.0
|
||||
virtualenv = 20.17.1+ds
|
||||
include-system-site-packages = false
|
||||
base-prefix = /usr
|
||||
base-exec-prefix = /usr
|
||||
base-executable = /usr/bin/python3
|
5
teil29/requirements.txt
Normal file
5
teil29/requirements.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
numpy==2.2.3
|
||||
opencv-python==4.11.0.86
|
||||
PyQt6==6.8.1
|
||||
PyQt6-Qt6==6.8.2
|
||||
PyQt6_sip==13.10.0
|
30
teil29/sizewindow.py
Executable file
30
teil29/sizewindow.py
Executable file
@@ -0,0 +1,30 @@
|
||||
#! /usr/bin/python
|
||||
# Datei: sizewindow.py
|
||||
|
||||
import sys
|
||||
from PyQt6.QtCore import QSize, Qt
|
||||
from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton
|
||||
|
||||
|
||||
# abgeleitet von QMainWindow können wir unser GUI besser einstellen und
|
||||
# z.B. die Dimensionen des Fensters ändern.
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.setWindowTitle("Fenstergröße")
|
||||
|
||||
button = QPushButton("Bitte klicken")
|
||||
|
||||
self.setFixedSize(QSize(400, 300))
|
||||
|
||||
# der Button sitzt als zentrales Widget im Fenster.
|
||||
self.setCentralWidget(button)
|
||||
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
window = MainWindow()
|
||||
window.show()
|
||||
|
||||
app.exec()
|
BIN
teil29/user.jpg
Normal file
BIN
teil29/user.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
23
teil29/window.py
Executable file
23
teil29/window.py
Executable file
@@ -0,0 +1,23 @@
|
||||
#! /usr/bin/python
|
||||
#Datei: window.py
|
||||
|
||||
# Die benötigten Qt Widgets
|
||||
from PyQt6.QtWidgets import QApplication, QWidget
|
||||
|
||||
# Für die Kommandozeilenparameter
|
||||
import sys
|
||||
|
||||
# QTApplication instanziieren. Die Kommandozeilenparameter geben wir
|
||||
# mit.
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
# Window Widget erzeugen
|
||||
window = QWidget()
|
||||
window.show() # Das Fenster muss immer manuell angzeigt werden.
|
||||
|
||||
# Wvent-Loop starten.
|
||||
app.exec()
|
||||
|
||||
|
||||
# So lang die Event-Loop läuft kommen wir hier nicht hin,
|
||||
# sie kann durch den "Schließen" Button des Fensters unterbrochen werden.
|
Reference in New Issue
Block a user