Python gi.repository.Gtk.DrawingArea() Examples

The following are 30 code examples of gi.repository.Gtk.DrawingArea(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gi.repository.Gtk , or try the search function .
Example #1
Source File: custom.py    From Dindo-Bot with MIT License 6 votes vote down vote up
def __init__(self, background_color='#CECECE', show_grid=True, grid_color='#DDDDDD', grid_size=(15, 15), point_radius=3):
		Gtk.Frame.__init__(self)
		self.points = []
		self.point_opacity = 0.7
		self.point_radius = point_radius
		self.show_grid = show_grid
		self.grid_color = grid_color
		self.grid_size = grid_size
		self.background_color = background_color
		self.use_origin_colors = False
		self.add_borders = False
		self.drawing_area = Gtk.DrawingArea()
		self.drawing_area.set_has_tooltip(True)
		self.drawing_area.connect('draw', self.on_draw)
		self.drawing_area.connect('query-tooltip', self.on_query_tooltip)
		self.add(self.drawing_area) 
Example #2
Source File: HtreePedigreeView.py    From addons-source with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, view, format_helper, person):
        Gtk.DrawingArea.__init__(self)
        self.view = view
        self.format_helper = format_helper
        self.person = person
        self.force_mouse_over = False
        self.in_drag = False
        self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
        self.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK)
        if self.person:
            self.connect("button-release-event", self.cb_on_button_release)
            self.connect("drag_data_get", self.cb_drag_data_get)
            self.connect("drag_begin", self.cb_drag_begin)
            self.connect("drag_end", self.cb_drag_end)
            # Enable drag
            self.drag_source_set(Gdk.ModifierType.BUTTON1_MASK,
                                [],
                                Gdk.DragAction.COPY)
            tglist = Gtk.TargetList.new([])
            tglist.add(DdTargets.PERSON_LINK.atom_drag_type,
                       DdTargets.PERSON_LINK.target_flags,
                       DdTargets.PERSON_LINK.app_id)
            #allow drag to a text document, info on drag_get will be 0L !
            tglist.add_text_targets(0)
            self.drag_source_set_target_list(tglist) 
Example #3
Source File: scribble.py    From pympress with GNU General Public License v2.0 6 votes vote down vote up
def draw_scribble(self, widget, cairo_context):
        """ Perform the drawings by user.

        Args:
            widget (:class:`~Gtk.DrawingArea`): The widget where to draw the scribbles.
            cairo_context (:class:`~cairo.Context`): The canvas on which to render the drawings
        """
        ww, wh = widget.get_allocated_width(), widget.get_allocated_height()

        cairo_context.set_line_cap(cairo.LINE_CAP_ROUND)

        for color, width, points in self.scribble_list:
            points = [(p[0] * ww, p[1] * wh) for p in points]

            cairo_context.set_source_rgba(*color)
            cairo_context.set_line_width(width)
            cairo_context.move_to(*points[0])

            for p in points[1:]:
                cairo_context.line_to(*p)
            cairo_context.stroke() 
Example #4
Source File: gtk_ui.py    From python-gui with Apache License 2.0 5 votes vote down vote up
def start(self, bridge):
        """Start the UI event loop."""
        debug_ext_env = os.environ.get("NVIM_PYTHON_UI_DEBUG_EXT", "")
        extra_exts = {x:True for x in debug_ext_env.split(",") if x}
        bridge.attach(80, 24, rgb=True, **extra_exts)
        drawing_area = Gtk.DrawingArea()
        drawing_area.connect('draw', self._gtk_draw)
        window = Gtk.Window()
        window.add(drawing_area)
        window.set_events(window.get_events() |
                          Gdk.EventMask.BUTTON_PRESS_MASK |
                          Gdk.EventMask.BUTTON_RELEASE_MASK |
                          Gdk.EventMask.POINTER_MOTION_MASK |
                          Gdk.EventMask.SCROLL_MASK)
        window.connect('configure-event', self._gtk_configure)
        window.connect('delete-event', self._gtk_quit)
        window.connect('key-press-event', self._gtk_key)
        window.connect('key-release-event', self._gtk_key_release)
        window.connect('button-press-event', self._gtk_button_press)
        window.connect('button-release-event', self._gtk_button_release)
        window.connect('motion-notify-event', self._gtk_motion_notify)
        window.connect('scroll-event', self._gtk_scroll)
        window.connect('focus-in-event', self._gtk_focus_in)
        window.connect('focus-out-event', self._gtk_focus_out)
        window.show_all()
        im_context = Gtk.IMMulticontext()
        im_context.set_client_window(drawing_area.get_window())
        im_context.set_use_preedit(False)  # TODO: preedit at cursor position
        im_context.connect('commit', self._gtk_input)
        self._pango_context = drawing_area.create_pango_context()
        self._drawing_area = drawing_area
        self._window = window
        self._im_context = im_context
        self._bridge = bridge
        Gtk.main() 
Example #5
Source File: mpl_with_glade3_sgskip.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def main():
    builder = Gtk.Builder()
    builder.add_objects_from_file(os.path.join(os.path.dirname(__file__),
                                               "mpl_with_glade3.glade"),
                                  ("window1", ""))
    builder.connect_signals(Window1Signals())
    window = builder.get_object("window1")
    sw = builder.get_object("scrolledwindow1")

    # Start of Matplotlib specific code
    figure = Figure(figsize=(8, 6), dpi=71)
    axis = figure.add_subplot(111)
    t = np.arange(0.0, 3.0, 0.01)
    s = np.sin(2*np.pi*t)
    axis.plot(t, s)

    axis.set_xlabel('time [s]')
    axis.set_ylabel('voltage [V]')

    canvas = FigureCanvas(figure)  # a Gtk.DrawingArea
    canvas.set_size_request(800, 600)
    sw.add_with_viewport(canvas)
    # End of Matplotlib specific code

    window.show_all()
    Gtk.main() 
Example #6
Source File: graphical_editor.py    From RAFCON with Eclipse Public License 1.0 5 votes vote down vote up
def __init__(self):
        """View holding the graphical editor

        The purpose of the view is only to hold the graphical editor. The class ob the actual editor with the OpenGL
        functionality is GraphicalEditor
        """
        View.__init__(self)

        # Configure OpenGL frame buffer.
        # Try to get a double-buffered frame buffer configuration,
        # if not successful then exit program
        display_mode = (Gtk.gdkgl.MODE_RGB | Gtk.gdkgl.MODE_DEPTH | Gtk.gdkgl.MODE_DOUBLE)
        try:
            glconfig = Gtk.gdkgl.Config(mode=display_mode)
        except Gtk.gdkgl.NoMatches:
            raise SystemExit

        self.v_box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        self.editor = GraphicalEditor(glconfig)
        self.editor.add_events(Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.BUTTON_MOTION_MASK |
                               Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK | Gdk.EventMask.POINTER_MOTION_MASK)
        self.editor.set_size_request(0, 0)
        self.editor.set_flags(Gtk.CAN_FOCUS)

        self.v_box.pack_end(self.editor, True, True, 0)

        self['main_frame'] = self.v_box
        self.top = 'main_frame'


# old; GTK TODO
# class GraphicalEditor(Gtk.DrawingArea, Gtk.gtkgl.Widget): 
Example #7
Source File: graphical_editor.py    From RAFCON with Eclipse Public License 1.0 5 votes vote down vote up
def __init__(self, glconfig):
        """The graphical editor manages the OpenGL functions.

        It only works in combination with its controller.

        :param glconfig: Configuration flags for OpenGl
        """
        Gtk.DrawingArea.__init__(self)

        # default outer coordinate values which will later be overwritten by the controller
        self.left = -10
        self.right = 110
        self.top = 10
        self.bottom = -110

        # Used to generate unique ids for drawn objects
        self.name_counter = 0

        # Set OpenGL-capability to the drawing area
        self.set_gl_capability(glconfig)

        # Needed for glut functions
        glutInit([])

        # Connect the relevant signals.
        self.connect_after('realize', self._realize)
        self.connect('configure_event', self._configure)
        # self.connect('expose_event',    self.expose) 
Example #8
Source File: identicon.py    From syncthing-gtk with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, device_id):
		Gtk.DrawingArea.__init__(self)
		self.value = re.sub(r'[\W_]', "", device_id, 1)
		self.color = (1, 1, 0.95, 1)		# icon color, rgba
		self.size = 5 
Example #9
Source File: tools.py    From Dindo-Bot with MIT License 5 votes vote down vote up
def get_widget_location(widget):
	if widget:
		# get widget allocation (relative to parent)
		allocation = widget.get_allocation()
		# get widget position (relative to root window)
		if type(widget) in (Gtk.DrawingArea, Gtk.EventBox, Gtk.Socket):
			pos = widget.get_window().get_origin()
			return (pos.x, pos.y, allocation.width, allocation.height)
		else:
			pos_x, pos_y = widget.get_window().get_root_coords(allocation.x, allocation.y)
			return (pos_x, pos_y, allocation.width, allocation.height)
	else:
		return None

# Check if position is inside given bounds 
Example #10
Source File: custom.py    From Dindo-Bot with MIT License 5 votes vote down vote up
def get_tooltip_widget(self, point):
		# on draw function
		def on_draw(widget, cr):
			cr.set_line_width(1)
			# draw point
			color_key = self.get_color_key()
			color = Gdk.color_parse(point[color_key])
			cr.set_source_rgba(float(color.red) / 65535, float(color.green) / 65535, float(color.blue) / 65535, self.point_opacity)
			cr.arc(self.point_radius, self.point_radius, self.point_radius, 0, 2*math.pi)
			cr.fill()
		# tooltip widget
		if point['name'] is not None:
			widget = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=3)
			color_key = self.get_color_key()
			if point[color_key] is not None:
				drawing_area = Gtk.DrawingArea()
				point_diameter = self.point_radius*2
				drawing_area.set_size_request(point_diameter, point_diameter)
				drawing_area.connect('draw', on_draw)
				box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
				box.pack_start(drawing_area, True, False, 0)
				widget.add(box)
			widget.add(Gtk.Label(point['name']))
			widget.show_all()
		else:
			widget = None
		return widget 
Example #11
Source File: extras.py    From pympress with GNU General Public License v2.0 5 votes vote down vote up
def draw_zoom_target(self, widget, cairo_context):
        """ Perform the drawings by user.

        Args:
            widget (:class:`~Gtk.DrawingArea`): The widget where to draw the scribbles.
            cairo_context (:class:`~cairo.Context`): The canvas on which to render the drawings
        """
        ww, wh = widget.get_allocated_width(), widget.get_allocated_height()

        if self.zoom_selecting and self.zoom_points:
            xmin, xmax = sorted(p[0] * ww for p in self.zoom_points)
            ymin, ymax = sorted(p[1] * wh for p in self.zoom_points)

            rect = Gdk.Rectangle()
            rect.x = xmin
            rect.width = xmax - xmin
            rect.y = ymin
            rect.height = ymax - ymin

            cairo_context.set_line_width(3)
            cairo_context.set_line_cap(cairo.LINE_CAP_SQUARE)
            Gdk.cairo_rectangle(cairo_context, rect)
            cairo_context.set_source_rgba(.1, .1, 1, .4)
            cairo_context.stroke()

            Gdk.cairo_rectangle(cairo_context, rect)
            cairo_context.set_source_rgba(.5, .5, 1, .2)
            cairo_context.fill() 
Example #12
Source File: backend_gtk3.py    From ImageFusion with MIT License 5 votes vote down vote up
def destroy(self):
        #Gtk.DrawingArea.destroy(self)
        self.close_event()
        GLib.source_remove(self._idle_event_id)
        if self._idle_draw_id != 0:
            GLib.source_remove(self._idle_draw_id) 
Example #13
Source File: draw_text.py    From chamanti_ocr with Apache License 2.0 5 votes vote down vote up
def __init__ (self, upper=9, text=''):
##        Gtk.Widget.__init__(self)
        Gtk.DrawingArea.__init__(self)
        self.set_size_request (200, 200)
##        self.show_all() 
Example #14
Source File: xdot.py    From bokken with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self):
        Gtk.DrawingArea.__init__(self)

        self.graph = Graph()
        self.openfilename = None

        self.set_can_focus(True)

        self.connect("draw", self.on_draw)
        self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK)
        self.connect("button-press-event", self.on_area_button_press)
        self.connect("button-release-event", self.on_area_button_release)
        self.add_events(Gdk.EventMask.POINTER_MOTION_MASK | 
                        Gdk.EventMask.POINTER_MOTION_HINT_MASK | 
                        Gdk.EventMask.BUTTON_RELEASE_MASK | 
                        Gdk.EventMask.SCROLL_MASK)
        self.connect("motion-notify-event", self.on_area_motion_notify)
        self.connect("scroll-event", self.on_area_scroll_event)
        self.connect("size-allocate", self.on_area_size_allocate)

        self.connect('key-press-event', self.on_key_press_event)
        self.last_mtime = None

        GLib.timeout_add(1000, self.update)

        self.x, self.y = 0.0, 0.0
        self.zoom_ratio = 1.0
        self.zoom_to_fit_on_resize = False
        self.animation = NoAnimation(self)
        self.drag_action = NullAction(self)
        self.presstime = None
        self.highlight = None 
Example #15
Source File: backend_gtk3.py    From CogAlg with MIT License 5 votes vote down vote up
def destroy(self):
        #Gtk.DrawingArea.destroy(self)
        self.close_event()
        if self._idle_draw_id != 0:
            GLib.source_remove(self._idle_draw_id) 
Example #16
Source File: window.py    From gagar with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, world):
        self.world = world
        self.player = None  # the focused player, or None to show full world

        # the class instance on which to call on_key_pressed and on_mouse_moved
        self.input_subscriber = None
        # same for draw_background, draw_cells, draw_hud
        self.draw_subscriber = None

        self.win_size = Vec(1000, 1000 * 9 / 16)
        self.screen_center = self.win_size / 2
        self.screen_scale = 1
        self.world_center = Vec(0, 0)
        self.mouse_pos = Vec(0, 0)

        window = Gtk.Window()
        window.set_title('agar.io')
        window.set_default_size(self.win_size.x, self.win_size.y)
        window.connect('delete-event', Gtk.main_quit)

        self.drawing_area = Gtk.DrawingArea()
        window.add(self.drawing_area)

        window.set_events(Gdk.EventMask.POINTER_MOTION_MASK)
        window.connect('key-press-event', self.key_pressed)
        window.connect('motion-notify-event', self.mouse_moved)
        window.connect('button-press-event', self.mouse_pressed)

        self.drawing_area.connect('draw', self.draw)

        window.show_all() 
Example #17
Source File: graph.py    From bldc-sim with MIT License 5 votes vote down vote up
def __init__ (self, scale):
        Gtk.DrawingArea.__init__(self)
        self.connect('draw', self.draw)

        self.scale = scale
        # Data elements are 2-tuples of desired and actual

        self.data = []

    # Add new values to graphs 
Example #18
Source File: dna.py    From addons-source with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self):
        Gtk.DrawingArea.__init__(self)

        self.add_events(Gdk.EventMask.POINTER_MOTION_MASK |
                        Gdk.EventMask.BUTTON_PRESS_MASK |
                        Gdk.EventMask.BUTTON_RELEASE_MASK)
        self.connect('motion-notify-event', self.on_pointer_motion)
        self.connect('button-press-event', self.on_button_press)

        self.title = ''
        self.axis = ''
        self.grid_lines = True
        self.__rects = None
        self.__active = -1

        self.chromosomes = (
            ('1', 248956422),
            ('2', 242193529),
            ('3', 198295559),
            ('4', 190214555),
            ('5', 181538259),
            ('6', 170805979),
            ('7', 159345973),
            ('8', 145138636),
            ('9', 138394717),
            ('10', 133797422),
            ('11', 135086622),
            ('12', 133275309),
            ('13', 114364328),
            ('14', 107043718),
            ('15', 101991189),
            ('16', 90338345),
            ('17', 83257441),
            ('18', 80373285),
            ('19', 58617616),
            ('20', 64444167),
            ('21', 46709983),
            ('22', 50818468),
            ('X', 156040895))

        self.labels = [chromo[0] for chromo in self.chromosomes] 
Example #19
Source File: backend_gtk3.py    From Computable with MIT License 5 votes vote down vote up
def destroy(self):
        #Gtk.DrawingArea.destroy(self)
        self.close_event()
        GObject.source_remove(self._idle_event_id)
        if self._idle_draw_id != 0:
            GObject.source_remove(self._idle_draw_id) 
Example #20
Source File: backend_gtk3.py    From Mastering-Elasticsearch-7.0 with MIT License 5 votes vote down vote up
def destroy(self):
        #Gtk.DrawingArea.destroy(self)
        self.close_event()
        if self._idle_draw_id != 0:
            GLib.source_remove(self._idle_draw_id) 
Example #21
Source File: backend_gtk3.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def destroy(self):
        #Gtk.DrawingArea.destroy(self)
        self.close_event()
        GObject.source_remove(self._idle_event_id)
        if self._idle_draw_id != 0:
            GObject.source_remove(self._idle_draw_id) 
Example #22
Source File: vlcbox.py    From kickoff-player with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
    Gtk.Box.__init__(self, *args, **kwargs)

    self.canvas = Gtk.DrawingArea()
    self.pack_start(self.canvas, True, True, 0)

    self.instance = vlc.Instance()
    self.canvas.connect('realize', self.on_canvas_realized)
    self.canvas.connect('draw', self.on_canvas_draw)

    self.player = self.instance.media_player_new()
    self.player.video_set_scale(0)
    self.player.video_set_aspect_ratio('16:9')
    self.player.video_set_deinterlace('on')
    self.player.video_set_mouse_input(False)
    self.player.video_set_key_input(False)

    add_widget_class(self, 'player-video') 
Example #23
Source File: mpvbox.py    From kickoff-player with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
    Gtk.Box.__init__(self, *args, **kwargs)

    self.vid_url = None
    self.stopped = False

    self.canvas = Gtk.DrawingArea()
    self.pack_start(self.canvas, True, True, 0)

    self.player = mpv.MPV(ytdl=True, input_cursor=False, cursor_autohide=False)
    self.canvas.connect('realize', self.on_canvas_realize)
    self.canvas.connect('draw', self.on_canvas_draw)

    add_widget_class(self, 'player-video') 
Example #24
Source File: backend_gtk3.py    From neural-network-animation with MIT License 5 votes vote down vote up
def destroy(self):
        #Gtk.DrawingArea.destroy(self)
        self.close_event()
        GLib.source_remove(self._idle_event_id)
        if self._idle_draw_id != 0:
            GLib.source_remove(self._idle_draw_id) 
Example #25
Source File: entrygrid.py    From addons-source with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self):
        Gtk.DrawingArea.__init__(self)
        self.connect('draw', self._draw)
        self.active = False
        self.set_size_request(5, -1) 
Example #26
Source File: HtreePedigreeView.py    From addons-source with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, child, father, frel, mother, mrel, direction):
        Gtk.DrawingArea.__init__(self)

        self.child_box = child
        self.father_box = father
        self.mother_box = mother
        self.frel = frel
        self.mrel = mrel
        self.direction = direction

        self.connect("draw", self.expose) 
Example #27
Source File: taglist.py    From addons-source with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, tag_list=None):
        Gtk.DrawingArea.__init__(self)

        self.add_events(Gdk.EventMask.POINTER_MOTION_MASK |
                        Gdk.EventMask.BUTTON_PRESS_MASK |
                        Gdk.EventMask.BUTTON_RELEASE_MASK)
        self.connect('motion-notify-event', self.on_pointer_motion)
        self.connect('button-press-event', self.on_button_press)

        self.__active = -1
        self.__rects = []
        if tag_list is None:
            self.tag_list = []
        else:
            self.tag_list = tag_list 
Example #28
Source File: timeline.py    From addons-source with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, position='middle'):
        Gtk.DrawingArea.__init__(self)

        self.add_events(Gdk.EventMask.POINTER_MOTION_MASK |
                        Gdk.EventMask.BUTTON_PRESS_MASK |
                        Gdk.EventMask.BUTTON_RELEASE_MASK)
        self.connect('motion-notify-event', self.on_pointer_motion)
        self.connect('button-press-event', self.on_button_press)

        self.position = position
        self.__active = False 
Example #29
Source File: ClockGramplet.py    From addons-source with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self):
        Gtk.DrawingArea.__init__(self)

        self.connect("draw", self.on_draw)
        self.timer = GObject.timeout_add(1000, self.tick) 
Example #30
Source File: QuiltView.py    From addons-source with GNU General Public License v2.0 4 votes vote down vote up
def build_widget(self):
        """
        Builds the interface and returns a gtk.Container type that
        contains the interface. This containter will be inserted into
        a gtk.ScrolledWindow page.
        """
        self.scrolledwindow = Gtk.ScrolledWindow(hadjustment=None,
                                                 vadjustment=None)
        self.scrolledwindow.set_policy(Gtk.PolicyType.AUTOMATIC,
                                       Gtk.PolicyType.AUTOMATIC)

        self.canvas = Gtk.DrawingArea()

        self.canvas.connect("draw", self.on_draw)
        self.canvas.connect("button-press-event", self.press_cb)
        self.canvas.connect("button-release-event", self.release_cb)
        self.canvas.connect("motion-notify-event", self.motion_notify_cb)
        self.canvas.connect("scroll-event", self.scrolled_cb)

        self.canvas.add_events(Gdk.EventMask.BUTTON_PRESS_MASK |
                               Gdk.EventMask.BUTTON_RELEASE_MASK |
                               Gdk.EventMask.POINTER_MOTION_MASK |
                               Gdk.EventMask.SCROLL_MASK |
                               Gdk.EventMask.KEY_PRESS_MASK)
        self.on_draw_ok = -1

        self.scrolledwindow.add(self.canvas)

        self.preview_rect = None

        self.vbox = Gtk.Box(homogeneous=False, spacing=4,
                            orientation=Gtk.Orientation.VERTICAL)
        self.vbox.set_border_width(4)
        hbox = Gtk.Box(homogeneous=False, spacing=4,
                       orientation=Gtk.Orientation.HORIZONTAL)
        self.vbox.pack_start(hbox, False, False, 0)

        self.name_store = Gtk.ListStore(str, str)
        self.name_combo = Gtk.ComboBox.new_with_model_and_entry(self.name_store)
        self.name_combo.set_tooltip_text(
            _("Select the name for which you want to see."))
        self.name_combo.connect('changed', self._entry_key_event)
        self.name_combo.set_entry_text_column(0)
        hbox.pack_start(self.name_combo, False, False, 0)

        clear = Gtk.Button(label=_("Clear"))
        clear.set_tooltip_text(
            _("Clear the entry field in the name selection box."))
        clear.connect('clicked', self._erase_name_selection)
        hbox.pack_start(clear, False, False, 0)

        self.message = Gtk.Label()
        self.message.set_label(_("Nothing is selected"))
        hbox.pack_start(self.message, False, False, 0)

        self.vbox.pack_start(self.scrolledwindow, True, True, 0)

        return self.vbox