sorry,
but its to much. i have a dialog where the user
can change the app-wide font.
All is ok, but a little preview problem there is...
i warn you, its a lot of code, but i can't make it
less bigger yet..
first i show the code, then i spend some words to it:
hm, Good Luck!
dbuser is my databaseconnection module.
from wxPython.wx import *
# import win32api,res
# from idmod import getid
# from dbexec import db, dbuser, dbdata
from wxPython.lib.colourselect import *
idmap={}
def getid(wantedID):
global idmap
if not idmap.has_key(wantedID):
idmap[wantedID]=wxNewId()
return idmap[wantedID]
def CloseIdMap():
global idmap
idmap=None
# Listbox, in der die Fonts bearbeitet werden und
# die Eintragungen in die Datenbank für alle
# elemente auf dieser Registerseite
class fontbox(wxListBox):
def __init__(self, parent, id, pos, size, list, style):
self.lastselection=""
self.standardtype="wxNORMAL"
self.standardfont="Arial"
self.standardpoint=11
self.beginnerfont="Arial" # normally -->
dbuser.GetFont()
self.beginnerpoint=11 # normally -->
dbuser.GetFontPoint()
self.beginnertype=self.ChangewxTYPE("wxNORMAL")
#-->(dbuser.GetFontType())
self.font="Arial" #
-->dbuser.GetFont()
self.point=11 #
-->dbuser.GetFontPoint()
self.type=self.ChangewxTYPE("wxNORMAL")
#-->(dbuser.GetFontType())
self.list=[]
self.Filllist()
wxListBox.__init__(self, parent, getid("fontbox"),
wxDefaultPosition, wxSize(350,225), self.list, wxLB_SINGLE )
EVT_LISTBOX(self, getid("fontbox"), self.ChangePreviewOnListEvt)
self.SetStringSelection(self.font)
def Filllist(self): #Fülle die Liste mit allen vorhandenen Schriftarten
e = wxFontEnumerator()
e.EnumerateFacenames()
self.list = e.GetFacenames()
self.list.sort()
self.fonttest=self.font
self.lastselection=self.font
def GetFont(self): # Gebe zum init. der Vorschau das selektierte
Element der liste aus!
return self.fonttest
def ShowPreview(self,func): #Zeige Vorschautext
self.showprev=func
def SetPreviewFont(self,func): #Setze Font für Previewtext
self.setprevfont=func
def FirstPreview(self): # Initialisieren der Vorschau
self.showprev("")
self.showprev(self.lastselection)
self.setprevfont( wxFont( self.point, wxSWISS, wxNORMAL, self.type, FALSE, self.font ) )
self.showprev(self.lastselection)
def ChangePreviewOnListEvt(self,event): # Ändere die Vorschau bei
Listenauswahl
self.showprev("")
self.CheckChoiceSel()
self.lastselection=str(self.GetString(event.GetSelection()))
self.showprev(self.lastselection)
#dbuser.SetFont(self.lastselection)
self.setprevfont( wxFont( self.point, wxSWISS, wxNORMAL, self.type, FALSE, self.lastselection ) )
self.showprev(self.lastselection)
def SetSpin(self,objekt): #Objekt wird übergeben und Handler installiert
self.spin=objekt
EVT_SPINCTRL(self.spin, -1, self.OnChangeSpin)
# Funktioniert nicht...
EVT_TEXT_ENTER(self.spin, -1, self.OnChangeSpinWithEnter)
# begin doesen'T work
def OnChangeSpinWithEnter(self,event): #wenn die größe geändert wird,
dann wird auch die Schrift aktualisiert!
self.showprev("")
print("Hallo?")
self.CheckChoiceSel()
self.showprev(self.lastselection)
self.point=self.GetPoint()
# dbuser.SetFontPoint(self.GetPoint())
self.setprevfont( wxFont( self.point, wxSWISS, wxNORMAL, self.type, FALSE, self.lastselection ) )
self.showprev(self.lastselection)
# end doesen't work
def OnChangeSpin(self,event): #wenn die größe geändert wird, dann wird
auch die Schrift aktualisiert!
self.showprev("")
event.GetSelection()
self.CheckChoiceSel()
self.showprev(self.lastselection)
self.point=self.GetPoint()
# dbuser.SetFontPoint(self.point)
self.setprevfont( wxFont( self.point, wxSWISS, wxNORMAL, self.type, FALSE, self.lastselection ) )
self.showprev(self.lastselection)
def GetPointSize(self,func): #Hol die Funktion zum Abfrage der
aktuellen Größe
self.GetPoint=func
def SetPointSize(self,func): #Hol dir die aktuell eingestellte Größe
self.SetPoint=func
def SetChoice(self,objekt): #Hier wird das Objekt übergeben
(Schriftstil), damit der Event-Handler gestartet werden kann...
self.choice=objekt
EVT_CHOICE(self.choice, getid("Schriftart_auswaehlen"),
self.OnChangeChoice)
# HERE ISTHE PROBLEMATIC FUNCTION #
def OnChangeChoice(self,event): # Wenn der Schriftstil geändert wird, dann wird hier die Vorschau aktualisiert
#showprex=PreviewStaticText.SetLabel()
self.showprev("")
event.GetSelection()
self.CheckChoiceSel()
# self.lastselection=String with the fontname
self.showprev(self.lastselection)
self.setprevfont( wxFont ( self.point, wxSWISS, wxNORMAL,
self.type, FALSE, self.lastselection ) )
# self.vorschaulabel.SetFont( wxFont( self.point, wxSWISS,
wxNORMAL, self.type, FALSE, self.lastselection ) )
print( self.type, self.GetPoint(),self.lastselection)
self.showprev(self.lastselection)
self.vorschaulabel.Refresh()
self.vorschausizer.Layout()
self.showprev(self.lastselection)
event.Skip()
# id o all double and more, but it won't works here.... at the other all is ok...
# ALL CODE BEEN EXECUTED, BUT NOTHING CHANGED #
def GetChoiceselection(self,func): # hia wird die Abfrage für den
Schriftstil übergeben und ausgeführt
self.getsel=func
def SetChoiceSelection(self,func):
self.setsel=func
def CheckChoiceSel(self,event=None):
if self.getsel() == 0:
# dbuser.SetFontType("wxNORMAL")
self.type=wxNORMAL
elif self.getsel() == 1:
self.type=wxBOLD
# dbuser.SetFontType("wxBOLD")
elif self.getsel() == 2:
self.type=wxLIGHT
# dbuser.SetFontType("wxLIGHT")
return self.type
def GetVorschauLabelObjekt(self, item):
self.vorschaulabel=item
def GetTestSizer(self,sizer): # only because of the problem
self.vorschausizer=sizer
def GetStandard(self,item):
self.standard=item
EVT_BUTTON(self.standard, -1, self.SetStandard) # button
"Standardfont setzen"
def SetStandard(self, event):
# Setze DB neu
# dbuser.SetFont(self.standardfont)
# dbuser.SetFontPoint(self.standardpoint)
# dbuser.SetFontType(self.standardtype)
self.font=self.standardfont
self.point=self.standardpoint
self.type=self.SetType4Buttons(self.standardtype)
self.lastselection=self.standardfont
#Setze Anzeige neu
self.SetStringSelection(self.standardfont)
self.SetPoint(self.standardpoint)
self.setsel(self.SetType4Buttons(self.standardtype))
self.setprevfont( wxFont( self.standardpoint, wxSWISS, wxNORMAL,
self.ChangewxTYPE(self.standardtype), FALSE, self.standardfont ) )
self.showprev(self.standardfont)
def SetBack(self,item): # Font, die geladen wurde...
self.back=item
EVT_BUTTON(self.back, -1, self.GetBack)
def GetBack(self, event):
# Setze DB neu
# dbuser.SetFont(self.beginnerfont)
# dbuser.SetFontPoint(self.beginnerpoint)
# dbuser.SetFontType(self.beginnertype)
self.font=self.beginnerfont
self.point=self.beginnerpoint
self.type=self.beginnertype
#Setze Anzeige neu
self.SetStringSelection(self.beginnerfont)
self.SetPoint(self.beginnerpoint)
self.setsel(self.beginnertype)
self.setprevfont( wxFont( self.beginnerpoint, wxSWISS, wxNORMAL,
self.beginnertype, FALSE, self.beginnerfont ) )
self.showprev(self.beginnerfont)
def SetType4Buttons(self,type):
if type=="wxNORMAL":
return 0
if type=="wxBOLD":
return 1
if type=="wxLIGHT":
return 2
def ChangewxTYPE(self,type):
if type=="wxNORMAL":
return wxNORMAL
elif type=="wxLIGHT":
return wxLIGHT
elif type=="wxBOLD":
return wxBOLD
elif type==wxNORMAL:
return "wxNORMAL"
elif type==wxLIGHT:
return "wxLIGHT"
elif type==wxBOLD:
return "wxBOLD"
def Schriftartfestlegen( parent, call_fit = true, set_sizer = true,
frame=None): # <------------------I used wxDesigner at the
beginning
item0 = wxBoxSizer( wxVERTICAL )
item4 = fontbox( parent, getid("fontbox"), wxDefaultPosition,
wxSize(350,225), [], wxLB_SINGLE)
item0.AddWindow( item4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 10 )
item1 = wxBoxSizer( wxVERTICAL )
item2 = wxStaticText( parent, getid("ID_TEXT"), "Schriftart : ",
wxDefaultPosition, wxDefaultSize, 0 )
item1.AddWindow( item2, 0, wxALIGN_LEFT|wxALL, 10 )
item3 = wxStaticText( parent, getid("vorschau_Schrifteinstellungen"), item4.GetFont(), wxDefaultPosition, wxSize(290,30), wxALIGN_LEFT )
item1.AddWindow( item3, 0, wxALIGN_LEFT|wxALL, 5 )
item4.GetTestSizer(item1)
item4.ShowPreview(item3.SetLabel)
item4.SetPreviewFont(item3.SetFont)
item4.GetVorschauLabelObjekt(item3)
item4.FirstPreview()
item0.AddSizer( item1, 0, wxALIGN_LEFT|wxALL, 5 )
item5 = wxBoxSizer( wxHORIZONTAL )
item8 = wxButton( parent, getid("ButtonUndo"), "Standardschriftart
herstellen", wxDefaultPosition, wxDefaultSize, 0 )
item4.GetStandard(item8)
item5.AddWindow( item8, 0, wxALIGN_CENTRE|wxALL, 5 )
item0.AddSizer( item5, 0, wxALIGN_CENTRE|wxALL, 5 )
item10 = wxStaticBox( parent, -1, "Details" )
item9 = wxStaticBoxSizer( item10, wxVERTICAL )
item11 = wxBoxSizer ( wxHORIZONTAL)
item12 = wxBoxSizer( wxVERTICAL )
item13 = wxStaticText( parent, getid("ID_TEXT2"), "Schriftgröße", wxDefaultPosition, wxDefaultSize, 0 )
item12.AddWindow( item13, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 )
item14 = wxSpinCtrl( parent, getid("ID_SPINCTRL"), "11",
wxDefaultPosition, wxSize(100,23), 0, 7, 30, 11 )
#str(dbuser.GetFontPoint())
item12.AddWindow( item14, 0, wxALIGN_CENTRE|wxALL, 10 )
item4.GetPointSize(item14.GetValue)
item4.SetPointSize(item14.SetValue)
item4.SetSpin(item14)
item11.AddSizer( item12, 0, wxALIGN_CENTER_VERTICAL|wxALL, 0 )
item15 = wxBoxSizer( wxVERTICAL )
item16 = wxStaticText( parent, getid("ID_TEXT2"), "Schrifstil",
wxDefaultPosition, wxDefaultSize, 0 )
item15.AddWindow( item16, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 )
item17 = wxChoice( parent, getid("Schriftart_auswaehlen"),
wxDefaultPosition, wxSize(150,-1),
["Normal","Fett","Leicht"] , 0 )
# if dbuser.GetFontType()[2:] == "NORMAL":
item17.SetStringSelection("Normal")
# elif dbuser.GetFontType()[2:] == "LIGHT":
# item17.SetStringSelection("Leicht")
# elif dbuser.GetFontType()[2:] == "BOLD":
# item17.SetStringSelection("Fett")
item15.AddWindow( item17, 0, wxALIGN_CENTER_VERTICAL|wxALL, 10 )
item4.GetChoiceselection(item17.GetSelection)
item4.SetChoiceSelection(item17.SetSelection)
item4.SetChoice(item17)
# EVT_CHOICE(item17, getid("Schriftart_auswaehlen"),
item4.OnChangeChoice)
item11.AddSizer( item15, 0, wxALIGN_CENTRE|wxALL, 0 )
item9.AddSizer( item11, 0, wxALIGN_CENTRE|wxALL, 5 )
item0.AddSizer( item9, 0, wxALIGN_CENTRE|wxALL, 10 )
item20 = wxBoxSizer ( wxHORIZONTAL )
item18 = wxButton( parent, -1, "Schriftart auf Ausgangswert setzen",
wxDefaultPosition, wxDefaultSize, 0 )
item4.SetBack(item18)
item20.AddWindow( item18, 0, wxALIGN_CENTRE|wxALIGN_BOTTOM|wxALL, 5 )
item0.AddSizer( item20, 0, wxALIGN_CENTRE|wxALL, 10 )
if set_sizer == true:
parent.SetAutoLayout( true )
parent.SetSizer( item0 )
if call_fit == true:
item0.Fit( parent )
item0.SetSizeHints( parent )
item3.SetLabel(item3.GetLabel())
return item0
class MyFrame(wxFrame):
def __init__(self, parent, ID, title):
wxFrame.__init__(self, parent, ID, title)
self.SetBackgroundColour(wxNamedColour("LIGHT_GREY"))
self.SetSize(wxSize(377,570))
self.panel2=wxPanel(self,-1)
Schriftartfestlegen(self.panel2,true)
self.panel2.Layout()
def OnCloseWindow(self, event):
CloseIdMap()
self.Destroy()
class MyApp(wxApp):
def OnInit(self):
frame = MyFrame(NULL, -1, "example - selecting failed")
frame.Show(true)
self.SetTopWindow(frame)
frame.CentreOnScreen(wxBOTH)
return true
wxBeginBusyCursor()
app = MyApp(0)
wxEndBusyCursor()
app.MainLoop()
The problem is in class fontbox, there i add all needed
functions of the dialog and initialize the EVT_handlers.
All is in there. Its a huge "little sample" i know.
i can't find the failure.
if the user select another type for the font e.g BOLD
the previewtext should get updated, it does so, but
the previewtext has the same (seen) fonttype at all.
the variables changed their content and if you select
another pointsize or font, the fonttype is right at the previewtext now,
but not if you change it with the combobox ...nothing happen
hope you checked out, what i meant, in spite of my bad english.
bad? horrible. sometimes, i can't read it by myself *g
P.S. Can someone give me the name of the Eventhandler, which
i need, if the spincontrol is updated by entered text, and not by
using the spinbuttons???
thx,thx,thx
thx, 4 your time which you spend to this post, reen
···
----
Rene Freund nur ein toter bug ist ein guter bug
rene@meder.de