def run(self): self.frame = frame = JFrame('WSAShelp_09', layout=BorderLayout(), componentResized=self.frameResized, defaultCloseOperation=JFrame.EXIT_ON_CLOSE) #----------------------------------------------------------------------- # RegExp used to locate method names #----------------------------------------------------------------------- methRE = re.compile(r'^(\w+)(?:\s+.*)$', re.MULTILINE) #----------------------------------------------------------------------- # Add our menu bar to the frame #----------------------------------------------------------------------- frame.setJMenuBar(self.MenuBar()) #----------------------------------------------------------------------- # Create & Populate the JTabbedPane #----------------------------------------------------------------------- WASobjs = [ ('wsadmin', None), # Special case ('Help', Help), ('AdminApp', AdminApp), ('AdminConfig', AdminConfig), ('AdminControl', AdminControl), ('AdminTask', AdminTask) ] tabs = self.tabs for name, WASobj in WASobjs: #------------------------------------------------------------------- # Use a single ScrollPane for the AdminTask help #------------------------------------------------------------------- if name in ['wsadmin', 'AdminTask']: if WASobj: data = WASobj.help().expandtabs() else: data = Help.wsadmin().expandtabs() pane = JTextPane(text=data, editable=0, font=monoFont) #--------------------------------------------------------------- # Move the caret to ensure that the starting text is shown #--------------------------------------------------------------- pane.moveCaretPosition(0) tabs.addTab(name, JScrollPane(pane)) self.tPanes[name] = [pane] else: #--------------------------------------------------------------- # Use a RegExp to identify where the 1st method starts. #--------------------------------------------------------------- text = WASobj.help().expandtabs() mo = re.search(methRE, text) # Match Object desc = text[:mo.start(1)].strip() meth = text[mo.start(1):].strip() #--------------------------------------------------------------- # The description section is before the 1st method #--------------------------------------------------------------- topPane = JTextPane(text=desc, editable=0, font=monoFont) topPane.moveCaretPosition(0) top = JScrollPane(topPane) #--------------------------------------------------------------- # For the other scripting objects, use a vertically split pane # with the top containing the description section, and the # bottom (eventually) containing the method details. #--------------------------------------------------------------- splitPane = JSplitPane( JSplitPane.VERTICAL_SPLIT, top, JLabel('One moment please...'), resizeWeight=0.5, # divider position = 50% oneTouchExpandable=1) #--------------------------------------------------------------- # Start a separate thread to parse the method text and build a # a JTable to be put into the bottom part of this splitPane #--------------------------------------------------------------- self.tPanes[name] = [topPane] tableTask( meth, # Help text to be parsed / processed splitPane, # SplitPane to be updated self.tPanes[name], # tPanes entry to be updated WASobj # WAS scripting object ).execute() tabs.addTab(name, splitPane) #----------------------------------------------------------------------- # Add the tabbed pane to the frame & show the result #----------------------------------------------------------------------- frame.add(tabs, 'Center') frame.pack() self.center(frame) frame.setVisible(1)
def run(self): frame = JFrame('WSAShelp_05', layout=BorderLayout(), defaultCloseOperation=JFrame.EXIT_ON_CLOSE) #----------------------------------------------------------------------- # RegExp used to locate the method name portion of the help text #----------------------------------------------------------------------- methRE = re.compile(r'^(\w+)(?:\s+.*)$', re.MULTILINE) monoFont = Font('Courier', Font.PLAIN, 12) #----------------------------------------------------------------------- # Create & Populate the JTabbedPane #----------------------------------------------------------------------- objs = [ ('wsadmin', None), # Special case ('Help', Help), ('AdminApp', AdminApp), ('AdminConfig', AdminConfig), ('AdminControl', AdminControl), ('AdminTask', AdminTask) ] self.tPanes = {} highlighters = {} self.tabs = tabs = JTabbedPane(stateChanged=self.tabPicked) for name, obj in objs: #------------------------------------------------------------------- # Use a single ScrollPane for the AdminTask help #------------------------------------------------------------------- if name in ['wsadmin', 'AdminTask']: if obj: data = obj.help().expandtabs() else: data = Help.wsadmin().expandtabs() pane = JTextPane(text=data, editable=0, font=monoFont) pane.moveCaretPosition(0) tabs.addTab(name, JScrollPane(pane)) self.tPanes[name] = [pane] # print 'tPanes[ "%s" ]' % name else: #--------------------------------------------------------------- # Use a RegExp to identify where the 1st method starts. #--------------------------------------------------------------- text = obj.help().expandtabs() mo = re.search(methRE, text) # Match Object desc = text[:mo.start(1)].strip() meth = text[mo.start(1):].strip() #--------------------------------------------------------------- # The description section is before the 1st method #--------------------------------------------------------------- topPane = JTextPane(text=desc, editable=0, font=monoFont) topPane.moveCaretPosition(0) top = JScrollPane(topPane) #--------------------------------------------------------------- # The method section starts at the 1st method #--------------------------------------------------------------- botPane = JTextPane(text=meth, editable=0, font=monoFont) botPane.moveCaretPosition(0) bot = JScrollPane(botPane) #--------------------------------------------------------------- # For the other scripting objects, use a vertically split pane # with the top containing the description section, and the # bottom containing the method details. #--------------------------------------------------------------- tabs.addTab( name, JSplitPane( JSplitPane.VERTICAL_SPLIT, top, bot, resizeWeight=0.5, # divider position = 50% oneTouchExpandable=1)) self.tPanes[name] = [topPane, botPane] # print 'tPanes[ "%s" ]' % name #----------------------------------------------------------------------- # Add the tabbed pane to the frame & show the result #----------------------------------------------------------------------- frame.add(tabs, 'Center') #----------------------------------------------------------------------- # Label & input field for user input #----------------------------------------------------------------------- info = JPanel(BorderLayout()) info.add(JLabel('Highlight text:'), 'West') self.textField = JTextField(actionPerformed=self.lookFor) info.add(self.textField, 'Center') frame.add(info, 'South') frame.pack() self.center(frame) frame.setVisible(1) self.textField.requestFocusInWindow()