Browse files

Get spreadsheet saving working

* Restore doesn't seem to work
* added a TODO with some notes
* expanded the read sleep to wait for socialcalc to load
  • Loading branch information...
1 parent f3bfab0 commit c46e186969430d21702b08ad5eb928b07466e6b0 Luke Closs committed Apr 26, 2008
Showing with 41 additions and 25 deletions.
  1. +1 −1 SocialCalcActivity.py
  2. +3 −0 TODO
  3. +11 −2 XOCom.py
  4. +26 −22 web/index.html
View
2 SocialCalcActivity.py
@@ -35,5 +35,5 @@ def read_file(self, filename):
# We must delay this to give the browser time to start up
# It would be better if this send_to_browser was instead triggered
# once the browser had finished loading.
- gobject.timeout_add(2000, self.xocom.send_to_browser, 'read', content)
+ gobject.timeout_add(5000, self.xocom.send_to_browser, 'read', content)
View
3 TODO
@@ -0,0 +1,3 @@
+* if the sheet has no data, it's save string should be empty
+* the spreadsheet doesn't seem to be loading in the save string correctly
+* change the sleep during read_file into something better
View
13 XOCom.py
@@ -2,6 +2,8 @@
from hulahop.webview import WebView
from xpcom import components
+debug = True
+
class XOCom:
# Constructor gives full XPCom access by default
# This should be improved for future apps that may not need/want full access
@@ -39,6 +41,9 @@ def create_webview(self):
# The command will execute a javascript method registered with the same name,
# and return any value received from the javascript
def send_to_browser(self, command, parameter=None):
+ if debug:
+ print "sending: %s - (%s)"%(command, parameter)
+
# Set up an array for parameters and return values for the XPCom call
array = components.classes["@mozilla.org/array;1"].createInstance(
components.interfaces.nsIMutableArray)
@@ -56,9 +61,13 @@ def send_to_browser(self, command, parameter=None):
ob_serv.notifyObservers(array, "xo-message", command);
# check if the browser returned anything
+ result = None
if array.length:
iter = array.enumerate()
result = iter.getNext()
result = result.QueryInterface(components.interfaces.nsISupportsString)
- return result.toString()
- return None
+ result = result.toString()
+
+ if debug:
+ print "result: %s - (%s)"%(command, result)
+ return result
View
48 web/index.html
@@ -3,6 +3,7 @@
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SocialCalc 0.7.5</title>
+<script type="text/javascript" src="xocom.js"></script>
<script type="text/javascript" src="socialcalc-3.js"></script>
<script type="text/javascript" src="socialcalctableeditor.js"></script>
<script type="text/javascript" src="formatnumber2.js"></script>
@@ -100,31 +101,34 @@
// Done initialization
-//
-// Example of how to get the serialized data
-//
-
-function dosave() {
- savestr = spreadsheet.CreateSpreadsheetSave();
- }
-
-//
-// Example of how to reload the serialized data
-//
+ //
+ // Reload the serialized data
+ //
+ XO.register('read', function(content) {
+ var parts = spreadsheet.DecodeSpreadsheetSave(savestr);
+ if (parts) {
+ if (parts.sheet) {
+ spreadsheet.sheet.ResetSheet();
+ spreadsheet.ParseSheetSave(
+ savestr.value.substring(parts.sheet.start, parts.sheet.end));
+ }
+ if (parts.edit) {
+ spreadsheet.editor.LoadEditorSettings(
+ savestr.value.substring(parts.edit.start, parts.edit.end));
+ }
+ }
+ spreadsheet.FullRefreshAndRender();
+ })
+
+ //
+ // Get the serialized data
+ //
+ XO.register('write', function() {
+ return spreadsheet.CreateSpreadsheetSave();
+ })
function doreload() {
- var parts = spreadsheet.DecodeSpreadsheetSave(savestr);
- if (parts) {
- if (parts.sheet) {
- spreadsheet.sheet.ResetSheet();
- spreadsheet.ParseSheetSave(savestr.value.substring(parts.sheet.start, parts.sheet.end));
- }
- if (parts.edit) {
- spreadsheet.editor.LoadEditorSettings(savestr.value.substring(parts.edit.start, parts.edit.end));
- }
- }
- spreadsheet.FullRefreshAndRender();
}
// This is just as a demo to show we might have graphing someday. It may be better to have it

0 comments on commit c46e186

Please sign in to comment.