def startRecording(self, topics, msg_type): if os.path.isfile(self.__filepath): self.__bag = rosbag.Bag(self.__filepath, 'a') else: self.__bag = rosbag.Bag(self.__filepath, 'w') if type(topics) is not list and type(topics) is not tuple: topics = [topics] if type(msg_type) is not list and type(msg_type) is not tuple: msg_type = [msg_type] * len(topics) self.__topics = topics self.__recording = True self.__sub = [] self.__queue = {} self.__manage_queue = True for t in topics: self.__queue[t] = Queue.Queue() thread = threading.Thread(target=self.__queue_manager) thread.daemon = True thread.start() for topic, mtype in zip(self.__topics, msg_type): self.__sub.append( rospy.Subscriber( topic, mtype, cutil.make_closure(self.__msg_callback, [topic])))
def __addEntryPrompt(self, title, okay_func, cancel_func=None): self.__destroy_menu() self.current_title = title self.current_menu = None self.menu_title = Label(self.menu_frame.interior, text=title, font=("Times", 30, "bold")) self.menu_title.pack() self.buttons = [self.menu_title] entry = Entry(self.menu_frame.interior, font=("Times", 20, "normal")) entry.pack() self.buttons.append(entry) def okay_callback(): self.__wait_for_button(func=cutil.make_closure(okay_func, [entry.get()])) def entry_callback(event): okay_callback() entry.bind('<Return>', entry_callback) entry.bind('<KP_Enter>', entry_callback) okay = Button(self.menu_frame.interior, text="Okay", command=okay_callback, font=("Times", 20, "normal")) okay.pack() self.buttons.append(okay) if cancel_func is not None: cancel = Button(self.menu_frame.interior, text="Cancel", command=cutil.make_closure(self.__wait_for_button, [cancel_func]), font=("Times", 20, "normal")) cancel.pack() self.buttons.append(cancel) entry.focus_set()
def select_from_list(title, options, cancel=True): print(title) menu = [] locks = [] def lock_callback(to_lock): to_lock.acquire() for i in range(len(options)): lock = threading.Lock() locks.append(lock) menu.append((options[i], cutil.make_closure(lock_callback, [lock]))) cancel_lock = threading.Lock() if cancel: menu.append(("Cancel", cutil.make_closure(lock_callback, [cancel_lock]))) global gui previous_menu = gui.current_menu previous_title = gui.current_title previous_enable = gui.areButtonsEnabled() gui.addMenu(title, menu) r = rospy.Rate(500) ret = None while ret is None: for i in range(len(locks)): if not locks[i].acquire(False): ret = i else: locks[i].release() if not cancel_lock.acquire(False): ret = -1 else: cancel_lock.release() r.sleep() gui.addMenu(previous_title, previous_menu) gui.enableButtons(enable=previous_enable) if ret >= 0: print("Selected " + options[ret]) else: print("Selected Cancel") return ret
def __init__(self, title, buttons): global gui menu = [(x, cutil.make_closure(self.__button_callback, [y])) for x, y in zip(buttons, range(len(buttons)))] self.counts = [0]*len(buttons) self.count_lock = threading.Lock() self.buttons = buttons self.previous_menu = gui.current_menu self.previous_title = gui.current_title self.previous_enable = gui.areButtonsEnabled() gui.addMenu(title, menu) print(title)
def __addMenu(self, title, menu): self.__destroy_menu() self.current_title = title self.current_menu = menu self.menu_title = Label(self.menu_frame.interior, text=title, font=("Times", 30, "bold")) self.menu_title.pack() self.buttons = [self.menu_title] for title, func in menu: b = Button(self.menu_frame.interior, text=title, command=cutil.make_closure(self.__wait_for_button, [func]), font=("Times", 20, "normal")) b.pack() self.buttons.append(b)
def __wait_for_button(self, func, args=()): # self.enableButtons(enable=False) # # thread = threading.Thread(target=func, args=args) # thread.daemon = True # thread.start() # # r = rospy.Rate(500) # while thread.isAlive(): # self.root.update() # r.sleep() # # self.enableButtons(enable=True) self.queue_lock.acquire() self.process_queue.put(cutil.make_closure(func, args)) self.queue_lock.release()
def printString(self, val): self.__wait_for_call(cutil.make_closure(self.__printString, [val]))
def okay_callback(): self.__wait_for_button(func=cutil.make_closure(okay_func, [entry.get()]))
def addEntryPrompt(self, title, okay_func, cancel_func=None): self.__wait_for_call(cutil.make_closure(self.__addEntryPrompt, [title, okay_func, cancel_func]))
def addMenu(self, title, menu): self.__wait_for_call(cutil.make_closure(self.__addMenu, [title, menu]))
def enableButtons(self, enable=True): self.__wait_for_call(cutil.make_closure(self.__enableButtons, [enable]))