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 select_scn_file(): from org.eclipse.swt.widgets import Display, FileDialog, Shell from org.eclipse.swt import SWT display = Display.getDefault().getActiveShell() shell = Shell(display) fd = FileDialog(shell, SWT.OPEN) fd.setText('Open') filterExt = ['*.scn', '*.*'] fd.setFilterExtensions(filterExt) return fd.open()
def __init__(self, rootDataObjects, getChildrenFun, isLeafFun, getImageFun=None, getTextFun=None, title="Explorer", getGrayedFun=None, getBackgroundFun=None, getForegroundFun=None, onSelectionFun=None): def _addRootDataObjects(): # add the roots to the tree for rootDataObject in rootDataObjects: node = TreeItem(self.tree, 0) _decorateTreeItem(node, rootDataObject) # add a dummy node if this is not a leaf if not isLeafFun(rootDataObject): TreeItem(node, 0) def _decorateTreeItem(node, dataObject): node.setData(dataObject) if getTextFun is not None: text = getTextFun(dataObject) else: text = unicode(dataObject) if text is not None: node.setText(text) if getImageFun is not None: image = getImageFun(dataObject) if image is not None: # print "not none" node.setImage(image) if getGrayedFun is not None: grayed = getGrayedFun(dataObject) if grayed is not None: node.setGrayed(grayed) if getBackgroundFun is not None: background = getBackgroundFun(dataObject) if background is not None: node.setBackground(background) if getForegroundFun is not None: foreground = getForegroundFun(dataObject) if foreground is not None: node.setForeground(foreground) class ThisTreeExpandListener(Listener): def handleEvent(self, event): node = event.item # print "expanding node "+str(node.getData()), items = node.getItems() # print ": ",len(items),"children" # check if this subtree has already been expanded before # if so there is nothing to do, otherwise remove dummy nodes for item in items: # print " object",item.getData(),type(item.getData()), if item.getData() is not None: # print "already visited. Stop" return else: # print "remove this node" item.dispose() # get the children and add them to the tree for childDataObject in getChildrenFun(node.getData()): item = TreeItem(node, 0) _decorateTreeItem(item, childDataObject) if not isLeafFun(childDataObject): # create a dummy node TreeItem(item, 0) class ThisTreeSelectionListener(Listener): def handleEvent(self, event): node = event.item # print "item selected",node,type(node) # print "details",event.detail if onSelectionFun is not None: onSelectionFun(node.getData()) parentShell = Display.getDefault().getActiveShell() self.window = Shell(parentShell, SWT.CLOSE | SWT.RESIZE) self.window.setText(title) self.window.setLayout(FillLayout()) self.tree = Tree(self.window, SWT.BORDER) self.tree.addListener(SWT.Expand, ThisTreeExpandListener()) self.tree.addListener(SWT.Selection, ThisTreeSelectionListener()) _addRootDataObjects() size = self.tree.computeSize(300, SWT.DEFAULT) width = max(300, size.x) height = max(300, size.y) self.window.setSize(self.window.computeSize(width, height)) self.window.open()