Changeset 253
- 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
-
|
r250
|
r253
|
|
| 63 | 63 | |
| 64 | 64 | class 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 !!! |
| 66 | 66 | wx.TR_HAS_VARIABLE_ROW_HEIGHT | |
| 67 | 67 | wx.TR_LINES_AT_ROOT | |
| … |
… |
|
| 75 | 75 | wx.EVT_RIGHT_UP(self, self.on_default_right_up) |
| 76 | 76 | 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 |
| 78 | 78 | |
| 79 | 79 | def add_tree_item(self, resource, parent = None): |
| … |
… |
|
| 803 | 803 | if not resource.template and isinstance(resource, CGlumolObject): |
| 804 | 804 | 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)) |
| 806 | 808 | l = getmembers(cl, isclass) |
| 807 | 809 | for (name, cl2) in l: # Name, class |
| … |
… |
|
| 922 | 924 | item = event.GetItem() |
| 923 | 925 | 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 | |
| 926 | 936 | def on_find(self, evt): |
| 927 | 937 | if self.active_editor and self.active_editor.name == "akiki": |
-
|
r208
|
r253
|
|
| 1 | 1 | import wx |
| 2 | 2 | from script import get_full_name |
| | 3 | from identifierctrl import IdentifierCtrl |
| 3 | 4 | |
| 4 | 5 | class ChooseNameDialog(wx.Dialog): |
| … |
… |
|
| 20 | 21 | sizer2.Add(self.text, 0, wx.ALIGN_CENTRE | wx.ALL, 5) |
| 21 | 22 | |
| 22 | | self.name = wx.TextCtrl(self, -1, "", size = (200, 20)) |
| | 23 | self.name = IdentifierCtrl(self, -1, "", size = (200, 20)) |
| 23 | 24 | sizer2.Add(self.name, 1, wx.ALIGN_CENTRE | wx.ALL, 5) |
| 24 | 25 | self.name.SetValue(name) |
-
|
r204
|
r253
|
|
| 67 | 67 | try: |
| 68 | 68 | classe = self.getattr(script.realname) |
| | 69 | if not classe: raise |
| 69 | 70 | except: |
| | 71 | print "except 1" |
| 70 | 72 | try: |
| 71 | 73 | classe = self.getattr(script.name) |
| | 74 | if not classe: raise |
| 72 | 75 | except: |
| | 76 | print "except 2" |
| 73 | 77 | 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) |
| 74 | 79 | return self.create_object(classe, None, args) |
-
|
r155
|
r253
|
|
| 1 | 1 | import string |
| 2 | 2 | import wx |
| | 3 | import wx.lib.masked as masked |
| 3 | 4 | |
| 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): |
| | 5 | class IdentifierCtrl(masked.TextCtrl): |
| 42 | 6 | def __init__(self, parent = None, id = -1, value = "", pos = wx.DefaultPosition, |
| 43 | 7 | size = wx.DefaultSize, style = 0, validator = wx.DefaultValidator, |
| 44 | 8 | 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) |
-
|
r250
|
r253
|
|
| 7 | 7 | from depplatform import get_image_path |
| 8 | 8 | import 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 |
| | 9 | from choosename import IdentifierCtrl |
| 21 | 10 | |
| 22 | 11 | class NewProject: |
| … |
… |
|
| 100 | 89 | box = wx.BoxSizer(wx.HORIZONTAL) |
| 101 | 90 | |
| 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 | | |
| 134 | 91 | label = wx.StaticText(self, -1, _("Short name :")) |
| 135 | 92 | label.SetHelpText(_("Will be used to name files")) |
| 136 | 93 | box.Add(label, 0, wx.GROW|wx.ALL, 2) |
| 137 | 94 | |
| 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)) |
| 140 | 96 | self.normname.SetHelpText(_("Will be used to name files")) |
| 141 | 97 | box.Add(self.normname, 1, wx.GROW|wx.ALL, 2) |
-
|
r250
|
r253
|
|
| 11 | 11 | |
| 12 | 12 | 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) |
| 14 | 14 | self.speculoos = speculoos |
| 15 | 15 | self.creating = False |
| … |
… |
|
| 51 | 51 | |
| 52 | 52 | def OnChar(self, event): |
| 53 | | try: key = event.KeyCode() |
| 54 | | except: key = event.KeyCode |
| | 53 | pass |
| 55 | 54 | |
| 56 | 55 | def on_size(self, evt): |
| … |
… |
|
| 75 | 74 | ind = evt.GetIndex() |
| 76 | 75 | liste = self.GetListCtrl() |
| | 76 | |
| 77 | 77 | if evt.IsEditCancelled() and self.creating: |
| 78 | 78 | self.creating = False |
| … |
… |
|
| 80 | 80 | evt.Skip() |
| 81 | 81 | 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 | |
| 83 | 98 | if not evt.GetText(): txt = liste.GetItemText(ind) |
| 84 | 99 | else: txt = evt.GetText() |
| | 100 | |
| | 101 | self.creating = False |
| 85 | 102 | if ind == liste.GetItemCount() - 1 and txt: |
| 86 | 103 | bxsystem = BoxSystem() |
-
|
r250
|
r253
|
|
| 12 | 12 | import wx |
| 13 | 13 | import sys |
| | 14 | from bike.refactor.rename import rename |
| | 15 | from bike.transformer.save import save |
| 14 | 16 | |
| 15 | 17 | class CProject(CScript): |
| … |
… |
|
| 101 | 103 | filename = self.get_output_filename() |
| 102 | 104 | |
| | 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 | |
| 103 | 145 | def get_relative_path(self, filename): |
| 104 | 146 | project_path = normpath(normcase(self.project_path)) |
-
|
r235
|
r253
|
|
| 204 | 204 | return None |
| 205 | 205 | |
| | 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 | |
| 206 | 212 | def refresh_editor(self): |
| 207 | 213 | if self.active_editor: |
| … |
… |
|
| 314 | 320 | return None |
| 315 | 321 | |
| 316 | | |
| 317 | 322 | def get_templates_menu(self, section="", callback = None, prefix = "", suffix = "", parent_menu = None, id = 10000): |
| 318 | 323 | sections = section |
Download in other formats:
|
|