我们从Python开源项目中,提取了以下21个代码示例,用于说明如何使用gi.repository.Gtk.DrawingArea()。
def __init__(self, n, front, back, step): from gi.repository import Gtk from gi.repository import GObject Render.__init__(self, n, front, back) window = Gtk.Window() self.window = window window.resize(self.n, self.n) self.step = step window.connect("destroy", self.__destroy) darea = Gtk.DrawingArea() # darea.connect("expose-event", self.expose) self.darea = darea window.add(darea) window.show_all() #self.cr = self.darea.window.cairo_create() self.steps = 0 GObject.idle_add(self.step_wrap)
def __init__(self): Gtk.ScrolledWindow.__init__(self) self.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER) self.m_callback = None self.m_engravers = [] self.m_fontsize = 20 self.m_clickables = [] self.g_d = Gtk.DrawingArea() self.g_d.show() self.add_with_viewport(self.g_d) self.g_d.connect("draw", self.on_draw) self.g_d.add_events(Gdk.EventMask.EXPOSURE_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.BUTTON_PRESS_MASK|Gdk.EventMask.POINTER_MOTION_MASK) self.g_d.connect("button_press_event", self.on_button_press_event) self.m_width = self.m_height = 0
def __init__(self, num_octaves, lowest_c, key_w=15): Gtk.DrawingArea.__init__(self) CairoCommon.__init__(self) self.connect("draw", self.draw) self.connect("button-press-event", self._on_button_press) self.set_events(Gdk.EventMask.BUTTON_PRESS_MASK) # Piano stuff self.m_num_octaves = num_octaves self.m_lowest_c = mpd.MusicalPitch.new_from_notename(lowest_c) self.m_lowest_tone = self.m_lowest_c.get_octave_notename() self.m_highest_tone = (self.m_lowest_c.clone() + 12 * num_octaves - 1).get_octave_notename() self.m_white_h = key_w * 3.4 self.m_black_h = key_w * 2.0 self.m_key_w = key_w self.m_last_redraw = 0 self.m_black_w = 0.6 self.set_size_request(int(num_octaves * 7 * key_w + 1), int(self.m_white_h + 1))
def color_swatch_new(self, str_color): color = Gdk.color_parse(str_color) rgba = Gdk.RGBA.from_color(color) button = Gtk.Button() area = Gtk.DrawingArea() area.set_size_request(24, 24) area.override_background_color(0, rgba) button.add(area) return button # --------------------------------- # create_flowbox # ---------------------------------
def color_swatch_new(self, str_color): color = Gdk.color_parse(str_color) rgba = Gdk.RGBA.from_color(color) button = Gtk.Button() area = Gtk.DrawingArea() area.set_size_request(24, 24) area.override_background_color(0, rgba) button.add(area) return button # print("Pedro deconnected") # --------------------------------- # color_widget # ---------------------------------
def main(): win = Gtk.Window() win.connect('destroy', Gtk.main_quit) win.set_default_size(Width, Height) global drawingarea drawingarea = Gtk.DrawingArea() drawingarea.connect('draw', draw) drawing_event_box = Gtk.EventBox() drawing_event_box.add(drawingarea) drawing_event_box.connect('button-press-event', mouse_pressed) drawing_event_box.connect('motion-notify-event', mouse_dragged) check_useIk = Gtk.CheckButton("Lock Forearm & Hand") check_useIk.set_active(True) check_useIk.connect("toggled", check_toggled) box = Gtk.VBox() box.pack_start(check_useIk, False, True, 0) box.pack_start(drawing_event_box, True, True, 0) win.add(box) win.show_all() Gtk.main()
def __init__(self, config, cavaconfig): self.silence_value = 0 self.config = config self.cavaconfig = cavaconfig self.audio_sample = [] self.color = None self.area = Gtk.DrawingArea() self.area.connect("draw", self.redraw) self.area.add_events(Gdk.EventMask.BUTTON_PRESS_MASK) self.sizes = AttributeDict() self.sizes.area = AttributeDict() self.sizes.bar = AttributeDict() self.area.connect("configure-event", self.size_update) self.color_update()
def __init__(self): super(VideoPlayerGtk3, self).__init__() self.uri = "" # gtk ui self.movie_window = Gtk.DrawingArea() self.pack_start(self.movie_window, True, True, 0) self.button = Gtk.Button(_("Play")) self.pack_start(self.button, False, True, 0) self.button.connect("clicked", self.on_play_clicked) # player self.player = Gst.ElementFactory.make("playbin2", "player") # bus stuff bus = self.player.get_bus() bus.add_signal_watch() bus.enable_sync_message_emission() bus.connect("message", self.on_message) # FIXME: no sync messages currently so no playing in the widget :/ # the former appears to be not working anymore with GIR, the # later is not exported (introspectable=0 in the GIR) bus.connect("sync-message", self.on_sync_message) #bus.set_sync_handler(self.on_sync_message)
def __init__(self, filename, has_colors = False): Gtk.DrawingArea.__init__(self) self.connect('size_allocate', self.on_size_allocate) self.has_colors = has_colors self.set_filename(filename)
def __init__(self, size, detector): Gtk.DrawingArea.__init__(self) self._size = size self._detector = detector self._points = deque([], 256) self.connect('draw', self.draw) self.set_size_request(size, size) self.set_colors()
def start(self, bridge): """Start the UI event loop.""" bridge.attach(80, 24, rgb=True) 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()
def __init__(self, callback, strings, string_thickness=(1, 1, 1, 1, 1, 1)): Gtk.DrawingArea.__init__(self) CairoCommon.__init__(self) self.m_callback = callback self.m_strings = strings self.m_string_thickness = string_thickness self.m_fretdist = (20, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 30, 30) self.m_stringdist = 17 self.m_numstring = len(self.m_strings) self.m_neckborder = 6 self.m_neckl = 0 self.m_xlist = [] self.m_lowest_tone = mpd.int_to_octave_notename( min(map(mpd.notename_to_int, self.m_strings))) self.m_highest_tone = mpd.int_to_octave_notename( len(self.m_fretdist) - 1 + max(map(mpd.notename_to_int, self.m_strings))) self.m_stringtuning = map(mpd.notename_to_int, self.m_strings) tmp = 0 for x in self.m_fretdist: tmp = tmp + x self.m_xlist.append(tmp) tmp = self.m_neckborder + self.m_stringdist/2 self.m_ylist = [tmp] for y in range(self.m_numstring-1): tmp = tmp + self.m_stringdist self.m_ylist.append(tmp) for x in self.m_fretdist: self.m_neckl = self.m_neckl + x self.m_neckl = self.m_neckl + 2 self.m_neckw = self.m_neckborder \ + (self.m_numstring-1)*self.m_stringdist \ + 1 + self.m_neckborder self.set_events(Gdk.EventMask.BUTTON_PRESS_MASK|Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.ENTER_NOTIFY_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK) self.connect('draw', self.draw) self.m_mouse_pos = None, None self.connect('motion-notify-event', self.on_motion_notify_event) self.connect('leave-notify-event', self.on_leave_notify_event) self.connect('button-press-event', self.on_button_press_event) self.set_size_request(self.m_neckl, self.m_neckw)
def __init__(self, callback, keyboard_system): Gtk.DrawingArea.__init__(self) CairoCommon.__init__(self) self.m_callback = callback def ff(first, count): i = mpd.notename_to_int(first) return [mpd.int_to_octave_notename(i + x * 3) for x in range(count)] keyboard_def = {'norwegian': (ff("g,", 19), ff("f,", 20), ff("fis,", 19), ff("e,", 20), ff("f,", 19))} keyboard_def['swedish'] = ( ff("e,", 19), ff("dis,", 20), ff("f,", 19), ff("e,", 20), ff("fis,", 19)) keyboard_def['finnish'] = ( ff("dis,", 19), ff("d,", 20), ff("e,", 19), ff("dis,", 20), ff("f,", 19)) keyboard_def['belgian'] = ( ff("fis,", 19), ff("e,", 20), ff("f,", 19), ff("es,", 20), ff("e,", 19) ) self.m_notenames = keyboard_def[keyboard_system] self.m_lowest_tone = mpd.HIGHEST_NOTENAME self.m_highest_tone = mpd.LOWEST_NOTENAME for v in self.m_notenames: if mpd.compare_notenames(self.m_lowest_tone, v[0]) > 0: self.m_lowest_tone = v[0] if mpd.compare_notenames(self.m_highest_tone, v[-1]) < 0: self.m_highest_tone = v[-1] self.m_button_radius = 9 self.m_button_xdist = 20 self.m_button_ydist = 18 self.connect('draw', self.draw) self.connect('button-press-event', self._on_button_press) self.set_events(Gdk.EventMask.BUTTON_PRESS_MASK)
def abort(self): self.dot_widget.queue_draw() #class DotWidget(Gtk.DrawingArea):
def __init__(self): #Gtk.DrawingArea.__init__(self) Gtk.Layout.__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
def __init__(self,parent): Gtk.DrawingArea.__init__(self) self.connect("draw",self.on_draw) self.set_events(Gdk.EventMask.BUTTON_PRESS_MASK) self.coords = [] self.connect("button-press-event", self.on_button_press)
def __init__(self): Gtk.ScrolledWindow.__init__(self) self.view = Gtk.DrawingArea() self.view.set_hexpand(True) self.view.set_vexpand(True) self.view.set_events(Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventType.MOTION_NOTIFY | Gdk.EventMask.POINTER_MOTION_MASK) self.view.connect('draw', self.draw) self.view.connect('button-press-event', self.press) self.view.connect('motion-notify-event', self.motion) self.add(self.view)
def __init__(self, mode, images): self.hbox = Gtk.Box(Gtk.Orientation.HORIZONTAL) self.menu_revealer = self._build_revealer() self.video_monitor = Gtk.DrawingArea() self.video_monitor.set_margin_left(6) self.video_monitor.set_margin_right(6) self.video_monitor.set_margin_bottom(6) self.video_monitor.set_halign(Gtk.Align.FILL) self.video_monitor.set_valign(Gtk.Align.FILL) self.video_monitor.set_size_request(700, 400) self.placeholder_pipeline = self.get_placeholder_pipeline() self.placeholder_bus = self.create_gstreamer_bus( self.placeholder_pipeline.pipeline) self.pipeline = self.create_pipeline_instance(mode) self.bus = self.create_gstreamer_bus(self.pipeline.pipeline) self.xid = None self.video_menu = VideoMenu( self.pipeline, self.menu_revealer, self.placeholder_pipeline) self.audio_menu = AudioMenu( self.pipeline, self.menu_revealer, self.placeholder_pipeline) self.stream_menu = StreamMenu(self.pipeline, self.menu_revealer) self.store_menu = StoreMenu(self.pipeline, self.menu_revealer) self.settings_menu = SettingsMenu(self.pipeline, self.menu_revealer) self.images = images self.controls = ControlBar(self.pipeline, self.menu_revealer, self.images, self.video_menu, self.audio_menu, self.stream_menu, self.store_menu, self.settings_menu, self.placeholder_pipeline) self.controls.overlay_container.add(self.video_monitor) self.controls.display_controls() self.vumeter_box = self._build_vumeter() self.controls.overlay_container.add_overlay(self.vumeter_box) self.hbox.pack_start(self.controls.overlay_container, True, True, 0) self.hbox.pack_start(self.menu_revealer, False, False, 0)