Changeset 4138

Show
Ignore:
Timestamp:
06/15/08 11:43:22 (4 months ago)
Author:
ed
Message:

Improved some of the basic functionality. Added support for editing .cnxml files.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/ed-ide/Studio.py

    r4081 r4138  
    1111import components 
    1212from components.ClassDesigner import ClassDesigner 
    13 from components.CxnEditor import CxnEditor 
     13from components.CxnEditor import CxnEditorPage 
    1414from components.MenuDesigner import MenuDesigner 
    1515from components.ReportDesigner import ReportDesigner 
    1616from components.TextEditor import TextEditorPage 
     17 
     18 
    1719 
    1820class ProjectTree(dabo.ui.dTreeView): 
     
    4345        nd = self._context["node"] 
    4446        pth = self._context["filepath"] 
    45         if pth.endswith(".py"): 
    46             self.controller.editFile(pth)            
    47  
     47        self.controller.editFile(pth)            
     48         
    4849 
    4950class StudioToolBar(dabo.ui.dToolBar): 
     
    6768 
    6869 
     70 
    6971class StudioForm(dabo.ui.dDockForm): 
    7072    def initProperties(self): 
     
    8688                ShowCaption=False, ShowGripper=True, BottomDockable=False,  
    8789                LeftDockable=False, RightDockable=False) 
    88         self.toolbar.Sizer = dabo.ui.dSizer("h") 
     90        self.toolbar.Sizer = dabo.ui.dSizer("h", DefaultSpacing=10) 
     91        # Automatically add child controls to the toolbar sizer 
     92        self.toolbar.bindEvent(dEvents.ChildBorn, self.onToolbarItemAdded) 
    8993        cp = self.CenterPanel 
    9094        csz = cp.Sizer = dabo.ui.dSizer("v") 
     
    9397        self._toolSets = {None: []} 
    9498        self._currentToolBar = None 
    95         self.pgfEditors = dabo.ui.dPageFrame(self.CenterPanel, PageCount=0) 
     99        dabo.ui.setAfter(self, "CurrentToolBar", None) 
     100        self.pgfEditors = dabo.ui.dDockTabs(self.CenterPanel, PageCount=0) 
    96101        csz.append1x(self.pgfEditors) 
    97102         
     
    99104        self.registerComponents() 
    100105        self.registerPlugins() 
     106         
     107        self._currentProject = None 
     108        # See if there is a saved project 
     109        proj = self.PreferenceManager.lastOpenedProject 
     110        print "LAST", proj 
     111        if isinstance(proj, basestring) and os.path.exists(proj): 
     112            self.openProject(proj) 
    101113 
    102114        # Make sure that all components are visible 
    103115        dabo.ui.callAfter(self._showAllPanels) 
     116 
     117 
     118    def onToolbarItemAdded(self, evt): 
     119        self.toolbar.Sizer.append(evt.child) 
    104120 
    105121 
     
    116132            try: 
    117133                comp.register(self) 
    118             except AttributeError: 
     134            except AttributeError, e: 
     135                print "ERR", e 
    119136                dabo.errorLog.write(_("Component '%s' lacks a 'register()' method.") % comp) 
    120137 
     
    129146 
    130147    def editFile(self, pth): 
    131         pg = self.pgfEditors.appendPage(TextEditorPage) 
    132         pg.openFile(pth) 
    133         self.pgfEditors.SelectedPage = pg 
    134         self.CurrentToolBar = "TextEditor" 
     148        if pth.endswith(".py"): 
     149            pg = self.pgfEditors.appendPage(TextEditorPage) 
     150            pg.openFile(pth) 
     151            self.pgfEditors.SelectedPage = pg 
     152            self.CurrentToolBar = "TextEditor" 
     153        elif pth.endswith(".cnxml"): 
     154            pg = self.pgfEditors.appendPage(CxnEditorPage) 
     155            pg.openFile(pth) 
     156            self.pgfEditors.SelectedPage = pg 
     157            self.CurrentToolBar = "CxnEditor" 
    135158 
    136159 
    137160    def onOpenProject(self, evt): 
    138         self.openProject() 
    139  
    140  
    141     def openProject(self): 
    142161        pjd = dabo.ui.getDirectory(_("Select Project Base")) 
    143162        if pjd: 
    144             self.tree.makeDirTree(pjd, ignored=["*pyc", "*~"], expand=False) 
    145             self.tree.getRootNode().Expanded = True 
     163            self.openProject(pjd) 
     164 
     165 
     166    def openProject(self, proj): 
     167        self.Application._currentProject = proj 
     168        self.tree.makeDirTree(proj, ignored=["*pyc", "*~"], expand=False) 
     169        self.tree.getRootNode().Expanded = True 
    146170 
    147171 
     
    155179            if val not in self._toolSets: 
    156180                dabo.errorLog.write(_("Invalid toolbar specified: '%s'") % val) 
    157                  
    158181                print self._toolSets.keys() 
    159182                return 
    160             # Hide all visible buttons 
    161             for btn in self.toolbar.Children[::-1]: 
    162                 self.toolbar.remove(btn, False) 
    163183            self._currentToolBar = val 
    164             # Show the new button set 
    165             for btn in self._toolSets[self._currentToolBar]: 
    166                 try: 
    167                     self.toolbar.appendItem(btn) 
    168                 except AttributeError: 
    169                     # A control, not a tool item 
    170                     btn.Visible = True 
     184            sz = self.toolbar.Sizer 
     185            curr = self._toolSets[self._currentToolBar] 
     186            for itm in self.toolbar.Children: 
     187                itm.Visible = (itm in curr) 
     188            self.toolbar.layout() 
    171189        else: 
    172190            self._properties["CurrentToolBar"] = val 
     
    178196 
    179197 
     198class StudioApp(dabo.dApp): 
     199    def afterFinish(self): 
     200        # Save the current project being edited. 
     201        pm = self.PreferenceManager 
     202        print "CURR", self._currentProject 
     203        if self._currentProject is None: 
     204            pm.removePref(lastOpenedProject) 
     205        else: 
     206            pm.lastOpenedProject = self._currentProject 
     207         
     208         
    180209def main(): 
    181     app = dabo.dApp() 
     210    app = StudioApp() 
    182211    app.BasePrefKey = "DeveloperStudio" 
    183212    app.MainFormClass = StudioForm 
  • branches/ed-ide/components/CxnEditor/CxnEditor.py

    r4061 r4138  
    1616 
    1717 
    18 class EditorForm(dui.dForm): 
    19     def afterSetMenuBar(self): 
    20         self.createMenu() 
    21          
    22          
     18class CxnEditorPage(dui.dPage): 
    2319    def afterInit(self): 
    2420        self.newFileName = "Untitled" 
     
    3026                "SQLite" : None } 
    3127        connKeys = ["host", "dbtype", "port", "database", "user", "password"] 
     28        # Create the attributes 
     29        for key in connKeys: 
     30            setattr(self, key, "") 
    3231        self.connDict = dict.fromkeys(connKeys) 
    3332        self._origConnDict = dict.fromkeys(connKeys) 
     
    5150     
    5251    def createControls(self): 
    53         self.Caption = "Connection Editor" 
    54         self.Size= (500, 800) 
    55         self.bg = dui.dPanel(self, BackColor="LightSteelBlue") 
    56          
    5752        gbsz = dui.dGridSizer(VGap=12, HGap=5, MaxCols=2) 
    5853         
    5954        # Add the fields 
     55        self.dataFields = {} 
    6056        # Connection Dropdown 
    61         cap = dui.dLabel(self.bg, Caption="Connection") 
    62         ctl = dui.dDropdownList(self.bg, Choices=[""],  
    63                 RegID="connectionSelector") 
    64         ctl.bindEvent(dEvents.Hit, self.onConnectionChange) 
    65         btn = dui.dButton(self.bg, Caption="Edit Name", RegID="cxnEdit") 
     57        cap = dui.dLabel(self, Caption="Connection") 
     58        ctl = dui.dDropdownList(self, Choices=[""], OnHit=self.onConnectionChange) 
     59        self.dataFields["name"] = ctl 
     60        self.connectionSelector = ctl 
     61        ctl.controller = self 
     62        btn = dui.dButton(self, Caption="Edit Name", OnHit=self.onCxnEdit) 
     63        self.cxnEdit = btn 
     64        btn.controller = self 
    6665        hsz = dui.dSizer("h") 
    6766        hsz.append(ctl) 
     
    6968        hsz.append(btn) 
    7069 
    71         btn = dui.dButton(self.bg, Caption="Delete This Connection", RegID="cxnDelete", 
    72                 DynamicEnabled=self.hasMultipleConnections) 
     70        btn = dui.dButton(self, Caption="Delete This Connection", 
     71                DynamicEnabled=self.hasMultipleConnections, 
     72                OnHit = self.onCxnDelete) 
     73        self.cxnDelete = btn 
     74        btn.controller = self 
    7375        hsz.appendSpacer(10) 
    7476        hsz.append(btn) 
     
    7880         
    7981        # Backend Type 
    80         cap = dui.dLabel(self.bg, Caption="Database Type") 
    81         ctl = dui.dDropdownList(self.bg, RegID="DbType",  
    82                 Choices=["MySQL", "Firebird", "PostgreSQL", "MsSQL", "SQLite"],  
    83                 DataSource="form", DataField="dbtype", 
     82        cap = dui.dLabel(self, Caption="Database Type") 
     83        ctl = dui.dDropdownList(self, Choices=["MySQL", "Firebird", "PostgreSQL", "MsSQL", "SQLite"],  
    8484                OnHit=self.onDbTypeChanged) 
     85        self.dataFields["dbtype"] = ctl 
     86        self.DbType = ctl 
     87        ctl.controller = self 
    8588        gbsz.append(cap, halign="right") 
    8689        gbsz.append(ctl) 
     
    8891         
    8992        # Host 
    90         cap = dui.dLabel(self.bg, Caption="Host") 
    91         ctl = dui.dTextBox(self.bg, DataSource="form", DataField="host") 
     93        cap = dui.dLabel(self, Caption="Host") 
     94        ctl = dui.dTextBox(self) 
     95        self.dataFields["host"] = ctl 
     96        ctl.controller = self 
    9297        gbsz.append(cap, halign="right") 
    9398        gbsz.append(ctl, "expand") 
     
    95100         
    96101        # Port 
    97         cap = dui.dLabel(self.bg, Caption="Port") 
    98         ctl = dui.dTextBox(self.bg, DataSource="form", DataField="port") 
     102        cap = dui.dLabel(self, Caption="Port") 
     103        ctl = dui.dTextBox(self) 
     104        self.dataFields["port"] = ctl 
     105        ctl.controller = self 
    99106        gbsz.append(cap, halign="right") 
    100107        gbsz.append(ctl, "expand") 
     
    102109         
    103110        # Database 
    104         cap = dui.dLabel(self.bg, Caption="Database") 
    105         ctl = dui.dTextBox(self.bg, DataSource="form", DataField="database") 
     111        cap = dui.dLabel(self, Caption="Database") 
     112        ctl = dui.dTextBox(self) 
     113        self.dataFields["database"] = ctl 
     114        self.dbText = ctl 
     115        ctl.controller = self 
    106116        hsz = dui.dSizer("h") 
    107         self.btnDbSelect = dui.dButton(self.bg, Caption=" ... ", RegID="btnDbSelect", 
    108                Visible=False) 
     117        self.btnDbSelect = dui.dButton(self, Caption=" ... ", Visible=False, OnHit=self.onDbSelect) 
     118        self.btnDbSelect.controller = self 
    109119        hsz.append1x(ctl) 
    110120        hsz.appendSpacer(2) 
     
    112122        gbsz.append(cap, halign="right") 
    113123        gbsz.append(hsz, "expand") 
    114         self.dbText = ctl 
    115124         
    116125        # Username 
    117         cap = dui.dLabel(self.bg, Caption="User Name") 
    118         ctl = dui.dTextBox(self.bg, DataSource="form", DataField="user") 
     126        cap = dui.dLabel(self, Caption="User Name") 
     127        ctl = dui.dTextBox(self) 
     128        self.dataFields["user"] = ctl 
     129        self.userText = ctl 
     130        ctl.controller = self 
    119131        gbsz.append(cap, halign="right") 
    120132        gbsz.append(ctl, "expand") 
    121         self.userText = ctl 
    122133         
    123134        # Password 
    124         cap = dui.dLabel(self.bg, Caption="Password") 
    125         ctl = dui.dTextBox(self.bg, PasswordEntry=True,  
    126                 DataSource="form", DataField="password") 
     135        cap = dui.dLabel(self, Caption="Password") 
     136        ctl = dui.dTextBox(self, PasswordEntry=True) 
     137        self.dataFields["password"] = ctl 
     138        self.pwText = ctl 
     139        ctl.controller = self 
    127140        gbsz.append(cap, halign="right") 
    128141        gbsz.append(ctl, "expand") 
    129         self.pwText = ctl 
    130  
    131         # Open Button 
     142 
    132143        btnSizer1 = dui.dSizer("h") 
    133144        btnSizer2 = dui.dSizer("h") 
    134         btnTest = dui.dButton(self.bg, RegID="btnTest", Caption="Test...") 
    135         btnSave = dui.dButton(self.bg, RegID="btnSave", Caption="Save") 
    136         btnNewConn = dui.dButton(self.bg, RegID="btnNewConn",  
    137                 Caption="New Connection") 
    138         btnNewFile = dui.dButton(self.bg, RegID="btnNewFile",  
    139                 Caption="New File") 
    140         btnOpen = dui.dButton(self.bg, RegID="btnOpen",  
    141                 Caption="Open File...") 
    142         btnSizer1.append(btnTest, 0, border=3) 
    143         btnSizer1.append(btnSave, 0, border=3) 
    144         btnSizer2.append(btnNewConn, 0, border=3) 
    145         btnSizer2.append(btnNewFile, 0, border=3) 
    146         btnSizer2.append(btnOpen, 0, border=3) 
     145        self.btnTest = dui.dButton(self, Caption="Test...", OnHit=self.onTest) 
     146        self.btnSave = dui.dButton(self, Caption="Save", OnHit=self.onSave) 
     147        self.btnNewConn = dui.dButton(self, Caption="New Connection", OnHit=self.onNewConn) 
     148        self.btnNewFile = dui.dButton(self, Caption="New File", OnHit=self.onNewFile) 
     149        self.btnOpen = dui.dButton(self, Caption="Open File...", OnHit=self.onOpenFile) 
     150        self.btnTest.controller = self.btnSave.controller = self.btnNewConn.controller = \ 
     151                self.btnNewFile.controller = self.btnOpen.controller = self 
     152        btnSizer1.append(self.btnTest, 0, border=3) 
     153        btnSizer1.append(self.btnSave, 0, border=3) 
     154        btnSizer2.append(self.btnNewConn, 0, border=3) 
     155        btnSizer2.append(self.btnNewFile, 0, border=3) 
     156        btnSizer2.append(self.btnOpen, 0, border=3) 
    147157         
    148158        gbsz.setColExpand(True, 1) 
    149159        self.gridSizer = gbsz 
    150160         
    151         self.bg.Sizer = dui.dSizer("v") 
    152         self.bg.Sizer.append(gbsz, 0, "expand", halign="center", border=20) 
    153         self.bg.Sizer.append(btnSizer1, 0, halign="center") 
    154         self.bg.Sizer.append(btnSizer2, 0, halign="center") 
    155         self.Sizer = dui.dSizer("h") 
    156         self.Sizer.append(self.bg, 1, "expand", halign="center") 
    157         self.Layout() 
     161        self.Sizer = dui.dSizer("v") 
     162        self.Sizer.append(gbsz, 0, "expand", halign="center", border=20) 
     163        self.Sizer.append(btnSizer1, 0, halign="center") 
     164        self.Sizer.append(btnSizer2, 0, halign="center") 
     165        self.layout() 
    158166 
    159167 
     
    162170     
    163171     
    164     def onHit_cxnDelete(self, evt): 
     172    def onCxnDelete(self, evt): 
    165173        if not dabo.ui.areYouSure(_("Delete this connection?"),  
    166174                title=_("Confirm Deletion"), cancelButton=False): 
     
    178186             
    179187         
    180     def onHit_cxnEdit(self, evt): 
     188    def onCxnEdit(self, evt): 
    181189        chc = self.connectionSelector.Choices 
    182190        idx = self.connectionSelector.PositionValue 
     
    198206                 
    199207 
    200     def onHit_btnTest(self, evt): 
     208    def onTest(self, evt): 
    201209        self.testConnection() 
    202210     
    203211     
    204     def onHit_btnOpen(self, evt): 
     212    def onOpenFile(self, evt): 
    205213        # Update the values 
    206214        self.updtFromForm() 
     
    209217     
    210218     
    211     def onHit_btnNewFile(self, evt): 
     219    def onNewFile(self, evt): 
    212220        # Update the values 
    213221        self.updtFromForm() 
     
    218226         
    219227     
    220     def onHit_btnNewConn(self, evt): 
     228    def onNewConn(self, evt): 
    221229        # Update the values 
    222230        self.updtFromForm() 
     
    225233         
    226234         
    227     def onHit_btnSave(self, evt): 
     235    def onSave(self, evt): 
    228236        self.saveFile() 
    229237         
     
    255263 
    256264     
    257     def onHit_btnDbSelect(self, evt): 
     265    def onDbSelect(self, evt): 
    258266        dbFile = dui.getFile() 
    259267        if dbFile: 
     
    262270     
    263271 
    264     def onHit_connectionSelector(self, evt): 
    265         self.currentConn = self.connectionSelector.StringValue       
    266         self.updtToForm() 
    267         self.enableControls() 
    268         self.update() 
    269          
    270      
    271272    def testConnection(self): 
    272273        # Update the values 
     
    293294        the connection dictionary with them. 
    294295        """ 
     296        print "UPDT form FORM" 
    295297        # Make sure that changes to the current control are used. 
    296         self.activeControlValid() 
     298        self.Form.activeControlValid() 
    297299        if self.currentConn is not None: 
    298300            dd = self.connDict[self.currentConn] 
    299301            for fld in dd.keys(): 
    300                 val = eval("self.%s" % fld) 
     302                val = self.dataFields[fld].Value 
    301303                if fld == "password": 
    302304                    origVal = self.crypt.decrypt(dd[fld]) 
     
    315317        dictionary. 
    316318        """ 
     319        print "UPDT TO FORM" 
    317320        if self.currentConn is not None: 
    318321            dd = self.connDict[self.currentConn] 
     
    323326                else: 
    324327                    val = dd[fld] 
    325                 if isinstance(val, basestring): 
    326                     val = self.escQuote(val)        # Add quotes 
    327                 exec("self.%s = %s" % (fld, val) ) 
     328                self.dataFields[fld].Value = val 
    328329 
    329330     
     
    339340        self.connDict = {} 
    340341        # Set the form caption 
    341         self.Caption = "Dabo Connection Editor: %s" % os.path.basename(self.connFile) 
     342        self.Caption = os.path.basename(self.connFile) 
    342343        # Add a new blank connection 
    343344        self.newConnection() 
     
    398399    def populate(self): 
    399400        self.updtToForm() 
    400       self.update() 
     401#     self.update() 
    401402        conn = self.currentConn 
    402403        self.connectionSelector.Value = conn 
     
    404405 
    405406    def openFile(self, connFile=None): 
    406         self.activeControlValid() 
     407        self.Form.activeControlValid() 
    407408        # See if the user wants to save changes (if any) 
    408409        if not self.confirmChanges(): 
     
    433434            self.currentConn = self.connDict.keys()[0] 
    434435            # Set the form caption 
    435             self.Caption = _("Dabo Connection Editor: %s") % os.path.basename(self.connFile) 
     436            self.Caption = os.path.basename(self.connFile) 
    436437            # Fill the controls 
    437438            self.populate() 
     
    443444     
    444445    def confirmChanges(self): 
    445         self.activeControlValid() 
     446        self.Form.activeControlValid() 
    446447        self.updtFromForm() 
    447448        if self._origConnDict != self.connDict: 
  • branches/ed-ide/components/CxnEditor/__init__.py

    r4063 r4138  
    22# -*- coding: utf-8 -*- 
    33 
    4 from CxnEditor import EditorForm 
     4import dabo 
     5import dabo.dEvents as dEvents 
     6from dabo.dLocalize import _ 
     7import CxnEditor 
     8from CxnEditor import CxnEditorPage 
     9 
     10 
     11masterForm = None 
     12 
     13def register(master): 
     14    global masterForm 
     15    masterForm = master 
     16    tb = master.toolbar 
     17 
     18    dummyBtn = dabo.ui.dBitmapButton(tb, Picture="open", AutoSize=False,  
     19            OnMouseLeftDown=onDummy) 
     20 
     21    master.setToolBarGroup("CxnEditor", [dummyBtn]) 
     22 
     23 
     24def onDummy(self, evt): 
     25    print "DUMMY BUTTON" 
     26 
  • branches/ed-ide/components/TextEditor/__init__.py

    r4081 r4138  
    1515    tb = master.toolbar 
    1616 
    17     funcBtn = tb.appendButton(_("Functions"),  
    18             dabo.ui.bitmapFromData(TextEditor.funcButtonData()), 
    19             toggle=False, 
     17    funcBtn = dabo.ui.dBitmapButton(tb,  
     18            Picture=dabo.ui.bitmapFromData(TextEditor.funcButtonData()), 
    2019            OnMouseLeftDown=onFuncButton) 
    21     bmkBtn = tb.appendButton(_("Bookmarks"),  
    22             dabo.ui.bitmapFromData(TextEditor.bmkButtonData()), 
    23             toggle=False, 
     20    bmkBtn = dabo.ui.dBitmapButton(tb, 
     21            Picture=dabo.ui.bitmapFromData(TextEditor.bmkButtonData()), 
    2422            OnMouseLeftDown=onBmkButton) 
    25     printBtn = tb.appendButton(_("Print"),  
    26             "print", 
    27             toggle=False, 
    28             OnHit=onPrint) 
     23    printBtn = dabo.ui.dBitmapButton(tb, Picture="print", OnHit=onPrint) 
    2924    lexSelector = dabo.ui.dDropdownList(tb, ValueMode="String", 
    30         Choices = dabo.ui.dEditor.getAvailableLanguages(), 
    31         OnHit = onLexSelect) 
    32     tb.appendControl(lexSelector) 
     25        Choices=dabo.ui.dEditor.getAvailableLanguages(), OnHit=onLexSelect) 
    3326 
    3427    master.setToolBarGroup("TextEditor", [funcBtn, bmkBtn, printBtn, lexSelector]) 
     
    4437    masterForm.Caption = evt.EventObject.Value 
    4538 
    46    def updateLex(self): 
    47            if not self.lexSelector.Choices: 
    48                self.lexSelector.Choices = self.CurrentEditor.getAvailableLanguages() 
     39def updateLex(self): 
     40    if not self.lexSelector.Choices: 
     41        self.lexSelector.Choices = self.CurrentEditor.getAvailableLanguages()