#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6.3 on Tue Apr  7 15:42:58 2009

import wx
import sys
import os
import string
import re
from threading import Thread

import roslib; roslib.load_manifest('tabletop_objects')

from std_msgs.msg import String
import rospy

from tabletop_objects.srv import *


# begin wxGlade: extracode
# end wxGlade


def call_service():
    try:
        print "Waiting for service"
        rospy.wait_for_service('table_top/find_object_poses', 1.0)
        # create a handle to the add_two_ints service
        find_object_poses = rospy.ServiceProxy('table_top/find_object_poses', FindObjectPoses)

        # simplified style
        resp = find_object_poses()

#        for p in resp.objects:
#            print p

    except rospy.ServiceException, e:
        print "Service call failed: %s"%e
    except rospy.ROSException, e:
        print "Got exceptio: %s"%e


class PublishThread(Thread):

    def __init__(self,publisher,value):
        Thread.__init__(self)
        self.publisher = publisher
        self.value = value

    def run(self):
        rospy.sleep(.5)
        self.publisher.publish(self.value)


class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        
        self.pub = rospy.Publisher('/publish_scene/prefix', String)
        rospy.init_node('publish_stereo_data', anonymous=True)
        # begin wxGlade: MyFrame.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.dir_picker = wx.DirPickerCtrl(self, -1, os.getcwd())
        self.button_load = wx.Button(self, -1, "Load")
        self.list_images = wx.ListCtrl(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
        self.button_publish = wx.Button(self, -1, "Publish")
        self.button_1 = wx.Button(self, -1, "Close")

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_BUTTON, self.onLoad, self.button_load)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onListSelected, self.list_images)
        self.Bind(wx.EVT_BUTTON, self.onPublish, self.button_publish)
        self.Bind(wx.EVT_BUTTON, self.onClose, self.button_1)
        # end wxGlade
        
        self.list_images.InsertColumn(0,"Scene")

    def __set_properties(self):
        # begin wxGlade: MyFrame.__set_properties
        self.SetTitle("Scene chooser")
        self.SetSize((527, 706))
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MyFrame.__do_layout
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_3 = wx.BoxSizer(wx.VERTICAL)
        sizer_4 = wx.BoxSizer(wx.VERTICAL)
        sizer_4.Add(self.dir_picker, 0, wx.EXPAND, 0)
        sizer_4.Add(self.button_load, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
        sizer_4.Add(self.list_images, 1, wx.EXPAND, 0)
        sizer_2.Add(sizer_4, 1, wx.EXPAND, 0)
        sizer_3.Add(self.button_publish, 0, wx.ALL, 10)
        sizer_2.Add(sizer_3, 1, wx.EXPAND, 0)
        sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
        sizer_1.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
        self.SetSizer(sizer_1)
        self.Layout()
        # end wxGlade

    def onPublish(self, event): # wxGlade: MyFrame.<event_handler>
        call_service()
        event.Skip()

    def onClose(self, event): # wxGlade: MyFrame.<event_handler>
        sys.exit(0)
        event.Skip()

    def onListSelected(self, event): # wxGlade: MyFrame.<event_handler>
        dir = str(self.dir_picker.GetPath())
        prefix =  str(event.GetText())
        value = String(dir+"/"+prefix)

        thread = PublishThread(self.pub,value)
        thread.start()

        print "Calling service"
        call_service()
        print "Service returned"
        event.Skip()

    def onLoad(self, event): # wxGlade: MyFrame.<event_handler>
        dir = self.dir_picker.GetPath()
        i=0
#        self.list_images.ClearAll()
        for file in os.listdir(dir):
            if os.path.isfile(os.path.join(dir,file)):
                i += 1
                if file.endswith('.pcd'):
                    prefix = re.search('[a-z]+\.[0-9]+\.[TN]\.[a-zA-Z]+',file).group()
                    self.list_images.InsertStringItem(i,prefix)

# end of class MyFrame


if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    frame_1 = MyFrame(None, -1, "")
    app.SetTopWindow(frame_1)
    frame_1.Show()
    app.MainLoop()

a34db6bc97dc5877262ccc9498273c1773afb150
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6.3 on Tue Apr  7 15:42:58 2009

import wx
import sys
import os
import string
import re
from threading import Thread

import roslib; roslib.load_manifest('tabletop_objects')

from std_msgs.msg import String
import rospy

from tabletop_objects.srv import *


# begin wxGlade: extracode
# end wxGlade


def call_service():
    try:
        print "Waiting for service"
        rospy.wait_for_service('table_top/find_object_poses', 1.0)
        # create a handle to the add_two_ints service
        find_object_poses = rospy.ServiceProxy('table_top/find_object_poses', FindObjectPoses)

        # simplified style
        resp = find_object_poses()

#        for p in resp.objects:
#            print p

    except rospy.ServiceException, e:
        print "Service call failed: %s"%e
    except rospy.ROSException, e:
        print "Got exceptio: %s"%e


class PublishThread(Thread):

    def __init__(self,publisher,value):
        Thread.__init__(self)
        self.publisher = publisher
        self.value = value

    def run(self):
        rospy.sleep(.5)
        self.publisher.publish(self.value)


class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        
        self.pub = rospy.Publisher('/publish_scene/prefix', String)
        rospy.init_node('publish_stereo_data', anonymous=True)
        # begin wxGlade: MyFrame.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.dir_picker = wx.DirPickerCtrl(self, -1, os.getcwd())
        self.button_load = wx.Button(self, -1, "Load")
        self.list_images = wx.ListCtrl(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
        self.button_publish = wx.Button(self, -1, "Publish")
        self.button_1 = wx.Button(self, -1, "Close")

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_BUTTON, self.onLoad, self.button_load)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onListSelected, self.list_images)
        self.Bind(wx.EVT_BUTTON, self.onPublish, self.button_publish)
        self.Bind(wx.EVT_BUTTON, self.onClose, self.button_1)
        # end wxGlade
        
        self.list_images.InsertColumn(0,"Scene")

    def __set_properties(self):
        # begin wxGlade: MyFrame.__set_properties
        self.SetTitle("Scene chooser")
        self.SetSize((527, 706))
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MyFrame.__do_layout
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_3 = wx.BoxSizer(wx.VERTICAL)
        sizer_4 = wx.BoxSizer(wx.VERTICAL)
        sizer_4.Add(self.dir_picker, 0, wx.EXPAND, 0)
        sizer_4.Add(self.button_load, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
        sizer_4.Add(self.list_images, 1, wx.EXPAND, 0)
        sizer_2.Add(sizer_4, 1, wx.EXPAND, 0)
        sizer_3.Add(self.button_publish, 0, wx.ALL, 10)
        sizer_2.Add(sizer_3, 1, wx.EXPAND, 0)
        sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
        sizer_1.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
        self.SetSizer(sizer_1)
        self.Layout()
        # end wxGlade

    def onPublish(self, event): # wxGlade: MyFrame.<event_handler>
        call_service()
        event.Skip()

    def onClose(self, event): # wxGlade: MyFrame.<event_handler>
        sys.exit(0)
        event.Skip()

    def onListSelected(self, event): # wxGlade: MyFrame.<event_handler>
        dir = str(self.dir_picker.GetPath())
        prefix =  str(event.GetText())
        value = String(dir+"/"+prefix)

        thread = PublishThread(self.pub,value)
        thread.start()

        print "Calling service"
        call_service()
        print "Service returned"
        event.Skip()

    def onLoad(self, event): # wxGlade: MyFrame.<event_handler>
        dir = self.dir_picker.GetPath()
        i=0
#        self.list_images.ClearAll()
        for file in os.listdir(dir):
            if os.path.isfile(os.path.join(dir,file)):
                i += 1
                if file.endswith('.pcd'):
                    prefix = re.search('[a-z]+\.[0-9]+\.[TN]\.[a-zA-Z]+',file).group()
                    self.list_images.InsertStringItem(i,prefix)

# end of class MyFrame


if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    frame_1 = MyFrame(None, -1, "")
    app.SetTopWindow(frame_1)
    frame_1.Show()
    app.MainLoop()
