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
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)
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)
def __init__(self, name): super(BrushEditorWindow, self).__init__(name, ID='BEW', Width=320, Height=100, CloseOnReq=True) self.name = name # UI self.RootObject = topbox = pymui.VGroup() self.AddChild(topbox) # Brush preview self.bprev = BrushPreview() topbox.AddChild(self.bprev) self.namebt = pymui.String(Frame='String', CycleChain=True) topbox.AddChild(pymui.HGroup(Child=[pymui.Label(_T('Name')+':'), self.namebt ])) topbox.AddChild(pymui.HBar(2)) # Brush parameters table = pymui.ColGroup(2) topbox.AddChild(table) self.prop = {} self.prop['radius_min'] = self._add_slider(table, 'radius_min', -2, 5, 3, .1, .5, islog=True) self.prop['radius_max'] = self._add_slider(table, 'radius_max', -2, 5, 3, .1, .5, islog=True) self.prop['yratio'] = self._add_slider(table, 'yratio', 1.0, 32., 1., 0.1, 2) self.prop['angle'] = self._add_slider(table, 'angle', -180., 180.0, 0.0, 0.5, 1) self.prop['spacing'] = self._add_slider(table, 'spacing', 0.01, 4.0, 0.25, .01, 0.1) self.prop['opacity_min'] = self._add_slider(table, 'opacity_min', 0, 1, 1, 1/255., 10/255.) self.prop['opacity_max'] = self._add_slider(table, 'opacity_max', 0, 1, 1, 1/255., 10/255.) self.prop['opa_comp'] = self._add_slider(table, 'opa_comp', 0, 2, .9, 0.01, 0.1) self.prop['hardness'] = self._add_slider(table, 'hardness', 0, 1, 1, .01, 0.1) self.prop['erase'] = self._add_slider(table, 'erase', 0, 1, 1, .01, 0.1) self.prop['grain'] = self._add_slider(table, 'grain', 0, 1, 1, .01, 0.1) self.prop['motion_track'] = self._add_slider(table, 'motion_track', 0.0, 2.0, 1.0, .1, 1) self.prop['hi_speed_track'] = self._add_slider(table, 'hi_speed_track', 0.0, 2.0, 0.0, .01, 0.1) self.prop['smudge'] = self._add_slider(table, 'smudge', 0, 1, 0, .01, 0.1) self.prop['smudge_var'] = self._add_slider(table, 'smudge_var', 0, 1, 0, .01, 0.1) self.prop['color_shift_h'] = self._add_slider(table, 'color_shift_h', -.1, .1, 0, .01, 0.1) self.prop['color_shift_s'] = self._add_slider(table, 'color_shift_s', -.1, .1, 0, .01, 0.1) self.prop['color_shift_v'] = self._add_slider(table, 'color_shift_v', -.1, .1, 0, .01, 0.1) self.prop['dab_radius_jitter'] = self._add_slider(table, 'dab_radius_jitter', 0.0, 1.0, 0.0, .01, 0.1) self.prop['dab_pos_jitter'] = self._add_slider(table, 'dab_pos_jitter', 0.0, 5.0, 0.0, .01, 0.1) self.prop['direction_jitter'] = self._add_slider(table, 'direction_jitter', 0.0, 1.0, 0.0, .01, 0.1) self.prop['alpha_lock'] = self._add_slider(table, 'alpha_lock', 0.0, 1.0, 0.0, 1.0, 1.0) self.Title = 'Brush Editor' # overwritten by mediator self.on_value_changed_cb = utils.idle_cb
def add_bind(self, page, **extras): # Delete bind button del_bt = pymui.Image(Frame='ImageButton', Spec=pymui.MUII_Close, InputMode='RelVerify', ShortHelp=_T("Remove this binding.")) # Event type cycle event_type = pymui.Cycle(self._event_types, Weight=0, CycleChain=True, ShortHelp=_T("Event type to listen to.")) # Key adjustment (disabled by default) key_adj = pymui.Keyadjust( AllowMouseEvents=True, AllowMultipleKeys=False, Disabled=True, CycleChain=True, ShortHelp=_T("Key that trigs the specified action.")) # Any toggle button any_bt = pymui.CheckMark( CycleChain=True, ShortHelp=_T( "Doesn't take care of any modificators when key is pressed to trig the action." )) # Repeat toggle button repeat_bt = pymui.CheckMark( CycleChain=True, InnerRight=4, ShortHelp=_T( "If selected, only the first occurance of an event is used, repeated ones are discarded." )) class Bind: def __init__(self, key_adj, event_type, any_bt, repeat_bt, action_str): self.key_adj = key_adj self.event_type = event_type self.any_bt = any_bt self.repeat_bt = repeat_bt self.action_str = action_str @property def data(self): # Convert MUI gadgets states into binding prefs data evtcl = contexts.ALL_EVENT_TYPES[self.event_type.Active.value] key = self.key_adj.Contents.contents.strip() any = self.any_bt.Selected.value repeat = self.repeat_bt.Selected.value action = page.ctx.AVAIL_ACTIONS.get( self.action_str.Contents.contents) if action: return dict(evtcl=evtcl, action=action, key=key, any=any, repeat=repeat) str_action = pymui.String( Frame='String', CycleChain=True, ShortHelp=_T( "Action to execute.\nAvailable actions depend on current context." )) action_popup = pymui.Poplist(Array=page.ctx.AVAIL_ACTION_NAMES, Button=pymui.Image(Frame='ImageButton', Spec=pymui.MUII_PopUp, InputMode='RelVerify'), String=str_action) bind = Bind(key_adj, event_type, any_bt, repeat_bt, str_action) page.vgp.InitChange() try: grp = pymui.HGroup(Child=[ del_bt, pymui.Label(_T('Action') + ':'), action_popup, pymui.Label(_T('When') + ':'), event_type, pymui.Label(_T('Key') + ':'), key_adj, pymui.Label(_T('Any') + ':'), any_bt, pymui.Label(_T('Repeat') + ':'), repeat_bt ], SameHeight=True) page.vg.AddChild(grp, lock=True) page.vg.MoveMember( grp, -2) # MUI magic to replace the space at the bottom finally: page.vgp.ExitChange() page.bindings[grp] = bind event_type.Notify('Active', self._on_evt_active, key_adj) del_bt.Notify('Pressed', self._on_del_bind, page, grp, when=False) any_bt.Notify('Selected', self._on_any_bt, key_adj) if extras: event_type.Active = self._event_types.index( extras.get('evtcl', 0).NAME) key_adj.Contents = extras.get('key', '') any_bt.Selected = extras.get('any', False) repeat_bt.Selected = extras.get('repeat', False) str_action.Contents = extras.get('action', '')._act_name
def __init__(self, name): super(BrushHouseWindow, self).__init__(name, ID='BRHO', LeftEdge=0, TopDeltaEdge=0, CloseOnReq=True) self.name = name self._brushes = set() self._all = None self._current = None self._pages = [] self._drawbrush = DrawableBrush() # used for preview # UI self._top = topbox = self.RootObject = pymui.VGroup() # Brush context menu self._brushmenustrip = pymui.Menustrip() menu = pymui.Menu(_T('Brush actions')) self._brushmenustrip.AddTail(menu) self._menuitems = {} for k, text in [('use-preview-icon', _T('Use preview icon')), ('use-image-icon', _T('Use image icon')), ('change-icon', _T('Change image icon...')), ('as-eraser', _T('As eraser brush...')), ('dup', _T('Duplicate')), ('delete', _T('Delete'))]: o = self._menuitems[k] = pymui.Menuitem(text) menu.AddChild(o) # Pages controls box = pymui.HGroup() topbox.AddChild(box) bt = pymui.SimpleButton(_T('New page'), Weight=0) box.AddChild(bt) bt.Notify('Pressed', self._on_add_page, when=False) bt = self._del_page_bt = pymui.SimpleButton(_T('Delete page'), Weight=0, Disabled=True) box.AddChild(bt) bt.Notify('Pressed', self._on_del_page, when=False) bt = pymui.SimpleButton(_T('New brush'), Weight=0) box.AddChild(bt) bt.Notify('Pressed', self._on_new_brush, when=False) bt = pymui.SimpleButton(_T('Save all'), Weight=0) box.AddChild(bt) bt.Notify('Pressed', self._on_save_all, when=False) box.AddChild(pymui.HSpace(0)) # Notebook nb = self._nb = pymui.VGroup(Frame='Register', PageMode=True, Background='RegisterBack', CycleChain=True, muiargs=[(MUIA_Group_PageMax, False)]) self._titles = pymui.Title(Closable=False, Newable=False) nb.AddChild(self._titles) nb.Notify('ActivePage', self._on_active_page) topbox.AddChild(nb) self._pagenamebt = pymui.String(Frame='String', Background='StringBack', Disabled=True, CycleChain=True) self._pagenamebt.Notify('Acknowledge', lambda ev, v: self._change_page_name(v), pymui.MUIV_TriggerValue) self._brushnamebt = pymui.Text(Frame='String', PreParse=pymui.MUIX_C) grp = pymui.HGroup(Child=[ pymui.Label(_T('Page name') + ':'), self._pagenamebt, pymui.Label(_T('Active brush') + ':'), self._brushnamebt ]) topbox.AddChild(grp) # Add the 'All brushes' page self._all = self.add_page(_T('All brushes'), close=False) self._del_page_bt.Disable = True if len(self._brushes) == 1: self._menuitems['delete'].Enabled = False
def __init__(self, name): super(DocInfoWindow, self).__init__(name, ID='INFO', CloseOnReq=True) self.name = name top = pymui.VGroup() self.RootObject = top # Document name name = pymui.Text(Frame='Text') top.AddChild(name) # Dimensions dim_grp = pymui.VGroup(GroupTitle=_T("Dimensions")) use_full_bt = pymui.SimpleButton(_T("No limits"), CycleChain=True) use_cur_bt = pymui.SimpleButton(_T("Set to current size"), CycleChain=True) ori_x = pymui.String(Frame='String', Accept="-0123456789", CycleChain=True) ori_y = pymui.String(Frame='String', Accept="-0123456789", CycleChain=True) size_x = pymui.String(Frame='String', Accept="-0123456789", CycleChain=True) size_y = pymui.String(Frame='String', Accept="-0123456789", CycleChain=True) box = pymui.ColGroup(2) box.AddChild(pymui.Label(_T("X Origin") + ':')) box.AddChild(ori_x) box.AddChild(pymui.Label(_T("Y Origin") + ':')) box.AddChild(ori_y) box.AddChild(pymui.Label(_T("Width") + ':')) box.AddChild(size_x) box.AddChild(pymui.Label(_T("Height") + ':')) box.AddChild(size_y) ori_x.Notify('Acknowledge', self._modify_dim, 0) ori_y.Notify('Acknowledge', self._modify_dim, 1) size_x.Notify('Acknowledge', self._modify_dim, 2) size_y.Notify('Acknowledge', self._modify_dim, 3) pp = pymui.Text(_T("Passe-Partout"), InputMode='Toggle', Frame='Button', Background='ButtonBack', PreParse=pymui.MUIX_C, Selected=False) pp.Notify('Selected', self._toggle_pp) dim_grp.AddChild(pp) dim_grp.AddChild(pymui.HGroup(Child=(use_full_bt, use_cur_bt))) dim_grp.AddChild(box) top.AddChild(dim_grp) def callback(evt): self.__docproxy.set_metadata(dimensions=None) use_full_bt.Notify('Pressed', callback, when=False) def callback(evt): _, _, w, h = area = self.__docproxy.document.area if not (w and h): area = None self.__docproxy.set_metadata(dimensions=area) use_cur_bt.Notify('Pressed', callback, when=False) # Density dpi_grp = pymui.VGroup(GroupTitle=_T("Density")) use_calib_bt = pymui.SimpleButton(_T("Set from calibration"), CycleChain=True) dpi_x = pymui.String(Frame='String', Accept="0123456789.", CycleChain=True) dpi_y = pymui.String(Frame='String', Accept="0123456789.", CycleChain=True) box = pymui.ColGroup(2) box.AddChild(pymui.Label(_T("X") + ':')) box.AddChild(dpi_x) box.AddChild(pymui.Label(_T("Y") + ':')) box.AddChild(dpi_y) dpi_grp.AddChild(use_calib_bt) dpi_grp.AddChild(box) top.AddChild(dpi_grp) def callback(evt): dpi_x = Ruler.METRICS['in'][2] dpi_y = Ruler.METRICS['in'][3] self.__docproxy.set_metadata(densities=[dpi_x, dpi_y]) use_calib_bt.Notify('Pressed', callback, when=False) self.widgets = { 'name': name, 'dpi-x': dpi_x, 'dpi-y': dpi_y, 'dim-x': size_x, 'dim-y': size_y, 'ori-x': ori_x, 'ori-y': ori_y, }
def __init__(self, layer, mediator): super(LayerCtrl, self).__init__(Horiz=True, Draggable=False, SameHeight=True) self._ev = pymui.EventHandler() self.mediator = mediator self.layer = layer #self.preview = LayerPreview() self.name = pymui.String(layer.name.encode('latin1', 'replace'), Frame='Button', Background='StringBack', CycleChain=True, FrameDynamic=True) self.name.ctrl = self image_path = os.path.join(resolve_path(prefs['view-icons-path']), "updown.png") handler = pymui.Dtpic( image_path, Frame='None', InputMode='RelVerify', ShowSelState=False, LightenOnMouse=True, ShortHelp=_T( "Click and drag this icon to re-order the layer in stack")) self.activeBt = pymui.Dtpic( self._get_active_image(0), Frame='None', InputMode='Toggle', Selected=False, ShowSelState=False, LightenOnMouse=True, ShortHelp=_T("Active layer has this checkmark selected.")) self.visBt = pymui.Dtpic( self._get_visible_image(layer.visible), Frame='None', InputMode='Toggle', Selected=layer.visible, ShowSelState=False, LightenOnMouse=True, ShortHelp=_T( "Layer visibility status.\nPress ALT key to toggle also all others layers" )) self.lockBt = pymui.Dtpic( self._get_lock_image(layer.locked), Frame='None', InputMode='Toggle', Selected=layer.locked, ShowSelState=False, LightenOnMouse=True, ShortHelp=_T( "Layer locked status (write protection).\nPress ALT key to toggle also all others layers" )) grp = pymui.HGroup(Child=(handler, self.activeBt, self.name, self.visBt, self.lockBt)) self.AddChild( pymui.HGroup(Child=[pymui.HSpace(6), grp, pymui.HSpace(6)])) handler.Notify('Pressed', lambda *a: self.DoDrag(0x80000000, 0x80000000, 0), when=True) self.activeBt.Notify('Selected', self._on_active_sel) self.visBt.Notify('Selected', self._on_visible_sel) self.lockBt.Notify('Selected', self._on_lock_sel)