Changeset 2397


Ignore:
Timestamp:
Feb 24, 2010 12:17:16 AM (10 years ago)
Author:
wehart
Message:

Initial rework of GUI. I have the options table working, and
I'm close to getting a Pyomo thread of execution working...

Location:
coopr.gui.pyomo/trunk/coopr/gui/pyomo
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.gui.pyomo/trunk/coopr/gui/pyomo/GUI.py

    r2144 r2397  
    22from java.awt import GridBagLayout, GridBagConstraints, FlowLayout
    33from pawt import GridBag
    4 #RIGHT = swing.JLabel.RIGHT
    54APPROVE_OPTION = swing.JFileChooser.APPROVE_OPTION
    65import java.io
    76import pickle
    87import os
     8from Options import OptionsTable
     9import coopr.pyomo.scripting
     10from threading import Thread
     11
    912
    1013class Container(dict):
     
    7881
    7982
     83class RunPyomo(Thread):
     84
     85    def __init__(self, options, args, parser):
     86        self.options=options
     87        self.args=args
     88        self.parser=parser
     89
     90    def run(self):
     91        self.ostream = StringIO.StringIO()
     92        pyutilib.misc.redirect(self.ostream)
     93        coopr.pyomo.scripting.pyomo.run_pyomo(options, args, parser)
     94        pyutilib.misc.reset_redirect()
     95
    8096
    8197class GUI:
     
    100116        self.chooser = swing.JFileChooser()
    101117        self.chooser.currentDirectory = java.io.File(os.getcwd())
     118
    102119        # Finish up and set the size
    103120        self.frame.pack()
     
    108125        self.tab_id += 1
    109126        tab = Container()
    110         self.tab_info[self.tab_id] = tab
     127        self.tab_info[self.tab_id-1] = tab
    111128        #
    112129        # Setting up the panel for the tab
     
    139156        ##bag.addRow(tab.input)
    140157        ##tab.input.append("COMMAND %d" % self.tab_id)
     158
     159        #
     160        # create panel for the options in the command line
     161        #
     162        options_panel = swing.JPanel(FlowLayout(alignment=FlowLayout.LEFT))
     163        tab.parser = coopr.pyomo.scripting.pyomo.create_parser()
     164        tab.parse_options = tab.parser.parse_args(args=['pyomo'])[0]
     165        tab.options_pane, tab.options_table = self.create_options_table(tab.parser, tab.parse_options)
     166        options_panel.add(tab.options_pane)
     167        bag.addRow(options_panel)
    141168        #
    142169        # create panel for buttons that manage command execution/output
     
    155182        bag.addRow(pane, weighty=1.0)
    156183        tab.output.append("DRAFT GUI for PYOMO COMMAND DRIVER\n\n")
     184
     185    def create_options_table(self, parser, parse_options):
     186        options_table = OptionsTable()
     187        options_table.initialize(parser, parse_options)
     188        scrollPane = swing.JScrollPane()
     189        scrollPane.setPreferredSize(java.awt.Dimension(600,200))
     190        scrollPane.getViewport().setView(options_table)
     191        return scrollPane, options_table
    157192
    158193    def create_menubar(self):
     
    182217        file = swing.JMenu("Help")
    183218        file.add(swing.JMenuItem("Console", actionPerformed = self._helpConsole))
    184         file.add(swing.JMenuItem("COIN-OR wiki", actionPerformed = self._helpCoinWiki))
    185         file.add(swing.JMenuItem("Coopr wiki", actionPerformed = self._helpCooprWiki))
     219        #file.add(swing.JMenuItem("COIN-OR wiki", actionPerformed = self._helpCoinWiki))
     220        #file.add(swing.JMenuItem("Coopr wiki", actionPerformed = self._helpCooprWiki))
    186221        file.add(swing.JMenuItem("About", actionPerformed = self._helpAbout))
    187222        menubar.add(file)
     
    244279
    245280    def _buttonExecute(self, event=None):
    246         pass
     281        if not self.tab_info[self.tabbed.getSelectedIndex()].thread is None:
     282            return
     283        tab = self.tab_info[self.tabbed.getSelectedIndex()]
     284        options = tab.options_table.get_options()
     285        #
     286        thread = RunPyomo(options, ['pyomo', tab.text1.text, tab.text2.text], tab.parser)
     287        tab.thread = thread
     288        thread.start()
    247289
    248290    def _buttonClearOutput(self, event=None):
    249         pass
     291        self.tab_info[self.tabbed.getSelectedIndex()].output.text = ""
    250292
    251293    def _select_file(self):
     
    258300    def _buttonInput1(self, event=None):
    259301        file, absfile = self._select_file()
    260         self.tab_info[1].text1.text = absfile
     302        self.tab_info[self.tabbed.getSelectedIndex()].text1.text = absfile
    261303
    262304    def _buttonInput2(self, event=None):
    263305        file, absfile = self._select_file()
    264         self.tab_info[1].text2.text = absfile
    265 
     306        self.tab_info[self.tabbed.getSelectedIndex()].text2.text = absfile
    266307
    267308
Note: See TracChangeset for help on using the changeset viewer.