def new_color(parent, label, color): rgb = pymui.c_ULONG.ArrayType(3)(*tuple( int(x * 255) * 0x01010101 for x in color[:3])) field = pymui.Colorfield(CycleChain=True, InputMode='RelVerify', Frame='ImageButton', FixWidth=64, RGB=rgb) cadj = pymui.Coloradjust(CycleChain=True, RGB=rgb) bt = pymui.SimpleButton(_T("Close"), CycleChain=True) grp = pymui.VGroup(Frame='Group') grp.AddChild(cadj) grp.AddChild(bt) popup = pymui.Popobject(Button=field, Object=grp) alpha = pymui.Numericbutton(CycleChain=True, Min=0, Max=100, Default=100, Value=int(color[3] * 100), Format="%lu%%", ShortHelp=_T("Transparency level")) cadj.Notify('RGB', lambda evt: field.SetAttr('RGB', evt.value)) bt.Notify('Pressed', lambda evt: popup.Close(0), when=False) parent.AddChild(pymui.Label(_T(label) + ':')) parent.AddChild(popup) parent.AddChild(alpha) return field, alpha
class BrushStrokeModal(ModalContext): NAME = 'Brush Stroke' def setup(self, event): vp = self.viewport vp.lock_focus() vp.enable_motion_events() vp.show_brush_cursor(False) vp.docproxy.draw_start(vp.device) def cleanup(self, event): vp = self.viewport vp.docproxy.draw_end() vp.unlock_focus() # User trigged Actions # @action(_T('draw at cursor')) def draw(self, event): self.viewport.docproxy.record(self.viewport.get_device_state(event)) @action(_T('set erase mode')) def set_erase_mode(self, event): self.docproxy.drawbrush.set_erase(0.0) @action(_T('unset erase mode')) def unset_erase_mode(self, event): self.docproxy.drawbrush.set_erase(1.0)
def __init__(self, min, max, default=None, cb=None, cb_args=(), islog=False, **kwds): super(FloatValue, self).__init__(Horiz=True, **kwds) if default is None: default = min assert min < max and min <= default and max >= default self.islog = islog self._min = min self._max = max self._range = (max - min)/1000. self._default = default self._cb = cb self._cb_args = cb_args self._value = pymui.String(MaxLen=7, Accept="0123456789.", Format='r', FixWidthTxt="-##.###", Frame='String', Background=None, CycleChain=True) self._value.Notify('Acknowledge', self.OnStringValue) self._slider = FloatSlider(self._min, self._range, islog) self._slider.Notify('Value', self.OnSliderValue) self.AddChild(self._value, self._slider) reset = pymui.SimpleButton(_T('R'), ShortHelp=_T('Reset value'), CycleChain=True, Weight=0) self.AddChild(reset) reset.Notify('Pressed', lambda *a: self.SetDefault()) del self.value
class ModalContext(Context): def on_confirm(ctx, event): pass # User trigged Actions # @action(_T('confirm')) def confirm(ctx, event): try: ctx.viewport.get_device_state(event) cmd = ctx.on_confirm(event) finally: newctx = ctx.exit_context() if cmd in ALL_COMMANDS: res = ALL_COMMANDS[cmd](view.app.ctx) if res: # TODO: horrible trick! change me soon! ctx.enter_context(res)._set_parent(newctx) @action(_T('cancel')) def cancel(ctx, event): ctx.exit_context() @action(_T('eat event')) def eat_event(self, event): pass
def __init__(self): super(AssignICCWindow, self).__init__(_T("Assign Profile"), CloseOnReq=True) self._profiles = profile.Profile.get_all() top = pymui.VGroup() self.RootObject = top self._radio_grp = pymui.VGroup(GroupTitle=_T("Assign Profile") + ':') self._cb = pymui.Cycle(map(str, self._profiles), CycleChain=True, Disabled=True) self._cb.Notify('Active', self._on_profile_active) self._radio_grp.AddTail(self._cb) top.AddChild(self._radio_grp) top.AddChild(pymui.HBar(0)) grp = pymui.HGroup() top.AddChild(grp) grp.AddChild(pymui.HSpace(0)) bt = pymui.SimpleButton(_T("Assign"), CycleChain=True) grp.AddChild(bt)
def __init__(self): super(AboutWindow, self).__init__('GB3 - ' + _T('About'), ID=0, # no position remembering Position=('centered', 'centered'), CloseOnReq=True) root = pymui.VGroup() self.RootObject = root top = pymui.HGroup() root.AddChild(top) root.AddChild(pymui.HBar(0)) okbt = pymui.SimpleButton(_T('Ok')) okbt.Notify('Pressed', lambda *a: self.CloseWindow(), when=False) root.AddChild(pymui.HCenter(okbt)) top.AddChild(pymui.Dtpic('PROGDIR:data/internal/app_logo.png', InnerLeft=6, InnerRight=6)) top.AddChild(pymui.Text(about_msg.safe_substitute(base=BASE, description=DESCRIPTION, version=main.VERSION, build=main.BUILD, date=main.DATE, copyright=COPYRIGHT), Frame='Text'))
def _on_doc_save_result(self, docproxy, result, err=None): if not result: msg = "%s:\n'%s'\n\n%s:\n\n%s" % (_T("Failed to save document"), docproxy.docname, _T("Reason"), err) self.show_error_dialog(msg) else: self.show_info_dialog(_T("Document saved"))
def confirm_close(self): "Request user confirmation to close the window." return pymui.DoRequest(pymui.GetApp(), gadgets=_T("_Yes|*_No"), title=_T("Need confirmation"), format=_T("This window contains modified" "and not yet saved work\n" "Are you sure to close it?"))
class ApplicationCtx(Context): NAME = 'Application' @action(_T('new-document')) def undo(self, event): self.app.mediator.new_document() @action(_T('load-document')) def undo(self, event): self.app.mediator.load_document()
def __init__(self, name): super(LayerMgr, self).__init__(ID='LayerMgr', Title=name, CloseOnReq=True) self.name = name self.__layctrllist = [] self._active = None top = pymui.VGroup() self.RootObject = top self.layctrl_grp = pymui.VGroupV(Frame='Virtual', Spacing=VIRT_GROUP_SPACING) self.__space = pymui.VSpace(0) self.layctrl_grp.AddTail(self.__space) # Layer info group layerinfo = pymui.ColGroup(2) layerinfo.AddChild(pymui.Label(_T("Blending") + ':')) self.blending = pymui.Cycle(model.Layer.OPERATORS_LIST, CycleChain=True, ShortHelp=_T("Set layer's blending mode")) layerinfo.AddChild(self.blending) layerinfo.AddChild(pymui.Label(_T("Opacity") + ':')) self.opacity = pymui.Slider(Value=100, Format='%u%%', CycleChain=True, ShortHelp=_T("Set layer's opacity value")) layerinfo.AddChild(self.opacity) # Layer management buttons btn_grp = pymui.ColGroup(4) self.btn = {} for name, label in [ ('add', 'Add'), ('del', 'Del'), ('dup', 'Copy'), ('merge', 'Merge'), ('up', 'Up'), ('down', 'Down'), ('top', 'Top'), ('bottom', 'Bottom'), ]: o = self.btn[name] = pymui.SimpleButton(label) btn_grp.AddChild(o) sc_gp = pymui.Scrollgroup(Contents=self.layctrl_grp, FreeHoriz=False) self.__vertbar = sc_gp.VertBar.object top.AddChild(sc_gp) top.AddChild(pymui.HBar(0)) top.AddChild(layerinfo) top.AddChild(pymui.HBar(0)) top.AddChild(pymui.HCenter(btn_grp))
def __init__(self, docproxy, parent=None): super(AssignCMSDialog, self).__init__(_T("Assign Profile"), parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) self._bt = [] self._current = docproxy.profile self._profiles = Profile.get_all() frame = gtk.Frame(_T("Assign Profile") + ':') self.vbox.pack_start(frame, False, False) vbox = gtk.VBox() frame.add(vbox) # Nothing bt1 = gtk.RadioButton(None, _T("No color management on this document")) self._bt.append(bt1) vbox.pack_start(bt1, False, False) # Current if docproxy.profile: bt2 = gtk.RadioButton(bt1, _T("Working") + ': %s' % docproxy.profile) bt2.set_active() self._bt.append(bt2) vbox.pack_start(bt2, False, False) else: self._bt.append(None) # New one bt3 = gtk.RadioButton(bt1, _T("Profile") + ': ') self._bt.append(bt3) cb = gtk.combo_box_new_text() for profile in self._profiles: cb.append_text(str(profile)) cb.set_active(0) self._cb = cb hbox = gtk.HBox() hbox.pack_start(bt3, False, False) hbox.pack_start(cb) vbox.pack_start(hbox, False, False) self.show_all()
class PickModal(ModalContext): NAME = 'Pick Mode' def __init__(self, **kwds): super(PickModal, self).__init__(**kwds) def setup(self, event): vp = self.viewport vp.enable_motion_events() vp.show_brush_cursor(True) vp.pick_mode(True) def cleanup(self, event): self.viewport.pick_mode(False) def on_confirm(self, event): color = self.viewport.get_exact_color(*event.get_cursor_position()) if color: self.docproxy.set_brush_color_rgb(*color) # User trigged Actions # @action(_T('move brush cursor')) def move_cursor(self, event): self.viewport.repaint_cursor(*event.get_cursor_position())
class HandlerModal(ModalContext): NAME = 'Handler' def setup(self, event): assert hasattr(self, 'handler') vp = self.viewport vp.lock_focus() vp.enable_motion_events() vp.show_brush_cursor(False) def cleanup(self, event): self.viewport.unlock_focus() # User trigged Actions # @action(_T('cursor move')) def cursor_move(self, event): hl = self.handler tool = hl.tool tool.move_handler(hl, *event.get_cursor_position()) # Clear old and draw new position self.viewport.repaint_tools(tool.area, redraw=True) self.viewport.repaint_tools(tool.area, redraw=True)
def open_document(self, filename): vo = model.vo.FileDocumentConfigVO(filename) try: docproxy = model.DocumentProxy.new_doc(vo) except IOError: self.show_error_dialog(_T("Can't open file:\n%s" % filename)) self.drawingroot_mediator.add_docproxy(docproxy)
def _do_page_inputs(self, reg): self._event_types = map(str, contexts.ALL_EVENT_TYPES) top = self._grp_inputs = pymui.HGroup() reg.AddChild(self._grp_inputs) # List of contexts self._ctx_names = sorted(contexts.ALL_CONTEXTS.keys()) self._list_ctx = o = pymui.List(Title=pymui.MUIX_B + _T('Contexts'), SourceArray=self._ctx_names, Frame='ReadList', CycleChain=True, AdjustWidth=True) top.AddChild(pymui.Listview(List=o, Input=False)) # List of currents bindings g = pymui.VGroup(GroupTitle=pymui.MUIX_B + _T('Bindings on selected context')) top.AddChild(g) self._bt_new = pymui.SimpleButton(_T('Add binding'), CycleChain=True) g.AddChild(self._bt_new) self._ctx_page_grp = pymui.VGroup(PageMode=True) g.AddChild(self._ctx_page_grp) self._ctx_pages = {} def add_ctx_page(name): page = pymui.VGroup(GroupTitle=name) page.vg = pymui.VGroupV() page.vg.AddChild(pymui.HVSpace()) page.vgp = pymui.Scrollgroup(Contents=page.vg, FreeHoriz=False) page.ctx = contexts.ALL_CONTEXTS[name] page.bindings = {} page.AddChild(page.vgp) self._ctx_page_grp.AddChild(page) self._ctx_pages[name] = page for name in self._ctx_names: add_ctx_page(name) # Notifications self._list_ctx.Notify('Active', self._on_ctx_active) self._bt_new.Notify('Pressed', self._on_new_bind, when=False)
def vp_insert_layer(ctx): dp = ctx.active_viewport.docproxy doc = dp.document vo = model.vo.GenericVO(docproxy=dp, pos=doc.index(doc.active)+1, layer=None, name=_T("untitled")) dp.sendNotification(main.DOC_LAYER_ADD, vo)
class RotateLayerModal(ModalContext): NAME = 'Rotate Layer' def __init__(self, **kwds): super(RotateLayerModal, self).__init__(**kwds) self._text = tools.Text() self._rot = tools.Rotate() def setup(self, event): vp = self.viewport vp.lock_focus() vp.enable_motion_events() vp.show_brush_cursor(False) self._old_mat = cairo.Matrix(*self.docproxy.document.active.matrix) pos = vp.width/2, vp.height/2 pos = vp.get_model_point(*pos) self._ro = vp.docproxy.get_layer_pos(*pos) self._angle = 0. self._rot.set_cursor_pos(vp.device.current.cpos) self._text.set_text("Angle: 0") vp.add_tool(self._rot) vp.add_tool(self._text) vp.enable_fast_filter() def cleanup(self, event): vp = self.viewport vp.unlock_focus() vp.rem_tool(self._rot) vp.rem_tool(self._text) # Force fine display vp.enable_fast_filter(False) vp.repaint() def on_confirm(self, event): docproxy = self.viewport.docproxy layer = docproxy.active_layer docproxy.record_layer_matrix(layer, self._old_mat) # User trigged Actions # @action(_T('rotate Layer')) def rotate_Layer(self, event): vp = self.viewport self._rot.set_cursor_pos(event.get_cursor_position()) self._text.set_text("Angle: %u" % math.degrees(self._angle)) # update display vp.repaint_tools(self._text.area, redraw=True) vp.repaint_tools(self._rot.area, redraw=True) vp.docproxy.layer_rotate(-self._rot.dr, *self._ro) self._angle = (self._angle + self._rot.dr) % (2*math.pi)
def __init__(self): super(Application, self).__init__( Title = "Gribouillis", Version = "$VER: Gribouillis %s.%d (%s)" % (main.VERSION, main.BUILD, main.DATE), Copyright = COPYRIGHT, Author = "Guillaume ROGUEZ", Description = DESCRIPTION, Base = BASE, Menustrip = self._create_menustrip()) self.fullscreen_win = FullscreenDocWindow() self.AddChild(self.fullscreen_win) self.windows = dwin = {} dwin['LayerMgr'] = LayerMgr(_T("Layer Manager")) dwin['CmdHist'] = CommandsHistoryList(_T("Commands History")) dwin['ColorMgr'] = ColorHarmoniesWindow(_T("Color Manager")) dwin['BrushEditor'] = BrushEditorWindow(_T("Brush Editor")) dwin['BrushHouse'] = BrushHouseWindow(_T("Brush House")) #self.cms_assign_win = AssignICCWindow() #self.cms_conv_win = ConvertICCWindow() dwin['Splash'] = Splash(_T("Splash")) dwin['About'] = AboutWindow() dwin['DocInfo'] = DocInfoWindow(_T("Document Information")) # List of window that can be automatically open at startup self.startup_windows = ['LayerMgr', 'CmdHist', 'ColorMgr', 'BrushEditor', 'BrushHouse', 'Splash'] # Should be created after startup-open-window list #self.appprefwin = AppPrefWindow() for win in dwin.itervalues(): self.AddChild(win)
class DocumentCtx(Context): NAME = 'Document' # User trigged Actions # @action(_T('save-document')) def save_document(self, event): self.app.mediator.save_document() @action(_T('save-as-document')) def save_as_document(self, event): self.app.mediator.save_as_document() @action(_T('undo')) def undo(self, event): self.docproxy.sendNotification(main.UNDO) @action(_T('redo')) def redo(self, event): self.docproxy.sendNotification(main.REDO) @action(_T('lighten brush color of 10%')) def color_lighten(self, event): self.docproxy.multiply_color(1.0, 1.0, 1.1) @action(_T('darken brush color of 10%')) def color_darken(self, event): self.docproxy.multiply_color(1.0, 1.0, 0.9) @action(_T('saturate brush color of 10%')) def color_saturate(self, event): self.docproxy.multiply_color(1.0, 1.1, 1.0) @action(_T('desaturate brush color of 10%')) def color_desaturate(self, event): self.docproxy.multiply_color(1.0, 0.9, 1.0) @action(_T('clear active layer')) def clear_active_layer(self, event): self.docproxy.clear_layer(self.docproxy.active_layer) @action(_T('toggle rulers visibility')) def toggle_rulers(self, event): self.window.toggle_rulers()
def __init__(self): super(ConvertICCWindow, self).__init__(_T("Convert to Profile"), CloseOnReq=True) self._profiles = profile.Profile.get_all() top = pymui.VGroup() self.RootObject = top grp = pymui.VGroup(GroupTitle=_T("Source") + ':') top.AddChild(grp) self._cur_label = pymui.Text() grp.AddChild(self._cur_label) grp = pymui.VGroup(GroupTitle=_T("Destination") + ':') top.AddChild(grp) hgrp = pymui.HGroup() grp.AddChild(hgrp) hgrp.AddChild(pymui.Text(_T("Profile") + ': ')) self._pro_cycle = pymui.Cycle(map(str, self._profiles), CycleChain=True) hgrp.AddTail(self._pro_cycle) grp = pymui.VGroup(GroupTitle=_T("Options") + ':') top.AddChild(grp) self._intents = profile.INTENTS.keys() cycle = pymui.Cycle(self._intents) cycle.Notify('Active', self._on_intent_active) hgrp = pymui.HGroup() grp.AddChild(hgrp) hgrp.AddChild(pymui.Text(_T("Intent") + ': ')) hgrp.AddChild(cycle) """ bt1 = gtk.CheckButton(_T("Use Black Point Compensation")+': ') bt2 = gtk.CheckButton(_T("Use Dither")+': ') bt3 = gtk.CheckButton(_T("Flatten Image")+': ') if len(docproxy.document.layers) == 1: bt3.set_sensitive(False) vbox.pack_start(bt1) vbox.pack_start(bt2) vbox.pack_start(bt3) self.show_all() """ top.AddChild(pymui.HBar(0)) grp = pymui.HGroup() top.AddChild(grp) grp.AddChild(pymui.HSpace(0)) bt = pymui.SimpleButton(_T("Convert"), CycleChain=True) grp.AddChild(bt)
def confirm_close(self): dlg = gtk.Dialog(_T("Sure?"), self, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_YES, gtk.RESPONSE_OK, gtk.STOCK_NO, gtk.RESPONSE_CANCEL)) dlg.set_default_response(gtk.RESPONSE_CANCEL) response = dlg.run() dlg.destroy() return response == gtk.RESPONSE_OK
def new_document(self, *a): vo = model.vo.EmptyDocumentConfigVO() if self.viewComponent.get_new_document_type(vo): try: docproxy = model.DocumentProxy.new_doc(vo) except: self.show_error_dialog(_T("Failed to create document")) self.drawingroot_mediator.add_docproxy(docproxy)
def copy_layer(self, layer, pos=None): if pos is None: pos = self.data.get_layer_index(layer) + 1 new_layer = self.data.new_layer(_T('Copy of %s') % layer.name, pos) new_layer.copy(layer) self.sendNotification( main.DOC_LAYER_ADDED, (self, new_layer, self.data.get_layer_index(layer))) return new_layer
def _do_page_misc(self, reg): top = pymui.VGroup() reg.AddChild(pymui.HCenter(pymui.VCenter(top))) grp = pymui.ColGroup(2, GroupTitle=_T("Interface")) grp.AddChild(pymui.Label(_T("Windows to open at startup") + ':', )) box = pymui.ColGroup(2, Frame='Group') self._startup_win_bt = {} win_list = prefs['pymui-window-open-at-startup'] d = pymui.GetApp().startup_windows for key in sorted(d.keys(), cmp=lambda x, y: cmp(d[x].name, d[y].name)): bt = self._startup_win_bt[key] = pymui.CheckMark(key in win_list, CycleChain=True) box.AddChild(bt) box.AddChild(pymui.Label(pymui.MUIX_L + d[key].name)) grp.AddChild(box) top.AddChild(grp)
def _do_page_calibration(self, reg): top = pymui.VGroup() reg.AddChild(pymui.HCenter(pymui.VCenter(top))) # Contents automatically controled by the CalibrationBar object cal_result_x = pymui.String(Frame='String', Accept="0123456789.", FixWidthTxt="######", Format=pymui.MUIV_String_Format_Right, CycleChain=True) cal_result_y = pymui.String(Frame='String', Accept="0123456789.", FixWidthTxt="######", Format=pymui.MUIV_String_Format_Right, CycleChain=True) self.cal_bar_x = CalibrationBar(prefs['view-metrics-x'], cal_result_x, horiz=True, ShortHelp=_T(cal_text)) self.cal_bar_y = CalibrationBar(prefs['view-metrics-y'], cal_result_y, horiz=False, ShortHelp=_T(cal_text)) self.cal_unit = pymui.Cycle(CALIBRATION_UNITS, Active=CALIBRATION_UNITS.index( prefs['view-metrics-unit']), CycleChain=True) grp = pymui.ColGroup( 2, Frame='Group', Child=(pymui.Label(_T("Calibration unit") + ':'), self.cal_unit, pymui.Label(_T("Horizontal axis") + ':'), cal_result_x, pymui.Label(_T("Vertical axis") + ':'), cal_result_y)) top.AddChild(self.cal_bar_x) top.AddChild(pymui.HGroup(Child=(self.cal_bar_y, pymui.HCenter(grp)))) def callback(evt, wd): wd.value = evt.value.contents cal_result_x.Notify('Acknowledge', callback, self.cal_bar_x) cal_result_y.Notify('Acknowledge', callback, self.cal_bar_y)
class DragLayerModal(ModalContext): NAME = 'Drag Layer' def __init__(self, **kwds): super(DragLayerModal, self).__init__(**kwds) self._text = tools.Text() def setup(self, event): vp = self.viewport vp.lock_focus() vp.enable_motion_events() vp.show_brush_cursor(False) self._old_mat = cairo.Matrix(*self.docproxy.document.active.matrix) self._cpos = vp.device.current.cpos self._x = 0 self._y = 0 self._text.set_text("Dx=%-4u, Dy=%-4u" % (0,0)) vp.add_tool(self._text) vp.enable_fast_filter() def cleanup(self, event): vp = self.viewport vp.unlock_focus() vp.rem_tool(self._text) vp.enable_fast_filter(False) vp.repaint() def on_confirm(self, event): docproxy = self.viewport.docproxy layer = docproxy.active_layer docproxy.record_layer_matrix(layer, self._old_mat) # User trigged Actions # @action(_T('drag layer')) def drag_layer(self, event): vp = self.viewport tool = self._text # Compute cursor delta's cpos = event.get_cursor_position() dx = cpos[0] - self._cpos[0] dy = cpos[1] - self._cpos[1] self._x += dx self._y += dy self._cpos = cpos # update display tool.set_text("Dx=%-4u, Dy=%-4u" % (self._x, self._y)) vp.repaint_tools(tool.area, redraw=True) vp.docproxy.layer_translate(*vp.get_model_distance(dx, dy))
def get_new_document_type(self, vo, parent=None): """Open a dialog window to ask document type to user. The given DocumentVO is modified accordingly. """ dlg = gtk.Dialog(_T("New Document"), parent, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_NEW, gtk.RESPONSE_OK)) # Document name hbox = gtk.HBox() dlg.vbox.pack_start(hbox) hbox.pack_start(gtk.Label(_T("Document name:"))) name = gtk.Entry() hbox.pack_start(name) name.set_text(vo.name) hbox.show_all() # ComboBox combo = gtk.combo_box_new_text() dlg.vbox.pack_start(combo) # Add entries combo.append_text(_T("Select document type:")) for text in ['RGB']: combo.append_text(text) combo.set_active(0) combo.show() # run and check response response = dlg.run() if (response == gtk.RESPONSE_OK) and (combo.get_active() > 0): vo.name = name.get_text() vo.colorspace = combo.get_active_text() else: vo = None dlg.destroy() return vo
def _on_sv_pal_pressed(self, evt): filename = pymui.GetApp().get_filename(_T('Select palette filename for saving'), parent=self, pat=PAL_PAT, read=False) if filename: palette = model.Palette(os.path.splitext(os.path.basename(filename))[0]) for i, bt in enumerate(self._pal_bt): if bt.rgb is not None: palette[i].rgb = bt.rgb try: palette.savetofile(filename) except NotImplementedError: pymui.DoRequest(app=pymui.GetApp(), title="Error", format="Unkown palette file type", gadgets='*_Ok')
def new_entry(label, idx): icons_path = resolve_path(prefs['view-icons-path']) def get_icons(off): icons = pymui.ColGroup(4, Frame='Group') for name in sorted(contexts.ICONS.keys()): obj = pymui.Dtpic(Name=os.path.join( icons_path, name + '.png'), InputMode='RelVerify', LightenOnMouse=True) icons.AddChild(obj) obj.Notify('Pressed', self._on_popup_icon_sel, when=False, name=name, idx=idx, off=off) return icons colg.AddChild(pymui.Label(label + ':')) icons_names = prefs['view-icons-names'] bt = pymui.Dtpic(Name=os.path.join(icons_path, icons_names[idx] + '.png'), Frame='ImageButton', InputMode='RelVerify') popup = pymui.Popobject(Button=bt, Object=get_icons(0), Light=True) popup.name = icons_names[idx] colg.AddChild(popup) self._popup[idx] = popup bt = pymui.Dtpic(Name=os.path.join(icons_path, icons_names[8 + idx] + '.png'), Frame='ImageButton', InputMode='RelVerify') popup = pymui.Popobject(Button=bt, Object=get_icons(8), Light=True) popup.name = icons_names[8 + idx] colg.AddChild(popup) self._popup[8 + idx] = popup string = pymui.String( Frame='String', CycleChain=True, Contents=prefs['view-toolswheel-binding'][idx] or '', ShortHelp=_T("Command to execute when tool region selected")) self._toolswheel_strings[idx] = string popup = pymui.Poplist(Array=all_commands, String=string, Button=pymui.Image(Frame='ImageButton', Spec=pymui.MUII_PopUp, InputMode='RelVerify')) colg.AddChild(popup)
class LastColorModal(ModalContext): NAME = 'Last Colors Selector' _colors = [ None ] * 8 def __init__(self, **kwds): super(LastColorModal, self).__init__(**kwds) self._tool = tools.ColorWheel() self.push_color(self.viewport.docproxy.get_brush_color_rgb()) @classmethod def push_color(cl, rgb): if rgb != cl._colors[0]: cl._colors.insert(0, rgb) cl._colors.pop(-1) def setup(self, event): vp = self.viewport vp.enable_motion_events() vp.show_brush_cursor(False) self._tool.set_colors(self._colors) self._tool.set_center(vp.device.current.cpos) vp.add_tool(self._tool) def cleanup(self, event): self.viewport.rem_tool(self._tool) def on_confirm(self, event): i = self._tool.selection if i >= 0: # Slice the historic and put the selected color as first rgb = self._colors.pop(i) self._colors.insert(0, rgb) self.viewport.docproxy.set_brush_color_rgb(*rgb) # User trigged Actions # @action(_T('check cursor position')) def check_cursor(self, event): vp = self.viewport cpos = event.get_cursor_position() if vp.is_tool_hit(self._tool, *cpos): # TODO: CPU eating when pen used self._tool.cpos = cpos elif self._tool.cpos: self._tool.cpos = None else: return vp.repaint_tools(self._tool.area) vp.redraw(self._tool.area)