class ReadOnlyTextWidget: copyAll = lambda self, item: setClipboard(toStr(self.get_text())) def has_selection(): raise NotImplementedError def labelMenuAddCopyItems(self, menu): menu.add( labelStockMenuItem( 'Copy _All', gtk.STOCK_COPY, self.copyAll, )) #### itemCopy = labelStockMenuItem( '_Copy', gtk.STOCK_COPY, self.copy, ) if not self.has_selection(): itemCopy.set_sensitive(False) menu.add(itemCopy) def onPopup(self, widget, menu): menu = gtk.Menu() self.labelMenuAddCopyItems(menu) #### menu.show_all() self.tmpMenu = menu menu.popup(None, None, None, None, 3, 0) ui.updateFocusTime()
class ReadOnlyTextWidget: copyAll = lambda self, item: setClipboard(toStr(self.get_text())) def has_selection(): raise NotImplementedError def onPopup(self, widget, menu): # instead of creating a new menu, we should remove all the current items from current menu for item in menu.get_children(): menu.remove(item) #### menu.add( labelStockMenuItem( 'Copy _All', gtk.STOCK_COPY, self.copyAll, )) #### itemCopy = labelStockMenuItem( '_Copy', gtk.STOCK_COPY, self.copy, ) if not self.has_selection(): itemCopy.set_sensitive(False) menu.add(itemCopy) #### menu.show_all() self.tmpMenu = menu ui.updateFocusTime()
class DateLabel(gtk.Label): def __init__(self, text=None): gtk.Label.__init__(self, text) self.set_selectable(True) #self.set_cursor_visible(False)## FIXME self.set_can_focus(False) self.set_use_markup(True) self.connect('populate-popup', self.popupPopulate) #### self.menu = gtk.Menu() ## itemCopyAll = ImageMenuItem(_('Copy _All')) itemCopyAll.set_image(gtk.Image.new_from_stock(gtk.STOCK_COPY, gtk.IconSize.MENU)) itemCopyAll.connect('activate', self.copyAll) self.menu.add(itemCopyAll) ## itemCopy = ImageMenuItem(_('_Copy')) itemCopy.set_image(gtk.Image.new_from_stock(gtk.STOCK_COPY, gtk.IconSize.MENU)) itemCopy.connect('activate', self.copy) self.itemCopy = itemCopy self.menu.add(itemCopy) ## self.menu.show_all() def popupPopulate(self, label, menu): self.itemCopy.set_sensitive(self.get_property('cursor-position') > self.get_property('selection-bound'))## FIXME self.menu.popup(None, None, None, None, 3, 0) ui.updateFocusTime() def copy(self, item): start = self.get_property('selection-bound') end = self.get_property('cursor-position') setClipboard(toStr(self.get_text())[start:end]) copyAll = lambda self, label: setClipboard(self.get_text())
def copyAll(self, label): setClipboard(self.get_text())
def copy(self, item): start = self.get_property("selection-bound") end = self.get_property("cursor-position") setClipboard(toStr(self.get_text())[start:end])
def copy(self, item): buf = self.get_buffer() start_iter, end_iter = buf.get_selection_bounds() setClipboard(toStr(buf.get_text(start_iter, end_iter, True)))
def copy(self, item): bound = self.get_selection_bound() cursor = self.get_cursor_position() start = min(bound, cursor) end = max(bound, cursor) setClipboard(toStr(self.get_text())[start:end])
def copyAll(self, item): return setClipboard(toStr(self.get_text()))