Phonebook Entry Editor strangeness

Adit Panchal <[email protected]>
Newsgroups gmane.comp.mobile.bitpim.devel
Message-ID <[email protected]>
My final diff is attached to fix this problem. Now, whenever you select 
a tab, the first editable box gets focus. Before, this did not occur 
and pressing up, down, or delete would cause a crash. I fixed this be 
re-ordering the widgets. Also, when there is no data for a tab, if you 
press up, down, or delete it will complain. I returned 0 so that the 
function checking for the existence of widgets won't get screwed up.

Additionally, I fixed a capitalization error of the dialog title.

Thanks,

Adit



On Mar 8, 2005, at 01:32, Adit Panchal wrote:

> I forgot to mention that the non-selected text boxes only occurred on 
> the Mac. In Windows, this wasn't an issue. In this regard, I believe 
> the Mac and Linux builds are working (or not working, rather) the 
> same. I was originally going to write an OnNotebookPageChanged method, 
> but I realized that if it worked in Windows, it was an OS-specific 
> issue, and it wasn't necessary.
>
> Adit
>
> On Mar 8, 2005, at 01:23, Adit Panchal wrote:
>
>> I think I found where the problem is for the IndexError. If there is 
>> no widget selected, I just had the function return 0.
>>
>> While checking this out, I found out that one of the issues stems 
>> from the fact that there are no default widgets selected when you 
>> move from tab to tab. This is because the choice boxes are the first 
>> widgets created in the sizers. I switched the order around, placing 
>> the choice boxes at the end, and when moving between tabs, it 
>> automatically gives a focus box around the first text/"editable" box 
>> of the sizer. I believe this is the same problem you were 
>> encountering on Linux in the SetFocusOnValue function.
20050310.diff (application/octet-stream, 5.9 KB)
Index: phonebook.py
===================================================================
RCS file: /cvsroot/bitpim/bitpim/phonebook.py,v
retrieving revision 1.127
diff -u -r1.127 phonebook.py
--- phonebook.py        3 Mar 2005 08:14:09 -0000       1.127
+++ phonebook.py        10 Mar 2005 16:58:42 -0000
@@ -725,7 +725,7 @@
         dlg.Destroy()
 
     def OnAdd(self, _):
-        dlg=phonebookentryeditor.Editor(self, {'names': [{'full': 'New Entry'}]})
+        dlg=phonebookentryeditor.Editor(self, {'names': [{'full': 'New Entry'}]}, keytoopenon="names", dataindex=0)
         if dlg.ShowModal()==wx.ID_OK:
             data=phonebookobjectfactory.newdataobject(dlg.GetData())
             data.EnsureBitPimSerial()
Index: phonebookentryeditor.py
===================================================================
RCS file: /cvsroot/bitpim/bitpim/phonebookentryeditor.py,v
retrieving revision 1.33
diff -u -r1.33 phonebookentryeditor.py
--- phonebookentryeditor.py     3 Mar 2005 08:35:53 -0000       1.33
+++ phonebookentryeditor.py     10 Mar 2005 16:58:44 -0000
@@ -503,18 +503,18 @@
         wx.Panel.__init__(self, parent, -1)
 
         hs=wx.StaticBoxSizer(wx.StaticBox(self, -1, "Number details"), wx.HORIZONTAL)
-        hs.Add(wx.StaticText(self, -1, "Type"), 0, wx.ALIGN_CENTRE|wx.ALL, 5)
 
-        self.type=wx.ComboBox(self, -1, "None", choices=[desc for desc,name in self.choices], style=wx.CB_READONLY)
-        hs.Add(self.type, 0, wx.EXPAND|wx.ALL, 5)
+        hs.Add(wx.StaticText(self, -1, "Number"), 0, wx.ALIGN_CENTRE|wx.ALL, 5)
+        self.number=wx.TextCtrl(self, -1, "")
+        hs.Add(self.number, 1, wx.EXPAND|wx.ALL, 5)
 
         hs.Add(wx.StaticText(self, -1, "SpeedDial"), 0, wx.ALIGN_CENTRE|wx.ALL, 5)
         self.speeddial=wx.TextCtrl(self, -1, "", size=(32,10))
         hs.Add(self.speeddial, 0, wx.EXPAND|wx.ALL, 5)
 
-        hs.Add(wx.StaticText(self, -1, "Number"), 0, wx.ALIGN_CENTRE|wx.ALL, 5)
-        self.number=wx.TextCtrl(self, -1, "")
-        hs.Add(self.number, 1, wx.EXPAND|wx.ALL, 5)
+        hs.Add(wx.StaticText(self, -1, "Type"), 0, wx.ALIGN_CENTRE|wx.ALL, 5)
+        self.type=wx.ComboBox(self, -1, "None", choices=[desc for desc,name in self.choices], style=wx.CB_READONLY)
+        hs.Add(self.type, 0, wx.EXPAND|wx.ALL, 5)
 
         self.SetSizer(hs)
         hs.Fit(self)
@@ -558,11 +558,11 @@
 
         hs=wx.StaticBoxSizer(wx.StaticBox(self, -1, "Email Address"), wx.HORIZONTAL)
 
-        self.type=wx.ComboBox(self, self.ID_TYPE, "", choices=["", "Home", "Business"], style=wx.CB_READONLY)
-        hs.Add(self.type, 0, wx.EXPAND|wx.ALL, 5)
         self.email=wx.TextCtrl(self, -1, "")
         hs.Add(self.email, 1, wx.EXPAND|wx.ALL, 5)
-
+        self.type=wx.ComboBox(self, self.ID_TYPE, "", choices=["", "Home", "Business"], style=wx.CB_READONLY)
+        hs.Add(self.type, 0, wx.EXPAND|wx.ALL, 5)
+        
         self.SetSizer(hs)
         hs.Fit(self)
 
@@ -595,10 +595,10 @@
 
         hs=wx.StaticBoxSizer(wx.StaticBox(self, -1, "URL"), wx.HORIZONTAL)
 
-        self.type=wx.ComboBox(self, self.ID_TYPE, "", choices=["", "Home", "Business"], style=wx.CB_READONLY)
-        hs.Add(self.type, 0, wx.EXPAND|wx.ALL, 5)
         self.url=wx.TextCtrl(self, -1, "")
         hs.Add(self.url, 1, wx.EXPAND|wx.ALL, 5)
+        self.type=wx.ComboBox(self, self.ID_TYPE, "", choices=["", "Home", "Business"], style=wx.CB_READONLY)
+        hs.Add(self.type, 0, wx.EXPAND|wx.ALL, 5)
 
         self.SetSizer(hs)
         hs.Fit(self)
@@ -639,12 +639,12 @@
         vs=wx.StaticBoxSizer(wx.StaticBox(self, -1, "Address Details"), wx.VERTICAL)
 
         hs=wx.BoxSizer(wx.HORIZONTAL)
-        hs.Add(wx.StaticText(self, -1, "Type"), 0, wx.ALIGN_CENTRE|wx.ALL, 5)
-        self.type=wx.ComboBox(self, self.ID_TYPE, "Home", choices=["Home", "Business"], style=wx.CB_READONLY)
-        hs.Add(self.type, 0, wx.EXPAND|wx.ALL, 5)
         hs.Add(wx.StaticText(self, -1, "Company"), 0, wx.ALIGN_CENTRE|wx.ALL, 5)
         self.company=wx.TextCtrl(self, -1, "")
         hs.Add(self.company, 1, wx.EXPAND|wx.ALL, 5)
+        hs.Add(wx.StaticText(self, -1, "Type"), 0, wx.ALIGN_CENTRE|wx.ALL, 5)
+        self.type=wx.ComboBox(self, self.ID_TYPE, "Home", choices=["Home", "Business"], style=wx.CB_READONLY)
+        hs.Add(self.type, 0, wx.EXPAND|wx.ALL, 5)
 
         gs=wx.FlexGridSizer(6,2,2,5)
 
@@ -816,7 +816,9 @@
         while win is not None and win not in self.widgets:
             win=win.GetParent()
         if win is None:
-            raise IndexError("no idea who is selected")
+            #raise IndexError("no idea who is selected")
+            # No widget is selected
+            return 0
         if win not in self.widgets:
             raise IndexError("no idea what that thing is")
         pos=self.widgets.index(win)
@@ -974,7 +976,7 @@
         ("Ringtones", "ringtones", RingtoneEditor),
         ]
 
-    def __init__(self, parent, data, title="Edit PhoneBook entry", keytoopenon=None, dataindex=None, factory=database.dictdataobjectfactory):
+    def __init__(self, parent, data, title="Edit PhoneBook Entry", keytoopenon=None, dataindex=None, factory=database.dictdataobjectfactory):
         """Constructor for phonebookentryeditor dialog
 
         @param parent: parent window

@@ -1026,6 +1023,16 @@
                 if key==keytoopenon and dataindex is not None:
                     widget.SetFocusOnValue(dataindex)
 
+        print dataindex
+        # Set focus to the first tab (key) and first text box
+        # if this is a new entry that is being added
+#        if keytoopenon == "names":
+#            nb.SetSelection(0)
+#            widget=EditorManager(self.nb, self.tabsfactory[0][2])
+#            print widget.GetCurrentWidgetIndex()
+#            widget.SetFocusOnValue(widget.GetCurrentWidgetIndex())
+
+
         vs.Add(wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL), 0, wx.EXPAND|wx.ALL, 5)
         vs.Add(self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.HELP), 0, wx.ALIGN_CENTRE|wx.ALL, 5)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.