Da habe ich mir gedacht, das ist die ideale Gelegenheit, mal mein erstes wxPython-Programm zu schreiben, welches mir ä ö ü Ä Ö Ü ß anzeigt und von dem ich mir mal eben das gewuenschte Zeichen copy&pasten kann. Natuerlich ist das Programm konfigurierbar, man kann sich auch andere Sachen damit anzeigen lassen...

Hier der Code:
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import wx
import sys
import os
import optparse
######################################################################
# Options
def parse_opts():
"""
Parse command line options.
"""
version = "Umlaut Display Applet 0.1\n";
version += "2006 by Rebecca Breu. License: GPL";
parser = optparse.OptionParser(version=version);
parser.set_defaults(fg_color=None, bg_color=None, show="ä ö ü\nÄ Ö Ü\nß",
name=os.path.basename(sys.argv[0]), title="Umlaute",
geometry="60x60");
parser.add_option("--fgcolor", action="store", dest="fg_color",
help="Foreground colour.")
parser.add_option("--bgcolor", action="store", dest="bg_color",
help="Background colour.")
parser.add_option("--show", "-s", action="store", dest="show",
help="String to display in the frame. [default: %default]")
parser.add_option("--name", "-n", action="store", dest="name",
help="Window name under which resources are to be obtained.")
parser.add_option("--title", "-t", action="store", dest="title",
help= "Window title.")
parser.add_option("--geometry", "-g", action="store", dest="geometry",
help= "Geometry. [Default: %default]")
(options, args) = parser.parse_args()
return options;
def parse_geometry(geometry):
(width, height) = geometry.split("x");
return (int(width), int(height))
######################################################################
# GUI
class UmlautFrame(wx.Frame):
def __init__(self, parent, id, options):
wx.Frame.__init__(self, parent, id=id, name=options.name,
title=options.title)
size = parse_geometry(options.geometry)
umlautWidget = wx.TextCtrl(self, value=options.show, size=size,
style=wx.TE_MULTILINE|wx.TE_CENTRE|
wx.TE_READONLY|wx.NO_BORDER|wx.TE_CHARWRAP)
if not options.fg_color:
options.fg_color = self.GetForegroundColour()
umlautWidget.SetForegroundColour(options.fg_color)
self.SetForegroundColour(options.fg_color)
if not options.bg_color:
options.bg_color = self.GetBackgroundColour()
umlautWidget.SetBackgroundColour(options.bg_color)
self.SetBackgroundColour(options.bg_color)
sizer = wx.GridSizer(1, 1, 0, 0)
sizer.Add(umlautWidget, flag=wx.EXPAND)
self.SetSizerAndFit(sizer)
######################################################################
# Main
options = parse_opts()
app = wx.PySimpleApp()
frame = UmlautFrame(None, -1, options)
frame.Show(True)
app.MainLoop()
- Warum funktioniert das Einstellen der Vordergrundfarbe nicht?
- Geht das Ermitteln der Standard-Farben auch einfacher?