Basic Beginner scripting(Lists)
#1
So i have a basic knowledge of python programming and i have been reading xbmc scripting documentation but i am having difficulty grasping essential basic information required to develop some simple scripts. For example i would like to eventualy create a script to display information i have stored in sql database(but for now i will probably start out with displaying information i have stored in file on my local computer) but it seems i am not allowed to define labels using string variables and i am confused how to go about adding functionality to my script using my own variables and functions. I have seen other scripts calling other .py scripts inside the defualt.py script but this confuses me and seems overly complicated and can i not simply add functionality in the init function? for example.


Code:
import xbmc, xbmcgui

#get actioncodes from https://github.com/xbmc/xbmc/blob/master/xbmc/guilib/Key.h
ACTION_PREVIOUS_MENU = 10

class MyClass(xbmcgui.Window):
  def __init__(self):
    myList[]
    #read file storing relevent data to list
    #other functionality
    myList.append('hello world')

    self.strActionInfo = xbmcgui.ControlLabel(250, 80, 200, 200, '', 'font14', '0xFFBBBBFF')
    self.addControl(self.strActionInfo)
    self.strActionInfo.setLabel('Push BACK to quit')
    self.list = xbmcgui.ControlList(200, 150, 300, 400)
    self.addControl(self.list)
    self.list.addItem(myList.pop())

    self.setFocus(self.list)

  def onAction(self, action):
    if action == ACTION_PREVIOUS_MENU:
      self.close()

  def onControl(self, control):
    if control == self.list:
      item = self.list.getSelectedItem()
      self.message('You selected : ' + item.getLabel())  

  def message(self, message):
    dialog = xbmcgui.Dialog()
    dialog.ok(" My message title", message)

mydisplay = MyClass()
mydisplay.doModal()
del mydisplay

again this is very basic example of what i am trying to do and i assume i am going about this completely the wrong way. and would be extremely grateful if someone could help point me in the right direction.
Reply
#2
Just learning myself too, so I will be following this to my own education.

It occurs to me to ask whether this portion could be a method that gets called from the __init__?

Code:
self.strActionInfo = xbmcgui.ControlLabel(250, 80, 200, 200, '', 'font14', '0xFFBBBBFF')
    self.addControl(self.strActionInfo)
    self.strActionInfo.setLabel('Push BACK to quit')
    self.list = xbmcgui.ControlList(200, 150, 300, 400)
    self.addControl(self.list)
    self.list.addItem(myList.pop())

Also, I am sure I have seen labels being determined by string variables (rather than strings themselves). Are you able to point to a specific line or block of code that doesnt work?
Reply
#3
After spending hours reading and researching i feel silly and it appears simple syntax errors was the cause of my problems. I would still like to know why most of the scripts i have looked at call another script inside its main defualt.py instead of calling functions inside the xbmc init function. And also if there is an easier way to test scripts without actually installing and testing the addon inside xbmc.

And of course any advice or resources that could help me would be greatly appreciated
Reply
#4
it is difficult to define a window with content only with python.
define your basic window ad controls in xml and set the dynamic content and properties with python
look in my script http://forum.xbmc.org/showthread.php?tid=164067
there i have defined 3 dialogs which get/set data from database
Reply
#5
Moving code to other modules is just for readability. It's easier to maintain if all your similar functions are in the same place.
For testing, search github for xbmc stubs. These have all same functions as the in built modules but they print to the console instead of taking actions in xbmc
Reply

Logout Mark Read Team Forum Stats Members Help
Basic Beginner scripting(Lists)0