Problem beim Holen vom letzten Objekt auf dem Fokus war.

Plattformunabhängige GUIs mit wxWidgets.
Benutzeravatar
name
User
Beiträge: 254
Registriert: Dienstag 5. September 2006, 16:35
Wohnort: Wien
Kontaktdaten:

Problem beim Holen vom letzten Objekt auf dem Fokus war.

Beitragvon name » Sonntag 21. Januar 2007, 14:12

Ich habe diesen kleinen Vokabeltrainer( fuer Tuerkisch) als Uebung fuer wx programmiert, stehe aber gerade etwas beim Fokus an, ich mag in self.lastfocus speichern auf welchem Widget vorher der Fokus war, danke im Vorraus fuer euere Hilfe!
PS. print "changefocus" wird nie ausgefuehrt.
Der Code mit hervorhebung der wichtigen Zeilen: Pastebin

Code: Alles auswählen

# -*- coding: utf-8 -*-
import wx
import os
import random
if os.name == "posix":
    newline = "\n"
elif os.name == "nt":
    newline = "\r\n"
#import convert

class MyDialog(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(800, 600))
        #self.CreateStatusBar()
        self.outputt = wx.StaticText(self, -1, 'LALA!', (410, 300))
        #self.outputn =  wx.TextCtrl(self, -1, '', (150, 170))
        self.given = wx.TextCtrl(self, -1, '',  (400, 270), (150, -1))
        self.given.SetValue("Turkisch")
        self.asked = wx.TextCtrl(self, -1, '',  (250, 270), (150, -1))
        self.asked.SetValue("Deutsch")
        self.add1 = wx.TextCtrl(self, -1, '',  (250, 400), (150, -1))
        self.add1.SetValue("Turkisch")
        self.add = wx.TextCtrl(self, -1, '',  (400, 400), (150, -1))
        self.add.SetValue("Deutsch")
        self.given.SetFocus()
        self.G = wx.Button(self, 1, u'ğ', (50, 300))
        #compute_btn.SetFocus()
        self.I = wx.Button(self, 2, u'ı', (50, 325))
        #compute_btn.SetFocus()
        self.S = wx.Button(self, 4, u'ş', (50, 350))
        self.C = wx.Button(self, 5, u'ç', (50, 375))
        self.addVocButton = wx.Button(self, 6, 'Add Vocabulary', (550, 400))
        self.submit = wx.Button(self, 7, 'Submit', (550, 270))
        self.clear_btn = wx.Button(self, 3, 'Close', (20, 20))
        self.widgets = [self.given,self.asked,
                        self.add1,self.add,
                        self.G, self.I,
                        self.S, self.C,
                        self.addVocButton,self.submit,
                        self.clear_btn]
        for widget in self.widgets:
            self.Bind(wx.EVT_SET_FOCUS, self.ChangeFocus, widget)

        self.Bind(wx.EVT_BUTTON, self.OnG, self.G)
        self.Bind(wx.EVT_BUTTON, self.OnI, self.I)
        self.Bind(wx.EVT_BUTTON, self.OnClose, self.clear_btn)
        self.Bind(wx.EVT_BUTTON, self.OnS, self.S)
        self.Bind(wx.EVT_BUTTON, self.AddVoc, self.addVocButton)

        self.Bind(wx.EVT_BUTTON, self.Submit, self.submit)
        #wx.EVT_PAINT(self, self.OnPaint)
        self.getRandVoc()

        #self.Bind(wx.EVT_BUTTON, self.AddVoc, id=4)
        self.Bind(wx.EVT_CLOSE, self.OnClose)
    def ChangeFocus(self, event):
        print "changefocus"
        self.lastfocus = event.GetWindow()
    #def OnPaint(self, event): # Sets the BG Image
        #dc = wx.PaintDC(self)
        #dc.DrawBitmap(wx.Bitmap("turkvok.jpg",wx.BITMAP_TYPE_JPEG),0,0)
        #event.Skip()

    def Submit(self, event):
        print self.right
        self.given.GetValue()
        if self.given.GetValue() == self.right:
            self.outputt.SetLabel("Right")
            print self.right
            print "right"
        else:
            self.outputt.SetLabel(self.right)
            #self.outputt.Set
            #print "Richtig"
        self.getRandVoc()

    def getRandVoc(self, event=None):
        read = open ("vocs").readlines()
        intr = random.randint(0,1)
        if intr == 1:
            other = 0
        else:
            other = 1
        splitted = random.sample(read,1)[0][:-1].split("-")
        self.asked.SetValue(splitted[intr])
        self.right = splitted[other]
    def AddVoc(self, event):
        print "executing addvoc"
        cur = "%s-%s" % (self.add1.GetValue(),self.add.GetValue())
        read = open ("vocs").readlines()
        for line in read:
            print line
            print cur
            if cur == line[:-1]:
                print cur
                print line
                return True
        if os.path.exists("vocs"):
            file = open("vocs","a")
        else:
            file = open("vocs","w")
        file.write("%s-%s%s"% (self.add1.GetValue(),self.add.GetValue(),newline))
        file.close()

    #def AddBuch(self, event, buch):
        #self.asked.SetValue("%s%s" % (self.asked.GetValue(),unicode(buch)))
    def OnC(self, event):
        #print event
        self.lastfocus.SetValue("%s%s" % (self.lastfocus.GetValue(),u"ç"))
    def OnS(self, event):
        #print event
        self.lastfocus.SetValue("%s%s" % (self.lastfocus.GetValue(),u"ş"))
    def OnG(self, event):
        self.lastfocus.SetValue("%s%s" % (self.lastfocus.GetValue(),u"ğ"))
    def OnI(self, event):
        self.lastfocus.SetValue("%s%s" % (self.lastfocus.GetValue(),u"ı"))
    def OnClose(self, event):
        print wx.Window.FindFocus()
        self.Destroy()
class MyApp(wx.App):
    def OnInit(self):
        dlg = MyDialog(None, -1, 'TurkVoc')
        dlg.Show(True)
        dlg.Centre()
        return True
if __name__ == "__main__":
    app = MyApp(0)
    app.MainLoop()
Ohloh | Mein Blog | Jabber: segfaulthunter@swissjabber.eu | asynchia – asynchrone Netzwerkbibliothek

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.
Benutzeravatar
gerold
Python-Forum Veteran
Beiträge: 5554
Registriert: Samstag 28. Februar 2004, 22:04
Wohnort: Telfs (Tirol)
Kontaktdaten:

Re: Problem beim Holen vom letzten Objekt auf dem Fokus war.

Beitragvon gerold » Sonntag 21. Januar 2007, 15:57

name hat geschrieben:

Code: Alles auswählen

if os.name == "posix":
    newline = "\n"
elif os.name == "nt":
    newline = "\r\n"

Hi name!

Unabhängig von deinem Problem, welches ich nicht verstanden habe da du keine Frage gestellt hast.:

Code: Alles auswählen

print os.linesep

mfg
Gerold
:-)
http://halvar.at | Kleiner Bascom AVR Kurs
Wissen hat eine wunderbare Eigenschaft: Es verdoppelt sich, wenn man es teilt.
Benutzeravatar
gerold
Python-Forum Veteran
Beiträge: 5554
Registriert: Samstag 28. Februar 2004, 22:04
Wohnort: Telfs (Tirol)
Kontaktdaten:

Beitragvon gerold » Sonntag 21. Januar 2007, 16:09

Hi name!

Vielleicht habe ich dein Problem richtig verstanden:

Code: Alles auswählen

#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-

import wx

wx.SetDefaultPyEncoding("iso-8859-1")


class MyFrame(wx.Frame):
   
    def __init__(
        self, parent = None, id = -1, title = "Example", size = wx.Size(550, 420)
    ):
       
        wx.Frame.__init__(self, parent, id, title, size = size)
       
        self.lastfocus = None
       
        panel = wx.Panel(self)
       
        vbox_main = wx.BoxSizer(wx.VERTICAL)
        panel.SetSizer(vbox_main)
       
        btn1 = wx.Button(panel, -1, u"Button1")
        vbox_main.Add(btn1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 10)
        btn1.Bind(wx.EVT_KILL_FOCUS, self.on_button_kill_focus)
       
        btn2 = wx.Button(panel, -1, u"Button2")
        vbox_main.Add(btn2, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 10)
        btn2.Bind(wx.EVT_KILL_FOCUS, self.on_button_kill_focus)
       
        btn3 = wx.Button(panel, -1, u"Button3")
        vbox_main.Add(btn3, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 10)
        btn3.Bind(wx.EVT_KILL_FOCUS, self.on_button_kill_focus)
       
        panel.Fit()
        self.Fit()
        self.SetSizeHints(*self.GetSize())
   
   
    def on_button_kill_focus(self, event):
       
        self.lastfocus = event.GetEventObject()
       
        print self.lastfocus
        print self.lastfocus.GetLabel()
       
        event.Skip()


def main():
    """Testing"""
   
    app = wx.PySimpleApp()
    f = MyFrame()
    f.Center()
    f.Show()
    app.MainLoop()


if __name__ == "__main__":
    main()

mfg
Gerold
:-)
http://halvar.at | Kleiner Bascom AVR Kurs

Wissen hat eine wunderbare Eigenschaft: Es verdoppelt sich, wenn man es teilt.
Benutzeravatar
name
User
Beiträge: 254
Registriert: Dienstag 5. September 2006, 16:35
Wohnort: Wien
Kontaktdaten:

Beitragvon name » Sonntag 21. Januar 2007, 19:41

Ist ja schoen und gut, aber ich brauch das Objekt das VORHER den fokus hatte ^^
Ohloh | Mein Blog | Jabber: segfaulthunter@swissjabber.eu | asynchia – asynchrone Netzwerkbibliothek

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.
Benutzeravatar
name
User
Beiträge: 254
Registriert: Dienstag 5. September 2006, 16:35
Wohnort: Wien
Kontaktdaten:

Beitragvon name » Sonntag 21. Januar 2007, 19:52

Habs mit einer liste geloest!
Danke an euch alle, falls ihr noch wisst wie ich den char da einfueg wo der cursor war waers nett, aber net notwendig :)
Ohloh | Mein Blog | Jabber: segfaulthunter@swissjabber.eu | asynchia – asynchrone Netzwerkbibliothek

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder