Tests from two days ago with conversion from PNG format to SVG format with the python potrace package ...


Python tutorials with source code, examples, guides, and tips and tricks for Windows and Linux development.


pip install potracer[cli]
Collecting potracer[cli]
...
Successfully installed potrace-cli-0.0.4 potracer-0.0.4dir(potrace)
['BezierSegment', 'Bitmap', 'COS179', 'CornerSegment', 'Curve', 'INFTY', 'Optional', 'POTRACE_CORNER',
'POTRACE_CURVETO', 'POTRACE_TURNPOLICY_BLACK', 'POTRACE_TURNPOLICY_LEFT', 'POTRACE_TURNPOLICY_MAJORITY',
'POTRACE_TURNPOLICY_MINORITY', 'POTRACE_TURNPOLICY_RANDOM', 'POTRACE_TURNPOLICY_RIGHT', 'POTRACE_TURNPOLICY_WHITE',
'Path', 'Tuple', 'Union', '_Curve', '_Path', '_Point', '_Segment', '_Sums', '__builtins__', '__cached__', '__doc__',
'__file__', '__loader__', '__name__', '__package__', '__spec__', '_adjust_vertices', '_bestpolygon', '_calc_lon',
'_calc_sums', '_opticurve', '_smooth', 'bezier', 'bm_to_pathlist', 'cprod', 'cyclic', 'ddenom', 'ddist', 'detrand',
'detrand_t', 'dorth_infty', 'dpara', 'findnext', 'findpath', 'floordiv', 'interval', 'iprod', 'iprod1', 'majority',
'math', 'mod', 'np', 'opti_penalty', 'opti_t', 'pathlist_to_tree', 'penalty3', 'pointslope', 'process_path', 'quadform',
'reverse', 'setbbox_path', 'sign', 'sq', 'tangent', 'xor_path', 'xor_to_ref', 'xprod']from PyQt6.QtWidgets import QStyleFactory
print(QStyleFactory.keys())
['windows11', 'windowsvista', 'Windows', 'Fusion']import sys
from PyQt6.QtWidgets import (
QApplication, QLabel, QLineEdit, QComboBox, QPushButton,
QCheckBox, QSlider, QVBoxLayout, QWidget
)
from PyQt6.QtCore import Qt
app = QApplication(sys.argv)
app.setStyle('windows11')
window = QWidget()
layout = QVBoxLayout(window)
# 1. QLabel
layout.addWidget(QLabel("Acesta este un QLabel"))
# 2. QLineEdit
layout.addWidget(QLineEdit("Text editabil"))
# 3. QComboBox
combo = QComboBox()
combo.addItems(["Optiunea 1", "Optiunea 2", "Optiunea 3"])
layout.addWidget(combo)
# 4. QCheckBox
layout.addWidget(QCheckBox("Bifează această opțiune"))
# 5. QSlider
slider = QSlider(Qt.Orientation.Horizontal)
layout.addWidget(slider)
# 5. QPushButton
button = QPushButton('Simple button !')
layout.addWidget(button)
# show the main windows
window.show()
sys.exit(app.exec())import sys
import ssl
import socket
from datetime import datetime
from cryptography import x509
from cryptography.hazmat.backends import default_backend
from PyQt6.QtWidgets import (
QApplication, QWidget, QVBoxLayout, QLabel,
QLineEdit, QPushButton, QTextEdit
)
def fetch_certificate_raw(hostname):
"""
Connects to the server and retrieves the certificate in DER format.
Also returns a validation status message.
"""
# Create a default SSL context (validates certificates)
context = ssl.create_default_context()
try:
# First attempt: strict validation
with socket.create_connection((hostname, 443), timeout=5) as sock:
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
der_cert = ssock.getpeercert(binary_form=True)
return der_cert, "Certificate is VALID"
except ssl.SSLError as e:
# Certificate is invalid → try to retrieve it anyway
try:
unverified_context = ssl._create_unverified_context()
with socket.create_connection((hostname, 443), timeout=5) as sock:
with unverified_context.wrap_socket(sock, server_hostname=hostname) as ssock:
der_cert = ssock.getpeercert(binary_form=True)
return der_cert, f"Certificate is INVALID: {str(e)}"
except Exception:
return None, f"Could not retrieve certificate: {str(e)}"
except Exception as e:
return None, f"Connection error: {str(e)}"
def parse_certificate(der_cert):
"""
Converts a DER-encoded certificate into a cryptography.x509 object.
"""
return x509.load_der_x509_certificate(der_cert, default_backend())
class CertViewer(QWidget):
"""
Main GUI window for the HTTPS certificate viewer.
"""
def __init__(self):
super().__init__()
self.setWindowTitle("HTTPS Certificate Checker")
self.setGeometry(200, 200, 700, 600)
layout = QVBoxLayout()
# Input label + text field
layout.addWidget(QLabel("Enter URL (example: example.com):"))
self.input = QLineEdit()
layout.addWidget(self.input)
# Button to trigger certificate check
self.button = QPushButton("Check Certificate")
self.button.clicked.connect(self.check_certificate)
layout.addWidget(self.button)
# Output text box
self.output = QTextEdit()
self.output.setReadOnly(True)
layout.addWidget(self.output)
self.setLayout(layout)
def check_certificate(self):
"""
Triggered when the user presses the button.
Retrieves and displays certificate information.
"""
hostname = self.input.text().strip()
# Clean URL (remove http://, https://, and paths)
for prefix in ("https://", "http://"):
if hostname.startswith(prefix):
hostname = hostname[len(prefix):]
hostname = hostname.split("/")[0]
# Fetch certificate
der_cert, status = fetch_certificate_raw(hostname)
if der_cert is None:
self.output.setText(status)
return
# Parse certificate
cert = parse_certificate(der_cert)
# Build output text
text = f"=== CERTIFICATE STATUS ===\n{status}\n\n"
text += "=== CERTIFICATE DETAILS ===\n\n"
text += f"Subject:\n{cert.subject}\n\n"
text += f"Issuer:\n{cert.issuer}\n\n"
text += f"Serial Number: {cert.serial_number}\n\n"
text += f"Version: {cert.version}\n\n"
text += f"Valid From: {cert.not_valid_before}\n"
text += f"Valid To: {cert.not_valid_after}\n\n"
# Check expiration
if cert.not_valid_after < datetime.utcnow():
text += f"⚠ Certificate EXPIRED on: {cert.not_valid_after}\n\n"
# Subject Alternative Names (SAN)
try:
san = cert.extensions.get_extension_for_class(x509.SubjectAlternativeName)
text += f"Subject Alternative Names:\n{san.value}\n\n"
except Exception:
text += "Subject Alternative Names: (none)\n\n"
self.output.setText(text)
if __name__ == "__main__":
app = QApplication(sys.argv)
viewer = CertViewer()
viewer.show()
sys.exit(app.exec())
import win32serviceutil
import win32service
import win32event
import servicemanagerpython service_test_001.py install
Installing service MyPythonService
Service installedimport win32serviceutil
import win32service
import win32event
import servicemanager
import time
class MyService(win32serviceutil.ServiceFramework):
_svc_name_ = "MyPythonService"
_svc_display_name_ = "My Python Windows Service"
_svc_description_ = "A minimal Windows service example written in Python."
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.stop_event = win32event.CreateEvent(None, 0, 0, None)
self.running = True
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.stop_event)
self.running = False
def SvcDoRun(self):
servicemanager.LogInfoMsg("MyPythonService is starting.")
self.main()
def main(self):
while self.running:
# Your service logic goes here
time.sleep(5)
servicemanager.LogInfoMsg("MyPythonService heartbeat.")
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(MyService)
pip install pywin32python C:\Python313\Scripts\pywin32_postinstall.py -install
Parsed arguments are: Namespace(install=True, remove=False, wait=None, silent=False, quiet=False, destination= ...D:\Python313_64bit>python
Python 3.13.0 (tags/v3.13.0:60403a5, Oct 7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32api
>>> print(win32api.GetVersion())
import sys
import csv
import os
import subprocess
from datetime import datetime
from PyQt6.QtWidgets import (
QApplication, QWidget, QVBoxLayout, QCalendarWidget,
QInputDialog, QMessageBox
)
from PyQt6.QtCore import QDate
CSV_FILE = "note.csv"
class CalendarApp(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Calendar cu notițe")
self.resize(400, 300)
self.layout = QVBoxLayout()
self.setLayout(self.layout)
self.calendar = QCalendarWidget()
self.calendar.clicked.connect(self.adauga_nota)
self.layout.addWidget(self.calendar)
# Dicționar pentru notițe
self.note = {}
# La pornire, citește CSV și deschide în Notepad
self.incarca_note()
def adauga_nota(self, date: QDate):
zi = date.toString("yyyy-MM-dd")
text, ok = QInputDialog.getText(self, "Adaugă notiță",
f"Introdu text pentru {zi}:")
if ok and text.strip():
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M")
self.note[timestamp] = text.strip()
QMessageBox.information(self, "Salvat",
"Notița a fost adăugată.")
def incarca_note(self):
if os.path.exists(CSV_FILE):
try:
with open(CSV_FILE, "r", newline="", encoding="utf-8") as f:
reader = csv.reader(f)
for row in reader:
if len(row) == 2:
self.note[row[0]] = row[1]
# Deschide în Notepad
subprocess.Popen(["notepad.exe", CSV_FILE])
except Exception as e:
QMessageBox.warning(self, "Eroare",
f"Nu pot citi fișierul CSV:\n{e}")
def closeEvent(self, event):
try:
with open(CSV_FILE, "w", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
for timestamp, text in self.note.items():
writer.writerow([timestamp, text])
except Exception as e:
QMessageBox.warning(self, "Eroare",
f"Nu pot salva fișierul CSV:\n{e}")
event.accept()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = CalendarApp()
window.show()
sys.exit(app.exec())

Python 3.12.12 (main, Oct 10 2025, 08:52:57) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
