Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/GUI_Components/Edit_Pane.py
blob: 1b322682cf7128fc978c45036bea9c3acb40a589 (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
# Copyright (C) IBM Corporation 2008 
import pygtk
pygtk.require('2.0')
import gtk
from GUI_Components.Pane import Pane
from GUI_Components.Compound_Widgets.Reading_View import Reading_View
from GUI_Components.Compound_Widgets.Editing_View import Editing_View
from GUI_Components.Compound_Widgets.Library_View import Library_View
from Processing.Article.Article import Article
from Processing.IO_Manager import IO_Manager

class Edit_Pane(Pane):
    """
    Created by Jonathan Mace
    
    See __init__.py for overview of panes.
    
    The Edit Pane gives a side-by-side view of the source article and edit article
    and allows users to drag text selections from the left hand (source) to the right
    hand side (edited version).
    
    The article displayed in the left hand side (source) can be changed by the 
    drop-down menu (implemented in Compound_Widgets.Reading_View)
    
    The toolbar gives options to change the selection type.
    """
    
    def __init__(self):
        Pane.__init__(self)
        self.name = "Edit"    

        """
        Create reading and editing panels
        """
        self.panel = gtk.HBox()
        self.panel.set_homogeneous(True)
        self.panel.show()        
        
        self.readarticle = Reading_View()  
        self.panel.pack_start(self.readarticle)
        self.readarticle.show()
        
        self.editarticle = Editing_View()
        self.panel.pack_start(self.editarticle)
        self.editarticle.show()
        
        self.toolbar = gtk.Toolbar()
        
        self.label = gtk.Label("Snap selection to: ")
        self.label.show()
        
        self.labelcontainer = gtk.ToolItem()
        self.labelcontainer.add(self.label)
        self.toolbar.insert(self.labelcontainer, -1)
        self.labelcontainer.show()
        
        """ Snap selection box """
        self.combobox = gtk.combo_box_new_text()
        self.combobox.append_text("Nothing")
        self.combobox.append_text("Sentences")
        self.combobox.append_text("Paragraphs")
        self.combobox.append_text("Sections")
        self.combobox.connect("changed", self.selection_mode_changed, None)
        self.combobox.set_active(1)
        self.combobox.show()
        
        self.combocontainer = gtk.ToolItem()
        self.combocontainer.add(self.combobox)
        self.toolbar.insert(self.combocontainer, -1)
        self.combocontainer.show()
        
    """
    When highlighting text, while editing, different selection snap methods 
    can be used (characters, sentences, paragraphs and sections). Change the selection
    mode based on user request 
    """        
    def selection_mode_changed(self, widget, data):
        current_selection = widget.get_active_text()
        if current_selection == "Nothing":
            self.readarticle.set_full_edit_mode()
            self.editarticle.set_full_edit_mode()
        elif current_selection == "Sentences":
            self.readarticle.set_sentence_selection_mode()
            self.editarticle.set_sentence_selection_mode()
        elif current_selection == "Paragraphs":
            self.readarticle.set_paragraph_selection_mode()
            self.editarticle.set_paragraph_selection_mode()
        elif current_selection == "Sections":
            self.readarticle.set_section_selection_mode()
            self.editarticle.set_section_selection_mode()
        #print current_selection           
        
    def get_source_article(self):
        return self.readarticle.textbox.get_article()

    """
    Grab source article from IO manager and set up as editing source.
    """
    def set_source_article(self, article):
        # Populate the drop down menu with the articles in the current theme
        article_theme = article.article_theme
        article_title = article.article_title
        if article_title == None:
            article_title = ""
        """ Grab media wiki pages from default wikipedia theme """
        titles = IO_Manager().get_pages_in_theme("Wikipedia Articles")
        self.readarticle.articlemenu.get_model().clear()
        """ Check user has downloaded some source articles """
        if titles != []:
            self.readarticle.articlemenu.append_text("Select a source article from this menu")
            if article_title == "":
                buf = article.getBuffer()
                start = buf.get_start_iter()
                end = buf.get_end_iter()
                buf.delete(start, end)
                buf.insert(buf.get_start_iter(), "\nYou can choose a Wikipedia article to copy from by selecting it from the drop-down menu above.\n\n")
                buf.insert(buf.get_end_iter(), "If you want to download more articles from Wikipedia, you can do this in the Library tab.")
        else:
            buf = article.getBuffer()
            buf.insert(buf.get_start_iter(), "\nYou have not downloaded any articles from Wikipedia.\n\nYou can download new articles in the Library tab.")
       
        i = 0
        selectionindex = 0
        for title in titles:
            self.readarticle.articlemenu.append_text(title)
            i = i + 1
            if title == article_title:
                selectionindex = i
                
        self.readarticle.articlemenu.set_active(selectionindex)
        
        # Set the read article as appropriate.
        self.readarticle.textbox.set_article(article)
        
    
    def get_working_article(self):
        article = self.editarticle.textbox.get_article()
        return article
    
    def set_working_article(self, article):
        self.editarticle.articletitle.set_markup("<span size='medium'><b>Theme:</b>  %s  \n<b>Article:</b>  %s</span>"%(article.article_theme, article.article_title))
        self.editarticle.textbox.set_article(article)
        self.editarticle.article_theme = "Wikipedia Articles"