Ejemplo n.º 1
0
 def __init__(self, handle, idx, image, variables = None, code = None, 
              perspective = '', checkOptions = [False, True]):
     VerticalPanel.__init__(self)
     self._handle = handle
     self.idx = idx
     # set style
     self.setStyleName('os-mech-drawing')  
     # create widgets
     self._img = Image(image)
     self._img.setStyleName('os-mech-thumb')
     self._img.addClickListener(self.onClickDrawing)
     self._perspective = '%d - %s'%(idx, perspective.capitalize())
     self._optionPanel = MechOptionPanel(handle, idx, checkOptions)
     textArea  = TextArea(code)
     textArea.setText(code)
     textArea.setStyleName('os-mech-code-locked')
     textArea.setReadonly(self, True)
     # populate drawing
     self.add(self._img)
     self.add(self._optionPanel)
     self.add(textArea)
Ejemplo n.º 2
0
class NewBlog:
    def onModuleLoad(self):
        loggedInUser = getCookie("LoggedInUser")
        loggedInUserJsonData = json.loads(loggedInUser)

        self.username = loggedInUserJsonData["username"]

        self.remote_py = MyBlogService()

        dockPanel = DockPanel(BorderWidth=0,
                              Padding=0,
                              HorizontalAlignment=HasAlignment.ALIGN_CENTER,
                              VerticalAlignment=HasAlignment.ALIGN_MIDDLE)

        dockPanel.setSize('100%', '100%')

        headerDockPanel = DockPanel(
            BorderWidth=0,
            Padding=0,
            HorizontalAlignment=HasAlignment.ALIGN_LEFT,
            VerticalAlignment=HasAlignment.ALIGN_CENTER)
        headerDockPanel.setStyleName('header')
        headerDockPanel.setWidth('100%')

        dockPanel.add(headerDockPanel, DockPanel.NORTH)
        dockPanel.setCellHeight(headerDockPanel, '60px')

        self.siteImage = Image("/images/Testware_logo.png")
        self.siteImage.setStyleName('logo-image')
        headerDockPanel.add(self.siteImage, DockPanel.WEST)
        headerDockPanel.setCellWidth(self.siteImage, '30%')

        self.pageTitle = Label('New Blog')
        self.pageTitle.setStyleName('center-header')
        headerDockPanel.add(self.pageTitle, DockPanel.CENTER)
        headerDockPanel.setCellWidth(self.pageTitle, '40%')

        rightHeaderPanel = VerticalPanel(StyleName='right-header')
        headerDockPanel.add(rightHeaderPanel, DockPanel.EAST)
        headerDockPanel.setCellWidth(rightHeaderPanel, '30%')

        welcomeNoteLabel = Label('Hi %s %s!' %
                                 (loggedInUserJsonData["first_name"],
                                  loggedInUserJsonData["last_name"]))
        rightHeaderPanel.add(welcomeNoteLabel)

        logoutAnchor = Anchor(Widget=HTML('Logout'), Href='/', Title='Logout')
        logoutAnchor.setStyleName('logout')
        rightHeaderPanel.add(logoutAnchor)

        panel = HorizontalPanel(StyleName="header2")
        dockPanel.add(panel, DockPanel.NORTH)
        dockPanel.setCellHeight(panel, '50px')

        self.blogTitle = TextBox()
        self.blogTitle.setStyleName('blog-title')
        self.blogTitle.setPlaceholder("Blog Title")
        panel.add(self.blogTitle)

        self.blogContent = TextArea()
        self.blogContent.setStyleName('blog-content')

        dockPanel.add(self.blogContent, DockPanel.CENTER)
        createBlogButton = Button("Create Blog", self)
        createBlogButton.setStyleName('btn')
        panel.add(createBlogButton)

        RootPanel().add(dockPanel)

    def onClick(self, sender):
        self.createBlog()

    def createBlog(self):
        self.remote_py.callMethod('createBlog', [
            self.blogTitle.getText(),
            self.blogContent.getText(), self.username
        ], self)

    def onRemoteResponse(self, response, requestInfo):
        Window.setLocation("/home.html")

    def onRemoteError(self, code, error_dict, requestInfo):
        if code == 401:
            self.errorlabel.setText("Invalid Credentials. Please try again.")
Ejemplo n.º 3
0
class Circuit(object):
    def __init__(self, handle):
        self.log = logging.getConsoleLogger(type(self).__name__, lev)
        self.log.disabled = False
        self.log.debug('__init__: Instantiation')
        self._cacheBreaker = 0
        self._handle = handle 
        self.remoteService=DiagramService(handle.spinner)
        labelDisplay = Label('Diagram')
        self.display = HTMLPanel('No circuit created.')
        self.latex = TextArea()
        
        buttonPanel =  HorizontalPanel()
        
        labelFormatting = Label('Formatting')
        labelCheckbox = Label('Show: ')
        self.checkboxValue = CheckBox('value')
        self.checkboxValue.setID('CBXV1')
        self.checkboxValue.addClickListener(self.onCirctuiTikzClick)
        self.checkboxSymbol = CheckBox('symbol')
        self.checkboxSymbol.setID('CBXS1')
        self.checkboxSymbol.addClickListener(self.onCirctuiTikzClick)
        checkboxPanel =  HorizontalPanel()
        checkboxPanel.add(labelCheckbox)
        checkboxPanel.add(self.checkboxSymbol)
        checkboxPanel.add(self.checkboxValue)
        
        #layout
        self.layout=VerticalPanel(HorizontalAlignment=HasAlignment.ALIGN_LEFT, Spacing=10)
        self.layout.add(labelDisplay)
        self.layout.add(self.display)
        self.layout.add(Label('Circuitikz Markup'))
        self.layout.add(self.latex)
        self.layout.add(buttonPanel)
        self.layout.add(labelFormatting)
        self.layout.add(checkboxPanel)
        RootPanel().add(self.layout)
        
        #Set Default view
        self.actCircuitTikzLock(lock = True)
    def actClear(self):
        self.latex.setText('')
        self.layout.remove(self.display)
        self.display = HTMLPanel('No circuit created.')
        self.layout.insert(self.display, 1)
    def onMenuResume(self):
        self.remoteService.session_resume(self._handle)
    def onCirctuiTikzClick(self, sender, event):
        sendId = sender.getID()
        if sendId == 'CBXV1':
            self.log.debug('click value')
            self.remoteService.change_display(self._handle, 'value', self.checkboxValue.getChecked())
        elif sendId == 'CBXS1':
            self.log.debug('click symbol')
            self.remoteService.change_display(self._handle, 'symbol', self.checkboxSymbol.getChecked())
    def onCircuitTikzSubmit(self):
        self.log.debug('onCircuitTikzSubmit - entry')
        self.remoteService.render_circuitikz(self._handle, self.latex.getText())
    def actCircuitTikzSubmit(self, **kwargs):
        id = kwargs.get('id')
        app = 'Circuit'
        sessionId = getCookie('session_id')
        image = 'api/image?app=Diagram&tab=Circuit&Id=%d&Cache=%d'%(id, self._cacheBreaker)
        self.layout.remove(self.display)
        self.display = Image(image)
        self.layout.insert(self.display, 1)
        self._cacheBreaker = self._cacheBreaker + 1
    def actCircuitTikzLock(self, **kwargs):
        lock = bool(kwargs.get('lock'))
        self.latex.setReadonly(lock)
        self.latex.setStyleName('os-diagram-code-lock')
    def actCircuitTikzSet(self, **kwargs):
        latex = kwargs['latex']
        self.latex.setText(latex)
    def actCircuitTikzFail(self):
        pass
    def actCircuitTikzDisplayUpdate(self, **kwargs):
        symbol = kwargs.get('symbol', None)
        value = kwargs.get('value', None)
        if symbol != None:
            self.checkboxSymbol.setChecked(symbol)
        if value != None:
            self.checkboxValue.setChecked(value)
Ejemplo n.º 4
0
 def __init__(self, name, help):
     widget = TextArea()
     widget.setCharacterWidth(72)
     widget.setStyleName('form-control')
     widget.setVisibleLines(5)
     Form_Row.__init__(self, name, widget, help=help)
Ejemplo n.º 5
0
class Circuit(object):
    def __init__(self, handle):
        self.log = logging.getConsoleLogger(type(self).__name__, lev)
        self.log.disabled = False
        self.log.debug("__init__: Instantiation")
        self._cacheBreaker = 0
        self._handle = handle
        self.remoteService = DiagramService(handle.spinner)
        labelDisplay = Label("Diagram")
        self.display = HTMLPanel("No circuit created.")
        self.latex = TextArea()

        buttonPanel = HorizontalPanel()

        labelFormatting = Label("Formatting")
        labelCheckbox = Label("Show: ")
        self.checkboxValue = CheckBox("value")
        self.checkboxValue.setID("CBXV1")
        self.checkboxValue.addClickListener(self.onCirctuiTikzClick)
        self.checkboxSymbol = CheckBox("symbol")
        self.checkboxSymbol.setID("CBXS1")
        self.checkboxSymbol.addClickListener(self.onCirctuiTikzClick)
        checkboxPanel = HorizontalPanel()
        checkboxPanel.add(labelCheckbox)
        checkboxPanel.add(self.checkboxSymbol)
        checkboxPanel.add(self.checkboxValue)

        # layout
        self.layout = VerticalPanel(HorizontalAlignment=HasAlignment.ALIGN_LEFT, Spacing=10)
        self.layout.add(labelDisplay)
        self.layout.add(self.display)
        self.layout.add(Label("Circuitikz Markup"))
        self.layout.add(self.latex)
        self.layout.add(buttonPanel)
        self.layout.add(labelFormatting)
        self.layout.add(checkboxPanel)
        RootPanel().add(self.layout)

        # Set Default view
        self.actCircuitTikzLock(lock=True)

    def actClear(self):
        self.latex.setText("")
        self.layout.remove(self.display)
        self.display = HTMLPanel("No circuit created.")
        self.layout.insert(self.display, 1)

    def onMenuResume(self):
        self.remoteService.session_resume(self._handle)

    def onCirctuiTikzClick(self, sender, event):
        sendId = sender.getID()
        if sendId == "CBXV1":
            self.log.debug("click value")
            self.remoteService.change_display(self._handle, "value", self.checkboxValue.getChecked())
        elif sendId == "CBXS1":
            self.log.debug("click symbol")
            self.remoteService.change_display(self._handle, "symbol", self.checkboxSymbol.getChecked())

    def onCircuitTikzSubmit(self):
        self.log.debug("onCircuitTikzSubmit - entry")
        self.remoteService.render_circuitikz(self._handle, self.latex.getText())

    def actCircuitTikzSubmit(self, **kwargs):
        id = kwargs.get("id")
        app = "Circuit"
        sessionId = getCookie("session_id")
        image = "api/image?app=Diagram&tab=Circuit&Id=%d&Cache=%d" % (id, self._cacheBreaker)
        self.layout.remove(self.display)
        self.display = Image(image)
        self.layout.insert(self.display, 1)
        self._cacheBreaker = self._cacheBreaker + 1

    def actCircuitTikzLock(self, **kwargs):
        lock = bool(kwargs.get("lock"))
        self.latex.setReadonly(lock)
        self.latex.setStyleName("os-diagram-code-lock")

    def actCircuitTikzSet(self, **kwargs):
        latex = kwargs["latex"]
        self.latex.setText(latex)

    def actCircuitTikzFail(self):
        pass

    def actCircuitTikzDisplayUpdate(self, **kwargs):
        symbol = kwargs.get("symbol", None)
        value = kwargs.get("value", None)
        if symbol != None:
            self.checkboxSymbol.setChecked(symbol)
        if value != None:
            self.checkboxValue.setChecked(value)