def __init__(self): from gui import application app = application.get_app() assert app is not None self._current_background_pixbuf = None # set when changed flags = Gtk.DialogFlags.DESTROY_WITH_PARENT buttons = [ _('Save as Default'), RESPONSE_SAVE_AS_DEFAULT, Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT, ] windowing.Dialog.__init__( self, app=app, title=_('Background'), parent=app.drawWindow, flags=flags, buttons=buttons, ) # Set up window. self.connect('response', self._response_cb) notebook = self.nb = Gtk.Notebook() self.vbox.pack_start(notebook, True, True, 0) # Set up patterns tab. patterns_scroll = Gtk.ScrolledWindow() patterns_scroll.set_policy( Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC, ) notebook.append_page(patterns_scroll, Gtk.Label(_('Pattern'))) self.bgl = BackgroundList(self) patterns_scroll.add_with_viewport(self.bgl) self.connect("realize", self._realize_cb) self.connect("show", self._show_cb) self.connect("hide", self._hide_cb) # Set up colors tab. color_vbox = Gtk.VBox() notebook.append_page(color_vbox, Gtk.Label(_('Color'))) self.cs = Gtk.ColorSelection() self.cs.connect('color-changed', self._color_changed_cb) color_vbox.pack_start(self.cs, True, True, 0) b = Gtk.Button(_('Add color to Patterns')) b.connect('clicked', self._add_color_to_patterns_cb) color_vbox.pack_start(b, False, True, 0)
def __init__(self): import application app = application.get_app() assert app is not None flags = Gtk.DialogFlags.DESTROY_WITH_PARENT buttons = [ _('Save as Default'), RESPONSE_SAVE_AS_DEFAULT, Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT, ] windowing.Dialog.__init__( self, app=app, title=_('Background'), parent=app.drawWindow, flags=flags, buttons=buttons, ) #set up window self.connect('response', self._response_cb) notebook = self.nb = Gtk.Notebook() self.vbox.pack_start(notebook) #set up patterns tab patterns_scroll = Gtk.ScrolledWindow() patterns_scroll.set_policy( Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC, ) notebook.append_page(patterns_scroll, Gtk.Label(_('Pattern'))) self.bgl = BackgroundList(self) patterns_scroll.add_with_viewport(self.bgl) def lazy_init(*ignored): if not self.bgl.initialized: self.bgl.initialize() self.connect("realize", lazy_init) #set up colors tab color_vbox = Gtk.VBox() notebook.append_page(color_vbox, Gtk.Label(_('Color'))) self.cs = Gtk.ColorSelection() self.cs.connect('color-changed', self._color_changed_cb) color_vbox.pack_start(self.cs, expand=True) b = Gtk.Button(_('Add color to Patterns')) b.connect('clicked', self._add_color_to_patterns_cb) color_vbox.pack_start(b, expand=False)
def __init__(self, main_window): super().__init__(_("Painter"), main_window, (_("_Close"), Gtk.ResponseType.CLOSE), modal=False) self.f = main_window.f self.paint_toggle = Gtk.ToggleButton.new_with_label(_("Painting")) self.paint_toggle.connect('toggled', self.onChangePaintMode) self.csel = Gtk.ColorSelection() self.vbox.add(self.csel) self.vbox.add(self.paint_toggle) self.vbox.show_all()
def __init__(self, parent): Gtk.Dialog.__init__(self, 'Select Color', parent, 0, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK)) self.set_decorated(False) self.override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(.95, .95, .95, .95)) LalaWin.ClSel = Gtk.ColorSelection() LalaWin.ClSel.set_has_opacity_control(True) LalaWin.ClSel.set_current_rgba(Gdk.RGBA(dset.Cl[0], dset.Cl[1], dset.Cl[2], dset.Cl[3])) Box = self.get_content_area() Box.add(LalaWin.ClSel) self.show_all()
def init_ui(self): window = Gtk.Window() window.connect("destroy", self.quit) top_box = Gtk.VBox() save_button = Gtk.Button("Save file") save_button.connect("clicked", self.save_handler) load_button = Gtk.Button("Load file") load_button.connect("clicked", self.load_handler) brush_button = Gtk.Button("Load brush") brush_button.connect("clicked", self.change_brush_handler) self.color_selector = Gtk.ColorSelection() self.color_selector.connect("color-changed", self.color_change_handler) # Extract only the color triangle hsv_selector = find_widgets(self.color_selector, lambda w: w.get_name() == 'GtkHSV')[0] hsv_selector.unparent() self.view_widget = GeglGtk.View() self.view_widget.set_node(self.display_node) self.view_widget.set_autoscale_policy(GeglGtk.ViewAutoscale.DISABLED) self.view_widget.set_size_request(400, 400) self.view_widget.connect("draw-background", self.draw_background) event_box = Gtk.EventBox() event_box.connect("motion-notify-event", self.motion_to) event_box.connect("button-press-event", self.button_press) event_box.connect("button-release-event", self.button_release) button_box = Gtk.VBox() ui_box = Gtk.HBox() event_box.add(self.view_widget) button_box.pack_start(save_button, expand=False, fill=True, padding=0) button_box.pack_start(load_button, expand=False, fill=True, padding=0) button_box.pack_start(brush_button, expand=False, fill=True, padding=0) ui_box.pack_start(hsv_selector, expand=False, fill=True, padding=0) ui_box.pack_start(button_box, expand=True, fill=True, padding=0) top_box.pack_start(ui_box, expand=False, fill=True, padding=0) top_box.pack_start(event_box, expand=True, fill=True, padding=0) window.add(top_box) window.show_all() self.window = window
def __init__(self, main_window, f): dialog.T.__init__( self, _("Painter"), main_window, (Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE), modal=False ) self.f = f self.paint_toggle = Gtk.ToggleButton.new_with_label(_("Painting")) self.paint_toggle.connect('toggled', self.onChangePaintMode) self.csel = Gtk.ColorSelection() self.vbox.add(self.csel) self.vbox.add(self.paint_toggle) self.vbox.show_all()
def __init__(self): Gtk.Window.__init__(self) self.connect('delete-event', Gtk.main_quit) self.connect('motion-notify-event', self.motion_cb) self.connect('button-press-event', self.button_press) box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) #Setup area for coordinates and zoom window coordbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.xcoor = Gtk.Label("x: ") coordbox.pack_start(self.xcoor, True, False, 1) self.ycoor = Gtk.Label("y: ") coordbox.pack_start(self.ycoor, True, False, 1) self.zoomwin = Gtk.Image() #Trying to draw on Gtk.Image with cairo for crosshairs... Not working self.zoomwin.connect('draw', self.draw) self.zoomwin.set_app_paintable(True) coordbox.pack_start(self.zoomwin, True, True, 1) self.buttongo = Gtk.Button("Pick Color") self.buttongo.connect('clicked', self.gobutton_activate) coordbox.pack_start(self.buttongo, True, True, 1) box.pack_start(coordbox, True, False, 5) #Put in color wheel for tweaking color self.cp = Gtk.ColorSelection() self.cp.connect('color-changed', self.on_color_changed) box.pack_start(self.cp, True, True, 5) self.add(box) self.show_all() #Set some initial parameters self.w, self.h = 10, 10 #Size of zoomed image in pixels self.count = 0 self.window = self.get_window() #set initial zoom image self.zoomwin.set_from_pixbuf(self.get_image().scale_simple( 240, 240, GdkPixbuf.InterpType.TILES)) self.grabbing = False
#!/usr/bin/env python from gi.repository import Gtk def color_selected(widget): print("Colour selected: %s" % colorselection.get_current_color()) window = Gtk.Window() window.connect("destroy", lambda q: Gtk.main_quit()) colorselection = Gtk.ColorSelection() colorselection.connect("color-changed", color_selected) window.add(colorselection) window.show_all() Gtk.main()
def go(): w = Gtk.Window() w.connect("delete-event", lambda w, e: Gtk.main_quit()) w.set_title("Color distance model tester") w.set_size_request(600, 800) black = (0.0, ) * 3 + (1.0, ) model = Model(black, black, 0.0) # RGB distances and resulting-alpha display widgets rgb_dist_label = Gtk.Label("RGB Distance:") rgb_dist_label.set_alignment(1.0, 0.5) rgb_dist_label.set_margin_right(10) rgb_dist_field = Gtk.Label() rgb_dist_field.set_alignment(0.0, 0.5) rgb_alpha_label = Gtk.Label("RGB Fill-Alpha:") rgb_alpha_label.set_alignment(1.0, 0.5) rgb_alpha_label.set_margin_right(10) rgb_alpha_field = Gtk.Label() rgb_alpha_field.set_alignment(0.0, 0.5) # RGBA distances and resulting-alpha display widgets rgba_dist_label = Gtk.Label("RGBA Distance:") rgba_dist_label.set_alignment(1.0, 0.5) rgba_dist_label.set_margin_right(10) rgba_dist_field = Gtk.Label() rgba_dist_field.set_alignment(0.0, 0.5) rgba_alpha_label = Gtk.Label("RGBA Fill-Alpha:") rgba_alpha_label.set_alignment(1.0, 0.5) rgba_alpha_label.set_margin_right(10) rgba_alpha_field = Gtk.Label() rgba_alpha_field.set_alignment(0.0, 0.5) MAX_A = int(2**16 - 1) def update_values(): if model.rgb_distance is None: rgb_dist_field.set_markup(" - ") rgba_dist_field.set_markup(" - ") rgb_alpha_field.set_markup(" - ") rgba_alpha_field.set_markup(" - ") else: rgb_dist_field.set_markup("<big>%.4f</big>" % model.rgb_distance) rgb_alpha_field.set_markup("<big>%.4f</big>" % model.rgb_alpha) rgba_dist_field.set_markup("<big>%.4f</big>" % model.rgba_distance) rgba_alpha_field.set_markup("<big>%.4f</big>" % model.rgba_alpha) update_values() def tol_cb(adj): model.set_tol(adj.get_value()) update_values() def col_change_cb(col_sel, n): c = col_sel.get_current_rgba() col_sel.set_previous_rgba(c) col_sel.set_previous_alpha(MAX_A) model.set_col(n, c) update_values() tol_slider = Gtk.Scale() adj = Gtk.Adjustment(value=float(0.0), lower=0.0, upper=1.0, step_increment=0.01, page_increment=0.05, page_size=0) adj.connect("value-changed", tol_cb) tol_slider.set_draw_value(True) tol_slider.set_digits(4) tol_slider.set_hexpand(True) tol_slider.set_adjustment(adj) cp1 = Gtk.ColorSelection() cp1.set_has_opacity_control(True) cp1.set_current_alpha(MAX_A) cp1.set_halign(Gtk.Align.CENTER) cp1.connect("color-changed", col_change_cb, 0) cp2 = Gtk.ColorSelection() cp2.set_has_opacity_control(True) cp2.set_current_alpha(MAX_A) cp2.set_halign(Gtk.Align.CENTER) cp2.connect("color-changed", col_change_cb, 1) dist_func_store = Gtk.ListStore(str, object) func_combo = Gtk.ComboBox() def fill_store(): dist_func_store.clear() for func, name in dm.distance_functions: dist_func_store.append([name, func]) fill_store() func_combo.set_model(dist_func_store) cell = Gtk.CellRendererText() func_combo.pack_start(cell, True) func_combo.set_hexpand(True) func_combo.add_attribute(cell, "text", 0) def func_change_cb(combo): act = combo.get_active() if act != -1: model.set_distance_func(combo.get_model()[act][1]) update_values() func_combo.connect("changed", func_change_cb) if len(dist_func_store) > 0: func_combo.set_active(0) def reload_cb(_): old_func = func_combo.get_active() dist_func_store.clear() model.set_distance_func(None) reload_module(dm) fill_store() if 0 <= old_func < len(dist_func_store): func_combo.set_active(old_func) update_values() reload_button = Gtk.Button("Reload distance functions") reload_button.set_hexpand(True) reload_button.connect("clicked", reload_cb) grid = Gtk.Grid() grid.set_row_spacing(6) grid.set_margin_left(10) grid.set_margin_right(10) grid.set_margin_top(10) grid.set_margin_bottom(10) w.add(grid) fw = 2 r = attach_inc_row(grid, cp1, 0, 0, fw, 1) r = attach_inc_row(grid, cp2, 0, r, fw, 1) r = attach_inc_row(grid, tol_slider, 0, r, fw, 1) grid.attach(rgb_dist_label, 0, r, 1, 1) grid.attach(rgb_dist_field, 1, r, 1, 1) r += 1 grid.attach(rgb_alpha_label, 0, r, 1, 1) grid.attach(rgb_alpha_field, 1, r, 1, 1) r += 1 grid.attach(rgba_dist_label, 0, r, 1, 1) grid.attach(rgba_dist_field, 1, r, 1, 1) r += 1 grid.attach(rgba_alpha_label, 0, r, 1, 1) grid.attach(rgba_alpha_field, 1, r, 1, 1) r += 1 r = attach_inc_row(grid, func_combo, 0, r, fw, 1) grid.attach(reload_button, 0, r, fw, 1) w.show_all() Gtk.main()
return def save_file(self): global surface filename=button5.get_text() surface.write_to_png(filename) win = Gtk.Window() win.set_title('P Paint') win.connect('destroy',close_window) win.set_border_width(8) grid = Gtk.Grid() col = Gtk.ColorSelection(has_palette=True) #Color Pallete button1 = Gtk.Button(label="Width++") #Width of brush button2= Gtk.Button(label="Width--") button3=Gtk.ComboBoxText() button3.append("1","Rectangle") button3.append("2","Ellipse") button3.append("3","Circle") button4=Gtk.Button(label="Ok") button5=Gtk.Entry() button6=Gtk.Button(label="Save") button5.set_text("Enter file name with extn") range=Gtk.Adjustment(lower=1,upper=1000,step_increment=1) range2=Gtk.Adjustment(lower=1,upper=1000,step_increment=1)