Changeset 253

Show
Ignore:
Timestamp:
02/06/07 15:09:48 (2 years ago)
Author:
bob
Message:

Refactoring added

Location:
artub
Files:
91 added
8 modified
1 moved

Legend:

Unmodified
Added
Removed
  • artub/artub.py

    r250 r253  
    6363 
    6464class ArtubTree(wx.TreeCtrl): 
    65     def __init__(self, parent, artub, style = wx.TR_HAS_BUTTONS | # wx.TR_EDIT_LABELS | Crash on Windows !!! 
     65    def __init__(self, parent, artub, style = wx.TR_HAS_BUTTONS | wx.TR_EDIT_LABELS | #Crash on Windows !!! 
    6666                                              wx.TR_HAS_VARIABLE_ROW_HEIGHT | 
    6767                                              wx.TR_LINES_AT_ROOT | 
     
    7575        wx.EVT_RIGHT_UP(self, self.on_default_right_up) 
    7676        wx.EVT_KEY_DOWN(self, self.on_key_down) 
    77         # wx.EVT_TREE_END_LABEL_EDIT(self, tID, self.on_tree_end_label_edit) # Crash on my Windows 
     77        wx.EVT_TREE_END_LABEL_EDIT(self, tID, self.on_tree_end_label_edit) # Crash on my Windows 
    7878         
    7979    def add_tree_item(self, resource, parent = None): 
     
    803803        if not resource.template and isinstance(resource, CGlumolObject): 
    804804            gns = self.app.gns 
    805             cl = gns.get_value(resource.name) 
     805            try: 
     806                cl = gns.get_value(resource.name) 
     807            except: cl = gns.getattr(get_full_name(resource.name)) 
    806808            l = getmembers(cl, isclass) 
    807809            for (name, cl2) in l: # Name, class 
     
    922924        item = event.GetItem() 
    923925        res = self.tree.GetItemData(item) 
    924         res.name = evt.GetLabel() 
    925          
     926        if res: res = res.GetData() 
     927        newname = event.GetLabel() 
     928        if not newname: return 
     929        self.project.rename_class(res.name, newname) 
     930        self.rename_tab(res, newname) 
     931        if hasattr(res, "realname"): res.realname = get_full_name(res.parent.name, newname) 
     932        res.name = newname 
     933        self.update_treeitem(res) 
     934        self.refresh_editor() 
     935 
    926936    def on_find(self, evt): 
    927937        if self.active_editor and self.active_editor.name == "akiki": 
  • artub/choosename.py

    r208 r253  
    11import wx 
    22from script import get_full_name 
     3from identifierctrl import IdentifierCtrl 
    34 
    45class ChooseNameDialog(wx.Dialog): 
     
    2021        sizer2.Add(self.text, 0, wx.ALIGN_CENTRE | wx.ALL, 5) 
    2122         
    22         self.name = wx.TextCtrl(self, -1, "", size = (200, 20)) 
     23        self.name = IdentifierCtrl(self, -1, "", size = (200, 20)) 
    2324        sizer2.Add(self.name, 1,  wx.ALIGN_CENTRE | wx.ALL, 5) 
    2425        self.name.SetValue(name) 
  • artub/glumolnamespace.py

    r204 r253  
    6767        try: 
    6868            classe = self.getattr(script.realname) 
     69            if not classe: raise 
    6970        except: 
     71            print "except 1" 
    7072            try: 
    7173                classe = self.getattr(script.name) 
     74                if not classe: raise 
    7275            except: 
     76                print "except 2" 
    7377                classe = self.getattr(get_full_name(script.name)) 
     78        print "create_object", classe, None, args, getattr(script, "realname", ''), script.name, get_full_name(script.name) 
    7479        return self.create_object(classe, None, args) 
  • artub/identifierctrl.py

    r155 r253  
    11import string 
    22import wx 
     3import wx.lib.masked as masked 
    34 
    4 class ShortNameValidator(wx.PyValidator): 
    5     def __init__(self): 
    6         wx.PyValidator.__init__(self) 
    7         self.allowed_keys = string.digits + string.letters + "_" 
    8         self.Bind(wx.EVT_CHAR, self.OnChar) 
    9  
    10     def Clone(self): 
    11         return ShortNameValidator() 
    12          
    13     def TransferToWindow(self): 
    14         return True 
    15  
    16     def Validate(self, win): 
    17         tc = self.GetWindow() 
    18         val = tc.GetValue() 
    19          
    20         for x in val: 
    21             if x not in self.allowed_keys: 
    22                 return False 
    23  
    24         return True 
    25          
    26     def OnChar(self, event): 
    27         try: key = event.KeyCode() 
    28         except: key = event.KeyCode 
    29  
    30         if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255: 
    31             event.Skip() 
    32             return 
    33  
    34         if chr(key) in self.allowed_keys: 
    35             event.Skip() 
    36             return 
    37  
    38         if not wx.Validator_IsSilent(): 
    39             wx.Bell() 
    40  
    41 class IdentifierCtrl(wx.TextCtrl): 
     5class IdentifierCtrl(masked.TextCtrl): 
    426    def __init__(self, parent = None, id = -1, value = "", pos = wx.DefaultPosition,  
    437                 size = wx.DefaultSize, style = 0, validator = wx.DefaultValidator, 
    448                 name = wx.TextCtrlNameStr): 
    45         wx.TextCtrl.__init__(self, parent, id, value, pos, size, style, ShortNameValidator(), name) 
     9        masked.TextCtrl.__init__(self, parent, id, value, 
     10                                 mask         = "C{1}N{63}", 
     11                                 excludeChars = "", 
     12                                 formatcodes  = "C>", 
     13                                 includeChars = "_", 
     14                                 validRegex   = "^[a-zA-Z_][a-zA-Z_0-9]*", 
     15                                 validRange   = '', 
     16                                 choices      = '', 
     17                                 choiceRequired = True, 
     18                                 defaultValue = '', 
     19                                 demo         = True, 
     20                                 name         = 'identifier', 
     21                                 useFixedWidthFont = False) 
  • artub/newproject.py

    r250 r253  
    77from depplatform import get_image_path 
    88import string 
    9  
    10 allowed_keys = string.digits + string.letters + "_" 
    11                  
    12 def is_control_key(key): 
    13     if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255: 
    14         return True 
    15     return False 
    16  
    17 def is_valid_key(key): 
    18     if key in allowed_keys: 
    19         return True 
    20     return False 
     9from choosename import IdentifierCtrl 
    2110 
    2211class NewProject: 
     
    10089        box = wx.BoxSizer(wx.HORIZONTAL) 
    10190 
    102         class ShortNameValidator(wx.PyValidator): 
    103             def __init__(self): 
    104                 wx.PyValidator.__init__(self) 
    105                 self.Bind(wx.EVT_CHAR, self.OnChar) 
    106          
    107             def Clone(self): 
    108                 return ShortNameValidator() 
    109                  
    110             def TransferToWindow(self): 
    111                 return True 
    112  
    113             def Validate(self, win): 
    114                 tc = self.GetWindow() 
    115                 val = tc.GetValue() 
    116                  
    117                 for x in val: 
    118                     if x not in allowed_keys: 
    119                         return False 
    120          
    121                 return True 
    122                  
    123             def OnChar(self, event): 
    124                 try: key = event.KeyCode() 
    125                 except: key = event.KeyCode 
    126                  
    127                 if is_control_key(key) or is_valid_key(chr(key)): 
    128                     event.Skip() 
    129                     return 
    130  
    131                 if not wx.Validator_IsSilent(): 
    132                     wx.Bell() 
    133  
    13491        label = wx.StaticText(self, -1, _("Short name :")) 
    13592        label.SetHelpText(_("Will be used to name files")) 
    13693        box.Add(label, 0, wx.GROW|wx.ALL, 2) 
    13794 
    138         self.validator = ShortNameValidator() 
    139         self.normname = wx.TextCtrl(self, -1, "", size=(80,-1), validator=self.validator) 
     95        self.normname = IdentifierCtrl(self, -1, "", size=(80,-1)) 
    14096        self.normname.SetHelpText(_("Will be used to name files")) 
    14197        box.Add(self.normname, 1, wx.GROW|wx.ALL, 2) 
  • artub/plugins/speculoos/listboxes.py

    r250 r253  
    1111     
    1212    def __init__(self, speculoos, parent, id, title): 
    13         EditableListBox.__init__(self, parent, id, title, style = wxEL_ALLOW_NEW | wxEL_ALLOW_DELETE | wxEL_ALLOW_UPDOWN) 
     13        EditableListBox.__init__(self, parent, id, title, style = wxEL_ALLOW_EDIT | wxEL_ALLOW_NEW | wxEL_ALLOW_NEW | wxEL_ALLOW_DELETE | wxEL_ALLOW_UPDOWN) 
    1414        self.speculoos = speculoos 
    1515        self.creating = False 
     
    5151         
    5252    def OnChar(self, event): 
    53         try: key = event.KeyCode() 
    54         except: key = event.KeyCode 
     53        pass 
    5554 
    5655    def on_size(self, evt): 
     
    7574        ind = evt.GetIndex() 
    7675        liste = self.GetListCtrl() 
     76         
    7777        if evt.IsEditCancelled() and self.creating: 
    7878                self.creating = False 
     
    8080                evt.Skip() 
    8181                return 
    82         self.creating = False 
     82 
     83        if not self.creating: 
     84            artub = self.speculoos.artub 
     85            ind = liste.GetNextItem(-1, state = wx.LIST_STATE_SELECTED) 
     86            name = liste.GetItemText(ind) 
     87            newname = evt.GetText() 
     88            bxsystem = self.bxmanager.bxsystems[ind] 
     89            artub.active_editor.update(True) 
     90            baseclass = bxsystem.obj.__class__.__bases__[0].__name__ 
     91            artub.project.rename_class(bxsystem.obj.__class__.__name__, newname + baseclass) 
     92            res = self.speculoos.active_resource 
     93            res.get_class().remove_property(name) 
     94            res.get_class().set_property(newname, self.speculoos.active_resource.name + '.' + newname + baseclass + '(self)') 
     95            artub.active_editor.update(False) 
     96            return 
     97 
    8398        if not evt.GetText(): txt = liste.GetItemText(ind) 
    8499        else: txt = evt.GetText() 
     100 
     101        self.creating = False 
    85102        if ind == liste.GetItemCount() - 1 and txt: 
    86103            bxsystem = BoxSystem() 
  • artub/project.py

    r250 r253  
    1212import wx 
    1313import sys 
     14from bike.refactor.rename import rename 
     15from bike.transformer.save import save 
    1416 
    1517class CProject(CScript): 
     
    101103         filename = self.get_output_filename() 
    102104 
     105   def rename_class(self, oldname, newname): 
     106        import string 
     107        class FullListing:  
     108            def __init__(self): 
     109                self.listing = [] 
     110                self.lines = [] 
     111        full = FullListing() 
     112        def concat_listing(res, full): 
     113            if hasattr(res, "listing"): 
     114                full.lines.append(len(full.listing)) 
     115                full.listing += res.listing.split('\n') 
     116                 
     117        self.apply(concat_listing, full) 
     118        full.listing = string.join(full.listing, '\n') 
     119        full.lines.append(-1) 
     120         
     121        import re 
     122        import tempfile 
     123        import os.path 
     124        filename = os.path.join(tempfile.gettempdir(), "refactortemp.py") 
     125        open(filename, 'w').write(full.listing) 
     126        lines = full.listing.split('\n') 
     127        line = 1 
     128        for l in lines: 
     129            match = re.compile('class (\s)*(' + oldname + ')[^a-zA-Z_]').search(l) 
     130            if match: 
     131                rename(filename, line, match.start(2), newname) 
     132                save() 
     133                full.listing = open(filename).read().split('\n') 
     134                def restore_listing(res, full): 
     135                    if hasattr(res, "listing"): 
     136                        res.listing = string.join(full.listing[full.lines[0]:full.lines[1]], '\n') + '\n' 
     137                        res.listing_has_changed = True 
     138                        del full.lines[0] 
     139                self.apply(restore_listing, full) 
     140                break 
     141            line += 1 
     142        os.remove(filename) 
     143        self.exec_all_scripts() 
     144 
    103145   def get_relative_path(self, filename): 
    104146      project_path = normpath(normcase(self.project_path)) 
  • artub/resourceeditor.py

    r235 r253  
    204204        return None 
    205205 
     206    def rename_tab(self, res, newname): 
     207        for i in self.alive_editors: 
     208            if i.active_resource is res: 
     209                if i.name == "akiki": newname += ' (code)' 
     210                self.nb.SetPageText(self.get_page(i.window), newname) 
     211 
    206212    def refresh_editor(self): 
    207213        if self.active_editor: 
     
    314320        return None 
    315321 
    316          
    317322    def get_templates_menu(self, section="", callback = None, prefix = "", suffix = "", parent_menu = None, id = 10000): 
    318323        sections = section 
revenir en haut de la page