Beispiel #1
0
    def __begin(self, view, drag_ctx):

        model, paths = view.get_selection().get_selected_rows()
        surface = self.create_multi_row_drag_icon(paths, max_rows=3)

        if surface is not None:
            Gtk.drag_set_icon_surface(drag_ctx, surface)
Beispiel #2
0
 def _drag_begin_cb(self, view, context):
     self.drag_began()
     src_path = self._docmodel.layer_stack.get_current_path()
     self._drag_src_path = src_path
     self._drag_dest_path = None
     src_treepath = Gtk.TreePath(src_path)
     src_icon_surf = self.create_row_drag_icon(src_treepath)
     Gtk.drag_set_icon_surface(context, src_icon_surf)
     self._hover_expand_timer_id = None
Beispiel #3
0
 def _drag_begin_cb(self, view, context):
     self.drag_began()
     src_path = self._docmodel.layer_stack.get_current_path()
     self._drag_src_path = src_path
     self._drag_dest_path = None
     src_treepath = Gtk.TreePath(src_path)
     src_icon_surf = self.create_row_drag_icon(src_treepath)
     Gtk.drag_set_icon_surface(context, src_icon_surf)
     self._hover_expand_timer_id = None
Beispiel #4
0
 def on_drag_begin(self, widget, drag_context):
     row = widget.get_ancestor(TaskView)
     listbox = row.get_parent()
     listbox.select_row(row)
     surface = cairo.ImageSurface(
         cairo.Format.ARGB32, row.get_allocated_width(), row.get_allocated_height())
     context = cairo.Context(surface)
     row.draw(context)
     Gtk.drag_set_icon_surface(drag_context, surface)
Beispiel #5
0
    def _drag_begin_cb(self, eventbox, context):
        """Draws the drag icon."""
        row = eventbox.get_parent()
        alloc = row.get_allocation()

        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, alloc.width,
                                     alloc.height)
        ctx = cairo.Context(surface)

        row.draw(ctx)
        ctx.paint_with_alpha(0.35)

        Gtk.drag_set_icon_surface(context, surface)
Beispiel #6
0
    def drag_begin(self, widget, context):
        surface = self.get_drag_surface()

        if surface :
            surface.set_device_offset(0, 0)
            self.surface = surface
            Gtk.drag_set_icon_surface(context, surface)
        else:
            Gtk.drag_set_icon_default(context)

        self.stop_drag_check()
        
        # TODO : implement selection cache ?
        selection_cache = self.drag_create_selection_cache()
Beispiel #7
0
    def _drag_begin_cb(self, eventbox, context):
        # Draw drag-icon
        icon = self._drag_icon
        icon_height = icon.get_height()
        icon_width = icon.get_width()

        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, icon_width, icon_height)
        ctx = cairo.Context(surface)
        # Center the icon around the cursor.
        ctx.translate(icon_width / 2, icon_height / 2)
        surface.set_device_offset(-icon_width / 2, -icon_height / 2)

        Gdk.cairo_set_source_pixbuf(ctx, icon, 0, 0)
        ctx.paint_with_alpha(0.35)

        Gtk.drag_set_icon_surface(context, surface)
Beispiel #8
0
    def drag_begin(self, widget, drag_context, data):

        self.dnd_data_received = False

        # get x,y co-ords of source square
        x, y = data

        if gv.verbose:
            print u"in drag begin"
            print u"data=", data
            print u"widget_name=", widget.get_name()
            print u"source sq=", x, y

        stm = gv.jcchess.get_side_to_move()

        # convert the x, y co-ords into the shogi representation
        # (e.g. 8, 6 is 1g)
        sq = gv.board.get_square_posn(x, y)

        self.src = sq
        if gv.verbose:
            print u"source square: (x, y) = (", x, u",", y, u") ", sq
        self.src_x = x
        self.src_y = y

        # set the icon for the drag and drop to the piece that is being
        # dragged
        self.piece = gv.board.get_piece(x, y)
        # get width/height of board square
        a = gv.gui.get_event_box(x, y).get_allocation()
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, a.width, a.height)
        svghandle = gv.board.get_piece_handle(x, y)
        dim = svghandle.get_dimensions()

        cr = cairo.Context(surface)
        sfw = (a.width * 1.0 / dim.width) * SCALE
        sfh = (a.height * 1.0 / dim.height) * SCALE
        cr.scale(sfw, sfh)

        svghandle.render_cairo(cr)
        # set mouse pointer to be in middle of drag icon
        surface.set_device_offset(-a.width / 2, -a.height / 2)
        Gtk.drag_set_icon_surface(drag_context, surface)

        # clear the square where the piece is being moved from
        gv.board.set_square_as_unoccupied(x, y)
Beispiel #9
0
    def on_drag_begin(self, widget, drag_context):
        """ User starts a drag """
        row = widget.get_ancestor(Gtk.ListBoxRow)
        alloc = row.get_allocation()
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, alloc.width,
                                     alloc.height)
        ctx = cairo.Context(surface)

        row.get_style_context().add_class("drag-icon")
        row.draw(ctx)
        row.get_style_context().remove_class("drag-icon")

        (x, y) = widget.translate_coordinates(row, 0, 0)

        surface.set_device_offset(-x, -y)
        Gtk.drag_set_icon_surface(drag_context, surface)

        hand_cursor = Gdk.Cursor(Gdk.CursorType.HAND1)
        self.get_window().set_cursor(hand_cursor)
Beispiel #10
0
 def drag_begin(self, widget, context, preview_widget):
     # hide ctrl strip when dragging, so that more items can be present at once
     self.hb_editmode.set_sensitive(False)
     for x in self.codes:
         self.codes.get(x).ui.revealer.set_reveal_child(False)
     # add a temporary background-color & border to the preview box
     preview_widget.get_style_context().add_class("preview_box")
     # create a cairo representation of the row when dragging
     preview_alloc = preview_widget.get_allocation()
     cairo_surface = cairo.ImageSurface(cairo.Format.ARGB32,
                                        preview_alloc.width,
                                        preview_alloc.height)
     cairo_context = cairo.Context(cairo_surface)
     preview_widget.draw(cairo_context)
     Gtk.drag_set_icon_surface(context, cairo_surface)
     # remove temporary style class
     preview_widget.get_style_context().remove_class("preview_box")
     del preview_alloc
     del cairo_surface
     del cairo_context
Beispiel #11
0
 def do_drag_begin(self, context):
     drag_records, context.drag_refs = self.get_selection_rows()
     context.data = repr(drag_records).encode()
     if not drag_records:
         return
     icons = [
         self.create_row_drag_icon(ref.get_path())
         for ref in context.drag_refs
     ]
     xscale, yscale = icons[0].get_device_scale()
     width, height = icons[0].get_width(), icons[0].get_height() - yscale
     target = cairo.ImageSurface(
         cairo.FORMAT_ARGB32, int(width / xscale),
         int(height * len(context.drag_refs) / yscale) + 1)
     cr = cairo.Context(target)
     cr.set_source_rgba(0, 0, 0, 1)
     cr.paint()
     y = 2
     for icon in icons:
         cr.set_source_surface(icon, 2 / xscale, y / yscale)
         cr.paint()
         y += height
     icon.flush()
     Gtk.drag_set_icon_surface(context, target)
Beispiel #12
0
 def __begin(self, view, drag_ctx):
     model, paths = view.get_selection().get_selected_rows()
     surface = self.create_multi_row_drag_icon(paths, max_rows=3)
     if surface is not None:
         Gtk.drag_set_icon_surface(drag_ctx, surface)
Beispiel #13
0
    def _on_drag_begin(self, widget, drag_context):
        """Handler for ``drag-begin`` signal

        When drag action begins this function does several things:
            1. find the row for @widget,
            2. estimate the number of rows being moved
            3. unselect it (if selected)
            4. add a frame style for opaque background and borders
            5. create a cairo surface for row (if single), a text surface otherwise
            6. set it as icon for the drag context
            7. remove the frame style
            8. set the row as selected
        """
        row = widget.get_ancestor(Gtk.ListBoxRow.__gtype__)
        num_selected = len(self.get_selected_rows())
        if (not row.is_selected() and self.in_multi_selection_mode()):
            num_selected += 1

        self.unselect_row(row)
        style_context = row.get_style_context()
        style_context.add_class('draft-drag-icon')
        allocation = row.get_allocation()
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, allocation.width,
                                     allocation.height)

        context = cairo.Context(surface)
        if num_selected > 1:
            style_ctx = self.get_style_context()
            font = style_ctx.get_font(style_ctx.get_state())
            border_success, border_color = style_ctx.lookup_color('borders')
            bg_success, bg_color = style_ctx.lookup_color('content_view_bg')
            fg_success, fg_color = style_ctx.lookup_color('theme_fg_color')
            if border_success and bg_success and fg_success:
                offset = 10
                font_size = int((font.get_size() / Pango.SCALE) * 96 / 72)
                context.set_font_size(font_size)
                font_family = font.get_family()
                context.select_font_face(font_family, cairo.FontSlant.NORMAL,
                                         cairo.FontWeight.BOLD)
                text = _(" items selected")
                text = str(num_selected) + text
                extents = context.text_extents(text)
                context.set_source_rgba(border_color.red, border_color.green,
                                        border_color.blue)
                context.rectangle(0, 0, extents.width + (offset * 2),
                                  extents.height + (offset * 2))
                context.fill()
                context.set_source_rgb(bg_color.red, bg_color.green,
                                       bg_color.blue)
                context.rectangle(1, 1, (extents.width + (offset * 2)) - 2,
                                  (extents.height + (offset * 2)) - 2)
                context.fill()
                context.set_source_rgba(fg_color.red, fg_color.green,
                                        fg_color.blue)
                context.move_to(offset, offset + extents.height)
                context.show_text(text)
        else:
            row.draw(context)

        Gtk.drag_set_icon_surface(drag_context, surface)
        style_context.remove_class('draft-drag-icon')
        self.select_row(row)