class USEWindow(object): def __init__(self, title= None, toDisplay= None): parentShell = Display.getDefault().getActiveShell() self.window = Shell(parentShell, SWT.CLOSE | SWT.RESIZE) self.window.setText(title) self.window.setLayout(FillLayout()) self.window.setSize (self.window.computeSize(1400, 500)) self.text = Browser(self.window, SWT.NONE) self.text.setText( \ "<html><header><style>" + "<!--.tab { margin-left: 40px;} .tab2 { margin-left: 80px; }" + " .tab3 { margin-left: 120px; }.tab4 { margin-left: 160px; }-->" + "</style></header><body><div style=\"overflow: auto;\">" + toDisplay + "</div></body></html>") self.window.open ()
class HtmlWindow(object): def __init__(self, url=None, html=None, title="information", width=800, height=800, labeltext=""): parent = Display.getDefault().getActiveShell() self.window = Shell(parent, SWT.CLOSE | SWT.RESIZE) # give minimum size, location and size self.window.setMinimumSize(width, height) parentBounds = parent.getBounds() self.window.setLocation( \ (parentBounds.width-width)/2+parentBounds.x, \ (parentBounds.height-height)/2+parentBounds.y ) self.window.setSize(width, height) # layout gridLayout = GridLayout(1, 1) self.window.setLayout(gridLayout) self.window.setText(title) self._createLabel(labeltext) self._createBrowser(url=url, html=html) self._createOkButton() self._listenSelection() self.window.open() def _createLabel(self, labeltext): data = GridData(GridData.FILL_HORIZONTAL) data.verticalIndent = 5 self.label = Label(self.window, SWT.WRAP) self.label.setLayoutData(data) self.label.setText(labeltext) self.label.setLocation(10, 40) def _createBrowser(self, html=None, url=None): data = GridData(SWT.FILL, SWT.FILL, 1, 1) data.verticalIndent = 10 self.browser = Browser(self.window, SWT.BORDER) self.browser.setLayoutData(data) if url is not None: self.setURL(url) else: if html is not None: self.setText(html) else: pass def _createOkButton(self): data = GridData(GridData.HORIZONTAL_ALIGN_END) data.widthHint = 50 button = Button(self.window, SWT.FLAT) button.setLayoutData(data) button.setText("OK") class MyListener(Listener): def handleEvent(self, event): if (event.widget == button): button.getShell().close() button.addListener(SWT.Selection, MyListener()) self.okButton = button def _listenSelection(self): thebrowser = self.browser from org.modelio.api.modelio import Modelio from org.modelio.api.app.navigation import INavigationListener class SelectionListener(INavigationListener): #def navigateTo(self): # thebrowser.setText("selection is "+str(target.getName())) pass Modelio.getInstance().getNavigationService().addNavigationListener( SelectionListener()) def setText(self, html): self.browser.setText( \ "<html><header></header><body>" + html + "</body></html>") def setURL(self, url): self.browser.setUrl(url) def setLabel(self, text): self.label.setText(text)
class HtmlWindow(object): def __init__(self, url=None, html=None,title="information",width=800,height=800,labeltext=""): parent = Display.getDefault().getActiveShell() self.window = Shell(parent, SWT.CLOSE | SWT.RESIZE) # give minimum size, location and size self.window.setMinimumSize(width, height) parentBounds = parent.getBounds() self.window.setLocation( \ (parentBounds.width-width)/2+parentBounds.x, \ (parentBounds.height-height)/2+parentBounds.y ) self.window.setSize(width, height) # layout gridLayout = GridLayout(1, 1) self.window.setLayout(gridLayout) self.window.setText(title) self._createLabel(labeltext) self._createBrowser(url=url,html=html) self._createOkButton() self._listenSelection() self.window.open() def _createLabel(self,labeltext): data = GridData(GridData.FILL_HORIZONTAL) data.verticalIndent = 5; self.label = Label(self.window, SWT.WRAP) self.label.setLayoutData(data) self.label.setText(labeltext) self.label.setLocation(10, 40) def _createBrowser(self,html=None,url=None): data = GridData(SWT.FILL,SWT.FILL,1,1) data.verticalIndent = 10; self.browser = Browser(self.window, SWT.BORDER) self.browser.setLayoutData(data) if url is not None: self.setURL(url) else: if html is not None: self.setText(html) else: pass def _createOkButton(self): data = GridData(GridData.HORIZONTAL_ALIGN_END) data.widthHint = 50 button = Button(self.window, SWT.FLAT) button.setLayoutData(data) button.setText("OK") class MyListener(Listener): def handleEvent(self, event): if (event.widget == button): button.getShell().close() button.addListener(SWT.Selection, MyListener()) self.okButton = button def _listenSelection(self): thebrowser = self.browser from org.modelio.api.modelio import Modelio from org.modelio.api.app.navigation import INavigationListener class SelectionListener(INavigationListener): #def navigateTo(self): # thebrowser.setText("selection is "+str(target.getName())) pass Modelio.getInstance().getNavigationService().addNavigationListener(SelectionListener()) def setText(self,html): self.browser.setText( \ "<html><header></header><body>" + html + "</body></html>") def setURL(self,url): self.browser.setUrl(url) def setLabel(self,text): self.label.setText(text)