spv-dev team mailing list archive
-
spv-dev team
-
Mailing list archive
-
Message #00004
[Branch ~bouf10/slidepresenterview/refactor-pres-design] Rev 62: Standardize URI to indentify presentations instead of a file name.
------------------------------------------------------------
revno: 62
committer: F.A. Bourbonnais <bouf10pub@xxxxxxxxxxx>
branch nick: refactor-pres-design
timestamp: Sun 2010-05-09 14:15:55 -0400
message:
Standardize URI to indentify presentations instead of a file name.
modified:
slidepresenterview/presentations.py
slidepresenterview/session.py
slidepresenterview/tests/unit/test_session.py
--
lp:~bouf10/slidepresenterview/refactor-pres-design
https://code.launchpad.net/~bouf10/slidepresenterview/refactor-pres-design
Your team SlidePresenterView Development Team is subscribed to branch lp:~bouf10/slidepresenterview/refactor-pres-design.
To unsubscribe from this branch go to https://code.launchpad.net/~bouf10/slidepresenterview/refactor-pres-design/+edit-subscription
=== modified file 'slidepresenterview/presentations.py'
--- slidepresenterview/presentations.py 2010-05-07 04:36:20 +0000
+++ slidepresenterview/presentations.py 2010-05-09 18:15:55 +0000
@@ -27,30 +27,52 @@
##########
# Imports
#####
+import os
+
from PyQt4 import QtGui
+from slidepresenterview.utils.uri import Uri
+
from slidepresenterview.documents import errors
from slidepresenterview.documents.pdf import PDFDocument
class Presentation(object):
#TODO: Refactoring in progress... Branch refactor-pres-design
- def __init__(self):
- self.file_name = None
-
+ def __init__(self, uri):
+ if not isinstance(uri, Uri):
+ raise ValueError("Uri must an Uri object.")
+ self.uri = uri
+
+
+ def __cmp__(self, other_presentation):
+ return cmp(self.uri, other_presentation.uri)
+
+
+ def is_presenting(self, other_uri):
+ if other_uri.scheme != "file":
+ return self.uri == other_uri
+
+ try:
+ return os.path.samefile(self.uri.path, other_uri.path)
+ except OSError: # File doesn't exist. Use a string comparison.
+ return self.uri.path == other_uri.path
class EmptyPresentaton(Presentation):
#TODO: Refactoring in progress... Branch refactor-pres-design
- pass
+
+ URI = Uri("spv://presentations/empty")
+
+ def __init__(self):
+ Presentation.__init__(self, self.URI)
class FakeFilePresentation(Presentation):
#TODO: Refactoring in progress... Branch refactor-pres-design
- def __init__(self, file_name):
- Presentation.__init__(self)
- self.file_name = file_name
+ def __init__(self, file_uri):
+ Presentation.__init__(self, file_uri)
=== modified file 'slidepresenterview/session.py'
--- slidepresenterview/session.py 2010-05-07 15:09:50 +0000
+++ slidepresenterview/session.py 2010-05-09 18:15:55 +0000
@@ -22,6 +22,7 @@
See L{Session}
"""
+from slidepresenterview.utils.uri import file_path_to_uri
from slidepresenterview.presentations import FakeFilePresentation
from slidepresenterview.presentations import EmptyPresentaton
@@ -56,9 +57,17 @@
self.current_presentation = self._default_presentation
- def open_presentation_from_file(self, file_name):
- if self.current_presentation.file_name != file_name:
- self.current_presentation = FakeFilePresentation(file_name)
+ def open_presentation_from_file(self, file_path):
+ """
+ Open a presentation from a local file. Same as opening
+ the uri file://file_name.
+
+ @param file_path: The presentation local file
+ @type file_name: Unicode string (Python)
+ """
+ file_uri = file_path_to_uri(file_path)
+ if not self.current_presentation.is_presenting(file_uri):
+ self.current_presentation = FakeFilePresentation(file_uri)
self._notify_presentation_opened()
=== modified file 'slidepresenterview/tests/unit/test_session.py'
--- slidepresenterview/tests/unit/test_session.py 2010-05-07 15:17:40 +0000
+++ slidepresenterview/tests/unit/test_session.py 2010-05-09 18:15:55 +0000
@@ -26,6 +26,8 @@
from mock import Mock
+from slidepresenterview.utils.uri import file_path_to_uri
+
from slidepresenterview.session import Session
from slidepresenterview.session import SessionObserver
from slidepresenterview.presentations import EmptyPresentaton
@@ -91,8 +93,8 @@
#pylint: disable-msg=C0103
def test_default_presentation_should_be_an_EmptyPresentation(self):
- self.assertTrue(isinstance(self.session.current_presentation,
- EmptyPresentaton))
+ cur_pres = self.session.current_presentation
+ self.assertTrue(cur_pres.is_presenting(EmptyPresentaton.URI))
# pylint: disable-msg=R0904
@@ -108,12 +110,12 @@
self.assertTrue(self._did_nothing())
- def test_open_should_open_and_notify_the_new_one(self):
+ def test_open_file_should_open_and_notify_the_new_one(self):
self.session.open_presentation_from_file('mock.pdf')
pres = self.session.current_presentation
self.assertFalse(self._is_default_presentation())
- self.assertTrue("mock.pdf", pres.file_name)
+ self.assertTrue(pres.is_presenting(file_path_to_uri('mock.pdf')))
self.assertTrue(self._has_notified_opening_once(pres))
@@ -136,25 +138,26 @@
self.assertTrue(self._has_notified_opening_once(pres_after))
- def test_open_same_should_do_nothing(self):
+ def test_open_same_file_should_do_nothing(self):
self.session.open_presentation_from_file('mock.pdf')
self.assertTrue(self._did_nothing())
- def test_open_other_should_open_and_notidy_the_new_one(self):
+ def test_open_other_file_should_open_and_notify_the_new_one(self):
self.session.open_presentation_from_file('mock_other.pdf')
pres_after = self.session.current_presentation
self.assertNotEquals(self.pres_before, pres_after)
- self.assertTrue("mock_other.pdf", pres_after.file_name)
+ self.assertTrue(pres_after.is_presenting(
+ file_path_to_uri('mock_other.pdf')))
self.assertTrue(self._has_notified_opening_once(pres_after))
- def test_open_should_use_presentation_factory(self):
+ def test_open_file_should_use_presentation_factory(self):
self.fail("Not implemented")
- def test_open_factory_error_should_do_nothing(self):
+ def test_open_file_with_factory_error_should_do_nothing(self):
self.fail("Not implemented")