Changeset 2141 for coopr.gui.pyomo


Ignore:
Timestamp:
Jan 11, 2010 2:43:59 AM (10 years ago)
Author:
wehart
Message:

Adding some notes from Dave.
Drafting a preliminary GUI that supports tabbing for different
command-line executions.

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

    r2136 r2141  
    11from pawt import swing
     2from java.awt import GridBagLayout, GridBagConstraints, FlowLayout
    23from pawt import GridBag
    3 RIGHT = swing.JLabel.RIGHT
     4#RIGHT = swing.JLabel.RIGHT
    45APPROVE_OPTION = swing.JFileChooser.APPROVE_OPTION
    56import java.io
    67import pickle
    78import os
    8 from Console import Console
     9
     10class Container(dict):
     11    """
     12    A generalization of Bunch.  This class allows all other attributes to have a
     13    default value of None.  This borrows the output formatting ideas from the
     14    ActiveState Code Container (recipe 496697).
     15    """
     16
     17    def __init__(self, *args, **kw):
     18        for arg in args:
     19            for item in quote_split('[ \t]+',arg):
     20                r = item.find('=')
     21                if r != -1:
     22                    try:
     23                        val = eval(item[r+1:])
     24                    except:
     25                        val = item[r+1:]
     26                    kw[item[:r]] = val
     27        dict.__init__(self,kw)
     28        self.__dict__.update(kw)
     29        if not '_name_' in kw:
     30            self._name_ = self.__class__.__name__
     31
     32    def set_name(self, name):
     33        self._name_ = name
     34
     35    def __setitem__(self, name, val):
     36        self.__setattr__(name,val)
     37
     38    def __getitem__(self, name):
     39        return self.__getattr__(name)
     40
     41    def __setattr__(self, name, val):
     42        if name[0] != '_':
     43            dict.__setitem__(self, name, val)
     44        self.__dict__[name] = val
     45
     46    def __getattr__(self, name):
     47        try:
     48            return dict.__getitem__(self, name)
     49        except:
     50            if name[0] == '_':
     51                raise AttributeError, "Unknown attribute %s" % name
     52        return None
     53
     54    def __repr__(self):
     55        attrs = sorted("%s = %r" % (k, v) for k, v in self.__dict__.iteritems() if not k.startswith("_"))
     56        return "%s(%s)" % (self.__class__.__name__, ", ".join(attrs))
     57
     58    def __str__(self):
     59        return self.as_string()
     60
     61    def __str__(self, nesting = 1, indent='', print_name=True):
     62        attrs = []
     63        if not print_name:
     64            nesting -= 1
     65        indentation = indent+"    " * nesting
     66        for k, v in self.__dict__.iteritems():
     67            if not k.startswith("_"):
     68                text = [indentation, k, " = "]
     69                if isinstance(v, Container):
     70                    text.append(v.__str__(nesting + 1))
     71                else:
     72                    text.append(repr(v))
     73                attrs.append("".join(text))
     74        attrs.sort()
     75        if print_name:
     76            attrs.insert(0, indent+self._name_ + ":")
     77        return "\n".join(attrs)
     78
     79
    980
    1081class GUI:
    1182
    1283    def __init__(self):
    13         self.frame = swing.JFrame("Coopr", windowClosing=self._fileQuit)
     84        self.tab_id=0
     85        self.tab_info = {}
     86        self.frame = swing.JFrame("Pyomo Command Driver", windowClosing=self._fileQuit)
    1487        self.frame.JMenuBar = self.create_menubar()
    1588
    16         bag = GridBag(self.frame.contentPane, \
     89        self.bag = GridBag(self.frame.contentPane, \
    1790                        fill='BOTH', weightx=1.0)
    1891
    1992        # do the rest of the layout in a GridBag
    20         #self.do_layout(bag)
    21         c = Console()
    22         pane = swing.JScrollPane(c.textpane,\
    23                     verticalScrollBarPolicy=swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
    24                     size=(1000,10000))
    25         #pane.minimizeSizeSet(10,10)
    26         bag.addRow(pane, weighty=1.0)
    27         bag.addRow(swing.JLabel("Coopr version VERSION (DATE)"))
     93        #self.do_layout(self.bag)
     94        self.tabbed = swing.JTabbedPane()
     95        self.create_tab()
     96        self.bag.addRow(self.tabbed, weighty=1.0)
     97        self.bag.addRow(swing.JLabel("Pyomo version VERSION (DATE)"))
    2898
    2999        # Create a file chooser
    30100        self.chooser = swing.JFileChooser()
    31101        self.chooser.currentDirectory = java.io.File(os.getcwd())
    32         # Start Console
    33         c.write("DRAFT COOPR CONSOLE GUI\n\n"+Console.header, 'output')
    34         c.capturePythonOutput()
    35         c.textpane.requestFocus()
    36         c.newInput()
    37102        # Finish up and set the size
    38103        self.frame.pack()
     
    40105        self.frame.size = self.frame.getPreferredSize()
    41106
     107    def create_tab(self):
     108        self.tab_id += 1
     109        tab = Container()
     110        self.tab_info[self.tab_id] = tab
     111        #
     112        # Setting up the panel for the tab
     113        #
     114        panel = swing.JPanel()
     115        bag = GridBag(panel, fill='BOTH', weightx=1.0)
     116        self.tabbed.add(panel, 'Tab %d' % self.tab_id)
     117        #
     118        # Creating a text area for the command that will be executed
     119        #
     120        tab.input = swing.JTextArea("", 6, 80)
     121        bag.addRow(tab.input)
     122        tab.input.append("COMMAND %d" % self.tab_id)
     123        #
     124        # create panel for buttons that manage command execution/output
     125        #
     126        buttons = swing.JPanel(FlowLayout(alignment=FlowLayout.LEFT))
     127        tab.buttonExecute = swing.JButton("Execute", actionPerformed=self._buttonExecute)
     128        buttons.add(tab.buttonExecute)
     129        tab.buttonClearOutput = swing.JButton("Clear Output", actionPerformed=self._buttonClearOutput)
     130        buttons.add(tab.buttonClearOutput)
     131        bag.addRow(buttons)
     132        #
     133        tab.output = swing.JTextArea("",6,80)
     134        pane = swing.JScrollPane(tab.output,\
     135                    verticalScrollBarPolicy=swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
     136                    size=(1000,10000))
     137        bag.addRow(pane, weighty=1.0)
     138        tab.output.append("DRAFT GUI for PYOMO COMMAND DRIVER\n\n")
     139
    42140    def create_menubar(self):
    43141        """build menu bar"""
     
    45143        #
    46144        file = swing.JMenu("File")
     145        file.add(swing.JMenuItem("New Command", actionPerformed = self._fileNewCommand))
    47146        file.add(swing.JMenuItem("Load...", actionPerformed = self._fileLoad))
    48147        file.add(swing.JMenuItem("Save...", actionPerformed = self._fileSave))
     
    55154        file.add(swing.JMenuItem("Paste", actionPerformed = self._editPaste))
    56155        file.add(swing.JMenuItem("Quit", actionPerformed = self._editSelectAll))
    57         file.add(swing.JMenuItem("Clear console", actionPerformed = self._editClearConsole))
    58156        menubar.add(file)
    59157        #
    60         file = swing.JMenu("Packages")
    61         file.add(swing.JMenuItem("Versions", actionPerformed = self._packagesVersions))
    62         file.add(swing.JMenuItem("Install...", actionPerformed = self._packagesInstall))
    63         file.add(swing.JMenuItem("Update...", actionPerformed = self._packagesUpdate))
    64         menubar.add(file)
     158        ##file = swing.JMenu("Packages")
     159        ##file.add(swing.JMenuItem("Versions", actionPerformed = self._packagesVersions))
     160        ##file.add(swing.JMenuItem("Install...", actionPerformed = self._packagesInstall))
     161        ##file.add(swing.JMenuItem("Update...", actionPerformed = self._packagesUpdate))
     162        ##menubar.add(file)
    65163        #
    66164        file = swing.JMenu("Help")
     
    71169        menubar.add(file)
    72170        return menubar
     171
     172    def _fileNewCommand(self, event=None):
     173        self.create_tab()
    73174
    74175    def _fileLoad(self, event=None):
     
    103204            file.close()
    104205
    105     def _fileSaveToFile(selfself, event=None):
     206    def _fileSaveToFile(self, event=None):
    106207        pass
    107208
     
    110211        sys.exit(0)
    111212
    112     def _editCopy(selfself, event=None):
    113         pass
    114 
    115     def _editPaste(selfself, event=None):
    116         pass
    117 
    118     def _editSelectAll(selfself, event=None):
    119         pass
    120 
    121     def _editClearConsole(selfself, event=None):
    122         pass
    123 
    124     def _helpConsole(selfself, event=None):
    125         pass
    126 
    127     def _helpCoinWiki(selfself, event=None):
    128         pass
    129 
    130     def _helpCooprWiki(selfself, event=None):
    131         pass
    132 
    133     def _helpAbout(selfself, event=None):
    134         pass
    135 
    136     def _packagesVersions(selfself, event=None):
    137         pass
    138 
    139     def _packagesInstall(selfself, event=None):
    140         pass
    141 
    142     def _packagesUpdate(selfself, event=None):
     213    def _editCopy(self, event=None):
     214        pass
     215
     216    def _editPaste(self, event=None):
     217        pass
     218
     219    def _editSelectAll(self, event=None):
     220        pass
     221
     222    def _helpConsole(self, event=None):
     223        pass
     224
     225    def _helpCoinWiki(self, event=None):
     226        pass
     227
     228    def _helpCooprWiki(self, event=None):
     229        pass
     230
     231    def _helpAbout(self, event=None):
     232        pass
     233
     234    def _packagesVersions(self, event=None):
     235        pass
     236
     237    def _packagesInstall(self, event=None):
     238        pass
     239
     240    def _packagesUpdate(self, event=None):
     241        pass
     242
     243    def _buttonExecute(self, event=None):
     244        pass
     245
     246    def _buttonClearOutput(self, event=None):
    143247        pass
    144248
Note: See TracChangeset for help on using the changeset viewer.