• 1
  • 10
  • 11
  • 12(current)
  • 13
  • 14
  • 27
Release PyXBMCt: a Python framework for simple creating UI for XBMC addons
(2015-06-13, 18:36)SportySpice Wrote: This framework have worked great for me so far. I am really missing some kind of a scrolling function in each window I open though.
Is there any way to achieve this?

I will resort to a next button if all else fails.

I'm not sure what you need but xbmcgui module provides scrolling only in some of its Controls - FaldeLabel, List and TextBox. If your mean that all your controls do not fit into one screen, there's nothing you can do, at least with pure Python Controls, except to divide your UI into smaller sections.
Reply
Hi Roman,
You might have an answer to my question. I am trying to create a script which will gather gps data and output the data to a textbox or label on my dialog screen. I have come up with this so far but I cannot get the label text to accept my entry. I have highliged my trouble area. If you have a better solution, please assist.
Thanks

Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Licence: GPL v.3 http://www.gnu.org/licenses/gpl.html
# This is an XBMC addon for demonstrating the capabilities
# and usage of PyXBMCt framework.

import os
import sys
import time
import xbmc, xbmcaddon, xbmcgui
from pyxbmct.addonwindow import *
from gps import *
import threading

import subprocess


_addon = xbmcaddon.Addon()
_addon_path = _addon.getAddonInfo('path')


gpsd = None #seting the global variable

os.system('clear') #clear the terminal (optional)


    
class MyAddon(AddonDialogWindow):

    def __init__(self, title=''):
        super(MyAddon, self).__init__(title)
        self.setGeometry(1200, 750, 10, 3)
        self.set_info_controls()
        self.set_active_controls()
        # Connect a key action (Backspace) to close the window.
        self.connect(ACTION_NAV_BACK, self.close)

    def set_info_controls(self):

        label_center = Label ("Time")
        self.placeControl(label_center, 1,1)
        print "check 1"
        


      

    def set_active_controls(self):
        int_label = Label('Interactive Controls', alignment=ALIGN_CENTER)
        self.placeControl(int_label, 0, 2, 1, 2)
        print "check 2"

        # start_button_update
        self.button = Button('Close')
        self.placeControl(self.button, 8, 2)
        # Connect control to close the window.
        self.connect(self.button, self.close)
    
        print "check 3"


        # Update button caption on toggle
        [b]time_label = Label(GpsPoller.gpstime, alignment=ALIGN_CENTER)
[/b]        self.placeControl(int_label, 3, 1)
        print "check 4"



class GpsPoller(threading.Thread):
    print "check 5"
    def __init__(self):
        threading.Thread.__init__(self)
        global gpsd #bring it in scope
        gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
        self.current_value = None
        self.running = True #setting the thread running to true
        print "check 6"
    
    def run(self):
        print "check 7"
        global gpsd
        while gpsp.running:
            gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer
        print "check 8"

    def gpstime(self):
        global line1
        line1 = 'time utc    ' , gpsd.utc,' + ', gpsd.fix.time
        
    try:
        print "A"
        
        while True:
            print "B"
            #It may take a second or two to get good data
            #print gpsd.fix.latitude,', ',gpsd.fix.longitude,'  Time: ',gpsd.utc

            os.system('clear')

            #print
            #print ' GPS reading'
            #print '----------------------------------------'
            #print 'latitude    ' , gpsd.fix.latitude
            #print 'longitude   ' , gpsd.fix.longitude
            line1 = 'time utc    ' , gpsd.utc,' + ', gpsd.fix.time
            #print 'time utc    ' , gpsd.utc,' + ', gpsd.fix.time
            #print 'altitude (m)' , gpsd.fix.altitude
            #print 'eps         ' , gpsd.fix.eps
            #print 'epx         ' , gpsd.fix.epx
            #print 'epv         ' , gpsd.fix.epv
            #print 'ept         ' , gpsd.fix.ept
            #print 'speed (m/s) ' , gpsd.fix.speed
            #print 'climb       ' , gpsd.fix.climb
            #print 'track       ' , gpsd.fix.track
            #print 'mode        ' , gpsd.fix.mode
            #print
            #print 'sats        ' , gpsd.satellites


      
            print "check C"

            time.sleep(5)

    except (KeyboardInterrupt, SystemExit):
        #when you press ctrl+c
        print "\nKilling Thread..."
        gpsp.running = False
        gpsp.join() # wait for the thread to finish what it's doing
    print "Done.\nExiting."
  
if __name__ == '__main__':
    gpsp = GpsPoller() # create the thread
    window = MyAddon('PyXBMCt Demo')
    window.doModal()
Reply
2 ral6639

As far as PyXBMCt concerned, you seem to have forgotten to add your time_label object to your window. But as far as Python in general concerned, your code makes no sense to me. Does it even work or it is some very raw draft?
Reply
Roman, I made a few changes and the script does run but it is not outputting the information I need to be displayed in the Label ( the time from the gps). Here is the updated script:
Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Licence: GPL v.3 http://www.gnu.org/licenses/gpl.html
# This is an XBMC addon for demonstrating the capabilities
# and usage of PyXBMCt framework.

import os
import sys
import time
import xbmc, xbmcaddon, xbmcgui
from pyxbmct.addonwindow import *
from gps import *
import threading

import subprocess


_addon = xbmcaddon.Addon()
_addon_path = _addon.getAddonInfo('path')


gpsd = None #seting the global variable

os.system('clear') #clear the terminal (optional)


    
class MyAddon(AddonDialogWindow):

    def __init__(self, title=''):
        super(MyAddon, self).__init__(title)
        self.setGeometry(1200, 750, 10, 3)
        self.set_info_controls()
        self.set_active_controls()
        # Connect a key action (Backspace) to close the window.
        self.connect(ACTION_NAV_BACK, self.close)

    def set_info_controls(self):

        label_center = Label ("Time")
        self.placeControl(label_center, 1,1)
        print "check 1"
        


      

    def set_active_controls(self):
        int_label = Label('Interactive Controls', alignment=ALIGN_CENTER)
        self.placeControl(int_label, 0, 2, 1, 2)
        print "check 2"

        # start_button_update
        self.button = Button('Close')
        self.placeControl(self.button, 8, 2)
        # Connect control to close the window.
        self.connect(self.button, self.close)
    
        print "check 3"


        # Update button caption on toggle
        time_label = Label("%s" %(GpsPoller.gpstime), alignment=ALIGN_CENTER)
        self.placeControl(time_label, 3, 1)
        print "check 4"



class GpsPoller(threading.Thread):
    print "check 5"
    def __init__(self):
        threading.Thread.__init__(self)
        global gpsd #bring it in scope
        gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
        self.current_value = None
        self.running = True #setting the thread running to true
        print "check 6"
    
    def run(self):
        print "check 7"
        global gpsd
        while gpsp.running:
            gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer
        print "check 8"

    def gpstime(self):
        global line1
        line1 = 'time utc    ' , gpsd.utc,' + ', gpsd.fix.time
        

  
if __name__ == '__main__':
    gpsp = GpsPoller() # create the thread
    window = MyAddon('PyXBMCt Demo')
    window.doModal()
    try:
            

        print "A"
        gpsp.start()
        while True:
            print "B"
            #It may take a second or two to get good data
            #print gpsd.fix.latitude,', ',gpsd.fix.longitude,'  Time: ',gpsd.utc

            os.system('clear')

            #print
            #print ' GPS reading'
            #print '----------------------------------------'
            #print 'latitude    ' , gpsd.fix.latitude
            #print 'longitude   ' , gpsd.fix.longitude
            line1 = 'time utc    ' , gpsd.utc,' + ', gpsd.fix.time
            #print 'time utc    ' , gpsd.utc,' + ', gpsd.fix.time
            #print 'altitude (m)' , gpsd.fix.altitude
            #print 'eps         ' , gpsd.fix.eps
            #print 'epx         ' , gpsd.fix.epx
            #print 'epv         ' , gpsd.fix.epv
            #print 'ept         ' , gpsd.fix.ept
            #print 'speed (m/s) ' , gpsd.fix.speed
            #print 'climb       ' , gpsd.fix.climb
            #print 'track       ' , gpsd.fix.track
            #print 'mode        ' , gpsd.fix.mode
            #print
            #print 'sats        ' , gpsd.satellites

            print line1
      
            print "check C"

            time.sleep(5)

    except (KeyboardInterrupt, SystemExit):
        #when you press ctrl+c
        print "\nKilling Thread..."
        gpsp.running = False
        gpsp.join() # wait for the thread to finish what it's doing
    print "Done.\nExiting."

and here is the log info. ( note that the check 1, check 2, etc are only there to see the program status.)
Code:
1195.16:04:27 T:2853958688  NOTICE: check 5


1196.16:04:27 T:2853958688  NOTICE: check 6


1197.16:04:28 T:2853958688  NOTICE: check 1


1198.16:04:28 T:2853958688  NOTICE: check 2


1199.16:04:28 T:2853958688  NOTICE: check 3


1200.16:04:28 T:2853958688  NOTICE: check 4


1201.16:04:29 T:2706371616  NOTICE: B


1202.16:04:29 T:2706371616  NOTICE: check C


1203.16:04:29 T:2723148832  NOTICE: B


1204.16:04:30 T:2723148832  NOTICE: check C


1205.16:04:34 T:2706371616  NOTICE: B


1206.16:04:34 T:2706371616  NOTICE: check C


1207.16:04:35 T:2723148832  NOTICE: B


1208.16:04:35 T:2723148832  NOTICE: check C


1209.16:04:39 T:2706371616  NOTICE: B


1210.16:04:39 T:2706371616  NOTICE: check C


1211.16:04:40 T:2723148832  NOTICE: B


1212.16:04:40 T:2723148832  NOTICE: check C


1213.16:04:44 T:2706371616  NOTICE: B


1214.16:04:45 T:2706371616  NOTICE: check C


1215.16:04:45 T:2723148832  NOTICE: B


1216.16:04:45 T:2723148832  NOTICE: check C


1217.16:04:50 T:2706371616  NOTICE: B


1218.16:04:50 T:2706371616  NOTICE: check C


1219.16:04:50 T:2723148832  NOTICE: B


1220.16:04:50 T:2723148832  NOTICE: check C


1221.16:04:52 T:2853958688  NOTICE: A


1222.16:04:52 T:2853958688  NOTICE: B


1223.16:04:52 T:2738611232  NOTICE: check 7


1224.16:04:52 T:2853958688  NOTICE: ('time utc    ', u'2015-07-22T16:04:30.000Z', ' + ', u'2015-07-22T16:04:29.000Z')


1225.16:04:52 T:2853958688  NOTICE: check C


1226.16:04:54 T:2669536288  NOTICE: Thread JobWorker start, auto delete: true


1227.16:04:55 T:2706371616  NOTICE: Previous line repeats 1 times.


1228.16:04:55 T:2706371616  NOTICE: B


1229.16:04:55 T:2706371616  NOTICE: check C


1230.16:04:55 T:2723148832  NOTICE: B


1231.16:04:55 T:2723148832  NOTICE: check C


1232.16:04:57 T:2853958688  NOTICE: B


1233.16:04:58 T:2853958688  NOTICE: ('time utc    ', u'2015-07-22T16:04:58.000Z', ' + ', 1437581098.0)


1234.16:04:58 T:2853958688  NOTICE: check C


1235.16:04:58 T:2657088544  NOTICE: Thread LanguageInvoker start, auto delete: false


1236.16:04:58 T:2657088544  NOTICE: -->Python Interpreter Initialized<--


1237.16:04:59 T:2657088544  NOTICE: Kodi Log Uploader: started


1238.16:04:59 T:2657088544  NOTICE: Kodi Log Uploader: settings: len(email)=17


1239.16:04:59 T:2657088544  NOTICE: Kodi Log Uploader: settings: skip_oldlog=True


1240.16:05:00 T:2706371616  NOTICE: B


1241.16:05:00 T:2706371616  NOTICE: check C


1242.16:05:00 T:2723148832  NOTICE: B


1243.16:05:00 T:2723148832  NOTICE: check C


1244.16:05:02 T:2657088544  NOTICE: Kodi Log Uploader: reading log...
Reply
(2015-07-22, 18:11)ral6639 Wrote: Roman, I made a few changes and the script does run [b]but it is not outputting the information I need to be displayed in the Label ( the time from the gps).

Your code still has little sense to me. As far as I can see you haven't implemented any facilities to update the label text. Your time_label object has local scope in set_active_controls method and no public interface to interact with it. Not to mention this strange construction:
Code:
time_label = Label("%s" %(GpsPoller.gpstime), alignment=ALIGN_CENTER)

I'd recommend you first to learn Python language so that your understand it's basics: what is scope, how a class differs from an instance of the class, what is a class interface, etc.
Reply
Ignore this - realised my mistake after posting...

(I was going to say that the line looked ok then I looked at the whole code and I'm getting more and more confused. I therefore completely agree with everything Roman says.)
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
Roman,

I agree I need to learn python instead of just slicing code together found on the internet. The problem I have, even when I corrected the scope, is that I don't know how to reference the object in the time_label parameters. Is there any documentation for pyxbmct to pull data from a thread and input into the label text that is visible on the screen?

The threading code does work. I found this @ http://www.danmandle.com/blog/getting-gp...th-python/
When I run this code in python it yields information like this below.

('time utc ', u'2015-07-24T00:19:36.000Z', ' + ', 1437697176.0)

How do I get that data to be printed on the pyxmbct script window?
Reply
I don't particularly like the code, in particular, using global variables for an object inside a class but let's leave that for now...

Let's say the above result is created in a line:
Code:
gps_time_data = GpsPoller.gpstime
# as a result I expect this to be equivalent to
# gps_time_date = ('time utc ', u'2015-07-24T00:19:36.000Z', ' + ', 1437697176.0)
I've no idea if that's the command that gives you your line but I'm assuming it is.

The result you're showing is called a tuple. If I was going to so something with this in python, I'd start with the last number. That's "UNIX epoch time" (number of seconds since 00:00 UTC 1 January 1970). Python can handle that and then format it into any format you like:
Code:
from datetime import datetime

# Get the time data
gps_time_data = GpsPoller.gpstime

# Convert it into python datetime object
# fromtimestamp takes epoch seconds as an argument
# so we pull just that number from the tuple
pydate = datetime.fromtimestamp(gsp_time_data[3])

# format date
# this example returns date in the format dd/mm/yy HH:MM:SS
datestring = pydate.strftime("%d/%m/%y %H:%M:%S")

# you can now use this variable to create your label
time_label = Label(datestring), alignment=ALIGN_CENTER)

For other ways to format your date, look at this link: https://docs.python.org/2/library/dateti...e-behavior
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
(2015-07-24, 11:25)el_Paraguayo Wrote:
Code:
# you can now use this variable to create your label
time_label = Label(datestring, alignment=ALIGN_CENTER)

For other ways to format your date, look at this link: https://docs.python.org/2/library/dateti...e-behavior

I've fixed the typo your code above. Also, if you need to update the displayed label you need to call setLabel(<new string>) method on the label instance.
PyXBMCt is just a convenience wrapper around several xbmcgui classes, so Kodi Python docs are still valid.
Reply
(2015-07-24, 11:40)Roman_V_M Wrote:
(2015-07-24, 11:25)el_Paraguayo Wrote:
Code:
# you can now use this variable to create your label
time_label = Label(datestring, alignment=ALIGN_CENTER)

For other ways to format your date, look at this link: https://docs.python.org/2/library/dateti...e-behavior

I've fixed the typo your code above.
Many thanks Roman.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
Hello

I'm not good in python i come from the c# world. So phyton is very confusing to me. It would be nice if you could help me with this stuff.

I like to make a monitor window. So if i active the popup the popup should appear and in background every 3 seconds it should poll a website and display the information in the popup.

If i click close the polling should killed and the window should close.

I can't get it to work. I have issues to get the background polling to work. Can someone point me how to code this?

Thx in advance
Reply
(2015-08-04, 16:15)_Andy_ Wrote: Hello

I'm not good in python i come from the c# world. So phyton is very confusing to me. It would be nice if you could help me with this stuff.

I like to make a monitor window. So if i active the popup the popup should appear and in background every 3 seconds it should poll a website and display the information in the popup.

If i click close the polling should killed and the window should close.

I can't get it to work. I have issues to get the background polling to work. Can someone point me how to code this?

Thx in advance

Not sure what it has to do with PyXBMCt, but here is a good starting point: https://docs.python.org/2/library/threading.html
I was assured that it is safe to update UI controls from a background thread, unlike in WinForms/WPF.
Reply
After 1 day of reading docs i have a result. Maybe it's a bad solution but it works. It's quick and dirty :-)
Reply
Thank you for your library. Finaly i have my result. A hardware monitor which updates every 2 seconds. In addition i can switch on/off my room lights :-)

Image
Reply
Roman,
What do you mean setLabel(<new string>). I cannot find a reference to this anywhere. Do you have an example of how it should be written in my script?

(2015-07-24, 11:40)Roman_V_M Wrote:
(2015-07-24, 11:25)el_Paraguayo Wrote:
Code:
# you can now use this variable to create your label
time_label = Label(datestring, alignment=ALIGN_CENTER)

For other ways to format your date, look at this link: https://docs.python.org/2/library/dateti...e-behavior

I've fixed the typo your code above. Also, if you need to update the displayed label you need to call setLabel(<new string>) method on the label instance.
PyXBMCt is just a convenience wrapper around several xbmcgui classes, so Kodi Python docs are still valid.
Reply
  • 1
  • 10
  • 11
  • 12(current)
  • 13
  • 14
  • 27

Logout Mark Read Team Forum Stats Members Help
PyXBMCt: a Python framework for simple creating UI for XBMC addons4