#!/usr/bin/env python

print "SHR: initializing..."
import e_dbus, dbus, elementary
from sys import argv

if len(argv)==1:
  print "SHR: module is not passed in arguments. Aborting..."
  exit(0)

modname = argv[1]

(submodname, classname) = modname.split('.',1)

print "SHR: import "+classname+" from "+submodname
module   = __import__('shr_settings_modules.' + submodname, globals(), locals(), classname)
ModClass = module.__getattribute__(classname)

def close(obj, *args, **kargs):
    print "SHR: stopUpdate"
    mod.stopUpdate()
    print "SHR: destroy"
    mod.destroy()
    print "SHR: closing..."
    elementary.exit()


elementary.init()
mainloop = e_dbus.DBusEcoreMainLoop()
bus = dbus.SystemBus(mainloop=mainloop)
win = elementary.Window("shr-settings-debug", elementary.ELM_WIN_BASIC)
win.show()
bg = elementary.Background(win)
bg.size_hint_min_set(200,300)
win.resize_object_add(bg)
bg.show()

print "SHR: constructor"
mod = ModClass(win, bus)
print "SHR: isEnabled"
print "SHR: enabled = "+str(mod.isEnabled())
print "SHR: createView"
view = mod.createView()
scroll = elementary.Scroller(win)
win.resize_object_add(scroll)
scroll.bounce_set(0, 1)
scroll.show()

frame = elementary.Frame(win)
frame.label_set(mod.getName())
frame.content_set(view)
frame.show()

frame.size_hint_weight_set(1.0, 0.0)

scroll.content_set(frame)

view.size_hint_align_set(-1.0, -1.0)
view.size_hint_weight_set(1.0, 0.0)
view.show()
win.callback_delete_request_add(close)

elementary.run()
elementary.shutdown()
