class UserTab(EntityTab): def __init__(self,app, uid): global gw EntityTab.__init__(self, app) self.table = FlexTable() self.uid = uid self.load() def load(self): global gw if self.uid == -1: self.setup(None) else: gw.getUserDetails(self.app.cookie, self.uid, self) def setup(self, x): edit = self.uid == self.app.uid or self.app.admin if not x: x = {'id': -1, 'handle': '', 'name': '' , 'admin': '', 'email': ''} self.uid = x['id'] self.name = TextBox() self.name.setText(x['name']) self.email = TextBox() self.email.setText(x['email']) self.password = PasswordTextBox() self.passwordRepeat = PasswordTextBox() self.handle = TextBox() self.admin = CheckBox() self.admin.setChecked( x['admin'] ) self.admin.setEnabled( self.app.admin ) self.table.setText(0,0, "ID"); self.table.setText(0,1, x['id']) self.table.setText(1,0, "Handle") if x['id'] == -1: self.table.setWidget(1,1, self.handle) else: self.table.setText(1,1, x['handle']) self.table.setText(2,0, "Name"); if edit: self.table.setWidget(2,1, self.name) else: self.table.setText(2,1, x['name']) self.table.setText(3,0, "Email") if edit: self.table.setWidget(3,1, self.email) else: self.table.setText(3,1, x['email']) self.table.setText(4,0, "Admin"); self.table.setWidget(4,1, self.admin) if edit: self.table.setText(5,0, "Password"); self.table.setWidget(5,1, self.password) self.table.setText(6,0, "Password Repeat"); self.table.setWidget(6,1, self.passwordRepeat) self.saveBtn = Button("Save",self.save) self.table.setWidget(7,1, self.saveBtn) if self.app.admin: self.table.setWidget(8,1, Button("Remove", self.delete)) if self.uid == -1: self.add('New user') else: self.add(x['handle']) def onUpdate(self, response, request_info): self.uid = response self.load() self.app.usersTab.reload() def save(self, _): global gw pwd="" if self.password.getText() != "" or self.passwordRepeat.getText() != "": if self.password.getText() != self.passwordRepeat.getText(): Window.alert("Passwords differ"); return pwd = pwhash(self.password.getText()) gw.updateUser(self.app.cookie, self.uid, self.handle.getText(), self.name.getText(), pwd, self.admin.isChecked(), self.email.getText(), RPCCall(self.onUpdate)) def onDelete(self, response, request_info): self.app.usersTab.reload() self.remove() def delete(self,_): global gw gw.deleteUser(self.app.cookie, self.uid, RPCCall(self.onDelete) ) def onRemoteResponse(self, response, request_info): self.setup(response)
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 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)