Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

merge with svn

git-svn-id: http://projects.conceptive.be/camelot/svn/trunk@2520 8325946a-aa55-0410-8760-f0bc8c33efaa
  • Loading branch information...
commit 39281656adc8d9a7ec6b1769c4608abe50a87043 1 parent 7409205
erikj authored
View
14 camelot/view/controls/editors/booleditor.py
@@ -22,7 +22,6 @@
#
# ============================================================================
-
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4.QtCore import Qt
@@ -31,7 +30,6 @@
from camelot.core import constants
from camelot.core.utils import ugettext
-
class BoolEditor(QtGui.QCheckBox, AbstractCustomEditor):
"""Widget for editing a boolean field"""
@@ -48,16 +46,12 @@ def __init__(self,
AbstractCustomEditor.__init__(self)
self.setObjectName( field_name )
self._nullable = nullable
- #if self._nullable:
- # self.setTristate( True )
- self.stateChanged.connect(self._state_changed)
+ self.clicked.connect( self._state_changed )
def set_value(self, value):
value = AbstractCustomEditor.set_value(self, value)
if value:
self.setCheckState(Qt.Checked)
- #elif value==None and self._nullable:
- # self.setCheckState(Qt.PartiallyChecked)
else:
self.setCheckState(Qt.Unchecked)
@@ -66,12 +60,11 @@ def get_value(self):
if value_loading is not None:
return value_loading
state = self.checkState()
- #if state==Qt.PartiallyChecked:
- # return None
if state==Qt.Unchecked:
return False
return True
+ @QtCore.pyqtSlot( bool )
def _state_changed(self, value=None):
self.editingFinished.emit()
@@ -84,7 +77,6 @@ def sizeHint(self):
size = QtGui.QComboBox().sizeHint()
return size
-
class TextBoolEditor(QtGui.QLabel, AbstractCustomEditor):
"""
:Parameter:
@@ -124,5 +116,3 @@ def set_value(self, value):
selfpalette = self.palette()
selfpalette.setColor(QtGui.QPalette.WindowText, self.color_no)
self.setPalette(selfpalette)
-
-
View
7 camelot/view/controls/editors/charteditor.py
@@ -187,6 +187,9 @@ def set_value(self, value):
from camelot.container.chartcontainer import structure_to_figure_container
self._value = structure_to_figure_container( super(ChartEditor, self).set_value(value) )
self.on_draw()
+
+ def get_value(self):
+ return self._value
# def _get_tightbbox(self, fig, pad_inches):
# renderer = fig.canvas.get_renderer()
@@ -231,7 +234,3 @@ def on_draw(self):
# #self.fig.subplots_adjust(bottom=0.3, right=0.9, top=0.9, left=0.1)
# self.tight_borders(self.fig)
# self.canvas.draw()
-
-
-
-
View
4 camelot/view/controls/editors/datetimeeditor.py
@@ -83,8 +83,8 @@ def __init__(self,
for i in range(0,24)))]
self.timeedit.addItems(time_entries)
self.timeedit.setValidator(TimeValidator(self, nullable))
- self.timeedit.currentIndexChanged.connect( self.editing_finished )
- self.timeedit.editTextChanged.connect( self.editing_finished )
+ self.timeedit.activated.connect( self.editing_finished )
+ self.timeedit.lineEdit().editingFinished.connect( self.editing_finished )
self.timeedit.setFocusPolicy( Qt.StrongFocus )
layout.addWidget(self.timeedit, 1)
View
10 camelot/view/controls/editors/smileyeditor.py
@@ -22,7 +22,7 @@
#
# ============================================================================
-from PyQt4 import QtGui
+from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import Qt
from customeditor import CustomEditor
@@ -79,7 +79,7 @@ def __init__(self,
else:
self.box.setEnabled(True)
- self.box.currentIndexChanged.connect(self.smiley_changed)
+ self.box.activated.connect( self.smiley_changed )
layout.addWidget(self.box)
layout.addStretch()
self.setLayout(layout)
@@ -90,11 +90,11 @@ def get_value(self):
def set_enabled(self, editable=True):
self.box.setEnabled(editable)
-
- def smiley_changed(self):
+
+ @QtCore.pyqtSlot( int )
+ def smiley_changed(self, _index ):
self.editingFinished.emit()
def set_value(self, value):
name = CustomEditor.set_value(self, value)
self.box.setCurrentIndex( self.position_by_name[name] )
-
View
103 test/test_view.py
@@ -7,6 +7,7 @@
import time
from camelot.core.utils import ugettext_lazy as _
+from camelot.core.files.storage import StoredFile, StoredImage, Storage
from camelot.test import ModelThreadTestCase, EntityViewsTest, SchemaTest
from camelot.view.art import ColorScheme
@@ -17,6 +18,7 @@
logger = logging.getLogger('view.unittests')
static_images_path = os.path.join(os.path.dirname(__file__), '..', 'doc', 'sphinx', 'source', '_static')
+storage = Storage()
def create_getter(getable):
@@ -25,6 +27,16 @@ def getter():
return getter
+class SignalCounter( QtCore.QObject ):
+
+ def __init__( self ):
+ super( SignalCounter, self ).__init__()
+ self.counter = 0
+
+ @QtCore.pyqtSlot()
+ def signal_caught( self ):
+ self.counter += 1
+
class EditorsTest(ModelThreadTestCase):
"""
Test the basic functionality of the editors :
@@ -39,6 +51,23 @@ class EditorsTest(ModelThreadTestCase):
from camelot.view.controls import editors
from camelot.view.proxy import ValueLoading
+ def assert_valid_editor( self, editor, value ):
+ """Test the basic functions of an editor that are needed to integrate
+ well with Camelot and Qt
+ """
+ #
+ # The editor should remember its when its value is ValueLoading
+ #
+ editor.set_value( self.ValueLoading )
+ self.assertEqual( editor.get_value(), self.ValueLoading )
+ #
+ # When a value is set, no editingFinished should be called
+ #
+ signal_counter = SignalCounter()
+ editor.editingFinished.connect( signal_counter.signal_caught )
+ editor.set_value( value )
+ self.assertEqual( signal_counter.counter, 0 )
+
def test_ChartEditor(self):
import math
from camelot.container import chartcontainer
@@ -51,6 +80,7 @@ def test_ChartEditor(self):
self.grab_widget( editor, 'editable' )
editor.set_field_attributes(editable=False)
self.grab_widget( editor, 'disabled' )
+ self.assert_valid_editor( editor, plot )
def test_DateEditor(self):
import datetime
@@ -61,8 +91,7 @@ def test_DateEditor(self):
editor.set_value( datetime.date(1980, 12, 31) )
self.grab_default_states( editor )
self.assertEqual( editor.get_value(), datetime.date(1980, 12, 31) )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
+ self.assert_valid_editor( editor, datetime.date(1980, 12, 31) )
def test_TextLineEditor(self):
editor = self.editors.TextLineEditor(parent=None, length=10)
@@ -77,13 +106,12 @@ def test_TextLineEditor(self):
self.assertEqual( editor.get_value(), self.ValueLoading )
editor.set_value( u'za coś tam' )
self.assertEqual( editor.get_value(), u'za coś tam' )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
editor.set_value( None )
self.assertEqual( editor.get_value(), None )
# pretend the user has entered some text
editor.setText( u'foo' )
self.assertTrue( editor.get_value() != None )
+ self.assert_valid_editor( editor, u'za coś tam' )
def grab_default_states( self, editor ):
editor.set_field_attributes( editable = True, background_color=ColorScheme.green )
@@ -110,8 +138,7 @@ def test_LocalFileEditor( self ):
editor.set_value( '/home/lancelot/quests.txt' )
self.grab_default_states( editor )
self.assertEqual( editor.get_value(), '/home/lancelot/quests.txt' )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
+ self.assert_valid_editor( editor, '/home/lancelot/quests.txt' )
def test_StarEditor(self):
editor = self.editors.StarEditor(parent=None, maximum=5)
@@ -119,8 +146,7 @@ def test_StarEditor(self):
editor.set_value( 4 )
self.grab_default_states( editor )
self.assertEqual( editor.get_value(), 4 )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
+ self.assert_valid_editor( editor, 4 )
def test_SmileyEditor(self):
editor = self.editors.SmileyEditor(parent=None)
@@ -128,8 +154,7 @@ def test_SmileyEditor(self):
editor.set_value( 'face-kiss' )
self.grab_default_states( editor )
self.assertEqual( editor.get_value(), 'face-kiss' )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
+ self.assert_valid_editor( editor, 'face-kiss' )
def test_BoolEditor(self):
editor = self.editors.BoolEditor(parent=None, editable=False, nullable=True)
@@ -147,10 +172,9 @@ def test_BoolEditor(self):
self.assertEqual( editor.get_value(), True )
editor.set_value( False )
self.assertEqual( editor.get_value(), False )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
editor.set_value( True )
editor.set_enabled( True )
+ self.assert_valid_editor( editor, True )
def test_CodeEditor(self):
editor = self.editors.CodeEditor(parent=None, parts=['AAA', '999'])
@@ -158,10 +182,7 @@ def test_CodeEditor(self):
editor.set_value( ['XYZ', '123'] )
self.grab_default_states( editor )
self.assertEqual( editor.get_value(), ['XYZ', '123'] )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
+ self.assert_valid_editor( editor, ['XYZ', '123'] )
def test_ColorEditor(self):
editor = self.editors.ColorEditor(parent=None, editable=True)
@@ -169,8 +190,7 @@ def test_ColorEditor(self):
editor.set_value( (255, 200, 255, 255) )
self.grab_default_states( editor )
self.assertEqual( editor.get_value(), (255, 200, 255, 255) )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
+ self.assert_valid_editor( editor, (255, 200, 255, 255) )
def test_ColoredFloatEditor(self):
editor = self.editors.ColoredFloatEditor(parent=None, editable=True)
@@ -180,8 +200,7 @@ def test_ColoredFloatEditor(self):
editor.set_value( 3.14 )
self.grab_default_states( editor )
self.assertEqual( editor.get_value(), 3.14 )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
+ self.assert_valid_editor( editor, 3.14 )
def test_ChoicesEditor(self):
editor = self.editors.ChoicesEditor(parent=None, editable=True)
@@ -202,20 +221,16 @@ def test_ChoicesEditor(self):
self.assertEqual( editor.get_value(), self.ValueLoading )
# try strings as keys
editor = self.editors.ChoicesEditor(parent=None, editable=True)
- editor.set_choices( [] )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
editor.set_choices( [('a',u'A'), ('b',u'B'), ('c',u'C')] )
editor.set_value( 'c' )
self.assertEqual( editor.get_value(), 'c' )
-
+ self.assert_valid_editor( editor, 'c' )
def test_FileEditor(self):
editor = self.editors.FileEditor(parent=None, editable=True)
self.assertEqual( editor.get_value(), self.ValueLoading )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
self.grab_default_states( editor )
+ self.assert_valid_editor( editor, StoredFile( storage, 'test.txt') )
def test_DateTimeEditor(self):
import datetime
@@ -224,8 +239,7 @@ def test_DateTimeEditor(self):
editor.set_value( datetime.datetime(2009, 7, 19, 21, 5, 10, 0) )
self.assertEqual( editor.get_value(), datetime.datetime(2009, 7, 19, 21, 5, 0 ) )
self.grab_default_states( editor )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
+ self.assert_valid_editor( editor, datetime.datetime(2009, 7, 19, 21, 5, 0 ) )
def test_FloatEditor(self):
editor = self.editors.FloatEditor(parent=None,
@@ -236,8 +250,6 @@ def test_FloatEditor(self):
editor.set_value( 3.14 )
self.grab_default_states( editor )
self.assertEqual( editor.get_value(), 3.14 )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
editor = self.editors.FloatEditor(parent=None,
suffix='suffix')
self.assertEqual( editor.get_value(), self.ValueLoading )
@@ -245,8 +257,6 @@ def test_FloatEditor(self):
self.assertEqual( editor.get_value(), 0.0 )
editor.set_value( 3.14 )
self.assertEqual( editor.get_value(), 3.14 )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
editor.set_value( 5.45 )
editor.set_value( None )
self.assertEqual( editor.get_value(), None )
@@ -260,13 +270,13 @@ def test_FloatEditor(self):
editor.set_value( 3.14 )
self.grab_widget( editor, 'no_calculator' )
self.assertTrue( editor.calculatorButton.isHidden() )
+ self.assert_valid_editor( editor, 3.14 )
def test_ImageEditor(self):
editor = self.editors.ImageEditor(parent=None, editable=True)
self.assertEqual( editor.get_value(), self.ValueLoading )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
self.grab_default_states( editor )
+ self.assert_valid_editor( editor, StoredImage( storage, 'test.png') )
def test_IntegerEditor(self):
editor = self.editors.IntegerEditor(parent=None, editable=True)
@@ -276,8 +286,6 @@ def test_IntegerEditor(self):
editor.set_value( 3 )
self.grab_default_states( editor )
self.assertEqual( editor.get_value(), 3 )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
editor.set_value( None )
# pretend the user changed the value
editor.spinBox.setValue( 0 )
@@ -288,15 +296,17 @@ def test_IntegerEditor(self):
editor = self.editors.IntegerEditor(parent=None,
calculator=False)
editor.set_field_attributes( editable=True )
- editor.set_value( 3.14 )
+ editor.set_value( 3 )
self.grab_widget( editor, 'no_calculator' )
self.assertTrue( editor.calculatorButton.isHidden() )
+ self.assert_valid_editor( editor, 3 )
def test_NoteEditor(self):
editor = self.editors.NoteEditor(parent=None)
editor.set_value('A person with this name already exists')
self.grab_widget( editor )
self.grab_default_states( editor )
+ self.assert_valid_editor( editor, 'A person with this name already exists' )
def test_LabelEditor(self):
editor = self.editors.LabelEditor(parent=None)
@@ -309,12 +319,12 @@ def test_LanguageEditor(self):
editor.set_value( 'en_US' )
self.grab_default_states( editor )
self.assertEqual( editor.get_value(), 'en_US' )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
+ self.assert_valid_editor( editor, 'en_US' )
def test_Many2OneEditor(self):
editor = self.editors.Many2OneEditor(parent=None)
self.grab_default_states( editor )
+ self.assert_valid_editor( editor, lambda:object )
def test_RichTextEditor(self):
editor = self.editors.RichTextEditor(parent=None)
@@ -322,8 +332,7 @@ def test_RichTextEditor(self):
editor.set_value( u'<h1>Rich Text Editor</h1>' )
self.grab_default_states( editor )
self.assertTrue( u'Rich Text Editor' in editor.get_value() )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
+ self.assert_valid_editor( editor, u'<h1>Rich Text Editor</h1>' )
def test_TimeEditor(self):
import datetime
@@ -332,8 +341,7 @@ def test_TimeEditor(self):
editor.set_value( datetime.time(21, 5, 0) )
self.grab_default_states( editor )
self.assertEqual( editor.get_value(), datetime.time(21, 5, 0) )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
+ self.assert_valid_editor( editor, datetime.time(21, 5, 0) )
def test_TextEditEditor(self):
editor = self.editors.TextEditEditor(parent=None, editable=True)
@@ -341,8 +349,7 @@ def test_TextEditEditor(self):
editor.set_value( 'Plain text' )
self.grab_default_states( editor )
self.assertEqual( editor.get_value(), 'Plain text' )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
+ self.assert_valid_editor( editor, 'Plain text' )
def test_VirtualAddressEditor(self):
editor = self.editors.VirtualAddressEditor(parent=None)
@@ -350,8 +357,7 @@ def test_VirtualAddressEditor(self):
editor.set_value( ('im','test') )
self.grab_default_states( editor )
self.assertEqual( editor.get_value(), ('im','test') )
- editor.set_value( self.ValueLoading )
- self.assertEqual( editor.get_value(), self.ValueLoading )
+ self.assert_valid_editor( editor, ('im','test') )
def test_MonthsEditor(self):
editor = self.editors.MonthsEditor(parent=None)
@@ -359,8 +365,7 @@ def test_MonthsEditor(self):
editor.set_value(12)
self.grab_default_states( editor )
self.assertEqual(editor.get_value(), 12)
- editor.set_value(self.ValueLoading)
- self.assertEqual(editor.get_value(), self.ValueLoading)
+ self.assert_valid_editor( editor, 12 )
from camelot.view import forms
Please sign in to comment.
Something went wrong with that request. Please try again.