Commit 00048eb9 authored by Olivier Aubert's avatar Olivier Aubert
Browse files

Code cleanup to prepare CORBA module update

parent 782abd5e
#! /usr/bin/python
# Simple CLI client for the corba module of vlc. Depends on pyorbit.
# Best used with IPython (completion, ...)
import sys
import ORBit, CORBA
def quit ():
try:
mc.exit()
except:
pass
print "IDL loading"
ORBit.load_typelib ("./MediaControl.so")
import VLC
if len(sys.argv) < 1:
print "Usage: %s" % sys.argv[0]
sys.exit(1)
print "ORB initialization"
orb = CORBA.ORB_init()
ior = open("/tmp/vlc-ior.ref").readline()
mc = orb.string_to_object(ior)
print "Object mc %s" % mc
pos = mc.get_media_position (0,0)
print "pos = mc.get_media_position (0,0)"
print pos
#! /bin/sh
# Helper prog
VLCPATH=/usr/local/src/vlc
cd $VLCPATH
${VLCPATH}/vlc --intf corba &
exit 0
--- pyorbit-1.99.3/src/pycorba-orb.c 2002-11-16 07:51:41.000000000 +0100
+++ pyorbit-1.99.3-modif/src/pycorba-orb.c 2003-01-22 14:43:30.000000000 +0100
@@ -154,6 +154,36 @@
return Py_None;
}
+static PyObject *
+pycorba_orb_work_pending(PyCORBA_ORB *self)
+{
+ CORBA_boolean ret;
+ CORBA_Environment ev;
+ PyObject *py_ret;
+
+ CORBA_exception_init(&ev);
+ ret = CORBA_ORB_work_pending (self->orb, &ev);
+
+ if (pyorbit_check_ex(&ev))
+ return NULL;
+ py_ret = ret ? Py_True : Py_False;
+ Py_INCREF(py_ret);
+ return py_ret;
+}
+
+static PyObject *
+pycorba_orb_perform_work (PyCORBA_ORB *self)
+{
+ CORBA_Environment ev;
+
+ CORBA_exception_init(&ev);
+ CORBA_ORB_perform_work (self->orb, &ev);
+ if (pyorbit_check_ex(&ev))
+ return NULL;
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
static PyMethodDef pycorba_orb_methods[] = {
{ "object_to_string", (PyCFunction)pycorba_orb_object_to_string, METH_VARARGS },
{ "string_to_object", (PyCFunction)pycorba_orb_string_to_object, METH_VARARGS },
@@ -161,6 +191,8 @@
{ "resolve_initial_references", (PyCFunction)pycorba_orb_resolve_initial_references, METH_VARARGS },
{ "run", (PyCFunction)pycorba_orb_run, METH_NOARGS },
{ "shutdown", (PyCFunction)pycorba_orb_shutdown, METH_VARARGS },
+ { "work_pending", (PyCFunction)pycorba_orb_work_pending, METH_VARARGS },
+ { "perform_work", (PyCFunction)pycorba_orb_perform_work, METH_VARARGS },
{ NULL, NULL, 0 }
};
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<glade-interface>
<widget class="GtkWindow" id="win">
<property name="visible">True</property>
<property name="title" translatable="yes">DVD Annote</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<signal name="delete_event" handler="on_exit" object="win" last_modification_time="Mon, 27 Jan 2003 14:07:29 GMT"/>
<signal name="key_press_event" handler="on_win_key_press_event" last_modification_time="Mon, 17 Feb 2003 16:23:35 GMT"/>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkMenuBar" id="menubar">
<property name="visible">True</property>
<child>
<widget class="GtkMenuItem" id="menuitem1">
<property name="visible">True</property>
<property name="label" translatable="yes">_File</property>
<property name="use_underline">True</property>
<child>
<widget class="GtkMenu" id="menuitem1_menu">
<child>
<widget class="GtkImageMenuItem" id="quit1">
<property name="visible">True</property>
<property name="label">gtk-quit</property>
<property name="use_stock">True</property>
<signal name="activate" handler="on_exit" last_modification_time="Mon, 27 Jan 2003 14:07:57 GMT"/>
</widget>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="menuitem4">
<property name="visible">True</property>
<property name="label" translatable="yes">_Help</property>
<property name="use_underline">True</property>
<child>
<widget class="GtkMenu" id="menuitem4_menu">
<child>
<widget class="GtkMenuItem" id="about1">
<property name="visible">True</property>
<property name="label" translatable="yes">_About</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_about1_activate" last_modification_time="Mon, 27 Jan 2003 14:07:57 GMT"/>
</widget>
</child>
</widget>
</child>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkHButtonBox" id="hbuttonbox2">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_SPREAD</property>
<property name="spacing">0</property>
<child>
<widget class="GtkButton" id="b_rewind">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Rewind</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Rewind</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_b_rewind_clicked" last_modification_time="Mon, 27 Jan 2003 14:19:30 GMT"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="b_play">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Play</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Play</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_b_play_clicked" last_modification_time="Mon, 27 Jan 2003 14:19:50 GMT"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="b_pause">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Pause</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Pause</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_b_pause_clicked" last_modification_time="Mon, 27 Jan 2003 14:19:56 GMT"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="b_stop">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Stop</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Stop</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_b_stop_clicked" last_modification_time="Mon, 27 Jan 2003 14:20:03 GMT"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="b_forward">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Forward</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Forward</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_b_forward_clicked" last_modification_time="Mon, 27 Jan 2003 14:20:10 GMT"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="b_addfile">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Add file</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Add file...</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_b_addfile_clicked" last_modification_time="Mon, 27 Jan 2003 14:20:15 GMT"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="b_selectdvd">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Select DVD</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Play DVD</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_b_selectdvd_clicked" last_modification_time="Mon, 27 Jan 2003 14:20:15 GMT"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="b_exit">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Exit</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-quit</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_b_exit_clicked" last_modification_time="Mon, 27 Jan 2003 14:20:26 GMT"/>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkFrame" id="Information">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="label_yalign">0.5</property>
<property name="shadow_type">GTK_SHADOW_ETCHED_IN</property>
<child>
<widget class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="n_rows">1</property>
<property name="n_columns">2</property>
<property name="homogeneous">True</property>
<property name="row_spacing">0</property>
<property name="column_spacing">10</property>
<child>
<widget class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="label" translatable="yes">Position</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">10</property>
<property name="ypad">2</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="position_label">
<property name="visible">True</property>
<property name="label" translatable="yes">N/C</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
</child>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="label" translatable="yes">Information</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="type">label_item</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_NEVER</property>
<property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTextView" id="logmessages">
<property name="height_request">100</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">False</property>
<property name="justification">GTK_JUSTIFY_LEFT</property>
<property name="wrap_mode">GTK_WRAP_CHAR</property>
<property name="cursor_visible">False</property>
<property name="pixels_above_lines">0</property>
<property name="pixels_below_lines">0</property>
<property name="pixels_inside_wrap">0</property>
<property name="left_margin">0</property>
<property name="right_margin">0</property>
<property name="indent">0</property>
<property name="text" translatable="yes"></property>
<signal name="insert_at_cursor" handler="on_logmessages_insert_at_cursor" last_modification_time="Mon, 27 Jan 2003 14:09:43 GMT"/>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
<widget class="GtkWindow" id="about">
<property name="title" translatable="yes">About</property>
<property name="type">GTK_WINDOW_POPUP</property>
<property name="window_position">GTK_WIN_POS_CENTER</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<child>
<widget class="GtkFrame" id="frame2">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="label_yalign">0.5</property>
<property name="shadow_type">GTK_SHADOW_ETCHED_IN</property>
<child>
<widget class="GtkVBox" id="vbox2">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkLabel" id="label4">
<property name="width_request">280</property>
<property name="height_request">64</property>
<property name="visible">True</property>
<property name="label" translatable="yes">DVD Annotation
En cours de developpement...</property>
<property name="use_underline">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_CENTER</property>
<property name="wrap">True</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button1">
<property name="border_width">1</property>
<property name="width_request">54</property>
<property name="height_request">34</property>
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Close about box</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="label">gtk-ok</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="about_hide" object="about" last_modification_time="Wed, 29 Jan 2003 12:52:15 GMT"/>
<accelerator key="Escape" modifiers="0" signal="clicked"/>
<accelerator key="Return" modifiers="0" signal="clicked"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</glade-interface>
#!/usr/bin/env python
import sys, time
# For gtk/glade
import pygtk
pygtk.require ('2.0')
import gtk
import gtk.glade
# For CORBA
import ORBit, CORBA
# FIXME: How do we make this portable to windows ?
ORBit.load_typelib ("./MediaControl.so")
import VLC
class Connect:
"""Abstract class defining helper functions to interconnect
glade XML files and methods of a python class."""
def create_dictionary (self):
"""Create a (name, function) dictionnary for the current class"""
dict = {}
self.create_dictionary_for_class (self.__class__, dict)
return dict
def create_dictionary_for_class (self, a_class, dict):
"""Create a (name, function) dictionnary for the specified class"""
bases = a_class.__bases__
for iteration in bases:
self.create_dictionary_for_class (iteration, dict)
for iteration in dir(a_class):
dict[iteration] = getattr(self, iteration)
def connect (self):
"""Connects the class methods with the UI"""
self.gui.signal_autoconnect(self.create_dictionary ())
def gtk_widget_hide (self, widget):
widget.hide ()
return gtk.TRUE
def on_exit(self, source=None, event=None):
"""Generic exit callback"""
gtk.main_quit()
class DVDControl (Connect):
def __init__ (self, gladefile):
"""Initializes the GUI and other attributes"""
# Glade init.
self.gui = gtk.glade.XML(gladefile)
self.connect ()
# Frequently used GUI widgets
self.gui.logmessages = self.gui.get_widget("logmessages")
self.gui.position_label = self.gui.get_widget("position_label")
self.gui.fs = gtk.FileSelection ("Select a file")
self.gui.fs.ok_button.connect_after ("clicked", lambda win: self.gui.fs.hide ())
self.gui.fs.cancel_button.connect ("clicked", lambda win: self.gui.fs.destroy ())
# CORBA init.
self.mc = None
self.currentpos = None
self.status = None
# FIXME: portability
self.iorfile = "/tmp/vlc-ior.ref"
# Various
# Default FF/RW time : 5 seconds
self.default_time_increment = 5
def update_title (self, title):
# Update the title of the main window
self.gui.get_widget ("win").set_title (title)
def launch_player (self):
"""Launch the VLC corba module"""
#print "Launching vlc server..."
# FIXME: spawn is portable, but how can we make sure that
# launch-vlc-corba launches the application in the background ?
# FIXME: portability
import distutils.spawn
distutils.spawn.spawn (["launch-vlc-corba"], True, True)
# Wait a little for the server to initialize. We could instead test
# on the existence and validity of self.iorfile
time.sleep (2)
return
def main (self):
"""Mainloop : CORBA initalization and Gtk mainloop setup"""
self.orb = CORBA.ORB_init(sys.argv)
errormessage = """Unable to get a MediaControl object
Please try to run the following command:
vlc --intf corba"""
try:
ior = open(self.iorfile).readline()
except:
# The iorfile does not existe : the player is maybe not active
self.launch_player ()
try:
ior = open(self.iorfile).readline()
except:
print errormessage
sys.exit(1)
self.mc = self.orb.string_to_object(ior)