Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pythonturtle.py
blob: 454840cbde9d9bf57e755c2e76dafabf7d8d99c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
"""
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()