Is there any new textbox function?
#1
A few years back I wanted to write a simple add-on to browse the (then XBMC) Kodi log file from inside Kodi

I did not manage to get complete control of how to scroll the textbox containing the log file contents.
Mainly I was missing a way to know how many lines were actually in the textbox.

I would like to complete it now, if possible.

Is there some new function or change in existing functions for textbox ?
(like self.textbox.scroll(position) returning a value if it exceeds the max position or a new function self.textbox.getlines())

Or, alternatively, maybe someone can recommend a better way to browse a file from within Kodi.
Reply
#2
I use the following method in my addons, this displays text in a window much the same as Kodi displays an addon's change log (in fact I normally use it to display my addons changelog when the version number changes)

Code:
def showText(heading, text, waitForClose=False):
    id = 10147

    xbmc.executebuiltin('ActivateWindow(%d)' % id)
    xbmc.sleep(100)

    win = xbmcgui.Window(id)

    retry = 50
    while (retry > 0):
        try:
            xbmc.sleep(10)
            win.getControl(1).setLabel(heading)
            win.getControl(5).setText(text)
            retry = 0
        except:
            retry -= 1

    if waitForClose:
        while xbmc.getCondVisibility('Window.IsVisible(%d)' % id) == 1:
            xbmc.sleep(50)

I'm assuming you know how to get the log file contents?

Window 10147 is the textviewer dialog (see here http://kodi.wiki/view/Window_IDs)
Reply
#3
Spoyser, thank you.

I can display the log contents fine. My problem is mainly with the navigation part.

I manage arrows and page down/up but I did not find a way to know when I reached the botton of the file, and this is important to keep track of which position the file is in.
Reply
#4
I don't know if this will help at all but I use the following code in my skin to know when I'm at the bottom of a scrolling textbox.

Code:
StringCompare(Container(ID_OF_TEXTBOX).CurrentPage,Container(ID_OF_TEXTBOX).NumPages)
Reply
#5
(2015-10-05, 10:58)Hitcher Wrote: I don't know if this will help at all but I use the following code in my skin to know when I'm at the bottom of a scrolling textbox.

Code:
StringCompare(Container(ID_OF_TEXTBOX).CurrentPage,Container(ID_OF_TEXTBOX).NumPages)

That's a step forward for me!
From not knowing at all where is the last line to knowing I am at the last page.
I will try it.
Thanks

PS: By any chance do you have any code to get the number of text lines in the textbox.height?
Reply
#6
That info's not available to skins, sorry.
Reply
#7
(2015-10-06, 09:15)Hitcher Wrote: That info's not available to skins, sorry.

I though of a way to do it!
Keep tab on:

Code:
Container(ID_OF_TEXTBOX).CurrentPage

when it changes, the difference in textbox position from the previous CurrentPage will tell how many lines are in the page.
I think I can mantain multiple tabs and average the result to get more acurate number.
I'll try to implement all this this weekend.
Reply
#8
I talked too soon about the entire solution.

I started refreshing my Kodi controls knowledge and it turns out a Text Box control is not a container, therefore CurrentPage and NumPages are not available.

Back to square 1.

Evenso from the GUITextBox.h it can be seen the functions are implemented, but they were defined as protected:

Code:
protected:
  virtual void UpdateVisibility(const CGUIListItem *item = NULL);
  virtual bool UpdateColors();
  virtual void UpdateInfo(const CGUIListItem *item = NULL);
  void UpdatePageControl();
  void ScrollToOffset(int offset, bool autoScroll = false);
  unsigned int GetRows() const;
  int GetCurrentPage() const;
  int GetNumPages() const;
Reply
#9
(2015-10-05, 10:01)ilomambo Wrote: Spoyser, thank you.

I can display the log contents fine. My problem is mainly with the navigation part.

I manage arrows and page down/up but I did not find a way to know when I reached the botton of the file, and this is important to keep track of which position the file is in.

My code will automatically show a scroll bar if needed, and the arrow keys should also work.
Reply
#10
(2015-10-07, 21:17)spoyser Wrote: ...
My code will automatically show a scroll bar if needed, and the arrow keys should also work.

So maybe I did not understand it well enough. How would you add a line to open the window on the last line of the text?
(I know that Scroll(-1) does it, but you cannot page up or move up from there)
Reply
#11
Hi All,

Thanks for the info, a very interesting discussion - sort of overlaps with something I have been trying to do.

I like the Container(ID).CurrentPage option to get where you are in the text box/scrollbar area.

Is there a way to "set the Current page" when the screen is next reloaded?" So that it gets to the point you saved when they last closed the screen?

Thanks

Rob

P.S. Sorry if this is a bit off-topic, but seemed very close.
Reply
#12
(2015-10-08, 08:38)ilomambo Wrote:
(2015-10-07, 21:17)spoyser Wrote: ...
My code will automatically show a scroll bar if needed, and the arrow keys should also work.

So maybe I did not understand it well enough. How would you add a line to open the window on the last line of the text?
(I know that Scroll(-1) does it, but you cannot page up or move up from there)

Tbh I'd read the log in, split into an array on end of lines, reverse array, and then display, therefore most recent would be at top and no scrolling necessary
Reply
#13
(2015-10-08, 14:47)spoyser Wrote: Tbh I'd read the log in, split into an array on end of lines, reverse array, and then display, therefore most recent would be at top and no scrolling necessary

I get your idea, but you just reversed the problem in case you want now to see the first line.

I think hat I am going to do something not so kosher, in the way that I am going to guess the number of lines by counting the newlines in the text and adding a 6% or 7% statistically for wrapped lines and consider this the last line number you can scroll to.
It is not very elegant, but it beats using negative scroll numbers and getting stucked.
Maybe in time an exact solution will present itself and then I will patch it into a newer version.

I want to finish it and release it to the Kodi repo, because I think it is quite useful to look at the log file from within Kodi, for those time when you get an add-on error and you want to see immediately the log file to see what was wrong.
At least I use it a lot.
Reply
#14
(2015-10-08, 21:19)ilomambo Wrote:
(2015-10-08, 14:47)spoyser Wrote: Tbh I'd read the log in, split into an array on end of lines, reverse array, and then display, therefore most recent would be at top and no scrolling necessary

I want to finish it and release it to the Kodi repo, because I think it is quite useful to look at the log file from within Kodi, for those time when you get an add-on error and you want to see immediately the log file to see what was wrong.
At least I use it a lot.

In which case my solution would be fine as it would put the most recent items (ie what has just occurred) at the top of the list and you wouldn't need to scroll at all.
Reply
#15
(2015-10-08, 14:05)robwebset Wrote: Is there a way to "set the Current page" when the screen is next reloaded?" So that it gets to the point you saved when they last closed the screen?

I am a newbie myself. You are asking how to make some value persistent, although I don't know how to do it, I am sure you can, because there is a folder called addons data under userdata, where you can see private data saved by the installed addons.
These days your best way to find is to Google the keywords (Kodi, addon_data, phyton)
Reply

Logout Mark Read Team Forum Stats Members Help
Is there any new textbox function?0