def _setp__action(self, key, value): DataTarget._setp__action(self, key, value) if (key == "on-file-drop"): self.get_widget().drag_dest_set(gtk.DEST_DEFAULT_ALL, self.__DND_FILE, gtk.gdk.ACTION_COPY) self.get_widget().connect("drag_data_received", self.__on_file_drop) elif (key == "on-link-drop"): self.get_widget().drag_dest_set(gtk.DEST_DEFAULT_ALL, self.__DND_LINK, gtk.gdk.ACTION_COPY) self.get_widget().connect("drag_data_received", self.__on_link_drop)
def handle_action(self, action, px, py, event): assert (isinstance(px, Unit.Unit)) assert (isinstance(py, Unit.Unit)) # we need the pointer position relative to the widget, so we have to # setup a new event structure for some actions if (action in (self.ACTION_CLICK, self.ACTION_DOUBLECLICK, self.ACTION_MOTION, self.ACTION_PRESS, self.ACTION_RELEASE)): x, y = self.get_widget().get_pointer() nil, nil, w, h = self.get_geometry() ux = Unit.Unit(x, Unit.UNIT_PX) uy = Unit.Unit(y, Unit.UNIT_PX) if (w.as_px() > 0): ux.set_100_percent(w.as_px()) if (h.as_px() > 0): uy.set_100_percent(h.as_px()) event["x"] = ux event["y"] = uy # FIXME: remove eventually :) if (action == self.ACTION_MOTION): event["_args"] = [x, y] DataTarget.handle_action(self, action, px, py, event)
def __init__(self, name, parent): # the action stamp helps us to detect ENTER and LEAVE events self.__action_stamp = 0 # the queue of actions self.__action_queue = [] # the layout object self.__layout_object = parent.new_layout_object() self.__layout_object.set_callback(self.__geometry_callback) self.__layout_object.set_action_callback(self.__action_callback) # the currently pushed mouse cursor self.__pushed_cursor = None # lock for geometry computations self._geometry_lock = True # the placement anchor self.__anchor = self.ANCHOR_NW # the value of the last notify_handle_action call self.__had_action = False DataTarget.__init__(self, name, parent) for prop, datatype in [("x", TYPE_UNIT), ("y", TYPE_UNIT), ("width", TYPE_UNIT), ("height", TYPE_UNIT)]: self._register_property(prop, datatype, self._setp_geometry, self._getp_geometry) self.set_prop("x", Unit.ZERO) self.set_prop("y", Unit.ZERO) self.set_prop("width", Unit.Unit()) self.set_prop("height", Unit.Unit()) self._register_property("relative-to", TYPE_LIST, self._setp_relative_to, self._getp) self._register_property("anchor", TYPE_STRING, self._setp_anchor, self._getp) self._register_property("cursor", TYPE_STRING, self._setp_cursor, self._getp) self._register_property("menu", TYPE_OBJECT, self._setp_menu, None) self._register_property("visible", TYPE_BOOL, self._setp_visible, self._getp) self._setp("visible", True) for action in (self.ACTION_ENTER, self.ACTION_LEAVE, self.ACTION_CLICK, self.ACTION_PRESS, self.ACTION_RELEASE, self.ACTION_SCROLL, self.ACTION_FILE_DROP, self.ACTION_LINK_DROP, self.ACTION_DOUBLECLICK, self.ACTION_MOTION, self.ACTION_MENU, self.ACTION_KEY_PRESS, self.ACTION_KEY_RELEASE): self._register_action(action)