ControlTextBox no longer takes focus
#1
Question 
Hi,

I have a simple script which toggles focus between two widgets, a ControlButton and a ControlTextBox.
The script works fine with the version 8.04 live, but if I try to run it from a recent SVN version (e.g. 19917) it gives me an error when trying to give focus to the ControlTextBox.


The error message is:

ERROR: Control 2 in window 13000 has been asked to focus, but it can't

The code is listed below:

Code:
import xbmc
import xbmcgui

class MyDialog(xbmcgui.Window):
   def onAction(self, action):
    try:
       if(action in [1,2,10]):
                    self.close()
       else:
          mySelection = self.getFocus()
          xbmc.log("The selection is %s" % mySelection)
          if (mySelection == self.myButton):
             self.myLabel.setLabel("Selecting textbox ")
             self.setFocus(self.myTextArea)
          elif(mySelection == self.myTextArea):
             self.myLabel.setLabel("Selecting button ")
             self.setFocus(self.myButton)
    except Exception, e:
     xbmc.log("Exception: %s" % e)
     self.myLabel.setLabel("Exception %s" % e)
   def __init__(self):
       self.myLabel=xbmcgui.ControlLabel(100,500,1000,50,'start')
       self.myButton=xbmcgui.ControlButton(100,10,100,100,"test button")
       self.myTextArea = xbmcgui.ControlTextBox(100,200,100,100)
       self.addControl(self.myButton)
       self.addControl(self.myLabel)
       self.addControl(self.myTextArea)
       self.setFocus(self.myButton)


myDialog=MyDialog()
myDialog.doModal()


Suggestions?

Thanks
Reply
#2
The textbox is not focusable. It's the same as a label pretty much (just has more info, and vertical scrolling and the like).

It used to have a spincontrol embedded in it for paging, but that was removed as it's far better to have an arbitrary pagecontrol outside of the textbox.

Thus, add a spincontrol or scrollbar control outside of the textbox and move the focus to that instead.

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#3
Oh, man! I don't know about the original poster, but that is exactly what I need. Any chance you can think of an example script that uses a textbox with a scrollbar?
For scripts, script development tools, and documentation, visit my website:
http://www.maskedfox.com/xbmc/
Reply
#4
Question 
jmarshall Wrote:The textbox is not focusable. It's the same as a label pretty much (just has more info, and vertical scrolling and the like).

It used to have a spincontrol embedded in it for paging, but that was removed as it's far better to have an arbitrary pagecontrol outside of the textbox.

Thus, add a spincontrol or scrollbar control outside of the textbox and move the focus to that instead.

Cheers,
Jonathan

Dear Jonathan,
Thanks for your reply.

How can I add a scrollbar or a spincontrol widget? They are not listed in the xbmcgui documentation ( http://xbmc.sourceforge.net/python-docs/xbmcgui.html ).

Please consider that I am not using WindowXML.

Regards,
vattila
Reply
#5
They're probably only supported via WindowXML in that case.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#6
Sad 
jmarshall Wrote:They're probably only supported via WindowXML in that case.

Would it make sense to add spincontrol and/or scrollbar also to the "standard API" Nod?

Im my case the use of WindowXML instead of the "standard API" means rewriting a large part of the code (which works perfectly with previous releases of XBMC Sad) : I don't know if I am the only one in this situation No.
Reply
#7
A patch would be most welcome. The trouble is finding someone with some time to do it!

It should be reasonably easy to implement just by following the button control example.

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#8
jmarshall Wrote:A patch would be most welcome. The trouble is finding someone with some time to do it!

It should be reasonably easy to implement just by following the button control example.

Cheers,
Jonathan

Hi,
I've tried to patch the api library.

The intention is to add an hidden spin control to be linked to a controltextbox.

It works in my code, but I don't know if there can be side effects (e.g. I had to expose a couple of protected methods in guilib/GUISpinControl.h.

The patch can be found here:
http://pastebin.com/f5b610eb5

The code should be further modified in order to make the spin control visible, but this is something I don't need in this moment.

The following example shows how to scroll up and down a controltextbox using the up and down keys (but also page up/ page down and left+enter and right+enter as per a standard spin control):

Code:
import xbmc
import xbmcgui

class MyDialog(xbmcgui.Window):
   def onAction(self, action):
    try:
       if(action == 10):
                    self.close()
       elif(action == 3):
          self.mySpin.moveUp()
       elif(action == 4):
          self.mySpin.moveDown()
       else:
          mySelection = self.getFocus()
    except Exception, e:
     xbmc.log("Exception: %s" % e)
   def __init__(self):
       self.myTextArea = xbmcgui.ControlTextBox(100,200,100,100)
       self.mySpin =xbmcgui.ControlSpin(500,500,100,100)
       self.addControl(self.myTextArea)
       self.addControl(self.mySpin)
       self.myTextArea.setPageControl(self.mySpin.getId())
       self.setFocus(self.mySpin)
       self.myTextArea.setText("""
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
line 10
line 11
line 12
line 13
line 14
line 15
line 16
line 17
line 18
line 19
line 20
line 21
line 22
line 23
line 24
line 25
line 26
line 27
line 28
line 29
line 30
""")

myDialog=MyDialog()
myDialog.doModal()
Reply
#9
Mind posting the patch on trac so that it's not lost - pastebin doesn't last forever.

A quick review:

1. You've commented some deinit functions - this looks dangerous.
2. You've commented a bunch of setting stuff in the constructor - why?
3. I'm not sure you need MoveUp and MoveDown exposed - I presume this is because you want the spincontrol hidden - does this _have_ to be this way?

Please post on trac as it's easier for developers to follow than here in the forums.

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#10
Dear Jonathan,
Thanks for your prompt review.


jmarshall Wrote:Mind posting the patch on trac so that it's not lost - pastebin doesn't last forever.
I will do it. First I wanted to know from you if the patch could make sense.

jmarshall Wrote:1. You've commented some deinit functions - this looks dangerous.
Actually it was a workaround for a problem you should be aware of (see tickets #6430 , #6431 ). It has very little to do with my patch and it should not be in there. I will remove it.
jmarshall Wrote:2. You've commented a bunch of setting stuff in the constructor - why?
Simply because they did not work.
Regarding the function ControlSpin1_New, it was already in the file (with the name ControlSpin_New) but commented out. I decommented and renamed it and left commented out the stuff that did not work (e..g. strText, strFont, and other attributes are not defined). I did not want to modify the ControlSpin structure in control.h since I don't know in depth how this component is used in other contexts (e.g. in the WindowXML stuff).

jmarshall Wrote:3. I'm not sure you need MoveUp and MoveDown exposed - I presume this is because you want the spincontrol hidden - does this _have_ to be this way?
You're right, they're not strictly needed. The thing is that the spincontrol, as it is now, is not visible and its normal behaviour (first select the arrow by moving left/right and then press select) is not easy to understand for the user. Further, my goal was to have a way to scroll text up and down in a textbox and a possible, and easy, way to do this is to press a key to go up and another to go down.
To sum up, it _has_not_to_be_ this way, but I would appreciate it Big Grin
Reply
#11
The patch is now also in trac ( Ticket #6613http://trac.xbmc.org/ticket/6613 )
Reply
#12
Hello,

First, thanks, thanks, thanks and more thanks. I've downloaded svn 20552 for windows from:

http://danielpatton.com/user-accounts/XB...v20552.exe

and executed this py

import xbmc
import xbmcgui

class MyDialog(xbmcgui.Window):
def onAction(self, action):
try:
if(action == 10):
self.close()
elif(action == 3):
self.mySpin.moveUp()
elif(action == 4):
self.mySpin.moveDown()
else:
mySelection = self.getFocus()
except Exception, e:
xbmc.log("Exception: %s" % e)

def __init__(self):
self.myTextArea = xbmcgui.ControlTextBox(100,200,100,100,'font14','0xffFFFFFF')
self.mySpin =xbmcgui.ControlSpin(500,500,100,100)
self.addControl(self.myTextArea)
self.addControl(self.mySpin)
self.myTextArea.setPageControl(self.mySpin.getId())
self.setFocus(self.mySpin)
self.myTextArea.setText("""
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
line 10
line 11
line 12
line 13
line 14
line 15
line 16
line 17
line 18
line 19
line 20
line 21
line 22
line 23
line 24
line 25
line 26
line 27
line 28
line 29
line 30
""")


myDialog=MyDialog()
myDialog.doModal()

but I get:

09:17:19 T:2064 M:236650496 NOTICE: Traceback (most recent call last):
09:17:19 T:2064 M:236650496 NOTICE: File "F:\XBMC\scripts\q.py", line 60, in ?
09:17:19 T:2064 M:236650496 NOTICE:
09:17:19 T:2064 M:236650496 NOTICE: myDialog=MyDialog()
09:17:19 T:2064 M:236650496 NOTICE: File "F:\XBMC\scripts\q.py", line 21, in __init__
09:17:19 T:2064 M:236650496 NOTICE:
09:17:19 T:2064 M:236650496 NOTICE: self.mySpin =xbmcgui.ControlSpin(500,500,100,100)
09:17:19 T:2064 M:236650496 NOTICE: AttributeError
09:17:19 T:2064 M:236650496 NOTICE: :
09:17:19 T:2064 M:236650496 NOTICE: 'module' object has no attribute 'ControlSpin'
09:17:19 T:2064 M:236650496 NOTICE:

I think it should works with this rev but I'm not really sure.
Reply
#13
The spin control stuff wasn't added. All that was added was a scroll(position) function to the textbox control.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#14
Ouch....

Thanks a lot
Reply

Logout Mark Read Team Forum Stats Members Help
ControlTextBox no longer takes focus0