def __init__(self, size=(300,300), name="Piddle-GTK", infoline=1): """Initialize the canvas and minimal supporting widgets. If |infoline| is true (the default), a status bar will be included at the bottom of the window to support the ,setInfoLine() method. If false, no statusbar will be used. """ import gtk # width, height = (int(round(size[0])), int(round(size[1]))) # top = self.__top = gtk.GtkWindow() vbox = self.__vbox = gtk.GtkVBox() da = gtk.GtkDrawingArea() # top.add(vbox) vbox.pack_start(da) if infoline: sbar = self.__sbar = gtk.GtkStatusbar() vbox.pack_end(sbar, expand=0) sbar.set_border_width(2) else: self.__sbar = None InteractiveCanvas.__init__(self, da, top) top.set_wmclass("canvas", "Canvas") da.realize() da.set_usize(width, height) top.show_all() top.set_icon_name(name) top.set_title(name) self.ensure_size(width, height) self.__status = None
def __init__(self, size=(300,300), name="Piddle-GTK"): import gtk # width, height = (int(round(size[0])), int(round(size[1]))) top = self.__top = gtk.GtkDialog() vbox = top.vbox frame = self.__frame = gtk.GtkFrame() frame.set_shadow_type(gtk.SHADOW_IN) da = gtk.GtkDrawingArea() button = gtk.GtkButton("Dismiss") button.connect("clicked", lambda button, top=top: top.destroy()) frame.set_border_width(10) bbox = self.__bbox = gtk.GtkHButtonBox() bbox.set_layout(gtk.BUTTONBOX_END) bbox.pack_end(button) top.action_area.pack_end(bbox) frame.add(da) vbox.pack_start(frame) InteractiveCanvas.__init__(self, da, top) top.set_wmclass("canvas", "Canvas") da.realize() da.set_usize(width, height) top.show_all() top.set_icon_name(name) top.set_title(name) self.ensure_size(width, height)
def __init__(self): self.canvas = None self.window = gtk.GtkWindow(gtk.WINDOW_TOPLEVEL) self.window.connect("delete_event", self.delete_event) self.window.set_title("jXPMap Editor") self.box0 = gtk.GtkVBox(gtk.FALSE, 0) menubar = self.buildMenuBar() self.box0.pack_start(menubar, gtk.FALSE, gtk.FALSE, 0) self.box1 = gtk.GtkHBox(gtk.FALSE, 0) self.box0.pack_start(self.box1, gtk.TRUE, gtk.TRUE, 0) self.window.add(self.box0) self.buildToolBar() #self.ActionMap() #self.buildInputMap() # The visual calls are needed to make sure drawing bitmaps # (draw_*_image) works # ... at least according to some documentation that doesn't look # entirely reliable gtk.push_rgb_visual() area = gtk.GtkDrawingArea() gtk.pop_visual() area.size(500, 500) self.box1.pack_start(area, gtk.TRUE, gtk.TRUE, 0) area.connect("expose-event", self.area_expose_cb) # Change the default background to black so that the window # doesn't flash badly when resizing style = area.get_style().copy() style.bg[gtk.STATE_NORMAL] = area.get_colormap().alloc(0, 0, 0) area.set_style(style) area.connect("button_press_event", self.mouse_event) area.connect("button_release_event", self.mouse_event) area.connect("motion_notify_event", self.mouse_event) area.connect("configure_event", self.configure_event) area.set_events(GDK.EXPOSURE_MASK | GDK.BUTTON_PRESS_MASK | GDK.BUTTON_RELEASE_MASK | GDK.POINTER_MOTION_MASK | GDK.POINTER_MOTION_HINT_MASK) # The HINT_MASK means there won't be a callback for every mouse # motion event, only after certain other events or after an explicit # reading of the location with x, y = window.pointer. # This helps to avoid getting a queue of events if they're not handled # quickly enough. area.show() self.zoom = 0 self.box1.show() self.box0.show() self.window.show() self.canvas = MapCanvas(area)
def __init__(self, area=None): if area is None: import gtk area = gtk.GtkDrawingArea() self.__area = area self.__setup = 0 self.__color_cache = {} self.backgroundColor = piddle.white self.__buffer = None self.__buffer_size = (-1, -1) self.__area.connect("expose_event", self.__expose_event) self.__area.connect("configure_event", self.__configure_event) piddle.Canvas.__init__(self)
def __init__(self, size=(500, 400), name="p4VASP graph", infoline=None, drawing_area=None, top=None, world=None, graphdata=None): self.lastmotiontime = 0 width, height = (int(round(size[0])), int(round(size[1]))) self.world = world if drawing_area is None: if top is None: top = gtk.GtkWindow() vbox = gtk.GtkVBox() da = gtk.GtkDrawingArea() top.add(vbox) vbox.pack_start(da) if infoline: sbar = self.__sbar = gtk.GtkStatusbar() vbox.pack_end(sbar, expand=0) sbar.set_border_width(2) else: self.__sbar = None else: da = drawing_area if infoline is None: self.__sbar = None else: self.__sbar = infoline self.top = top piddleGTKp4.InteractiveCanvas.__init__(self, da, top) # top.set_wmclass("canvas", "Canvas") da.realize() da.set_usize(width, height) # top.show_all() # top.set_icon_name(name) # top.set_title(name) self.ensure_size(width, height) self.__status = None self.world = world self.graphdata = graphdata self.onOver = self.onOverCallback self.onClick = self.onClickCallback self.onKey = self.onKeyCallback self.point = -1, -1 self.selected_begin = None
def main(): window = gtk.GtkWindow(gtk.WINDOW_TOPLEVEL) window.set_name ("Test Input") vbox = gtk.GtkVBox(gtk.FALSE, 0) window.add(vbox) vbox.show() window.connect("destroy", gtk.mainquit) # Create the drawing area drawing_area = gtk.GtkDrawingArea() drawing_area.size(200, 200) vbox.pack_start(drawing_area, gtk.TRUE, gtk.TRUE, 0) drawing_area.show() # Signals used to handle backing pixmap drawing_area.connect("expose_event", expose_event) drawing_area.connect("configure_event", configure_event) # Event signals drawing_area.connect("motion_notify_event", motion_notify_event) drawing_area.connect("button_press_event", button_press_event) drawing_area.set_events(GDK.EXPOSURE_MASK | GDK.LEAVE_NOTIFY_MASK | GDK.BUTTON_PRESS_MASK | GDK.POINTER_MOTION_MASK | GDK.POINTER_MOTION_HINT_MASK) # .. And a quit button button = gtk.GtkButton("Quit") vbox.pack_start(button, gtk.FALSE, gtk.FALSE, 0) button.connect_object("clicked", window.destroy, window) button.show() window.show() gtk.mainloop() return 0
def __init__(self): gtk.GtkTable.__init__(self, rows=2, cols=2) self.hadj = gtk.GtkAdjustment() self.vadj = gtk.GtkAdjustment() self._hscroll = gtk.GtkHScrollbar(adj=self.hadj) self._vscroll = gtk.GtkVScrollbar(adj=self.vadj) self._area = gtk.GtkDrawingArea() #set events for scrolling (not defined in GDK #self._area.set_events(1 << 21) self.contents = [] self.max_width = 0 self.max_length = 0 self.height = 0 self.line_height = 0 self.start_line = 0 self.start_col = 0 self.freeze_count = 0 self.updating = gtk.FALSE frm = gtk.GtkFrame() frm.set_shadow_type(gtk.SHADOW_ETCHED_OUT) frm.add(self._area) self.attach(frm, 0, 1, 0, 1) self.attach(self._vscroll, 1, 2, 0, 1, xoptions=gtk.SHRINK) self.attach(self._hscroll, 0, 1, 1, 2, yoptions=gtk.SHRINK) self.show_all() self._area.connect('expose-event', self.expose) self.connect('configure-event', self.configure) self.hadj.connect('value-changed', self.changed) self.vadj.connect('value-changed', self.changed) self._area.connect("scroll-event", self.event) self.connect('style-set', self.expose)
def __init__(self, editable=1): self._editable = editable if self._editable == 1: gtk.GtkTable.__init__(self, rows=3, cols=2) else: gtk.GtkTable.__init__(self, rows=2, cols=2) self.hadj = gtk.GtkAdjustment() self.vadj = gtk.GtkAdjustment() self._hscroll = gtk.GtkHScrollbar(adj=self.hadj) self._vscroll = gtk.GtkVScrollbar(adj=self.vadj) self._area = gtk.GtkDrawingArea() self._pixmap = None #this mask also seems to enable scrolling??? evt_mask = gtk.GDK.BUTTON_PRESS_MASK | gtk.GDK.BUTTON_RELEASE_MASK | \ gtk.GDK.KEY_PRESS_MASK | gtk.GDK.KEY_RELEASE_MASK self._area.set_events(evt_mask) if self._editable == 1: self._entry = gtk.GtkEntry() self._entry.set_sensitive(gtk.FALSE) self._entry.connect('changed', self.entry_changed) #the data source self.source = None self.source_changed_id = None self.subset = [] # indices/info for sorting (indices maps source index to nRow; inv_indices # maps nRow to source index, and similar for subindices). self.indices = None self.inv_indices = None self.subindices = None self.inv_subindices = None self.sort_reverse = 0 #string values to use as titles self.titles = [] #fonts for drawing titles and cells put here self.title_font = None self.cell_font = None #the overall size of the data set self.n_rows = 0 self.n_cols = 0 #the height of a single row and title row self.row_height = 0 self.title_height = 0 #the row/col to put in the top left corner self.start_row = 0 self.start_col = 0 #the current row/col selected (when we support clicking :) self.current_row = 0 # current row in display widget coordinates self.current_row_src = -1 # current row in source coordinates (source index) self.current_col = 0 self.col_widths = [] #the number of pixels around each cell self.cell_half = 4 self.cell_full = (self.cell_half) * 2 + 1 self.max_width = 0 self.max_height = 0 #flag to recalculate the adjustments self.bCalcAdjustments = gtk.TRUE # list of indices of currently selected shapes (NOT the same as the # currently editable cell) self.selected_shapes = None #set to true if changing some value that would end up causing multiple #expose events or an endless loop even. self.updating = gtk.FALSE frm = gtk.GtkFrame() frm.set_shadow_type(gtk.SHADOW_ETCHED_OUT) frm.add(self._area) if self._editable == 1: self.attach(self._entry, 0, 1, 0, 1, xoptions=gtk.FILL, yoptions=gtk.SHRINK) self.attach(frm, 0, 1, 1, 2, xoptions=gtk.FILL, yoptions=gtk.FILL) self.attach(self._vscroll, 1, 2, 1, 2, xoptions=gtk.SHRINK) self.attach(self._hscroll, 0, 1, 2, 3, yoptions=gtk.SHRINK) else: self.attach(frm, 0, 1, 0, 1, xoptions=gtk.FILL, yoptions=gtk.FILL) self.attach(self._vscroll, 1, 2, 0, 1, xoptions=gtk.SHRINK) self.attach(self._hscroll, 0, 1, 1, 2, yoptions=gtk.SHRINK) self.show_all() # signals: Note that the right-click (button 3) event # is a special case used internally to select cells for # editing. self.publish('clicked-selected-row') self.publish('clicked-unselected-row') self.publish('title-clicked') self._area.connect('expose-event', self.expose) self._area.connect('configure-event', self.configure) self._area.connect('button-press-event', self.click) self.hadj.connect('value-changed', self.changed) self.vadj.connect('value-changed', self.changed) self.connect('style-set', self.expose)