style fixes

This commit is contained in:
Felipe Polo-Wood 2013-10-28 11:16:22 -04:00
parent 1aae38cb8e
commit 9a07d6887b
13 changed files with 73 additions and 64 deletions

View File

@ -291,7 +291,8 @@ def main(args=None):
Settings.set_filename(portable_settings_file)
portable_settings = Settings()
# Set our data path
data_path = os.path.abspath(os.path.join(application_path, '..', '..', 'Data',))
data_path = os.path.abspath(os.path.join(application_path,
'..', '..', 'Data',))
log.info('Data path: %s', data_path)
# Point to our data path
portable_settings.setValue('advanced/data path', data_path)

View File

@ -163,8 +163,9 @@ class MediaMediaItem(MediaManagerItem):
service_item.title = 'webkit'
service_item.processor = 'webkit'
(path, name) = os.path.split(filename)
service_item.add_from_command(path, name,CLAPPERBOARD)
if self.media_controller.video(DisplayControllerType.Live, service_item, video_behind_text=True):
service_item.add_from_command(path, name, CLAPPERBOARD)
if self.media_controller.video(DisplayControllerType.Live,
service_item, video_behind_text=True):
self.reset_action.setVisible(True)
else:
critical_error_message_box(UiStrings().LiveBGError,

View File

@ -485,11 +485,11 @@ class ImpressDocument(PresentationDocument):
titles = []
notes = []
pages = self.document.getDrawPages()
for slideIndex in range(pages.getCount()):
for slide_no in range(pages.getCount()):
titles.append(
self.__get_text_from_page(slideIndex+1,TextType.Title).
replace('\n',' ') + '\n')
note = self.__get_text_from_page(slideIndex+1,TextType.Notes)
self.__get_text_from_page(slide_no+1, TextType.Title).
replace('\n', ' ') + '\n')
note = self.__get_text_from_page(slide_no+1, TextType.Notes)
if len(note) == 0:
note = ' '
notes.append(note)

View File

@ -33,8 +33,9 @@ import os
from PyQt4 import QtCore, QtGui
from openlp.core.common import Settings, UiStrings, translate
from openlp.core.lib import MediaManagerItem, Registry, ItemCapabilities, ServiceItemContext,\
build_icon, check_item_selected, create_thumb, validate_thumb
from openlp.core.lib import MediaManagerItem, Registry, ItemCapabilities, \
ServiceItemContext, build_icon, check_item_selected, \
create_thumb, validate_thumb
from openlp.core.lib.ui import critical_error_message_box, create_horizontal_adjusting_combo_box
from openlp.core.utils import get_locale_key
from openlp.plugins.presentations.lib import MessageListener

View File

@ -332,12 +332,12 @@ class PowerpointDocument(PresentationDocument):
except Exception as e:
log.exception(e)
text = ''
titles.append(text.replace('\n',' ').replace('\x0b',' ') + '\n')
titles.append(text.replace('\n', ' ').replace('\x0b', ' ') + '\n')
note = _get_text_from_shapes(slide.NotesPage.Shapes)
if len(note) == 0:
note = ' '
notes.append(note)
self.save_titles_and_notes(titles,notes)
self.save_titles_and_notes(titles, notes)
return
def _get_text_from_shapes(shapes):

View File

@ -211,11 +211,11 @@ class PptviewDocument(PresentationDocument):
# Let's remove the \n from the titles and
# just add one at the end
if node_type == 'ctrTitle':
text = text.replace('\n',' '). \
text = text.replace('\n', ' '). \
replace('\x0b', ' ') + '\n'
list_to_add[index] = text
# now let's write the files
self.save_titles_and_notes(titles,notes)
self.save_titles_and_notes(titles, notes)
return
def close_presentation(self):

View File

@ -305,7 +305,7 @@ class PresentationDocument(object):
except:
log.exception('Failed to open/read existing titles file')
titles = []
for slide_no, title in enumerate(titles,1):
for slide_no, title in enumerate(titles, 1):
notes_file = os.path.join(self.get_thumbnail_folder(),
'slideNotes%d.txt' % slide_no)
note = ''
@ -329,7 +329,7 @@ class PresentationDocument(object):
with open(titles_file, mode='w') as fo:
fo.writelines(titles)
if notes:
for slide_no, note in enumerate(notes,1):
for slide_no, note in enumerate(notes, 1):
notes_file = os.path.join(self.get_thumbnail_folder(),
'slideNotes%d.txt' % slide_no)
with open(notes_file, mode='w') as fn:

View File

@ -450,7 +450,8 @@ class HttpRouter(object):
Return the latest display image as a byte stream.
"""
result = {
'slide_image': 'data:image/png;base64,' + str(image_to_byte(self.live_controller.slide_image))
'slide_image': 'data:image/png;base64,' +
str(image_to_byte(self.live_controller.slide_image))
}
self.do_json_header()
return json.dumps({'results': result}).encode()
@ -513,12 +514,12 @@ class HttpRouter(object):
dataPath = AppLocation.get_data_path()
if frame['image'][0:len(dataPath)] == dataPath:
item['img'] = frame['image'][len(dataPath):]
#'data:image/png;base64,' + str(image_to_byte(resize_image(frame['image'],80,80)))
#'data:image/png;base64,' + str(image_to_byte(resize_image(frame['image'], 80, 80)))
item['text'] = str(frame['title'])
item['html'] = str(frame['title'])
item['selected'] = (self.live_controller.selected_row == index)
if current_item.notes:
item['notes'] = item.get('notes','') + '\n' + current_item.notes
item['notes'] = item.get('notes', '') + '\n' + current_item.notes
data.append(item)
json_data = {'results': {'slides': data}}
if current_item:

View File

@ -43,9 +43,9 @@ class TestLibModule(TestCase):
def setUp(self):
mocked_plugin = MagicMock()
mocked_plugin.settings_section = 'presentations'
self.file_name = os.path.join(TEST_PATH,'test.pptx')
self.file_name = os.path.join(TEST_PATH, 'test.pptx')
self.ppc = ImpressController(mocked_plugin)
self.doc = ImpressDocument(self.ppc,self.file_name)
self.doc = ImpressDocument(self.ppc, self.file_name)
def create_titles_and_notes_test(self):
"""
@ -60,7 +60,7 @@ class TestLibModule(TestCase):
# WHEN reading the titles and notes
self.doc.create_titles_and_notes()
# THEN save_titles_and_notes should have been called with empty arrays
self.doc.save_titles_and_notes.assert_called_once_with([],[])
self.doc.save_titles_and_notes.assert_called_once_with([], [])
# GIVEN: reset mock and set it to 2 pages
self.doc.save_titles_and_notes.reset_mock()
self.doc.document.getDrawPages().getCount.return_value = 2
@ -69,7 +69,7 @@ class TestLibModule(TestCase):
# THEN: save_titles_and_notes should have been called once with
# two arrays of two elements
self.doc.save_titles_and_notes.assert_called_once_with(
['\n','\n'], [' ',' '])
['\n', '\n'], [' ', ' '])
def get_text_from_page_out_of_bound_test(self):
"""
@ -77,17 +77,17 @@ class TestLibModule(TestCase):
"""
# GIVEN: mocked LibreOffice Document with one slide,
# two notes and three texts
self.doc.document = self._mock_a_LibreOffice_document(1,2,3)
self.doc.document = self._mock_a_LibreOffice_document(1, 2, 3)
# WHEN: __get_text_from_page is called with an index of 0x00
result = self.doc._ImpressDocument__get_text_from_page(0,TextType.Notes)
result = self.doc._ImpressDocument__get_text_from_page(0, TextType.Notes)
# THEN: the result should be an empty string
self.assertEqual(result, '', 'Result should be an empty string')
# WHEN: regardless of the type of text, index 0x00 is out of bounds
result = self.doc._ImpressDocument__get_text_from_page(0,TextType.Title)
result = self.doc._ImpressDocument__get_text_from_page(0, TextType.Title)
# THEN: result should be an empty string
self.assertEqual(result, '', 'Result should be an empty string')
# WHEN: when called with 2, it should also be out of bounds
result = self.doc._ImpressDocument__get_text_from_page(2,TextType.SlideText)
result = self.doc._ImpressDocument__get_text_from_page(2, TextType.SlideText)
# THEN: result should be an empty string ... and, getByIndex should
# have never been called
self.assertEqual(result, '', 'Result should be an empty string')
@ -100,9 +100,9 @@ class TestLibModule(TestCase):
"""
# GIVEN: mocked LibreOffice Document with one slide, two notes and
# three texts
self.doc.document = self._mock_a_LibreOffice_document(1,2,3)
self.doc.document = self._mock_a_LibreOffice_document(1, 2, 3)
# WHEN: called with TextType 3
result = self.doc._ImpressDocument__get_text_from_page(1,3)
result = self.doc._ImpressDocument__get_text_from_page(1, 3)
# THEN: result should be an empty string
self.assertEqual(result, '', 'Result should be and empty string')
self.assertEqual(self.doc.document.getDrawPages().getByIndex.call_count,
@ -114,7 +114,7 @@ class TestLibModule(TestCase):
"""
# GIVEN: mocked LibreOffice Document with one slide,
# two notes and three texts
self.doc.document = self._mock_a_LibreOffice_document(1,2,3)
self.doc.document = self._mock_a_LibreOffice_document(1, 2, 3)
# WHEN: __get_text_from_page is called to get the Notes
result = self.doc._ImpressDocument__get_text_from_page(1, TextType.Notes)
# THEN: result should be 'Note\nNote\n'

View File

@ -44,8 +44,8 @@ class TestLibModule(TestCase):
mocked_plugin = MagicMock()
mocked_plugin.settings_section = 'presentations'
self.ppc = PowerpointController(mocked_plugin)
self.file_name = os.path.join(TEST_PATH,"test.pptx")
self.doc = PowerpointDocument(self.ppc,self.file_name)
self.file_name = os.path.join(TEST_PATH, "test.pptx")
self.doc = PowerpointDocument(self.ppc, self.file_name)
# add _test to the name to enable
def verify_installation(self):
@ -66,7 +66,7 @@ class TestLibModule(TestCase):
# GIVEN: the filename
print(self.file_name)
# WHEN: loading the filename
self.doc = PowerpointDocument(self.ppc,self.file_name)
self.doc = PowerpointDocument(self.ppc, self.file_name)
self.doc.load_presentation()
result = self.doc.is_loaded()
# THEN: result should be true
@ -77,13 +77,13 @@ class TestLibModule(TestCase):
Test creating the titles from PowerPoint
"""
# GIVEN: mocked save_titles_and_notes, _get_text_from_shapes and two mocked slides
self.doc = PowerpointDocument(self.ppc,self.file_name)
self.doc = PowerpointDocument(self.ppc, self.file_name)
self.doc.save_titles_and_notes = MagicMock()
self.doc._PowerpointDocument__get_text_from_shapes = MagicMock()
slide = MagicMock()
slide.Shapes.Title.TextFrame.TextRange.Text = 'SlideText'
pres = MagicMock()
pres.Slides = [slide,slide]
pres.Slides = [slide, slide]
self.doc.presentation = pres
# WHEN reading the titles and notes
self.doc.create_titles_and_notes()
@ -96,7 +96,7 @@ class TestLibModule(TestCase):
Test creating the titles from PowerPoint when it returns no slides
"""
# GIVEN: mocked save_titles_and_notes, _get_text_from_shapes and two mocked slides
self.doc = PowerpointDocument(self.ppc,self.file_name)
self.doc = PowerpointDocument(self.ppc, self.file_name)
self.doc.save_titles_and_notes = MagicMock()
self.doc._PowerpointDocument__get_text_from_shapes = MagicMock()
pres = MagicMock()
@ -116,7 +116,7 @@ class TestLibModule(TestCase):
shape.PlaceholderFormat.Type = 2
shape.HasTextFrame = shape.TextFrame.HasText = True
shape.TextFrame.TextRange.Text = 'slideText'
shapes = [shape,shape]
shapes = [shape, shape]
result = _get_text_from_shapes(shapes)
self.assertEqual(result, 'slideText\nslideText\n',
'result should match \'slideText\nslideText\n\'')

View File

@ -42,8 +42,8 @@ class TestLibModule(TestCase):
mocked_plugin = MagicMock()
mocked_plugin.settings_section = 'presentations'
self.ppc = PptviewController(mocked_plugin)
self.file_name = os.path.join(TEST_PATH,"test.pptx")
self.doc = PptviewDocument(self.ppc,self.file_name)
self.file_name = os.path.join(TEST_PATH, "test.pptx")
self.doc = PptviewDocument(self.ppc, self.file_name)
#add _test to the function name to enable test
def verify_installation(self):
@ -65,7 +65,7 @@ class TestLibModule(TestCase):
# GIVEN: the filename
print(self.file_name)
# WHEN: loading the filename
self.doc = PptviewDocument(self.ppc,self.file_name)
self.doc = PptviewDocument(self.ppc, self.file_name)
self.doc.load_presentation()
result = self.doc.is_loaded()
# THEN: result should be true
@ -77,10 +77,10 @@ class TestLibModule(TestCase):
Test reading the titles from PowerpointViewer
"""
# GIVEN:
self.doc = PptviewDocument(self.ppc,self.file_name)
self.doc = PptviewDocument(self.ppc, self.file_name)
self.doc.create_titles_and_notes()
# WHEN reading the titles and notes
titles,notes = self.doc.get_titles_and_notes()
titles, notes = self.doc.get_titles_and_notes()
print("titles: ".join(titles))
print("notes: ".join(notes))
# THEN there should be exactly 5 titles and 5 notes
@ -111,12 +111,12 @@ class TestLibModule(TestCase):
patch('openlp.plugins.presentations.lib.presentationcontroller.check_directory_exists') as mocked_dir_exists:
mocked_exists.return_value = False
mocked_dir_exists.return_value = False
self.doc = PptviewDocument(self.ppc,'Idontexist.pptx')
self.doc = PptviewDocument(self.ppc, 'Idontexist.pptx')
self.doc.save_titles_and_notes = MagicMock()
# WHEN: reading the titles and notes
self.doc.create_titles_and_notes()
# THEN:
self.doc.save_titles_and_notes.assert_called_once_with(None,None)
self.doc.save_titles_and_notes.assert_called_once_with(None, None)
mocked_exists.assert_any_call('Idontexist.pptx')
self.assertEqual(mocked_open.call_count, 0,
'There should be no calls to open a file')
@ -132,12 +132,13 @@ class TestLibModule(TestCase):
mocked_is_zf.return_value = False
mocked_exists.return_value = True
mocked_open.filesize = 10
self.doc = PptviewDocument(self.ppc,os.path.join(TEST_PATH,"test.ppt"))
self.doc = PptviewDocument(self.ppc,
os.path.join(TEST_PATH, "test.ppt"))
self.doc.save_titles_and_notes = MagicMock()
# WHEN: reading the titles and notes
self.doc.create_titles_and_notes()
# THEN:
self.doc.save_titles_and_notes.assert_called_once_with(None,None)
self.doc.save_titles_and_notes.assert_called_once_with(None, None)
self.assertEqual(mocked_is_zf.call_count, 1,
'is_zipfile should have been called once')

View File

@ -56,17 +56,17 @@ class TestLibModule(TestCase):
notes = ['one', 'two']
# WHEN: calling save_titles_and_notes
mocked_get_thumbnail_folder.return_value = 'test'
self.document.save_titles_and_notes(titles,notes)
self.document.save_titles_and_notes(titles, notes)
# THEN: the last call to open should have been for slideNotes2.txt
mocked_open.assert_any_call(
os.path.join('test','titles.txt'), mode='w')
os.path.join('test', 'titles.txt'), mode='w')
mocked_open.assert_any_call(
os.path.join('test','slideNotes1.txt'), mode='w')
os.path.join('test', 'slideNotes1.txt'), mode='w')
mocked_open.assert_any_call(
os.path.join('test','slideNotes2.txt'), mode='w')
os.path.join('test', 'slideNotes2.txt'), mode='w')
self.assertEqual(mocked_open.call_count, 3,
'There should be exactly three files opened')
mocked_open().writelines.assert_called_once_with(['uno','dos'])
mocked_open().writelines.assert_called_once_with(['uno', 'dos'])
mocked_open().write.assert_called_any('one')
mocked_open().write.assert_called_any('two')
@ -82,7 +82,7 @@ class TestLibModule(TestCase):
notes = None
# WHEN: calling save_titles_and_notes
mocked_get_thumbnail_folder.return_value = 'test'
self.document.save_titles_and_notes(titles,notes)
self.document.save_titles_and_notes(titles, notes)
# THEN: No file should have been created
self.assertEqual(mocked_open.call_count, 0,
'No file should be created')
@ -112,9 +112,9 @@ class TestLibModule(TestCase):
'There should be two items in the notes')
self.assertEqual(mocked_open.call_count, 3,
'Three files should be opened')
mocked_open.assert_any_call(os.path.join('test','titles.txt'))
mocked_open.assert_any_call(os.path.join('test','slideNotes1.txt'))
mocked_open.assert_any_call(os.path.join('test','slideNotes2.txt'))
mocked_open.assert_any_call(os.path.join('test', 'titles.txt'))
mocked_open.assert_any_call(os.path.join('test', 'slideNotes1.txt'))
mocked_open.assert_any_call(os.path.join('test', 'slideNotes2.txt'))
self.assertEqual(mocked_exists.call_count, 3,
'Three files should have been checked')

View File

@ -116,16 +116,16 @@ class TestRouter(TestCase):
"""
Test the header sending logic
"""
headers = [ ['test.html','text/html'], ['test.css','text/css'],
['test.js','application/javascript'], ['test.jpg','image/jpeg'],
['test.gif','image/gif'],['test.ico','image/x-icon'],
['test.png','image/png'],['test.whatever','text/plain'],
['test','text/plain'],['','text/plain']]
headers = [ ['test.html', 'text/html'], ['test.css', 'text/css'],
['test.js', 'application/javascript'], ['test.jpg', 'image/jpeg'],
['test.gif', 'image/gif'], ['test.ico', 'image/x-icon'],
['test.png', 'image/png'], ['test.whatever', 'text/plain'],
['test', 'text/plain'], ['', 'text/plain']]
send_header = MagicMock()
self.router.send_header = send_header
for header in headers:
self.router.send_appropriate_header(header[0])
send_header.assert_called_with('Content-type',header[1])
send_header.assert_called_with('Content-type', header[1])
send_header.reset_mock()
def serve_thumbnail_without_params_test(self):
@ -149,7 +149,8 @@ class TestRouter(TestCase):
self.router.end_headers = MagicMock()
self.router.wfile = MagicMock()
# WHEN: pass a bad controller
self.router.serve_thumbnail('badcontroller','tecnologia 1.pptx/slide1.png')
self.router.serve_thumbnail('badcontroller',
'tecnologia 1.pptx/slide1.png')
# THEN: a 404 should be returned
self.assertEqual(len(self.router.send_header.mock_calls), 1,
'One header')
@ -160,12 +161,14 @@ class TestRouter(TestCase):
self.router.send_response.assert_called_once_with(404)
# WHEN: pass a bad filename
self.router.send_response.reset_mock()
self.router.serve_thumbnail('presentations','tecnologia 1.pptx/badfilename.png')
self.router.serve_thumbnail('presentations',
'tecnologia 1.pptx/badfilename.png')
# THEN: return a 404
self.router.send_response.assert_called_once_with(404)
# WHEN: a dangerous URL is passed
self.router.send_response.reset_mock()
self.router.serve_thumbnail('presentations','../tecnologia 1.pptx/slide1.png')
self.router.serve_thumbnail('presentations',
'../tecnologia 1.pptx/slide1.png')
# THEN: return a 404
self.router.send_response.assert_called_once_with(404)
@ -184,7 +187,8 @@ class TestRouter(TestCase):
mocked_exists.return_value = True
mocked_location.get_section_data_path.return_value = ''
# WHEN: pass good controller and filename
result = self.router.serve_thumbnail('presentations','another%20test/slide1.png')
result = self.router.serve_thumbnail('presentations',
'another%20test/slide1.png')
# THEN: a file should be returned
self.assertEqual(len(self.router.send_header.mock_calls), 1,
'One header')