Changeset 297

Show
Ignore:
Timestamp:
05/25/08 13:10:15 (8 months ago)
Author:
bob
Message:
 
Location:
trunk/artub
Files:
1 added
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/artub/artub.pyw

    r289 r297  
    1 execfile("artub.py") 
     1# Glumol - An adventure game creator 
     2# Copyright (C) 1998-2008  Sylvain Baubeau & Alexis Contour 
     3 
     4# This file is part of Glumol. 
     5 
     6# Glumol is free software: you can redistribute it and/or modify 
     7# it under the terms of the GNU General Public License as published by 
     8# the Free Software Foundation, either version 2 of the License, or 
     9# (at your option) any later version. 
     10 
     11# Glumol is distributed in the hope that it will be useful, 
     12# but WITHOUT ANY WARRANTY; without even the implied warranty of 
     13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     14# GNU General Public License for more details. 
     15 
     16# You should have received a copy of the GNU General Public License 
     17# along with Glumol.  If not, see <http://www.gnu.org/licenses/>. 
     18 
     19#!/usr/bin/python 
     20# -*- coding: utf-8 -*-" 
     21 
     22__version__ = "1.0" 
     23 
     24from depplatform import get_image_path, set_sys_path 
     25set_sys_path() 
     26from configmanager import config 
     27 
     28print "Running Artub version", __version__ 
     29import gettext 
     30gettext.install('artub', 'locale', unicode=1) 
     31import locale 
     32import wx 
     33print "Using wxPython", wx.VERSION_STRING 
     34 
     35def set_language(lang): 
     36    gettext.translation('artub', 'locale', languages=[lang]).install(unicode=1) 
     37    config["lang"] = lang 
     38     
     39try: 
     40    langue = config["lang"] 
     41    set_language(langue) 
     42except: 
     43    try: 
     44        langue = wx.Locale.GetLanguageInfo(wx.Locale.GetSystemLanguage()).CanonicalName[:2] 
     45        set_language(langue) 
     46    except: 
     47        print "Cannot find a translation for your language. Defaulting to english" 
     48        config["lang"] = "en" 
     49 
     50import os 
     51import os.path 
     52import sys 
     53import time 
     54 
     55try: os.chdir(os.path.dirname(__file__)) 
     56except: pass 
     57 
     58import wx.aui as PyAUI 
     59from artubnotebook import ArtubNotebook 
     60from resourceeditor import CEditorManager, AddResource 
     61import log 
     62from startuppage import StartupPage 
     63from toolbarmanager import ToolbarManager 
     64from propertiesbar import PropertiesBar 
     65from project import load_project, CProject 
     66from newproject import new_project 
     67from projectproperties import ProjectProperties 
     68from showoptions import OptionsWindow 
     69from debugger.glumoldebugger import ProjectDebugger 
     70from script import CScript, get_function_args, get_full_name, \ 
     71                   get_class_code, make_variable_name, make_class_name  
     72from glumolresource import VirtualGlumolResource 
     73from dialogue import CDialogue 
     74from glumolfont import CGlumolFont 
     75from glumolobject import CGlumolObject, VirtualGlumolObject 
     76from sound import CSound 
     77from animation import CAnimation, VirtualAnimation 
     78from inspect import getmembers, isclass 
     79from undoredo import undo_manager, Action 
     80import pypoujol 
     81from stackless import tasklet, run, schedule 
     82from redistributable import Redistributable  
     83from choosename import choose_a_name 
     84from propertiesbar.companions import Companion 
     85import types 
     86game = None 
     87 
     88class ArtubTree(wx.TreeCtrl): 
     89    def __init__(self, parent, artub, style = wx.TR_HAS_BUTTONS | wx.TR_EDIT_LABELS | # Crash on Windows !!! 
     90                                              wx.TR_HAS_VARIABLE_ROW_HEIGHT | 
     91                                              wx.TR_LINES_AT_ROOT | 
     92                                              wx.TR_HAS_BUTTONS): 
     93        self.artub = artub 
     94        self.dying = False 
     95 
     96        tID = wx.NewId() 
     97        wx.TreeCtrl.__init__(self, parent, tID, style = style) 
     98        wx.EVT_TREE_SEL_CHANGED(self, tID, self.on_sel_changed) 
     99        wx.EVT_RIGHT_UP(self, self.on_default_right_up) 
     100        wx.EVT_KEY_DOWN(self, self.on_key_down) 
     101        wx.EVT_TREE_END_LABEL_EDIT(self, tID, self.on_tree_end_label_edit) # Crash on my Windows 
     102         
     103    def add_tree_item(self, resource, parent = None): 
     104        if not parent: 
     105            data = wx.TreeItemData(resource) 
     106            item = self.AddRoot(resource.name, -1, -1, data) 
     107        else: 
     108            data = wx.TreeItemData(resource) 
     109            item = self.AppendItem(parent, resource.name, -1, -1, data) 
     110        resource.treeitem = item 
     111        return item 
     112         
     113    def add_new_resource(self, res): 
     114        self.artub.project.childs.append(res) 
     115        data = wx.TreeItemData(res) 
     116        res.treeitem = self.AppendItem(self.GetRootItem(), res.name, -1, -1, data) 
     117         
     118    def get_default_resource_menu(this): 
     119        class DefaultMenu(wx.Menu): 
     120            def __init__(self, tree): 
     121                wx.Menu.__init__(self) 
     122                this.artub.populate_resource_menu(self) 
     123       
     124        return DefaultMenu(this) 
     125     
     126    def on_key_down(self, evt): 
     127        self.artub.on_key_down(evt) 
     128         
     129    def on_tree_end_label_edit(self, event): 
     130        self.artub.on_tree_end_label_edit(event) 
     131 
     132    def on_right_down(self, event): 
     133        return 
     134         
     135    def on_default_right_up(self, event): 
     136        if not self.artub.project: return 
     137        self.on_right_up(event) 
     138         
     139    def on_right_up(self, event): 
     140        item, flag = self.HitTest(event.GetPosition()) 
     141        if item.IsOk() and self.GetSelection() != item: 
     142            self.SelectItem(item) 
     143        if not item.IsOk() and self.GetRootItem().IsOk(): 
     144            item = self.GetRootItem() 
     145        if item.IsOk(): 
     146            resource = self.GetItemData(item).GetData() 
     147            editor = self.artub.get_editor_from_resource(resource) 
     148            menu = None 
     149            if editor: 
     150                menu = editor.get_popup_menu(resource) 
     151            if not menu: 
     152                menu = self.get_default_resource_menu() 
     153            else: 
     154                self.artub.populate_resource_menu(menu) 
     155        else: 
     156            menu = self.get_default_resource_menu() 
     157         
     158        self.PopupMenu(menu, event.GetPosition()) 
     159        #event.Skip() 
     160         
     161    def on_sel_changed(self, event): 
     162        if self.dying: 
     163            return 
     164         
     165        item = event.GetItem() 
     166        if item: 
     167            data = self.GetItemData(item).GetData() 
     168            self.artub.edit_resource(data) 
     169            self.artub.project_frame.unselect_items() 
     170            #self.artub.todos.append((self.artub.nb.SetSelection, (self.artub.nb.GetPageCount() - 1,))) 
     171             
     172class TemplatesTree(ArtubTree): 
     173    def __init__(self, parent, artub): 
     174        ArtubTree.__init__(self, parent, artub, 
     175                             style = wx.TR_HAS_BUTTONS | 
     176                             wx.TR_HAS_VARIABLE_ROW_HEIGHT | 
     177                             wx.TR_HIDE_ROOT | 
     178                             wx.TR_LINES_AT_ROOT | 
     179                             wx.TR_HAS_BUTTONS) 
     180 
     181    def get_default_resource_menu(this): 
     182        class DefaultMenu(wx.Menu): 
     183            def __init__(self, tree): 
     184                wx.Menu.__init__(self) 
     185                propID = wx.NewId() 
     186                self.Append(propID, _("Import"), _("Import")) 
     187                wx.EVT_MENU(self, propID, this.artub.on_import) 
     188 
     189        return DefaultMenu(this) 
     190 
     191    def find_item(self, parent, name): 
     192        if not parent.IsOk(): return None 
     193        item = self.GetFirstChild(parent)[0] 
     194        while item.IsOk(): 
     195            if self.GetItemText(item) == name: 
     196                return item 
     197            item = self.GetNextSibling(item) 
     198        return None 
     199     
     200    def add_template(self, resource, exec_script = True): 
     201        if exec_script: resource.exec_listing() 
     202        c = wx.GetApp().gns.getattr(resource.name) 
     203        item = self.GetRootItem() 
     204        def popo(c): 
     205            res = [] 
     206            if len(c.__bases__): 
     207                for i in c.__bases__: 
     208                    if i.__name__ == "object": 
     209                        if not self.find_item(self.GetRootItem(), c.__name__): 
     210                            res.append(self.GetRootItem()) 
     211                            return res 
     212                    item2 = popo(i) 
     213                    for j in item2: 
     214                        item3 = self.find_item(j, c.__name__) 
     215                        if item3: 
     216                            res.append(item3) 
     217                        else: 
     218                            res.append(self.AppendItem(j, c.__name__)) 
     219            else: 
     220                res.append(self.GetRootItem()) 
     221            return res 
     222        self.Refresh() 
     223                 
     224        def add_template_aux(item, bases): 
     225            for b in bases: 
     226                if type(b) == types.ListType: 
     227                    add_template_aux(b) 
     228                else: 
     229                    item2 = self.find_item(item, b[0].__name__) 
     230                    if item2: 
     231                        item = item2 
     232                    else: 
     233                        item = self.AppendItem(item, b[0].__name__) 
     234                    add_template_aux(item, b[1]) 
     235        import inspect 
     236        bases = inspect.getclasstree([c]) 
     237        l = popo(c) 
     238        for i in l: 
     239            self.SetPyData(i, resource) 
     240             
     241    def on_new(self, event): 
     242        item = self.GetSelection() 
     243        resource = self.GetItemData(item).GetData() 
     244        if resource: 
     245            res = CGlumolObject(resource) 
     246            base_classes = [wx.GetApp().gns.getattr(resource.name)] 
     247        else: 
     248            res = CGlumolObject(wx.GetApp().frame.project) 
     249            base_classes = [wx.GetApp().gns.getattr(self.GetItemText(item))] 
     250        res.name = choose_a_name(_("New_") + self.GetItemText(item)) 
     251        if not res.name: return 
     252        res.template = True 
     253        res.sync() 
     254        if base_classes: 
     255            args = get_function_args(base_classes[0].__init__) 
     256            args2 = get_function_args(base_classes[0].__init__, nodefaults=True) 
     257            if args.endswith(", extras"): 
     258                code = [ "def __init__(" + args[:-7] + "*extras):" ] 
     259                code += [ "    " + base_classes[0].__name__ + ".__init__(" + args2[:-7] + "*extras)" ] 
     260            else: 
     261                code = [ "def __init__(" + args + "):" ] 
     262                code += [ "    " + base_classes[0].__name__ + ".__init__(" + args2 + ")" ] 
     263            code += ["    self.__glumolinit__()", 
     264                 "def __glumolinit__(self):", 
     265                 "    super(" + res.name + ", self).__glumolinit__()" ] 
     266        else: 
     267            code = ["pass"] 
     268        self.Refresh() 
     269        c = res.add_class(res.name, base_classes = map(lambda x: x.__name__, base_classes), body = code) 
     270        res.topy() 
     271        res.exec_listing() 
     272        self.add_tree_item(res, item) 
     273             
     274    def on_delete(self, event): 
     275        pass 
     276         
     277    def on_right_up(self, event): 
     278        if not self.artub.project: return 
     279        item, flag = self.HitTest(event.GetPosition()) 
     280        if item.IsOk(): 
     281            resource = self.GetItemData(item).GetData() 
     282            class AMenu(wx.Menu): 
     283                def __init__(this): 
     284                    wx.Menu.__init__(this) 
     285                    propID = wx.NewId() 
     286                    this.Append(propID, _("New"), _("New")) 
     287                    wx.EVT_MENU(this, propID, self.on_new) 
     288                    if resource: 
     289                        propID = wx.NewId() 
     290                        this.Append(propID, _("Delete"), _("Delete")) 
     291                        wx.EVT_MENU(this, propID, self.on_delete) 
     292                             
     293            menu = AMenu() 
     294            self.PopupMenu(menu, event.GetPosition()) 
     295            event.Skip() 
     296            return 
     297                 
     298        menu = self.get_default_resource_menu() 
     299        self.PopupMenu(menu, event.GetPosition()) 
     300        event.Skip() 
     301         
     302    def populate(self, project): 
     303        self.DeleteAllItems() 
     304        root = self.AddRoot(" ") 
     305        item = self.AppendItem(self.GetRootItem(), "Sprite") 
     306        item = self.AppendItem(self.GetRootItem(), "Game") 
     307        item = self.AppendItem(self.GetRootItem(), "Region") 
     308        item = self.AppendItem(self.GetRootItem(), "Behaviour") 
     309         
     310    def on_sel_changed(self, event): 
     311        if self.dying: return 
     312        item = event.GetItem() 
     313        if item: 
     314            resource = self.GetItemData(item).GetData() 
     315            if resource: 
     316                self.artub.edit_resource(resource, self.artub.get_editor('akiki')) 
     317                self.artub.project_frame.unselect_items() 
     318     
     319class RoomTree(ArtubTree): 
     320    def __init__(self, parent, artub): 
     321        ArtubTree.__init__(self, parent, artub, 
     322                             style = wx.TR_HAS_BUTTONS | 
     323                             wx.TR_HAS_VARIABLE_ROW_HEIGHT | 
     324                             wx.TR_HIDE_ROOT | 
     325                             wx.TR_LINES_AT_ROOT | 
     326                             wx.TR_HAS_BUTTONS) 
     327        self.root = self.AddRoot(" ") 
     328 
     329    def get_default_resource_menu(self): 
     330        return self.artub.get_templates_menu( 
     331                callback = self.artub.on_new_class, 
     332                section = "Scene", prefix = "New ") 
     333         
     334class SoundsTree(ArtubTree): 
     335    def get_default_resource_menu(this): 
     336        class DefaultMenu(wx.Menu): 
     337            def __init__(self, tree): 
     338                wx.Menu.__init__(self) 
     339                propID = wx.NewId() 
     340                self.Append(propID, _("New sound"), _("New sound")) 
     341                wx.EVT_MENU(self, propID, this.on_new_sound) 
     342                 
     343        return DefaultMenu(this) 
     344             
     345    def on_new_sound(self, evt): 
     346        name = choose_a_name(_("New_sound")) 
     347        if not name: return 
     348        sound = CSound() 
     349        base_class = "Sound" 
     350        sound.name = self.artub.project.get_resource_name(name) 
     351        sound.listing = "class %s(%s):\n" % (sound.name, base_class) 
     352        sound.listing = sound.listing + "    filename = ''\n" 
     353        sound.listing = sound.listing + "    def __init__(self):\n" 
     354        sound.listing = sound.listing + "        %s.__init__(self)\n" % base_class 
     355        sound.listing = sound.listing + "        self.__glumolinit__()\n" 
     356        sound.listing = sound.listing + "    def __glumolinit__(self):\n" 
     357        sound.listing = sound.listing + "        super(" + sound.name + ", self).__glumolinit__()\n\n" 
     358        self.add_new_resource(sound) 
     359        self.add_new_resource(sound) 
     360         
     361class ProjectFrame(wx.Panel): 
     362    name = _("Project bar") 
     363    def __init__( 
     364        self, parent, id=-1, title="", pos=wx.DefaultPosition, size=wx.DefaultSize, 
     365        style=wx.DEFAULT_FRAME_STYLE 
     366        ): 
     367        self.artub = artub = parent 
     368        wx.Panel.__init__(self, artub, -1) 
     369        sizer = wx.BoxSizer(wx.VERTICAL) 
     370        project_nb = artub.project_nb = PyAUI.AuiNotebook(self, -1, wx.DefaultPosition, 
     371                                              wx.DefaultSize, style = PyAUI.AUI_NB_SCROLL_BUTTONS) 
     372        sizer.Add(parent.project_nb, 1, wx.EXPAND) 
     373 
     374        tree = artub.tree = ArtubTree(project_nb, artub) 
     375        project_nb.AddPage(tree, _("Project")) 
     376         
     377        imagelist = wx.ImageList(16, 16, True) 
     378        imagelist.Add( 
     379                    wx.Bitmap(get_image_path("cost.xpm"), wx.BITMAP_TYPE_XPM)) 
     380        imagelist.Add( 
     381                    wx.Bitmap(get_image_path("talk.xpm"), wx.BITMAP_TYPE_XPM)) 
     382        imagelist.Add( 
     383                    wx.Bitmap(get_image_path("object.xpm"), wx.BITMAP_TYPE_XPM)) 
     384        imagelist.Add( 
     385                    wx.Bitmap(get_image_path("script.xpm"), wx.BITMAP_TYPE_XPM)) 
     386        imagelist.Add( 
     387                    wx.Bitmap(get_image_path("project.xpm"), wx.BITMAP_TYPE_XPM)) 
     388        imagelist.Add( 
     389                    wx.Bitmap(get_image_path("font.xpm"), wx.BITMAP_TYPE_XPM)) 
     390        imagelist.Add( 
     391                    wx.Bitmap(get_image_path("scene.xpm"), wx.BITMAP_TYPE_XPM)) 
     392         
     393        tree.AssignImageList(imagelist) 
     394 
     395        #self.rooms = RoomTree(self.project_nb, self) 
     396        #self.project_nb.AddPage(self.rooms, _("Scenes")) 
     397 
     398        artub.templ_tree = TemplatesTree(project_nb, artub) 
     399        project_nb.AddPage(artub.templ_tree, _("Templates")) 
     400         
     401        # self.costs = ArtubTree(self.project_nb, self) 
     402        # self.project_nb.AddPage(self.costs, _("Sprites")) 
     403 
     404        artub.sounds = SoundsTree(project_nb, artub) 
     405        project_nb.AddPage(artub.sounds, _("Sounds")) 
     406 
     407        self.SetSizer(sizer) 
     408 
     409    def get_active_tree(self): 
     410        return self.get_tree_list()[self.artub.project_nb.GetSelection()] 
     411     
     412    def get_tree_list(self): 
     413        return [ self.artub.tree, self.artub.templ_tree, self.artub.sounds ] 
     414 
     415    def unselect_items(self, all=False): 
     416        if sys.platform != "win32": 
     417            n = 0 
     418            for i in [self.artub.tree, self.artub.templ_tree, self.artub.sounds]: 
     419                if all or (n != self.artub.project_nb.GetSelection()): 
     420                    i.dying = True 
     421                    i.UnselectAll() 
     422                    i.dying = False 
     423                n = n + 1 
     424 
     425    def on_close_window(self, evt): 
     426        self.manager.toggle_bar(self.menu_id) 
     427 
     428class ArtubFrame(wx.Frame, CEditorManager): 
     429    resource_icons = { CDialogue : 1, CAnimation : 0, CGlumolObject : 2, 
     430                       CProject : 4, CScript : 3, VirtualGlumolObject : 2, 
     431                       CGlumolFont : 5, VirtualAnimation : 0 } 
     432 
     433    def __init__(self, parent, id, title, config): 
     434        CEditorManager.__init__(self) 
     435 
     436        wx.Frame.__init__(self, parent, -1, title, size = (800, 600), 
     437                                style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE) 
     438 
     439        self.cwd = os.getcwd() 
     440        sys.path.append(self.cwd) 
     441        self.window = None 
     442        self.config = config 
     443        self.context = None 
     444        self.todos = [] 
     445         
     446        self.new_anim_id = wx.NewId() 
     447        self.new_scene_id = wx.NewId() 
     448        self.new_sprite_id = wx.NewId() 
     449        self.new_script_id = wx.NewId() 
     450        self.new_dialog_id = wx.NewId() 
     451        self.new_font_id = wx.NewId() 
     452 
     453        self.quitte = False 
     454 
     455        self.app = wx.GetApp() 
     456        self.app.artub_frame = self 
     457        self.app.frame = self 
     458 
     459        self.path = os.getcwd() 
     460        self.debugging = False 
     461         
     462        self.metaclasses = ["BehaviourMetaClass", "SpriteMetaClass", "AnimationMetaClass", "GameMetaClass", "SceneMetaClass"] 
     463         
     464        if __name__ != "__main__": 
     465            frame = wx.Frame(self, -1) 
     466            self.log = wx.TextCtrl(frame, -1, 
     467                                   style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL) 
     468            log.set_text_ctrl(self.log) 
     469            frame.Show(True) 
     470             
     471        self._mgr = PyAUI.AuiManager() 
     472 
     473        def OnFloatingPaneClosed(window): 
     474            self.toolbar_manager.on_close_toolbar(window) 
     475            return True 
     476         
     477        def OnPaneClosed(window): 
     478            self.toolbar_manager.on_close_toolbar(window) 
     479            return True 
     480         
     481        self._mgr.OnFloatingPaneClosed = OnFloatingPaneClosed 
     482        self._mgr.OnPaneClosed = OnPaneClosed 
     483         
     484        self._mgr.SetManagedWindow(self) 
     485        self._mgr.SetFlags(self._mgr.GetFlags() ^ PyAUI.AUI_MGR_ALLOW_ACTIVE_PANE) 
     486        self._mgr.GetArtProvider()._gradient_type = PyAUI.AUI_GRADIENT_NONE 
     487         
     488        self.toolbar_manager = ToolbarManager(self) 
     489 
     490        greta = wx.Icon(get_image_path("greta.ico"), wx.BITMAP_TYPE_ICO) 
     491        self.SetIcon(greta) 
     492         
     493        self.create_menus() 
     494        self.create_standard_toolbar() 
     495 
     496        self.load_plugins() 
     497        self.dist = Redistributable() 
     498 
     499        self.otherWin = None 
     500        wx.EVT_IDLE(self, self.on_idle) 
     501        wx.EVT_CLOSE(self, self.on_close_window) 
     502        wx.EVT_ICONIZE(self, self.on_iconify) 
     503        wx.EVT_MAXIMIZE(self, self.on_maximize) 
     504 
     505        self.Centre(wx.BOTH) 
     506        self.statusbar = self.CreateStatusBar(1, wx.ST_SIZEGRIP) 
     507 
     508        # Shell 
     509        import __builtin__ 
     510        globals()["artub"] = self 
     511        class MyShell(wx.py.shell.Shell): 
     512            def push(command, silent = False): 
     513                __ = __builtin__.__dict__["_"] 
     514                wx.py.shell.Shell.push(command, silent) 
     515                __builtin__.__dict__["_"] = __  
     516 
     517        self.shell = self.toolbar_manager.create_toolbar(MyShell, 
     518                            keywords = { "locals" : globals(), "introText" : "Welcome to the Glumol debugger" }, 
     519                            infos = PyAUI.AuiPaneInfo().Name(_("Shell")). 
     520                            Caption(_("Shell")).Left().Float().MinSize(wx.Size(200, 100))) 
     521         
     522        # Project frame 
     523        self.project_frame = self.toolbar_manager.create_toolbar( 
     524                                ProjectFrame, 
     525                                infos = PyAUI.AuiPaneInfo().Name(_("Project bar")). 
     526                                Caption(_("Project")).Left(). 
     527                                MinSize(wx.Size(200,100))) 
     528         
     529        # Notebook 
     530        self.nb = ArtubNotebook(self, -1, wx.CLIP_CHILDREN) 
     531        self._mgr.AddPane(self.nb, PyAUI.AuiPaneInfo().Name(_("Notebook")). 
     532                                   Caption(_("Notebook")).CenterPane()) 
     533 
     534        wx.EVT_MENU_RANGE(self, wx.ID_FILE1, wx.ID_FILE9, self.on_file_history) 
     535 
     536        # Startup page 
     537        self.ovr = StartupPage(self.nb, -1, self) 
     538        self.ovr.update_recent_files() 
     539        self.nb.AddPage(self.ovr, _("Startup")) 
     540        self.ovr.Refresh() 
     541         
     542        self.Show(True) 
     543 
     544        self.project = None 
     545         
     546        self.debugger = ProjectDebugger(self, self) 
     547         
     548        self.pb = self.toolbar_manager.create_toolbar(PropertiesBar, 
     549                      infos = PyAUI.AuiPaneInfo().Name(PropertiesBar.name). 
     550                      Caption(PropertiesBar.name).MinSize(wx.Size(200, 100)).Left()) 
     551         
     552        self.toolbar_manager.care_of_menu(self.windows) 
     553        self.SetMenuBar(self.mainmenu) 
     554        self.care_of_auto_load() 
     555        self._mgr.Update() 
     556        self._mgr.HideHint() 
     557 
     558    def CloseWindow(self, event): 
     559        self.Close() 
     560     
     561    def on_toggle_breakpoint(self, evt): 
     562        self.active_editor.on_toggle_breakpoint(evt) 
     563     
     564    def on_toggle_breakpoint_update_ui(self, evt): 
     565        if self.project and self.active_editor and self.active_editor.name == "akiki": evt.Enable(True) # Smart way didn't work 
     566        else: evt.Enable(False) 
     567 
     568    def create_standard_toolbar(self): 
     569        class MainToolBar(wx.ToolBar): 
     570            name = _("Main toolbar") 
     571            def __init__( 
     572                this, parent=None, id=-1, title = "", 
     573                pos = wx.DefaultPosition, size = wx.DefaultSize, 
     574                style = wx.TB_FLAT | wx.TB_NODIVIDER | wx.TB_DOCKABLE | wx.TB_FLAT | wx.TB_NODIVIDER | wx.TB_HORIZONTAL, 
     575                name = _(""), 
     576                value = None): 
     577                 
     578                wx.ToolBar.__init__(this, parent, id, pos, size, style | wx.TB_HORIZONTAL) 
     579                this.SetToolBitmapSize(wx.Size(16, 16)) 
     580                this.AddSimpleTool(10, self.bitmaps['new2.xpm'], _("New project"), _("Create a new project")) 
     581                this.Bind(wx.EVT_TOOL, self.on_new, id=10) 
     582                this.AddSimpleTool(11, self.bitmaps['open.xpm'], _("Open a project"), _("Open a project")) 
     583                this.Bind(wx.EVT_TOOL, self.on_open, id=11) 
     584                this.AddSimpleTool(12, self.bitmaps['save.xpm'], _("Save your project"), _("Save your project")) 
     585                this.Bind(wx.EVT_TOOL, self.on_save, id=12) 
     586                this.AddSimpleTool(13, self.bitmaps['cut.xpm'], _("Cut to the clipboard"), _("Cut to the clipboard")) 
     587                this.AddSimpleTool(14, self.bitmaps['copy.xpm'], _("Copy to the clipboard"), _("Copy to the clipboard")) 
     588                this.AddSimpleTool(15, self.bitmaps['paste.xpm'], _("Paste from the clipboard"), _("Paste from the clipboard")) 
     589                this.AddSimpleTool(self.undoID, self.bitmaps['undo.xpm'], _("Undo last change"), _("Undo last change")) 
     590                this.Bind(wx.EVT_TOOL, self.undo, id=self.undoID) 
     591                this.AddSimpleTool(self.redoID, self.bitmaps['redo.xpm'], _("Redo last change"), _("Redo last change")) 
     592                this.Bind(wx.EVT_TOOL, self.undo, id=self.redoID) 
     593                 
     594                this.Realize() 
     595 
     596        self.maintoolbar = self.toolbar_manager.create_toolbar(MainToolBar, 
     597                           infos = PyAUI.AuiPaneInfo().Name(_("Main toolbar")). 
     598                           Caption(_("Main toolbar")). 
     599                           ToolbarPane().Top()) 
     600                            
     601    def get_bitmap(self, filename): 
     602        item = self.bitmaps.get(filename, None) 
     603        if not item: 
     604            return self.load_and_store_bitmap(filename) 
     605        else: 
     606            return item 
     607 
     608    def load_and_store_bitmap(self, filename): 
     609        bmp = wx.Bitmap(get_image_path(filename), wx.BITMAP_TYPE_XPM) 
     610        self.bitmaps[filename] = bmp 
     611        return bmp 
     612         
     613    def create_menus(self): 
     614        self.mainmenu = wx.MenuBar() 
     615        menu = wx.Menu() 
     616        newID = wx.NewId() 
     617        self.bitmaps = {} 
     618        menuitem = wx.MenuItem(menu, newID, _("New project") + '\tCtrl-N', _("Create a new project")) 
     619        menuitem.SetBitmap(self.load_and_store_bitmap("new2.xpm")) 
     620        menu.AppendItem(menuitem) 
     621        openID = wx.NewId() 
     622        menuitem = wx.MenuItem(menu, openID, _("Open") + '\tCtrl-O', _("Open a project")) 
     623        menuitem.SetBitmap(self.load_and_store_bitmap("open.xpm")) 
     624        menu.AppendItem(menuitem) 
     625        saveID = wx.NewId() 
     626        menuitem = wx.MenuItem(menu, saveID, _("Save") + '\tCtrl-S', _("Save your project")) 
     627        menuitem.SetBitmap(self.load_and_store_bitmap("save.xpm")) 
     628        menu.AppendItem(menuitem) 
     629        saveasID = wx.NewId() 
     630        menuitem = wx.MenuItem(menu, saveasID, _("Save as") + '\tCtrl-Shift-S', _("Save as...")) 
     631        menuitem.SetBitmap(self.load_and_store_bitmap("saveas.xpm")) 
     632        menu.AppendItem(menuitem) 
     633        exitID = wx.NewId() 
     634        wx.App_SetMacExitMenuItemId(exitID) 
     635        menu.Append(exitID, _("Exit"), _("Exit Artub")) 
     636        self.mainmenu.Append(menu, _("File")) 
     637         
     638        self.filehistory = wx.FileHistory() 
     639        self.filehistory.UseMenu(menu) 
     640        self.filehistory.Load(self.config)         
     641         
     642        wx.EVT_MENU(self, newID, self.on_new) 
     643        wx.EVT_MENU(self, openID, self.on_open) 
     644        wx.EVT_MENU(self, saveID, self.on_save) 
     645        wx.EVT_MENU(self, saveasID, self.on_saveas) 
     646        wx.EVT_MENU(self, exitID, self.on_exit) 
     647         
     648        edit = wx.Menu() 
     649        undoID = wx.NewId() 
     650        self.undoID = undoID 
     651        menuitem = wx.MenuItem(menu, undoID, _("Undo") + '\tCtrl-Z', _("Undo last change")) 
     652        menuitem.SetBitmap(self.get_bitmap("undo.xpm")) 
     653        edit.AppendItem(menuitem) 
     654        redoID = wx.NewId() 
     655        self.redoID = redoID 
     656        menuitem = wx.MenuItem(menu, redoID, _("Redo") + '\tCtrl-Y', _("Redo last change")) 
     657        menuitem.SetBitmap(self.get_bitmap("redo.xpm")) 
     658        edit.AppendItem(menuitem) 
     659        cutID = wx.NewId() 
     660        menuitem = wx.MenuItem(menu, cutID, _("Cut") + '\tCtrl-X', _("Cut selection and put it into the clipboard")) 
     661        menuitem.SetBitmap(self.get_bitmap("cut.xpm")) 
     662        edit.AppendItem(menuitem) 
     663        copyID = wx.NewId() 
     664        menuitem = wx.MenuItem(menu, copyID, _("Copy") + '\tCtrl-C', _("Copy selection into the clipboard")) 
     665        menuitem.SetBitmap(self.get_bitmap("copy.xpm")) 
     666        edit.AppendItem(menuitem) 
     667        pasteID = wx.NewId() 
     668        self.pasteID = pasteID 
     669        menuitem = wx.MenuItem(menu, pasteID, _("Paste") + '\tCtrl-V', _("Paste from clipboard")) 
     670        menuitem.SetBitmap(self.get_bitmap("paste.xpm")) </