def create_canvas(canvas, title): # Setup drawing window view = GtkView() view.painter = DefaultPainter() view.canvas = canvas window = Gtk.Window() window.set_title(title) window.set_default_size(400, 400) win_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) window.add(win_box) win_box.pack_start(view, True, True, 0) # Draw first gaphas box b1 = Box(60, 60) b1.matrix = (1.0, 0.0, 0.0, 1, 10, 10) canvas.add(b1) # Draw second gaphas box b2 = Box(60, 60) b2.min_width = 40 b2.min_height = 50 b2.matrix.translate(170, 170) canvas.add(b2) # Draw gaphas line line = Line() line.matrix.translate(100, 60) canvas.add(line) line.handles()[1].pos = (30, 30) window.show_all() window.connect("destroy", Gtk.main_quit)
def __init__(self, canvas): Gtk.Window.__init__(self, title="Hello World") #connect the button widget #connect to its clicked signal #add is as child to the top-level window #self.button = Gtk.Button(label="Click Here") #self.button.connect("clicked", self.on_button_clicked) self.label = Gtk.Label() self.view = GtkView() #Gtk widget self.view.painter = DefaultPainter() self.view.canvas = canvas self.win_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) self.add(self.win_box) self.win_box.pack_start(self.label, True, True, 0) self.win_box.pack_start(self.view, True, True, 0) self.b2 = Box(60, 60) self.b2.min_width = 40 self.b2.min_height = 50 self.b2.matrix.translate(170, 170) canvas.add(self.b2) # Draw gaphas line self.line = Line() self.line.matrix.translate(100, 60) canvas.add(self.line) self.line.handles()[1].pos = (30, 30) self.segment = Segment(self.line, canvas) self.segment.split_segment(0)
def create_canvas(canvas, title): # Setup drawing window window = Gtk.Window() window.set_title(title) window.set_default_size(400, 400) view = GtkView() #Gtk widget view.painter = DefaultPainter() view.canvas = canvas win_box = Gtk.Box( orientation=Gtk.Orientation.HORIZONTAL) #added Gtk box to Gtk window window.add(win_box) win_box.pack_start(view, True, True, 0) #added "view" widget to the box # Draw gaphas box b2 = Box(60, 60) b2.min_width = 40 b2.min_height = 50 b2.matrix.translate(170, 170) canvas.add(b2) # Draw gaphas line line = Line() line.matrix.translate(100, 60) canvas.add(line) line.handles()[1].pos = (30, 30) segment = Segment(line, canvas) segment.split_segment(0) window.show_all() window.connect("destroy", Gtk.main_quit)
def __init__(self, model: Optional[Model] = None, selection: Selection = None): """Create a new view. Args: model (Model): optional model to be set on construction time. selection (Selection): optional selection object, in case the default selection object (hover/select/focus) is not enough. """ Gtk.DrawingArea.__init__(self) self._dirty_items: Set[Item] = set() self._back_buffer: Optional[cairo.Surface] = None self._back_buffer_needs_resizing = True self._controllers: Set[Gtk.EventController] = set() self.set_can_focus(True) if Gtk.get_major_version() == 3: self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK | Gdk.EventMask.SCROLL_MASK | Gdk.EventMask.STRUCTURE_MASK) self.set_app_paintable(True) else: self.set_draw_func(GtkView.do_draw) self.connect_after("resize", GtkView.on_resize) def alignment_updated(matrix: Matrix) -> None: if self._model: self._matrix *= matrix # type: ignore[misc] self._scrolling = Scrolling(alignment_updated) self._selection = selection or Selection() self._matrix = Matrix() self._painter: Painter = DefaultPainter(self) self._bounding_box_painter: ItemPainterType = ItemPainter( self._selection) self._matrix_changed = False self._qtree: Quadtree[Item, Tuple[float, float, float, float]] = Quadtree() self._model: Optional[Model] = None if model: self.model = model self._selection.add_handler(self.on_selection_update) self._matrix.add_handler(self.on_matrix_update)
def __init__(self, canvas=None): self._matrix = cairo.Matrix() self._painter = DefaultPainter(self) self._bounding_box_painter = BoundingBoxPainter(self) # Handling selections. # TODO: Move this to a context? self._selected_items = set() self._focused_item = None self._hovered_item = None self._dropzone_item = None self._qtree = Quadtree() self._bounds = Rectangle(0, 0, 0, 0) self._canvas = None if canvas: self._set_canvas(canvas)
def main(): builder = Gtk.Builder() builder.add_from_file("AppWindow.glade") graph_view = GtkView() graph_view.painter = DefaultPainter() graph_view.canvas = Canvas() gaphas_window = builder.get_object("GaphasWindow") gaphas_window.add(graph_view) main_view = MainView() controller = Controller(builder, main_view, graph_view) builder.connect_signals(controller) #view.connect("focus-changed", handler.focus_changed, "focus") window = builder.get_object("MainWindow") main_view.show_main_window(window) Gtk.main()
def __init__(self): Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL) log.info("Loading Workbench") canvas = Canvas() view = GtkView() __.canvas = canvas __.view = view view.painter = DefaultPainter() view.canvas = canvas self.pack_start(view, True, True, 20) self.index = interpreter() self.index.add_to_canvas(canvas) # # Draw first gaphas box # b1 = Box(Rectangle(1, 0, 60, 60)) # canvas.add(b1) # tx = Text(text="joo") # tx.matrix.translate(20, 20) # canvas.add(tx) # # Draw second gaphas box # b2 = Box(Rectangle(170, 170, 60, 60)) # canvas.add(b2) # # Draw gaphas line # line = Line() # line.matrix.translate(100, 60) # canvas.add(line) # line.handles()[1].pos = (30, 30) self.view = view self.canvas = canvas self.show_all() log.info("Workbench loaded") view.add_events(Gdk.EventMask.BUTTON_PRESS_MASK) # self.connect('clicked', self.on_field_click) # "set-focus-child" container, widget self.connect("focus", self.on_field_click)