-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathodfmobile.py
executable file
·199 lines (163 loc) · 5.97 KB
/
odfmobile.py
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/python
# -*- coding: utf-8 -*-
################################################################################
# ODF Mobile
#
# License: GPL
# Copyright (c) 2008 ODF Mobile team
#
#
# Last Modified: 2008-05-1 12:24
#
# License Information:
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# at your option.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
################################################################################
# Standart lib
import sys, os, osso, hildon, gtk, gobject
import gtkmozembed
# Working it thereding
from threading import Thread
gtk.gdk.threads_init()
# Project libs
from odt2html import *
from browser import *
version_string = "0.0.1"
osso_context = osso.Context("org.maemo.garage.odfmobile", version_string, False)
class oReader(hildon.Program):
document = None
def __init__(self):
hildon.Program.__init__(self)
self.home_dir = os.path.abspath(os.path.expanduser('~/.odfmobile'))
if not os.path.exists(self.home_dir):
os.makedirs(self.home_dir)
self.window = hildon.Window()
self.window_in_fullscreen = False
self.window.connect("destroy", self.close)
self.window.connect("key-press-event", self.on_key_press)
self.window.connect("window-state-event", self.on_window_state_change)
# Browser
self.browser = Browser(self, self.home_dir)
self.browser.open_local_url('index.html')
self.window.add(self.browser)
# Menu
self.menu = gtk.Menu()
item = gtk.ImageMenuItem(stock_id="gtk-open")
item.connect("activate", self.open_file)
self.menu.append(item)
item = gtk.ImageMenuItem(stock_id="gtk-quit")
item.connect("activate", self.close)
self.menu.append(item)
self.window.set_menu(self.menu)
# File dialog
# obs: hildon.FileChooserDialog not implement filters
self.dlg = hildon.FileChooserDialog(self.window, gtk.FILE_CHOOSER_ACTION_OPEN);
# TODO: Adicionar filtro de tipos de arquivo, para isso e necessario construi
# um novo FileChooserDialog para hildon pois o padrao nao implementa esta funcinalidade
#self.dlg = gtk.FileChooserDialog("Filename", self.window,
# gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
# gtk.STOCK_OPEN, gtk.RESPONSE_OK))
#self.dlg.set_default_response(gtk.RESPONSE_OK)
# Filter for files
#self.filter = gtk.FileFilter()
#self.filter.set_name("ODF files")
#self.filter.add_pattern("*.odt")
#self.filter.add_pattern("*.odp")
#self.filter.add_pattern("*.ods")
#self.dlg.add_filter(self.filter)
# Change state windows, alternate fullscreen and not fullscreen
def on_window_state_change(self, widget, event, *args):
if event.new_window_state & gtk.gdk.WINDOW_STATE_FULLSCREEN:
self.window_in_fullscreen = True
else:
self.window_in_fullscreen = False
# Working key press events
def on_key_press(self, widget, event, *args):
if event.keyval == gtk.keysyms.F6:
if self.window_in_fullscreen:
self.window.unfullscreen ()
else:
self.window.fullscreen ()
# Zoom
elif event.keyval == gtk.keysyms.F8 or event.keyval == gtk.keysyms.F7: # or self.document['opened']:
if event.keyval == gtk.keysyms.F8:
self.browser.open_url("javascript:decreaseFont()")
else:
self.browser.open_url("javascript:increaseFont()")
# Open files dialog
def open_file(self, target):
response = self.dlg.run()
self.dlg.hide()
if response == gtk.RESPONSE_OK:
self.close_document()
self.document = {
"document": self.dlg.get_filename(),
"processed": 0,
"opened": 0,
"paths": '',
"title": '',
}
self.open_document()
def finalize_open(self, odf):
# Wait process file
banner = hildon.hildon_banner_show_animation(self.window, None, " Opening... ")
while odf.processed == 0: continue
banner.destroy()
gobject.idle_add(self.open_url, 'file://%s' % odf.result[0])
self.document['paths'] = odf.result
self.close_button = gtk.ImageMenuItem(stock_id="gtk-close")
self.close_button.connect("activate", self.close_document)
self.menu.insert(self.close_button, 1)
self.menu.show_all()
self.document['opened'] = self.document['processed'] = 1
def open_url(self, url):
self.browser.open_url(url)
def open_document(self, target = None):
if self.document['opened'] == 0:
odf = odt2html(self.document['document'])
#odf.run()
#self.finalize_open(odf)
Thread(target=odf.run).start()
Thread(target=self.finalize_open, args=(odf,)).start()
def alert(self, target = None):
self.browser.send_command('alert', 'Abrindo!!!');
def close_document(self, target = None):
if self.document != None:
if len(self.document['paths']) > 0:
os.system('rm -Rf %s' % self.document['paths'][1])
self.browser.open_local_url('index.html')
self.document = None
# Remove close menu
self.menu.remove(self.close_button)
self.menu.show_all()
def get_app_dir(self):
path = os.path.abspath(os.path.dirname(sys.argv[0]))
if os.path.exists(path + "/odfmobile.py"):
return path
else:
return "/usr/share/odfmobile"
def show_settings_dialog(self):
pass
def run(self):
self.window.show_all()
gtk.main()
self.browser.run()
def close(self, target):
self.close_document()
self.dlg.destroy()
gtk.gdk.threads_leave()
gtk.main_quit()
if __name__ == "__main__":
oReader().run()