class LoggerPanel(DisclosurePanel): def __init__(self, maxhistory=100, maxloglinelength=200, headerStyleName=None, panelStyleName=None, buttonStyleName=None, labelStyleName=None): super(LoggerPanel, self).__init__(self, header='BLAH', isOpen=False) self.labelStyleName = labelStyleName self.maxhistory = maxhistory self.maxloglinelength = maxloglinelength self.getHeader().setStyleName(headerStyleName) self.logpanel = VerticalPanel(StyleName=panelStyleName) self.setContent(self.logpanel) self.clearbutton = Button('Clear', listener=self.clear, StyleName=buttonStyleName) self.logpanel.add(self.clearbutton) self.updateHeaderText() def log(self, string): self.logpanel.add(Label(string[:self.maxloglinelength], StyleName=self.labelStyleName)) widgcnt = self.logpanel.getWidgetCount() if widgcnt > self.maxhistory: for i in range(0, widgcnt - self.maxhistory): self.logpanel.remove(self.logpanel.getWidget(i)) self.updateHeaderText() def __call__(self, string): self.log(string) return def updateHeaderText(self): self.getHeader().setText('Logging: %s items' % (self.logpanel.getWidgetCount() - 1)) def clear(self): self.logpanel.clear() self.logpanel.add(self.clearbutton) self.updateHeaderText()
class TheoremPanel(ScrollPanel): def __init__(self, after): ScrollPanel.__init__(self, Size=("630px", "500px")) self.after = after self.pok = VerticalPanel() self.add(self.pok) self.images = list() def onItemSelected(): item = self.list2.getItemText(self.list2.getSelectedIndex()) self.refresh_theorems(item) self.list2 = ListBox() self.list2.setVisibleItemCount(1) for f in Theorem.get_all_folders(): self.list2.addItem(f) self.pok.add(self.list2) self.list2.addChangeListener(onItemSelected) self.refresh_theorems(self.list2.getItemText(self.list2.getSelectedIndex())) def remove_images(self): for im in self.images: self.pok.remove(im) self.images = list() def refresh_theorems(self, folder): self.remove_images() def onClick(theorem): def name(n): return "var" + str(n + 1) def print_scheme(n): return ["\\alpha", "\\beta", "\\gamma", "\\delta", "\\epsilon"][n] def poas(sender): if len(theorem.operations) == 1: constants = [Operation("const" + str(i + 1), 0, print_scheme(i), name(i), Operation.EXPRESSION) for i in range(theorem.operations[0].no_of_args)] def after1(f): self.after( theorem.formula.substitute_definition(Formula([theorem.operations[0]] + constants), f), predecessors=[], rule_name="insert") request_formula([op for op in proof.get_operations()] + constants, after1, type=('rel' if theorem.operations[0].type == Operation.RELATION else 'exp')) else: self.after(theorem.formula, predecessors=[], rule_name="insert") return poas for ax in [x for x in Theorem.theorems if x.folder == folder]: im = Image() im.addClickListener(onClick(ax)) im.setUrl(latex_to_url(ax.formula.to_latex())) self.pok.add(im) self.images.append(im)
class SinkList(Composite): def __init__(self): Composite.__init__(self) self.vp_list = VerticalPanel() self.sinks = [] self.selectedSink = -1 self.initWidget(self.vp_list) self.setStyleName("ks-List") def add(self, info): name = info.getName() link = Hyperlink(name, False, TargetHistoryToken=name) link.setStyleName("ks-SinkItem") self.vp_list.add(link) self.sinks.append(info) def remove(self, info): if isinstance(info, str): info = self.find(info) name = info.getName() for hl in self.vp_list: if hl.getTargetHistoryToken() != name: continue self.vp_list.remove(hl) break self.sinks.remove(info) def clear(self): while len(self.sinks) > 0: info = self.sinks[0] self.remove(info) def find(self, sinkName): for info in self.sinks: if info.getName() == sinkName: return info return None def setSinkSelection(self, name): if self.selectedSink <> -1: self.vp_list.getWidget( self.selectedSink).removeStyleName("ks-SinkItem-selected") for i in range(len(self.sinks)): info = self.sinks[i] if (info.getName() == name): self.selectedSink = i widget = self.vp_list.getWidget(self.selectedSink) widget.addStyleName("ks-SinkItem-selected") return
class FormulaListPanel(ScrollPanel): def __init__(self,onClick): ScrollPanel.__init__(self, Size=("630px", "500px")) self.checkbox_list = [] self.hpanel_list = [] self.image_list = [] self.pok = VerticalPanel() self.add(self.pok) self.onclick=onClick def add_formula(self, f): h = HorizontalPanel() im = Image() im.setUrl(latex_to_url(f.to_latex())) c = CheckBox() h.add(c) h.add(im) self.pok.add(h) self.checkbox_list.append(c) self.hpanel_list.append(h) self.image_list.append(im) def set_checks_to_def(self,split_points): for i in range(len(self.checkbox_list)): self.checkbox_list[i].setChecked(False) if i in split_points: self.checkbox_list[i].setStyleAttribute('background-color','#FF0000') else: self.checkbox_list[i].setStyleAttribute('background-color', 'transparent') self.checkbox_list[-1].setChecked(True) def get_selected_indices(self): return [i for i, c in enumerate(self.checkbox_list) if c.isChecked()] def reload(self, formula_list,split_points): if len(formula_list)<len(self.hpanel_list): for h in self.hpanel_list[len(formula_list):]: self.pok.remove(h) self.hpanel_list=self.hpanel_list[:len(formula_list)] self.checkbox_list = self.checkbox_list[:len(formula_list)] self.image_list = self.image_list[:len(formula_list)] for f, im in zip(formula_list, self.image_list): im.setUrl(latex_to_url(f.to_latex())) x = formula_list[len(self.hpanel_list):] for f in x: self.add_formula(f) self.set_checks_to_def(split_points) for i in range(len(self.image_list)): self.image_list[i].clearClickListener() self.image_list[i].addClickListener(self.onclick(i))
class SinkList(Composite): def __init__(self): Composite.__init__(self) self.vp_list=VerticalPanel() self.sinks=[] self.selectedSink=-1 self.initWidget(self.vp_list) self.setStyleName("ks-List") def add(self, info): name = info.getName() link = Hyperlink(name, False, TargetHistoryToken=name) link.setStyleName("ks-SinkItem") self.vp_list.add(link) self.sinks.append(info) def remove(self, info): if isinstance(info, str): info = self.find(info) name = info.getName() for hl in self.vp_list: if hl.getTargetHistoryToken() != name: continue self.vp_list.remove(hl) break self.sinks.remove(info) def clear(self): while len(self.sinks) > 0: info = self.sinks[0] self.remove(info) def find(self, sinkName): for info in self.sinks: if info.getName()==sinkName: return info return None def setSinkSelection(self, name): if self.selectedSink <> -1: self.vp_list.getWidget(self.selectedSink).removeStyleName("ks-SinkItem-selected") for i in range(len(self.sinks)): info = self.sinks[i] if (info.getName()==name): self.selectedSink = i widget=self.vp_list.getWidget(self.selectedSink) widget.addStyleName("ks-SinkItem-selected") return
class AMSSnoopStack: def onModuleLoad(self): global statusbar statusbar = Label() self.button = Button("Display Current Stack Frames", self) self.buttonupdate = Button("Update data from AMS publisher", self) buttons = HorizontalPanel() buttons.add(self.button) buttons.add(self.buttonupdate) buttons.setSpacing(8) info = """<p>This example demonstrates the calling of the Memory Snooper in PETSc with Pyjamas and <a href="http://json-rpc.org/">JSON-RPC</a>.</p>""" self.panel = VerticalPanel() self.panel.add(HTML(info)) self.panel.add(buttons) self.panel.add(statusbar) RootPanel().add(self.panel) self.commobj = AMS.AMS_Comm() self.textarea = None def onClick(self, sender): global statusbar, boxes statusbar.setText('Button pressed') pass if sender == self.buttonupdate: self.commobj = AMS.AMS_Comm() statusbar.setText( 'Updating data: Press Display list button to refesh') if sender == self.button: if AMS.sent > AMS.recv: statusbar.setText('Press button again: sent ' + str(AMS.sent) + ' recv ' + str(AMS.recv)) if self.commobj.commname == 'No AMS publisher running' or not self.commobj.commname or self.commobj.comm == -1: if self.textarea: self.panel.remove(self.textarea) pass else: statusbar.setText('Memories for AMS Comm: ' + self.commobj.commname) result = self.commobj.get_memory_list() if self.textarea: self.panel.remove(self.textarea) self.textarea = TextArea() memory = self.commobj.memory_attach("Stack") size = memory.get_field_info("current size") functions = memory.get_field_info("functions") funcs = '\n'.join(functions[4]) self.textarea.setText(str(funcs)) self.textarea.setVisibleLines(size[4]) self.panel.add(self.textarea)
class AMSSnoopStack: def onModuleLoad(self): global statusbar statusbar = Label() self.button = Button("Display Current Stack Frames", self) self.buttonupdate = Button("Update data from AMS publisher", self) buttons = HorizontalPanel() buttons.add(self.button) buttons.add(self.buttonupdate) buttons.setSpacing(8) info = """<p>This example demonstrates the calling of the Memory Snooper in PETSc with Pyjamas and <a href="http://json-rpc.org/">JSON-RPC</a>.</p>""" self.panel = VerticalPanel() self.panel.add(HTML(info)) self.panel.add(buttons) self.panel.add(statusbar) RootPanel().add(self.panel) self.commobj = AMS.AMS_Comm() self.textarea = None def onClick(self, sender): global statusbar,boxes statusbar.setText('Button pressed') pass if sender == self.buttonupdate: self.commobj = AMS.AMS_Comm() statusbar.setText('Updating data: Press Display list button to refesh') if sender == self.button: if AMS.sent > AMS.recv: statusbar.setText('Press button again: sent '+str(AMS.sent)+' recv '+str(AMS.recv)) if self.commobj.commname == 'No AMS publisher running' or not self.commobj.commname or self.commobj.comm == -1: if self.textarea: self.panel.remove(self.textarea) pass else: statusbar.setText('Memories for AMS Comm: '+self.commobj.commname) result = self.commobj.get_memory_list() if self.textarea: self.panel.remove(self.textarea) self.textarea = TextArea() memory = self.commobj.memory_attach("Stack") size = memory.get_field_info("current size") functions = memory.get_field_info("functions") funcs = '\n'.join(functions[4]) self.textarea.setText(str(funcs)) self.textarea.setVisibleLines(size[4]) self.panel.add(self.textarea)
class AMSJavascriptExample: def onModuleLoad(self): self.status=Label() self.button = Button("Display list of all published memories and fields", self) self.buttonupdate = Button("Update data from AMS publisher", self) buttons = HorizontalPanel() buttons.add(self.button) buttons.add(self.buttonupdate) buttons.setSpacing(8) info = """<p>This example demonstrates the calling of the Memory Snooper in PETSc with Pyjamas and <a href="http://json-rpc.org/">JSON-RPC</a>.</p>""" self.panel = VerticalPanel() self.panel.add(HTML(info)) self.panel.add(buttons) self.panel.add(self.status) RootPanel().add(self.panel) self.commobj = AMS_Comm() self.tree = None def onClick(self, sender): global sent,recv self.status.setText('Button pressed') if sender == self.buttonupdate: self.commobj = AMS_Comm() self.status.setText('Updating data: Press Display list button to refesh') if sender == self.button: if sent > recv: self.status.setText('Press button again: sent '+str(sent)+' recv '+str(recv)) if self.commobj.commname == 'No AMS publisher running': self.status.setText(self.commobj.commname) else: self.status.setText('Memories for AMS Comm: '+self.commobj.commname) result = self.commobj.get_memory_list() if self.tree: self.panel.remove(self.tree) self.tree = Tree() for i in result: subtree = TreeItem(i) memory = self.commobj.memory_attach(i) fields = memory.get_field_list() for j in fields: field = memory.get_field_info(j) subtree.addItem(j+' = '+str(field[4])) self.tree.addItem(subtree) self.panel.add(self.tree)
class TheoremPanel(ScrollPanel): def __init__(self, after): ScrollPanel.__init__(self, Size=("630px", "500px")) self.after = after self.pok = VerticalPanel() self.add(self.pok) self.images = list() def onItemSelected(): item = self.list2.getItemText(self.list2.getSelectedIndex()) self.refresh_theorems(item) self.list2 = ListBox() self.list2.setVisibleItemCount(1) for f in Theorem.get_all_folders(): self.list2.addItem(f) self.pok.add(self.list2) self.list2.addChangeListener(onItemSelected) self.refresh_theorems( self.list2.getItemText(self.list2.getSelectedIndex())) def remove_images(self): for im in self.images: self.pok.remove(im) self.images = list() def refresh_theorems(self, folder): self.remove_images() def onClick(theorem): def name(n): return "var" + str(n + 1) def print_scheme(n): return [ "\\alpha", "\\beta", "\\gamma", "\\delta", "\\epsilon" ][n] def poas(sender): if len(theorem.operations) == 1: constants = [ Operation("const" + str(i + 1), 0, print_scheme(i), name(i), Operation.EXPRESSION) for i in range(theorem.operations[0].no_of_args) ] def after1(f): self.after(theorem.formula.substitute_definition( Formula([theorem.operations[0]] + constants), f), predecessors=[], rule_name="insert") request_formula([op for op in proof.get_operations()] + constants, after1, type=('rel' if theorem.operations[0].type == Operation.RELATION else 'exp')) else: self.after(theorem.formula, predecessors=[], rule_name="insert") return poas for ax in [x for x in Theorem.theorems if x.folder == folder]: im = Image() im.addClickListener(onClick(ax)) im.setUrl(latex_to_url(ax.formula.to_latex())) self.pok.add(im) self.images.append(im)
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)
class SubCategoryPanel(VerticalPanel): def __init__(self, subCategoryName='', subCategoryClassName='', openList=True): self.list = VerticalPanel(StyleName='block_list') self.list.setStyleAttribute("display", "block") VerticalPanel.__init__(self, StyleName='SubCategoryPanel') self.subCategoryName = subCategoryName if subCategoryName != '': self.title = Element(Element=DOM.createElement('dt'), StyleName=subCategoryClassName) DOM.setInnerHTML(self.title.getElement(), self.subCategoryName) self.collapse = FocusWidget(Element=DOM.createDiv(), StyleName='collapse close_up') self.collapse.addClickListener(self.showHide) self.title.add(self.collapse) self.add(self.title) if openList: self.list.setStyleAttribute("display", "block") self.collapse.setStyleName('collapse close_up') else: self.list.setStyleAttribute("display", "none") self.collapse.setStyleName('collapse open_down') self.add(self.list) self.blocks = [] self.count = 0 def changeTexts(self): if self.subCategoryName != '': DOM.setInnerHTML(self.title.getElement(), _(self.subCategoryName)) self.title.add(self.collapse) for block in self.blocks: block.changeTexts() def addBlock(self, block, classHelp='help_default', beforeIndex=None): panel = HorizontalPanel() panel.add(block) info = Label('i', StyleName='info_btn') info.block = block info.classHelp = classHelp info.addClickListener(self.showInfo) panel.add(info) if beforeIndex is not None: self.list.insert(panel, self.list.getBody(), 0) #deprecated else: self.list.add(panel) self.list.setStyleName(self.list.getWidgetTd(panel), 'block_info') self.blocks.append(block) if block.name in [ 'commandType', 'numericType', 'logicType', 'alphaNumericType' ]: panel.add(self.getRemoveCustomBlock(block)) info.addMouseListener(TooltipListener("Editar")) else: info.addMouseListener(TooltipListener("Ajuda")) def getRemoveCustomBlock(self, block): remove = Label('x', StyleName='remove_btn') remove.addMouseListener(TooltipListener("Remover")) remove.block = block remove.addClickListener(self.RemoveCustomBlock) return remove def RemoveCustomBlock(self, sender): self.list.remove(sender.block.getParent()) self.blocks.remove(sender.block) if len(self.blocks) == 0: self.getParent().reload() del createdBlocks[sender.block.varName] stateChange() def removeBlock(self, block): self.list.remove(block.getParent()) self.blocks.remove(block) def removeAllBlocks(self): while len(self.blocks) > 0: self.removeBlock(self.blocks[0]) def addWidget(self, widget): self.list.add(widget) def showInfo(self, sender): if sender.block.name in [ 'commandType', 'numericType', 'logicType', 'alphaNumericType' ]: createdBlocks[sender.block.varName].show() else: popup = Popup('<b>' + _('Help') + '</b>', None, None) popup.center.append( Widget(Element=DOM.createDiv(), StyleName=sender.classHelp)) popup.caption.setStyleAttribute('text-align', 'center') popup.show() def showHide(self): if self.list.getStyleAttribute('display') == 'none': self.list.setStyleAttribute("display", "block") self.collapse.setStyleName('collapse close_up') else: self.list.setStyleAttribute("display", "none") self.collapse.setStyleName('collapse open_down') def changeTitle(self, count): # faz perder o collapse DOM.setInnerHTML(self.title.getElement(), _(self.subCategoryName) + ': #' + str(count)) self.title.add(self.collapse) self.count = count
class CompoundWeights: def __init__(self): self.WEIGHT_TYPES = [ ProductWeights, OrderDependentWeights, PODWeights, ProjectionDependentWeights ] self._add_dialog, self._wtype = self._create_add_dialog() self.panel = VerticalPanel() self._list_panel = VerticalPanel(Spacing=8) self.panel.add(self._list_panel) link = Hyperlink("add...", StyleName="action") link.addClickListener(getattr(self, 'show_add_dialog')) self.panel.add(link) self._weights = [] self._dimension = 0 # public interface @property def dimension(self): return self._dimension @dimension.setter def dimension(self, value): self._dimension = value for w in self._weights: w.dimension = value @property def weights(self): for w in self._weights: yield w def add_weights(self, wclass): self._weights.append(wclass(getattr(self, 'remove_weights'))) self._list_panel.add(CaptionPanel(wclass.NAME, self._weights[-1].panel)) self._weights[-1].dimension = self.dimension def remove_weights(self, obj): self._list_panel.remove(obj.panel.getParent()) self._weights.remove(obj) def show_add_dialog(self): self._add_dialog.setPopupPosition(*window_center()) self._add_dialog.show() # private methods def _create_add_dialog(self): contents = VerticalPanel(StyleName="Contents", Spacing=4) wtype = ListBox(Width="14em") wtype.addChangeListener(self) for wclass in self.WEIGHT_TYPES: wtype.addItem(wclass.NAME, value=wclass) panel = HorizontalPanel(Spacing=8) panel.add(HTML("Weight type: ", **captionstyle)) panel.add(wtype) contents.add(panel) contents.add(Button("OK", getattr(self, '_close_add_dialog'))) dialog = DialogBox(glass=True) dialog.setHTML('<b>Add a new type of weights</b>') dialog.setWidget(contents) return dialog, wtype def _close_add_dialog(self): self._add_dialog.hide() wclass = self.WEIGHT_TYPES[self._wtype.getSelectedIndex()] self.add_weights(wclass) JS('top.Typeset();')
class Input_Form(Abstract_View): '''Input form that modifies itself depending on the proejct. ''' def __init__(self): Abstract_View.__init__(self) self.dev_fields = Dev_Fields() def register(self, controller): '''Register controller for view and its subviews''' self.controller = controller self.dev_fields.register(controller) def onModuleLoad(self): '''Create initial view of the panel. ''' # Container that keeps everything self.panel = VerticalPanel() self.panel.setSpacing(10) # Create list of projects proj_list = ListBox(Height='34px') proj_list.addItem('') proj_list.setVisibleItemCount(0) proj_list.addChangeListener(getattr(self, 'on_project_changed')) proj_list.setStyleName('form-control input-lg') self.proj_row = Form_Row('Select project', proj_list, help='project, status of which you want to report') # Project-specific container self.project_panel = VerticalPanel() # Submit report button self.submit_btn = Button('Submit report', getattr(self, 'send_data')) self.submit_btn.setStyleName('btn btn-primary btn-lg') self.submit_btn.setEnabled(False) self.msg_lbl = HTMLPanel('', Width='475px') # Add controls here self.panel.add(self.proj_row.panel()) self.panel.add(self.project_panel) self.panel.add(Label(Height='20px')) self.panel.add(self.msg_lbl) btn_holder = HorizontalPanel() btn_holder.add(self.submit_btn) help_btn = HTMLPanel('') help_btn.setHTML(MODAL_PNL) btn_holder.add(Label(Width='10px')) btn_holder.add(help_btn) self.panel.add(btn_holder) self.root = RootPanel('report') self.root.add(self.panel) def _load_project(self, project): '''Load project specific fields in the panel ''' if self.dev_fields is not None: self.project_panel.remove(self.dev_fields) # Remove the old one and add brand new self.dev_fields = Dev_Fields() self.project_panel.add(self.dev_fields) def send_data(self): '''Retrieve data for the active project fields and send to flask. ''' #data = self.dev_fields.prep_data() self.controller.process_msg(SEND_DATA_MSG) def on_project_changed(self, event): '''Change form fields depending on the proejct. ''' proj_list = self.proj_row.widget() project = proj_list.getItemText(proj_list.getSelectedIndex()) if project != '': self.controller.process_msg(PROJ_CHANGED_MSG, project)
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)
class ParamGroup(object): def __init__(self, container, kind, parent=None, level=0, draw=True, title=None): self.container = container self.kind = kind self.parent = parent self.level = level self.title = title self.panel = SimplePanel(StyleName='aur-search-advanced-group') if level % 2 == 0: self.panel.addStyleName('aur-search-advanced-group-nested') self.childPanel = VerticalPanel(StyleName='aur-search-advanced-group-list', Width='100%') self.paramPanel = VerticalPanel(StyleName='aur-search-advanced-param-list', Width='100%') self.listPanel = VerticalPanel(StyleName='aur-search-advanced-list-boundary', Width='100%', Visible=False) self.paramChooser = ListBox() self.children = [] self.parameters = [] self.isInverted = False self.operator = 'and' # assigned by parent, visual use only self.op = None if parent else Label('and') if draw: self.draw() def draw(self): cont = VerticalPanel(Width='100%') header = HorizontalPanel(Width='100%', VerticalAlignment='middle', StyleName='aur-search-advanced-group-header') params = self.paramChooser addParam = Image(url='/ico/tick.png', Title='Add parameter to this group') addGroup = Image(url='/ico/table_add.png', Title='Nest group within this group') addGroupFull = Image(url='/ico/table_lightning.png', Title='Nest group within this group; all parameters') invertSelf = Image(url='/ico/exclamation.png', Title='Invert this parameter group') self.container.add(self.panel) self.panel.setWidget(cont) cont.add(header) if self.parent: d = Image(url='/ico/cross.png', Title='Delete this parameter group') d.addStyleName('aur-search-advanced-delete') header.add(d) header.setCellWidth(d, '1px') d.addClickListener(getattr(self, 'delSelf')) if self.title: t = Label(self.title, StyleName='aur-search-advanced-group-header-title') header.add(t) header.setCellWidth(t, '1px') header.add(params) header.add(addParam) header.add(addGroup) header.add(addGroupFull) header.add(invertSelf) header.setCellWidth(params, '1px') header.setCellWidth(addGroup, '1px') header.setCellWidth(addGroupFull, '1px') header.setCellWidth(invertSelf, '1px') for x in self.kind: params.addItem(x['item'], x['index']) cont.add(self.listPanel) self.listPanel.add(self.paramPanel) self.listPanel.add(self.childPanel) addParam.addClickListener(getattr(self, 'addParam')) addGroup.addClickListener(getattr(self, 'addGroup')) addGroupFull.addClickListener(getattr(self, 'addGroupFull')) invertSelf.addClickListener(getattr(self, 'invertSelf')) def addGroup(self, sender): self.listPanel.setVisible(True) op = Label(self.operator, Title='Invert group operator', StyleName='aur-search-advanced-group-op', Visible=False) op.addClickListener(getattr(self, 'invertOperator')) if len(self.children) > 0 or len(self.parameters) > 0: op.setVisible(True) self.childPanel.add(op) self.childPanel.setCellHorizontalAlignment(op, 'right') g = ParamGroup(self.childPanel, self.kind, self, self.level+1) g.op = op self.children.append(g) def addGroupFull(self, sender): # this is a little hacky, but it's so fast you don't see it self.addGroup(None) group = self.children[len(self.children)-1] for x in range(group.paramChooser.getItemCount()): group.paramChooser.setSelectedIndex(x) group.addParam(None) group.paramChooser.setSelectedIndex(0) def addParam(self, sender): self.listPanel.setVisible(True) op = Label(self.operator, Title='Invert group operator', StyleName='aur-search-advanced-param-op', Visible=False) op.addClickListener(getattr(self, 'invertOperator')) if len(self.parameters) > 0: op.setVisible(True) self.paramPanel.add(op) self.paramPanel.setCellHorizontalAlignment(op, 'right') k = self.kind[self.paramChooser.getSelectedValues()[0]] p = Param(self.paramPanel, k, self) p.op = op self.parameters.append(p) if len(self.children) > 0: self.children[0].op.setVisible(True) def addParamFull(self, sender): # this is a little hacky, but it's so fast you don't see it old = self.paramChooser.getSelectedIndex() for x in range(self.paramChooser.getItemCount()): self.paramChooser.setSelectedIndex(x) self.addParam(None) self.paramChooser.setSelectedIndex(old) def delGroup(self, child): self.children.remove(child) self.childPanel.remove(child.op) self.childPanel.remove(child.panel) lp = len(self.parameters) lc = len(self.children) if lp == 0 and lc > 0: self.children[0].op.setVisible(False) if lp == 0 and lc == 0: self.listPanel.setVisible(False) def delParam(self, param): self.parameters.remove(param) self.paramPanel.remove(param.op) self.paramPanel.remove(param.panel) lp = len(self.parameters) lc = len(self.children) if lp > 0: self.parameters[0].op.setVisible(False) if lp == 0 and lc > 0: self.children[0].op.setVisible(False) if lp == 0 and lc == 0: self.listPanel.setVisible(False) def delSelf(self, sender): self.parent.delGroup(self) def invertSelf(self, sender): if self.isInverted: self.isInverted = False self.panel.removeStyleName('aur-search-advanced-group-inverted') self.op.setText(self.operator) else: self.isInverted = True self.panel.addStyleName('aur-search-advanced-group-inverted') self.op.setText(self.operator + ' not') def invertOperator(self, sender): self.operator = 'or' if self.operator == 'and' else 'and' for x in self.parameters: suffix = ' not' if x.isInverted else '' x.op.setText(self.operator + suffix) for x in self.children: suffix = ' not' if x.isInverted else '' x.op.setText(self.operator + suffix)
class AMSSnoopObjects: def onModuleLoad(self): global statusbar statusbar = Label() self.button = Button("Display list of all published memories and fields", self) self.buttonupdate = Button("Update data from AMS publisher", self) buttons = HorizontalPanel() buttons.add(self.button) buttons.add(self.buttonupdate) buttons.setSpacing(8) info = """<p>This example demonstrates the calling of the Memory Snooper in PETSc with Pyjamas and <a href="http://json-rpc.org/">JSON-RPC</a>.</p>""" self.panel = VerticalPanel() self.panel.add(HTML(info)) self.panel.add(buttons) self.panel.add(statusbar) RootPanel().add(self.panel) self.commobj = AMS.AMS_Comm() self.tree = None def textboxlistener(self, arg): global boxes, statusbar statusbar.setText("User changed value in text box to " + str(arg.getText()) + " " + str(boxes[arg])) # the user has changed this value we should send it back to the AMS program boxes[arg][2].set_field_info(boxes[arg][1], arg.getText()) def onClick(self, sender): global statusbar, boxes statusbar.setText("Button pressed") pass if sender == self.buttonupdate: self.commobj = AMS.AMS_Comm() statusbar.setText("Updating data: Press Display list button to refesh") if sender == self.button: if AMS.sent > AMS.recv: statusbar.setText("Press button again: sent " + str(AMS.sent) + " recv " + str(AMS.recv)) if ( self.commobj.commname == "No AMS publisher running" or not self.commobj.commname or self.commobj.comm == -1 ): if self.tree: self.panel.remove(self.tree) else: statusbar.setText("Memories for AMS Comm: " + self.commobj.commname) result = self.commobj.get_memory_list() if self.tree: self.panel.remove(self.tree) self.tree = Tree() for i in result: if i == "Stack": continue subtree = TreeItem(i) memory = self.commobj.memory_attach(i) fields = memory.get_field_list() if not isinstance(fields, list): fields = [fields] block = false for j in fields: field = memory.get_field_info(j) if str(field[1]) == "AMS_READ": if j == "Publish Block": if field[4] == "true": block = true else: subtree.addItem(j + " = " + str(field[4])) else: if j == "Block" and not block: continue PN = HorizontalPanel() PN.add(Label(Text=j + " =")) tb = TextBox(Text=str(field[4])) boxes[tb] = [i, j, memory] tb.addChangeListener(self.textboxlistener) PN.add(tb) subtree.addItem(PN) self.tree.addItem(subtree) self.panel.add(self.tree)
class AMSSnoopObjects: def onModuleLoad(self): global statusbar statusbar = Label() self.button = Button( "Display list of all published memories and fields", self) self.buttonupdate = Button("Update data from AMS publisher", self) buttons = HorizontalPanel() buttons.add(self.button) buttons.add(self.buttonupdate) buttons.setSpacing(8) info = """<p>This example demonstrates the calling of the Memory Snooper in PETSc with Pyjamas and <a href="http://json-rpc.org/">JSON-RPC</a>.</p>""" self.panel = VerticalPanel() self.panel.add(HTML(info)) self.panel.add(buttons) self.panel.add(statusbar) RootPanel().add(self.panel) self.commobj = AMS.AMS_Comm() self.tree = None def textboxlistener(self, arg): global boxes, statusbar statusbar.setText('User changed value in text box to ' + str(arg.getText()) + " " + str(boxes[arg])) # the user has changed this value we should send it back to the AMS program boxes[arg][2].set_field_info(boxes[arg][1], arg.getText()) def onClick(self, sender): global statusbar, boxes statusbar.setText('Button pressed') pass if sender == self.buttonupdate: self.commobj = AMS.AMS_Comm() statusbar.setText( 'Updating data: Press Display list button to refesh') if sender == self.button: if AMS.sent > AMS.recv: statusbar.setText('Press button again: sent ' + str(AMS.sent) + ' recv ' + str(AMS.recv)) if self.commobj.commname == 'No AMS publisher running' or not self.commobj.commname or self.commobj.comm == -1: if self.tree: self.panel.remove(self.tree) else: statusbar.setText('Memories for AMS Comm: ' + self.commobj.commname) result = self.commobj.get_memory_list() if self.tree: self.panel.remove(self.tree) self.tree = Tree() for i in result: if i == "Stack": continue subtree = TreeItem(i) memory = self.commobj.memory_attach(i) fields = memory.get_field_list() if not isinstance(fields, list): fields = [fields] block = false for j in fields: field = memory.get_field_info(j) if str(field[1]) == 'AMS_READ': if j == "Publish Block": if field[4] == "true": block = true else: subtree.addItem(j + ' = ' + str(field[4])) else: if j == "Block" and not block: continue PN = HorizontalPanel() PN.add(Label(Text=j + ' =')) tb = TextBox(Text=str(field[4])) boxes[tb] = [i, j, memory] tb.addChangeListener(self.textboxlistener) PN.add(tb) subtree.addItem(PN) self.tree.addItem(subtree) self.panel.add(self.tree)