class select(Event): # decorations simple_description = "event happens when this tab is selected" __unique_type_name__ = 'tabselect' # attributes oldtab = descriptors.str() newtab = descriptors.str()
class SelectByIDandType(_selectbyidandtype): # decorations simple_description = 'select an element by its ID and optionally its type' full_description = ( "This action selects an element using its ID and optionally its type. " "The constructed selector can be used to perform further " "actions on the selected element. Eg. selector.destory(). ") # attributes id = descriptors.str() type = descriptors.str() # for inspector def identify(self, inspector): return inspector.onSelectByIDandType(self)
class A(AttributeContainer): __unique_type_name__ = "A_test3" s1 = descriptors.str() pass
class Splitter(RivetedContainer): # decorators simple_description = 'A container of vertically or horizontally aligned sections' full_description = ( "A 'splitter' splits a space into sections vertically or horizontally. " "The orientation of the splitter is defined by its attribute 'orientation'. " ) examples = [ ''' # the follwoing code creates a splitter that is oriented horizontally and has 3 sections import luban splitter = luban.e.splitter(orientation='horizontal') left = splitter.section() middle = splitter.section() right = splitter.section() left.paragraph(text=['left']) middle.paragraph(text=['middle']) right.paragraph(text=['right']) ''', ] # properties orientation = descriptors.str(default='horizontal') orientation.validator = validators.choice(['vertical', 'horizontal']) orientation.tip = 'Orientation of the splitter' # methods # .. for inspector def identify(self, inspector): return inspector.onSplitter(self)
class A(AttributeContainer): __unique_type_name__ = "A_test1" # s = AttributeContainer.descriptors.str('a') s1 = descriptors.str() a2 = d.str() a1 = d.str() pass
class Alert(base): # decorations simple_description = 'an alert box with a message' full_description = '' # attributes message = descriptors.str() # methods def identify(self, inspector): return inspector.onAlert(self)
class GetAttr(ActionBase): # decorations # attributes entity = descriptors.object(dynamic=False) # entity the attribute is about name = descriptors.str() # name of the attribute def identify(self, inspector): return inspector.onGetAttr(self) pass # end of GetAttr
class Button(base): simple_description = 'A clickable button' full_description = ( 'A button is clickable. When clicked, an action will be triggered. ' 'A button has a label.') # attributes label = descriptors.str() label.tip = 'label of the button' # for inspector def identify(self, inspector): return inspector.onButton(self)
class HtmlDocument(SimpleElement): # decorators simple_description = 'A simple container of html text' full_description = ( 'A htmldocument widget can be used to display simple html-based content. ' 'It cannot handle complex html document with javascript, etc.') # properties text = descriptors.str() text.tip = 'Content of the html document' # for inspector def identify(self, inspector): return inspector.onHtmlDocument(self)
class Loading(base): # decorations simple_description = 'load from the UI controller' full_description = ( "A 'load' action loads from the UI controller. " "The loaded could be some simple data, a luban element, or an action." ) # attributes actor = descriptors.str() actor.tip = 'The actor that will handle this load action' routine = descriptors.str() routine.tip = 'The routine of the actor that will be called to handle this load action' args = descriptors.list() args.tip = "The arguments for the routine" params = descriptors.dict() params.tip = 'Addtional parameters as a dictionary' def __init__(self, actor=None, routine=None, *args, **params): '''load(actor, routine, **kwds) -> load from controller. The given routine of the given actor will be called with additional parameters specified in the keyword arguments. ''' super(Loading, self).__init__(actor=actor, routine=routine, args=args, params=params) return def identify(self, inspector): return inspector.onLoading(self)
class SimpleElementAction(base): # decorations # attributes actionname = descriptors.str() # name of the action params = descriptors.dict() # parameters of the action # overload ctor to provide better interface def __init__(self, element=None, actionname=None, **params): super().__init__(element=element, actionname=actionname, params=params) return def identify(self, inspector): return inspector.onSimpleElementAction(self)
class Paragraph(base): simple_description = 'a paragraph of text' full_description = '' examples = [ ''' from luban.ui import e as lue sometext = lue.paragraph(text=['text here']) ''', ] # attributes text = descriptors.str() text.tip = 'text in the paragraph' # for inspector def identify(self, inspector): return inspector.onParagraph(self)
class Frame(SimpleContainer): simple_description = "root node of a luban user interface hierarchy" full_description = ( 'Frame element is the root element of a luban user interface.' 'When a luban application starts up, an instance of Frame element' 'needs to be established.') # means no element can be a frame's parent parent_types = None # attributes title = descriptors.str() title.tip = 'Title of the frame' # for inspector def identify(self, inspector): return inspector.onFrame(self)
class SimpleAction(base): """simple actions that can be described by its name and its parameters """ # decorations # attributes actionname = descriptors.str() params = descriptors.dict() # methods def identify(self, inspector): return inspector.onSimpleAction(self) # overload ctor to provide better interface def __init__(self, actionname, **params): super().__init__(actionname=actionname, params=params) return
class Tab(_tabbase): # decorations simple_description = 'A tab in a "tabs" container' full_description = '' # parent_types = [Tabs] # attributes label = descriptors.str(default='tab') label.tip = 'label of this tab' selected = descriptors.bool() selected.tip = "whether this tab is selected or not. among siblings, only one can be selected" # events -- must have one-one correspondence with event handler from ..Event import Event class select(Event): # decorations simple_description = "event happens when this tab is selected" __unique_type_name__ = 'tabselect' # attributes oldtab = descriptors.str() newtab = descriptors.str() del Event # ************************************************************ # event handlers # event handlers will be automatically defined using event types # defined here (like "select" event above will cause a "onselect" # event handler automatically) # here is just an example in case one has to define a custom # event handler descriptor # onselect = descriptors.eventhandler() # happen when this tab got selected # onselect.tip = 'action when this tab is selected' # ************************************************************ # for inspector def identify(self, inspector): return inspector.onTab(self)
class ReStructuredTextDocument(SimpleElement): # decorations simple_description = 'A simple container of text in ReStructuredText format' full_description = ( 'A ReStructuredTextDocument widget can be used to display text' 'in ReStructuredText format. ' ) experimental = True # properties text = descriptors.str() text.tip = 'Content of the document' # methods # .. for inspector def identify(self, inspector): return inspector.onReStructuredTextDocument(self)
def test1(self): from luban.ui.descriptors import str s = str() # help(s) return
class Element(_base): """base class of all element types except null element """ simple_description = "base class of luban ui elements" # indicate this is abstract and cannot be instantiated abstract = True # what are the possible parent element types? # this is usually any element container types, but # special cases exist. see, for example, Frame and Tabs.Tab parent_types = 'any' # what are the possible child element types? child_types = 'any' # common ui element properties id = descriptors.id() id.tip = 'Identifier of this element. need to be unique among all elements' name = descriptors.str() name.tip = 'Name of this element. must be unique among siblings' # XXX: class is reserved. what would be a better name? Class = descriptors.list() Class.tip = 'Class of this element. Useful for styling the element' # events -- must have one-one correspondence with event handler from ..Event import Event class click(Event): # decorations simple_description = "event happens when a ui element is clicked" __unique_type_name__ = 'click' # no attributes class create(Event): # decorations simple_description = "event happens when a ui element is created" __unique_type_name__ = 'create' # no attributes del Event # ************************************************************ # event handlers # event handlers will be automatically defined using event types # defined here (like "click" event above will cause a "onclick" # event handler automatically) # here is just an example in case one has to define a custom # event handler descriptor # onclick = descriptors.eventhandler() # onclick.tip = 'action when a mouse click happens on this element' # ************************************************************ def addClass(self, kls): "add a classifier for this element" classes = self.Class or [] if kls not in classes: classes.append(kls) return self def __init__(self, name=None, id=None, **kwds): if name is None and id is not None: name = id if py_major_ver == 2: super(Element, self).__init__(name=name, id=id, **kwds) elif py_major_ver == 3: super().__init__(name=name, id=id, **kwds) return
class C(metaclass=DescriptorCollector): s = descriptors.str() pass