Example #1
0
 def test_constructor(self):
     ctx = osso.Context("test_osso", "0.1", False)
     self.assertTrue(isinstance(ctx, osso.Context))
     del ctx
     # third argument is ignored
     ctx = osso.Context("test_osso", "0.1", False)
     self.assertTrue(isinstance(ctx, osso.Context))
     # missing version
     self.assertRaises(TypeError, osso.Context, "test_osso")
def run(widget):
    if (has_hildon):
      print "+++ Hildon, yay!"
      widget.app = hildon.Program()
      window = hildon.Window()
      gtk.set_application_name(widget.display_name)
    else:
      print "--- No Hildon, sorry"
      window = gtk.Window()
      window.set_title(widget.display_name)
      
    widget.app_window = window
    window.resize(800, 480)
    window.add(widget)

    window.connect("delete-event", gtk.main_quit)
    window.connect("window-state-event", widget.do_window_state_event)
    window.connect("focus-in-event", widget.do_focus_in_event)
    window.connect("property-notify-event", widget.do_property_event)
    
    if (has_osso):
      print "+++ Have osso, yay!"
      try:
        osso_context = osso.Context(widget.dbus_name, widget.version, False)
        device = osso.DeviceState(osso_context)
        device.set_device_state_callback(state_change, system_inactivity=True, user_data=widget)
      except:
        print "*** Failed to initialise OSSO context. Power management disabled..."
        has_osoo = False

    window.present()
    widget.show()
    gtk.main()
Example #3
0
    def __init__(self):
        hildon.Program.__init__(self)
        self.window = hildon.Window()
        self.window.connect("destroy", self.quit)
        self.add_window(self.window)

        vbox = gtk.VBox()
        self.window.add(vbox)

        self.entry = gtk.Entry()
        vbox.add(self.entry)

        self.hscale = gtk.HScale(gtk.Adjustment(upper=10, step_incr=1))
        vbox.add(self.hscale)

        self.context = osso.Context("osso_test_statesaving", "0.0.1", False)
        self.stateSaving = osso.StateSaving(self.context)
        self.autosave = osso.Autosave(self.context)
        self.autosave.set_autosave_callback(self.save_state)

        self.connect("notify::is-topmost", self.topmost_change)

        self.state_read()

        #After the state_read call, set the callbacks for data change
        self.entry.connect("changed", self.entry_changed)
        self.hscale.connect("value-changed", self.hscale_changed)
        self.window.show_all()
Example #4
0
    def __init__(self):
        hildon.Program.__init__(self)

        self.window = hildon.Window()
        self.window.connect("delete-event", gtk.main_quit)
        self.add_window(self.window)

        # Osso stuff
        self.osso_c = osso.Context("osso_test_mime_icons", "0.0.1", False)
        self.mime = osso.Mime(self.osso_c)

        # Remaining widgets
        vbox = gtk.VBox()

        self.entry = gtk.Entry()
        vbox.pack_start(self.entry, expand=False, fill=True)

        self.button = gtk.Button("Ok")
        self.button.connect("clicked", self.button_cb)
        vbox.pack_start(self.button, expand=False, fill=True)

        scroll = gtk.ScrolledWindow()
        vbox.pack_start(scroll)

        self.model = gtk.ListStore(gtk.gdk.Pixbuf, str)

        self.iconview = gtk.IconView(self.model)
        self.iconview.set_pixbuf_column(0)
        self.iconview.set_text_column(1)
        self.iconview.set_margin(12)
        self.iconview.set_item_width(125)
        scroll.add(self.iconview)

        self.window.add(vbox)
        self.window.show_all()
Example #5
0
    def __init__(self):
        hildon.Program.__init__(self)

        self.context = osso.Context("filtermodelexample", "0.0.1", False)
        abook.init("filtermodelexample", self.context)

        self.window = hildon.Window()
        self.window.connect("destroy", gtk.main_quit)
        self.add_window(self.window)

        self.book = evo.open_addressbook("default")
        query = evo.EBookQuery.field_exists(evo.CONTACT_FULL_NAME)

        self.bookview = self.book.get_book_view(query)
        self.bookview.start()

        self.model = abook.ContactModel(self.bookview)
        self.view = abook.ContactView(self.model)

        button = gtk.Button("Edit contact")
        button.connect("clicked", self.edit_contact)

        vbox = gtk.VBox()
        vbox.pack_start(self.view)
        vbox.pack_start(button, expand=False, padding=5)

        self.window.add(vbox)
        self.window.show_all()
Example #6
0
def period(db, date_from, date_to):
    osso_c = osso.Context("mstore", "0.0.1", False)
    if date_from > date_to:
        temp = date_from
        date_from = date_to
        date_to = temp
    items = db.fetchPeriodItems(date_from, date_to)
    sums = db.getPeriodSums(date_from, date_to)
    data = header('Zisky ' + date_from + ' až ' + date_to)
    data += '<h3>Zisky ' + date_from + ' až ' + date_to + '</h3>'
    data += '<table width=\"100%\">\n'
    data += "<tr><td></td><td class=\"col_caption\">Nákupní suma</td><td class=\"col_caption\">Prodejní suma</td><td class=\"col_caption\">Zisk</td><td class=\"col_caption\">Počet</td></tr>\n"
    data += "<tr><td class=\"title\">Celkem</td><td class=\"sum\">" + str(
        roundPrice(sums[0])) + "</td><td class=\"sum\">" + str(
            roundPrice(sums[1])) + "</td><td class=\"sum\">" + str(
                roundPrice(sums[2])) + "</td><td class=\"sum\">" + str(
                    sums[3]) + "</td></tr>\n"
    for i in items:
        data += "<tr><td class=\"title\">" + i[
            0] + "</td><td class=\"number\">" + str(
                roundPrice(i[1])) + "</td><td class=\"number\">" + str(
                    roundPrice(i[2])) + "</td><td class=\"number\">" + str(
                        roundPrice(i[3])) + "</td><td class=\"number\">" + str(
                            i[4]) + "</td></tr>\n"
    data += '</table></body>'
    filename = config.appdir + '/zisky_' + date_from + '_' + date_to + '.html'
    fstore = open(filename, 'w')
    fstore.write(data)
    fstore.close()
    webbrowser.open(filename, context=osso_c)
Example #7
0
def store(db):
    osso_c = osso.Context("mstore", "0.0.1", False)
    datum = str(datetime.date.today())
    data = header('Stav skladu ' + datum)
    data += '<h3>Stav skladu ' + datum + '</h3>'
    sums = db.getItemSums()
    items = db.fetchItems()
    data += '<table width=\"100%\">\n'
    data += "<tr class=\"col_caption\"><td></td><td>Nákupní cena</td><td>Prodejní cena</td><td>Počet</td></tr>\n"
    data += "<tr><td class=\"title\">Celkem</td><td class=\"sum\">" + str(
        roundPrice(sums[0])) + "</td><td class=\"sum\">" + str(
            roundPrice(sums[1])) + "</td><td class=\"sum\">" + str(
                sums[2]) + "</td></tr>\n"
    for i in items:
        data += "<tr><td class=\"number\">" + i[
            1] + "</td><td class=\"number\">" + str(
                roundPrice(i[2])) + "</td><td class=\"number\">" + str(
                    roundPrice(i[3])) + "</td><td class=\"number\">" + str(
                        i[4]) + "</td></tr>\n"
    data += '</table></body>'
    filename = config.appdir + '/stav_skladu_' + datum + '.html'
    fstore = open(filename, 'w')
    fstore.write(data)
    fstore.close()
    webbrowser.open(filename, context=osso_c)
Example #8
0
    def __init__(self, app_name, main_window=None, version='1.0', mode=0):
        """Create a new rotation manager

        app_name    ... The name of your application (for osso.Context)
        main_window ... The root window (optional, hildon.StackableWindow)
        version     ... The version of your application (optional, string)
        mode        ... Initial mode for this manager (default: AUTOMATIC)
        """
        self._orientation = None
        self._main_window = main_window
        self._stack = hildon.WindowStack.get_default()
        self._mode = -1
        self._last_dbus_orientation = None
        self._keyboard_state = self._get_keyboard_state()
        app_id = '-'.join((app_name, self.__class__.__name__))
        self._osso_context = osso.Context(app_id, version, False)
        program = hildon.Program.get_instance()
        program.connect('notify::is-topmost', self._on_topmost_changed)
        system_bus = dbus.Bus.get_system()
        system_bus.add_signal_receiver(self._on_orientation_signal, \
                signal_name='sig_device_orientation_ind', \
                dbus_interface='com.nokia.mce.signal', \
                path='/com/nokia/mce/signal')
        system_bus.add_signal_receiver(self._on_keyboard_signal, \
                signal_name='Condition', \
                dbus_interface='org.freedesktop.Hal.Device', \
                path='/org/freedesktop/Hal/devices/platform_slide')
        self.set_mode(mode)
def main():

    osso_c = osso.Context("osso_test_statusbar", "0.0.1", False)

    statusbar = osso.Statusbar(osso_c)

    statusbar.statusbar_send_event("display", 1, 1, "")
Example #10
0
    def __init__(self):
        hildon.Program.__init__(self)

        # Init
        self.context = osso.Context("showcontacts", "0.0.1", False)
        abook.init("showcontacts", self.context)

        # Window
        self.window = hildon.Window()
        self.window.connect("destroy", gtk.main_quit)
        self.add_window(self.window)

        # Evolution stuff
        self.book = evo.open_addressbook("default")
        query = evo.EBookQuery.field_exists(evo.CONTACT_FULL_NAME)

        self.bookview = self.book.get_book_view(query)
        self.bookview.start()

        self.model = abook.GroupModel()
        self.view = abook.GroupSelector(self.model)

        button = gtk.Button("Show contacts")
        button.connect("clicked", self.show_group)

        vbox = gtk.VBox()
        vbox.pack_start(self.view)
        vbox.pack_start(button)

        # Menu stuf...

        self.window.add(vbox)

        self.window.show_all()
Example #11
0
    def __init__(self):
        hildon.Program.__init__(self)

        self.context = osso.Context("showcontacts", "0.0.1", False)
        abook.init("showcontacts", self.context)

        self.window = hildon.Window()
        self.window.connect("destroy", gtk.main_quit)
        self.add_window(self.window)
        self.book = evo.open_addressbook("default")
        query = evo.EBookQuery.field_exists(evo.CONTACT_FULL_NAME)

        self.bookview = self.book.get_book_view(query)
        self.bookview.start()

        self.model = abook.ContactModel(self.bookview)
        self.view = abook.ContactView(self.model)
        self.view.connect("contact-activated", self.contact_activated)

        self.bar = abook.AlphaBar(self.view)
        btbar = self.bar.create_button_row()

        vbox = gtk.VBox()

        vbox.pack_start(self.view)
        vbox.pack_start(btbar)

        # Menu stuf...

        self.menu = gtk.Menu()

        item_add = gtk.MenuItem("Add Account To Contact")
        self.menu.append(item_add)
        item_add.connect("activate", self.add_to_contact)

        item_block = gtk.MenuItem("Block Manager")
        self.menu.append(item_block)
        item_block.connect("activate", self.block_manager)

        item_edit = gtk.MenuItem("Edit Contact")
        self.menu.append(item_edit)
        item_edit.connect("activate", self.edit_contact)

        item_new = gtk.MenuItem("New Contact")
        self.menu.append(item_new)
        item_new.connect("activate", self.edit_contact, True)

        item_edit_group = gtk.MenuItem("Edit Contact Groups")
        self.menu.append(item_edit_group)
        item_edit_group.connect("activate", self.edit_groups)

        item_auth = gtk.MenuItem("Request Auth")
        self.menu.append(item_auth)
        item_auth.connect("activate", self.request_auth)

        self.window.set_menu(self.menu)
        self.window.add(vbox)

        self.window.show_all()
Example #12
0
def main():
    osso_c = osso.Context("osso_test_sender", "0.0.1", False)
    window = hildon.Window()
    window.connect("destroy", gtk.main_quit)
    send_button = gtk.Button("Put example app to foreground")
    window.add(send_button)
    send_button.connect("clicked", send_rpc, osso_c)
    window.show_all()
    gtk.main()
Example #13
0
def main():
    global count
    loop = gobject.MainLoop()
    osso_c = osso.Context("osso_test_device_on", "0.0.1", False)
    device = osso.DeviceState(osso_c)
    
    gobject.timeout_add(11000, blink_cb, device, loop)

    loop.run()
Example #14
0
def main():
    osso_c = osso.Context("osso_test_app", "0.0.1", False)
    print "osso_test_app started"
    program = hildon.Program()
    window = hildon.Window()
    label = gtk.Label("Sample app")
    window.add(label)

    window.show_all()
    gtk.main()
def main():
    if len(sys.argv) < 2:
        print "Usage: %s <mimetype>" % sys.argv[0]

    osso_c = osso.Context("osso_test_mime_category", "0.0.1", False)
    mime = osso.Mime(osso_c)

    cat = mime.get_category_for_mime_type(sys.argv[1])

    print "category is: %s " % cat
Example #16
0
def main():
    context = osso.Context("abook_test", "0.0.1", False)
    abook.init_with_name("abook_test", context)

    print "ABook and osso.Context initialized"
    abook.get_osso_context()

    dialog = abook.ContactEditor()

    dialog.run()
def main():
    global count
    loop = gobject.MainLoop()
    osso_c = osso.Context("osso_test_device_on", "0.0.1", False)
    device = osso.DeviceState(osso_c)

    device.display_blanking_pause()

    gobject.timeout_add(15000, quit_cb, loop)

    loop.run()
def main():
    global count
    loop = gobject.MainLoop()
    osso_c = osso.Context("osso_test_device_on", "0.0.1", False)
    device = osso.DeviceState(osso_c)

    device.set_device_state_callback(state_cb, user_data=loop)

    loop.run()

    device.set_device_state_callback(None)
def main():
    if len(sys.argv) < 2:
        print "Usage: %s <uri> [<mimetype>]" % sys.argv[0]

    osso_c = osso.Context("osso_test_mime_category", "0.0.1", False)
    mime = osso.Mime(osso_c)

    print "Testing osso.Mime.open_file with uri:'%s'" % sys.argv[1]
    ret = mime.open_file(sys.argv[1])

    print "Testing osso.Mime.open_file_list with uri:'%s'" % sys.argv[1]
    ret = mime.open_file_list([sys.argv[1]])
Example #20
0
def main():
    
    osso_c = osso.Context("osso_test_note", "0.0.1", False)

    note = osso.SystemNote(osso_c)

    result = note.system_note_infoprint("System Note test application")

    print result
    loop = gobject.MainLoop()

    loop.run()
Example #21
0
def main():

    osso_c = osso.Context("osso_test_timenotification", "0.0.1", False)
    timenot = osso.TimeNotification(osso_c)

    timenot.set_time_notification_callback(time_cb)

    old_time = time.localtime()

    time.sleep(2)

    timenot.set_time(old_time)

    loop = gobject.MainLoop()
    loop.run()
Example #22
0
def open_website(url):
    """
    Opens the specified URL using the default system web
    browser. This uses Python's "webbrowser" module, so
    make sure your system is set up correctly.
    """
    if gpodder.ui.maemo:
        import osso
        context = osso.Context('gPodder', gpodder.__version__, False)
        rpc = osso.Rpc(context)
        rpc.rpc_run_with_defaults('osso_browser', \
                                  'open_new_window', \
                                  (url,))
    else:
        threading.Thread(target=webbrowser.open, args=(url,)).start()
    def setUp(self):
        self.ctx = osso.Context("test_osso", "0.1")
        self.orig_service = "/usr/share/dbus-1/services/org.freedesktop.Notifications.service"
        self.test_service = "/usr/share/dbus-1/services/test_osso.service"
        self.receiver = "/tmp/test_osso.py"

        if os.path.exists(self.orig_service):
            os.rename(self.orig_service, self.orig_service + ".orig")
        f = file(self.receiver, "w")
        f.write(receiver_source)
        f.close()
        os.chmod(self.receiver, 0755)
        f = file(self.test_service, "w")
        f.write("[D-BUS Service]\n" + "Name=org.freedesktop.Notifications\n" +
                "Exec=" + self.receiver)
        f.close()
Example #24
0
def main():
    context = osso.Context("selectdialog", "0.0.1", False)
    abook.init("selectdialog", context)

    book = evo.open_addressbook("default")
    query = evo.EBookQuery.field_exists(evo.CONTACT_FULL_NAME)

    bookview = book.get_book_view(query)
    bookview.start()

    model = abook.ContactModel(bookview)
    view = abook.ContactView(model)

    dialog = abook.SelectDialog(tree_view=view, new_contact=True)
    dialog.run()
    dialog.destroy()
Example #25
0
    def __init__(self):
        self.context = osso.Context("example_hildon_help", "0.1", False)
        self.window = hildon.Window()
        self.window.connect("delete-event", gtk.main_quit)

        self.vbox = gtk.VBox()

        self.btn_show = gtk.Button("hildon help show")
        self.btn_show.connect("clicked", self.show_help)
        self.vbox.pack_start(self.btn_show)

        self.btn_dlg = gtk.Button("hildon help dialog help enable")
        self.btn_dlg.connect("clicked", self.show_diag)
        self.vbox.pack_start(self.btn_dlg)

        self.window.add(self.vbox)

        self.window.show_all()
Example #26
0
    def setUp(self):
        self.program = "test_osso_receiver"
        self.async_program = "test_osso_async_receiver"

        for p in [self.program, self.async_program]:
            self._set_dbus_data(p)
            recv = file("/tmp/%s.py" % p, "w")
            recv.write(
                receiver(p, "0.1", self.service, self.object_path,
                         self.interface))
            recv.close()
            os.chmod("/tmp/%s.py" % p, 0755)
            srv = file("/usr/share/dbus-1/services/%s.service" % p, "w")
            srv.write("[D-BUS Service]\nName=%s\nExec=%s\n" %
                      (self.service, "/tmp/%s.py" % p))
            srv.close()

        self.ctx = osso.Context("test_osso", "0.1", False)
Example #27
0
 def __init__(self):
     """ Load the evolution addressbook and prepare ctypes for ossoabook. """
     self.ab = evolution.ebook.open_addressbook("default")
     t1 = time.clock()
     self.osso_ctx = osso.Context("fMMS_CONTACTS", "0.1")
     self.osso_abook = ctypes.CDLL('libosso-abook-1.0.so.0')
     empty = ""
     argv_type = ctypes.c_char_p * len(empty)
     argv = argv_type(*empty)
     argc = ctypes.c_int(len(empty))
     self.osso_abook.osso_abook_init(ctypes.byref(argc), ctypes.byref(argv),
                                     hash(self.osso_ctx))
     self.ebook = ctypes.CDLL('libebook-1.2.so.5')
     err = ctypes.c_void_p()
     self.c_book = self.ebook.e_book_new_default_addressbook(
         ctypes.byref(err))
     self.glib = ctypes.CDLL('libglib-2.0.so.0')
     t2 = time.clock()
     log.info("loaded contacthandler in %s s" % round(t2 - t1, 5))
Example #28
0
    def __init__(self, app_name, main_window=None, version='1.0', mode=0):
        """Create a new rotation manager

        app_name    ... The name of your application (for osso.Context)
        main_window ... The root window (optional, hildon.StackableWindow)
        version     ... The version of your application (optional, string)
        mode        ... Initial mode for this manager (default: AUTOMATIC)
        """
        self._orientation = None
        self._main_window = main_window
        self._stack = hildon.WindowStack.get_default()
        self._mode = -1
        self._last_dbus_orientation = None
        self._keyboard_state = self._get_keyboard_state()
        app_id = '-'.join((app_name, self.__class__.__name__))
        self._osso_context = osso.Context(app_id, version, False)
        program = hildon.Program.get_instance()
        program.connect('notify::is-topmost', self._on_topmost_changed)
        system_bus = dbus.Bus.get_system()
        system_bus.add_signal_receiver(
            self._on_orientation_signal,
            signal_name='sig_device_orientation_ind',
            dbus_interface='com.nokia.mce.signal',
            path='/com/nokia/mce/signal')

        system_bus.add_signal_receiver(
            self._on_keyboard_signal,
            signal_name='Condition',
            dbus_interface='org.freedesktop.Hal.Device',
            path='/org/freedesktop/Hal/devices/platform_slide')
        self.set_mode(mode)

        # check for current orientation - the first signal comes after and orientation change,
        # so if the device is already in portrait when the app is launched, it won't
        # rotate to the correct orientation before being oriented to landscape and back

        mceRequest = system_bus.get_object('com.nokia.mce',
                                           '/com/nokia/mce/request')
        dir(mceRequest)
        orientationInfo = mceRequest.get_device_orientation()
        # send a fake CB with current orientation info
        self._on_orientation_signal(*orientationInfo)
Example #29
0
 def create_reset_dialog(self, parent=None):
     dialog = gtk.Dialog()
     dialog.set_transient_for(parent)
     dialog.set_title(_('Reset settings'))
     dialog.add_button(gtk.STOCK_YES, 1)
     dialog.add_button(gtk.STOCK_NO, 0)
     label = gtk.Label(_('Are you sure you want to reset all settings?'))
     dialog.vbox.add(label)
     dialog.show_all()
     ret = dialog.run()
     if ret == 1:
         import osso
         self.osso_c = osso.Context("fMMS", "1.0", False)
         note = osso.SystemNote(self.osso_c)
         note.system_note_dialog(
             _('Application will close after settings are removed'),
             'notice')
         self.reset_all_settings()
         import sys
         sys.exit(0)
     dialog.destroy()
Example #30
0
def gui_open(filename):
    """
    Open a file or folder with the default application set
    by the Desktop environment. This uses "xdg-open" on all
    systems with a few exceptions:

       on Win32, os.startfile() is used
       on Maemo, osso is used to communicate with Nokia Media Player
    """
    try:
        if gpodder.ui.maemo:
            try:
                import osso
            except ImportError, ie:
                log('Cannot import osso module on maemo.')
                return False

            log('Using Nokia Media Player to open %s', filename)
            context = osso.Context('gPodder', gpodder.__version__, False)
            filename = filename.encode('utf-8')

            # Fix for Maemo bug 7162 (for local files with "#" in filename)
            if filename.startswith('/'):
                filename = 'file://' + urllib.quote(filename)

            rpc = osso.Rpc(context)
            app = 'mediaplayer'

            _unneeded, extension = os.path.splitext(filename.lower())

            # Fix for Maemo bug 5588 (use PDF viewer and images app)
            if extension == '.pdf':
                app = 'osso_pdfviewer'
            elif extension in ('.jpg', '.jpeg', '.png'):
                app = 'image_viewer'

            svc, path = (x % app for x in ('com.nokia.%s', '/com/nokia/%s'))
            rpc.rpc_run(svc, path, svc, 'mime_open', (filename,))
        elif gpodder.win32:
            os.startfile(filename)