Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugaractivity.py
blob: c90bd4a19fb260021d79cdeef0f9d52ee21bc08d (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
# Copyright (C) IBM Corporation 2008

import gtk
from Infoslicer_GUI import Infoslicer_GUI
from sugar.activity import activity  
from Processing.IO_Manager import IO_Manager 

class sugaractivity( activity.Activity, Infoslicer_GUI ):
    """
    Created by Jonathan Mace
    
    This is the Sugar implementation of the infoslicer GUI.
    
    It sets things in the sugar.activity class in the abstract methods. 
    """
    
    """
    Set up Sugar specific GUI config and show interface
    """
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)
        gtk.gdk.threads_init()
        gtk.gdk.threads_enter()
        self.toolbox = activity.ActivityToolbox(self)
        Infoslicer_GUI.__init__(self)
        self._name = handle
        self.toolbox.connect("current-toolbar-changed", self.page_switched, None)
        
        self.set_title('InfoSlicer')
        
        self.set_toolbox(self.toolbox)
        self.toolbox.show() 
        
        self.show_all()
        self.toolbox.set_current_toolbar(2)
        
        print "dictionary:"
        print handle.get_dict()
        
    """
    Operating system specific file reading and writing methods are below
    """
    def read_file(self, file_path):
        print "reading the file"
        """ 
        At the moment, the format of a saved file will just be:
        sourcetitle
        edittitle
        edittheme
        currentindex
        """
        
        file = open(file_path, 'r')
        text = file.read()
        file.close()
        lines = text.splitlines()
        if len(lines) < 3:
            return
        sourcetitle = lines[0]
        workingtitle = lines[1]
        workingtheme = lines[2]
        currentindex = lines[3]
        
        print "file read"
        print "sourcetitle: %s, workingtitle: %s, workingtheme: %s, currentindex: %s" % (sourcetitle, workingtitle, workingtheme, currentindex)
        iomanager = IO_Manager()
        if iomanager.page_exists(sourcetitle, "Wikipedia Articles"):
            sourcearticle = iomanager.load_article(sourcetitle, "Wikipedia Articles")
        else:
            sourcearticle = Article()
            sourcearticle.article_title = sourcetitle
            sourcearticle.article_theme = "Wikipedia Articles"
        if iomanager.page_exists(workingtitle, workingtheme):
            workingarticle = iomanager.load_article(workingtitle, workingtheme)
        else:
            workingarticle = Article()
            workingarticle.article_title = workingtitle
            workingarticle.article_theme = workingtheme
        
        self.switch_page(currentindex)
        
        self.currentpane.set_source_article(sourcearticle)
        self.currentpane.set_working_article(workingarticle)
    
    def write_file(self, file_path):
        print "writing the file to %s" % file_path
        sourcearticle = self.currentpane.get_source_article()
        workingarticle = self.currentpane.get_working_article()
        
        sourcetitle = sourcearticle.article_title
        if not sourcetitle:
            sourcetitle = "none"
        workingtitle = workingarticle.article_title
        if not workingtitle:
            workingtitle = "none"
        workingtheme = workingarticle.article_theme
        if not workingtheme:
            workingtheme = "none"
        currentindex = self.currentindex
        
        file = open(file_path, 'w')
        print "writing source: %s, working: %s, theme: %s" % (sourcetitle, workingtitle, workingtheme)
        file.write("%s\n%s\n%s\n%s" % (sourcetitle, workingtitle, workingtheme, str(currentindex)))
        file.close()
        
        
        
    def settoolbars(self, toolbars, toolbarnames):
        for i in range(0, len(toolbars)):
            self.toolbox.add_toolbar(toolbarnames[i], toolbars[i])
            toolbars[i].show()
        
            
    def setpanel(self, panel):
        self._main_view = panel
        self.set_canvas(self._main_view)
        self._main_view.show()
        
        
    def page_switched(self, widget, page_num, data):
        print "page_switched to %s" % (page_num, )
        if page_num > 0:
            self.mode_switched(page_num - 1)
        
    def switch_page(self, page_num):
        self.mode_switched(page_num)
        
    def can_close(self):
        self.do_quit_event()
        return True