""" Main module which defines ApplicationWindow, the main window of PythonTurtle. """ # Now porting from wxPython to Gtk3 to use in Sugar #from customscrolledpanel import CustomScrolledPanel #import shelltoprocess import sys import turtlewidget import turtleprocess import multiprocessing import homedirectory; homedirectory.do() from misc.fromresourcefolder import from_resource_folder from gi.repository import Gtk import pyshell from sugar3.activity import activity from sugar3.graphics.toolbarbox import ToolbarBox from sugar3.activity.widgets import StopButton class ApplicationWindow(activity.Activity): """ The main window of PythonTurtle. """ def __init__(self, handle): activity.Activity.__init__(self, handle) # create the toolbar toolbar_box = ToolbarBox() stop = StopButton(self) toolbar_box.toolbar.insert(stop, -1) stop.show() self.set_toolbar_box(toolbar_box) toolbar_box.show() self.turtle_process = turtleprocess.TurtleProcess() self.turtle_process.start() self.turtle_queue = self.turtle_process.turtle_queue #self.init_menu_bar() #self.init_about_dialog_info() #self.splitter = wx.SplitterWindow(self, style=wx.SP_LIVE_UPDATE) self.box = Gtk.Paned(orientation=Gtk.Orientation.VERTICAL) self.add(self.box) self.turtle_widget = turtlewidget.TurtleWidget(self.turtle_queue) self.box.add1(self.turtle_widget) self.shell = pyshell.Shell_Gui(with_window=0, queue_pack=self.turtle_process.queue_pack) self.box.add2(self.shell.gui) self.box.set_position(100) #self.connect("destroy", Gtk.main_quit) self.set_canvas(self.box) self.box.show_all() #self.bottom_sizer_panel = wx.Panel(self.splitter) #self.shell = \ # shelltoprocess.Shell(self.bottom_sizer_panel, # queue_pack=self.turtle_process.queue_pack) def init_help_screen(self): """ Initializes the help screen. """ self.help_screen = wx.Panel(parent=self, size=(-1,-1)) self.help_notebook = \ wx.aui.AuiNotebook(parent=self.help_screen, style=wx.aui.AUI_NB_TOP) def give_focus_to_selected_page(event=None): selected_page_number = self.help_notebook.GetSelection() selected_page = self.help_notebook.GetPage(selected_page_number) if self.FindFocus() != selected_page: selected_page.SetFocus() self.help_notebook.Bind(wx.EVT_SET_FOCUS, give_focus_to_selected_page) self.help_notebook.Bind(wx.EVT_CHILD_FOCUS, give_focus_to_selected_page) self.help_images_list=[["Level 1", from_resource_folder("help1.png")], ["Level 2", from_resource_folder("help2.png")], ["Level 3", from_resource_folder("help3.png")], ["Level 4", from_resource_folder("help4.png")]] self.help_pages=[HelpPage(parent=self.help_notebook, bitmap=wx.Bitmap(bitmap_file), caption=caption) \ for [caption, bitmap_file] in self.help_images_list] for page in self.help_pages: self.help_notebook.AddPage(page, caption=page.caption) self.help_close_button_panel = wx.Panel(parent=self.help_screen) self.help_screen_sizer = wx.BoxSizer(wx.VERTICAL) self.help_screen_sizer.Add(self.help_notebook, 1, wx.EXPAND) self.help_screen_sizer.Add(self.help_close_button_panel, 0, wx.EXPAND) self.help_screen.SetSizer(self.help_screen_sizer) help_close_button_bitmap=wx.Bitmap(from_resource_folder("lets_code.png")) self.help_close_button = \ wx.lib.buttons.GenBitmapButton(self.help_close_button_panel, -1, help_close_button_bitmap) self.help_close_button_sizer = wx.BoxSizer(wx.HORIZONTAL) self.help_close_button_sizer.Add(self.help_close_button, 1, wx.EXPAND | wx.ALL, 5) self.help_close_button_panel.SetSizer(self.help_close_button_sizer) self.Bind(wx.EVT_BUTTON, self.hide_help, self.help_close_button) def show_help(self, event=None): self.help_shown=True self.help_menu_item.Check() self.sizer.Show(self.help_screen) self.sizer.Hide(self.splitter) self.help_notebook.SetFocus() self.sizer.Layout() def hide_help(self, event=None): self.help_shown=False self.help_menu_item.Check(False) self.sizer.Hide(self.help_screen) self.sizer.Show(self.splitter) self.shell.setFocus() self.sizer.Layout() def toggle_help(self, event=None): if self.help_shown: self.hide_help() else: self.show_help() def on_exit(self, event=None): return self.Close() def init_about_dialog_info(self): info = self.about_dialog_info = \ wx.AboutDialogInfo() description="""\ An educational environment for learning Python, suitable for beginners and children. Inspired by LOGO. Runs on Python 2.6, using wxPython, Psyco and py2exe. Thanks go to the developers responsible for these projects, as well as to the helpful folks at the user groups of these projects, and at StackOverflow.com, who have helped solved many problems that came up in the making of this program.""" info.SetCopyright("MIT License, (C) 2009 Ram Rachum (\"cool-RR\")") info.SetDescription(description) info.SetName("PythonTurtle") info.SetVersion("0.1.2009.8.2.1") info.SetWebSite("http://pythonturtle.com") def on_about(self, event=None): about_dialog = wx.AboutBox(self.about_dialog_info) def run(): multiprocessing.freeze_support() app = wx.PySimpleApp() my_app_win = ApplicationWindow(None,-1,"PythonTurtle",size=(600,600)) #import cProfile; cProfile.run("app.MainLoop()") app.MainLoop() #if __name__=="__main__": #run() #w = ApplicationWindow() #w.resize(600, 600) #Gtk.main()