예제 #1
0
    def setUp(self):
        app = wx.PySimpleApp()
        frame = wx.Frame(None)
        self.ohl = ObjectHtmlView(frame)
        frame.Show()

        def render(obj):
            return '%s' % obj

        self.ohl.SetRenderer(render)
예제 #2
0
class TestObjectHtmlViewExistance(unittest.TestCase):
    def setUp(self):
        app = wx.PySimpleApp()
        frame = wx.Frame(None)
        self.ohl = ObjectHtmlView(frame)
        frame.Show()

    def test_has_object(self):
        o = {'an': 'object'}
        self.ohl.AddObject(o)
        self.assertTrue(self.ohl.HasObject(o))

    def test_not_have_object(self):
        self.assertFalse(self.ohl.HasObject({'non': 'existant'}))
예제 #3
0
class TestObjectHtmlViewRefresh(unittest.TestCase):
    def setUp(self):
        app = wx.PySimpleApp()
        frame = wx.Frame(None)
        self.ohl = ObjectHtmlView(frame)
        frame.Show()

    def test_refresh_object(self):
        o = {'text': 'lots of text'}
        self.ohl.AddObject(o)
        o['random'] = 'new random string'
        self.ohl.RefreshObject(o)
        self.assertEqual(self.ohl.GetObjectAt(0)['random'], o['random'])
        self.assertEqual(self.ohl.GetString(0), self.ohl.renderer(o))
예제 #4
0
class TestObjectHtmlViewRendering(unittest.TestCase):
    def setUp(self):
        app = wx.PySimpleApp()
        frame = wx.Frame(None)
        self.ohl = ObjectHtmlView(frame)
        frame.Show()

    def test_set_non_callable(self):
        self.assertRaises(TypeError, self.ohl.SetRenderer, {})

    def test_set_callable(self):
        def callable(args):
            pass

        self.ohl.SetRenderer(callable)
        self.assertEqual(self.ohl.GetRenderer(), callable)
예제 #5
0
    def _init_panel(self):
        main_sizer = wx.BoxSizer(orient=wx.HORIZONTAL)
        right_sizer = wx.BoxSizer(orient=wx.VERTICAL)

        self.ohl = ObjectHtmlView(self)
        self.ohl.SetRenderer(renderer)

        add_button = wx.Button(self, wx.ID_ANY, 'Add Object')
        self.Bind(wx.EVT_BUTTON, self._handle_add, id=add_button.GetId())

        add_same_button = wx.Button(self, wx.ID_ANY, 'Same Object')
        self.Bind(wx.EVT_BUTTON,
                  self._handle_add_same,
                  id=add_same_button.GetId())

        change_button = wx.Button(self, wx.ID_ANY, 'Change Object')
        self.Bind(wx.EVT_BUTTON, self._handle_change, id=change_button.GetId())

        move_down_button = wx.Button(self, wx.ID_ANY, 'Move Down Object')
        self.Bind(wx.EVT_BUTTON,
                  self._handle_move_down,
                  id=move_down_button.GetId())

        move_up_button = wx.Button(self, wx.ID_ANY, 'Move Up Object')
        self.Bind(wx.EVT_BUTTON,
                  self._handle_move_up,
                  id=move_up_button.GetId())

        main_sizer.Add(self.ohl, proportion=1, flag=wx.GROW)
        right_sizer.Add(add_button)
        right_sizer.Add(add_same_button)
        right_sizer.Add(change_button)
        right_sizer.Add(move_down_button)
        right_sizer.Add(move_up_button)

        main_sizer.AddSizer(right_sizer)

        self.SetSizer(main_sizer)
예제 #6
0
class TestObjectHtmlViewRefresh(unittest.TestCase):
    
    def setUp(self):
        app = wx.PySimpleApp()
        frame = wx.Frame(None)
        self.ohl = ObjectHtmlView(frame)
        frame.Show()
    
    def test_refresh_object(self):
        o = {'text':'lots of text'}
        self.ohl.AddObject(o)
        o['random'] = 'new random string'
        self.ohl.RefreshObject(o)
        self.assertEqual(self.ohl.GetObjectAt(0)['random'], o['random'])
        self.assertEqual(self.ohl.GetString(0), self.ohl.renderer(o))
예제 #7
0
 def setUp(self):
     app = wx.PySimpleApp()
     frame = wx.Frame(None)
     self.ohl = ObjectHtmlView(frame)
     frame.Show()
예제 #8
0
class TestObjectHtmlViewOrder(unittest.TestCase):
    def setUp(self):
        app = wx.PySimpleApp()
        frame = wx.Frame(None)
        self.ohl = ObjectHtmlView(frame)
        frame.Show()

    def test_first_position(self):
        o = {'an': 'object'}
        self.ohl.AddObject(o)
        self.assertEqual(o, self.ohl.GetObjectAt(0))

    def test_second_position(self):
        o, o2 = {'object': '1'}, {'object': '2'}
        self.ohl.AddObjects((o, o2))
        self.assertEqual(o2, self.ohl.GetObjectAt(1))

    def test_wrong_index(self):
        self.assertRaises(IndexError, self.ohl.GetObjectAt, 0)

    def test_get_objects(self):
        o, o2 = {'object': '1'}, {'object': '2'}
        self.ohl.AddObjects((o, o2))
        self.assertTrue(o in self.ohl.GetObjects())
        self.assertTrue(o2 in self.ohl.GetObjects())

    def test_get_index(self):
        o = {'index': 'object'}
        self.ohl.AddObject(o)
        self.assertEqual(0, self.ohl.GetIndexOf(o))

    def test_get_index_two_object(self):
        o, o2 = {'index': 'object'}, {'index': 'object 2'}
        self.ohl.AddObjects((o, o2))
        self.assertEqual(1, self.ohl.GetIndexOf(o2))

    def test_get_index_non_exist(self):
        self.assertRaises(ValueError, self.ohl.GetIndexOf, {'non': 'existant'})
예제 #9
0
class TestObjectHtmlViewMovement(unittest.TestCase):
    def setUp(self):
        app = wx.PySimpleApp()
        frame = wx.Frame(None)
        self.ohl = ObjectHtmlView(frame)
        frame.Show()

    def test_move_up(self):
        o, o2 = {'top': 'object'}, {'bottom': 'object'}
        self.ohl.AddObjects((o, o2))
        self.ohl.MoveUp(o2)
        self.assertEqual(o2, self.ohl.GetObjectAt(0))

    def test_move_down(self):
        o, o2 = {'top': 'object'}, {'bottom': 'object'}
        self.ohl.AddObjects((o, o2))
        self.ohl.MoveDown(o)
        self.assertEqual(o, self.ohl.GetObjectAt(1))

    def test_move_up_top(self):
        o = {'top': 'object'}
        self.ohl.AddObject(o)
        self.ohl.MoveUp(o)
        self.assertEqual(0, self.ohl.GetIndexOf(o))

    def test_move_bottom(self):
        o = {'top': 'object'}
        self.ohl.AddObject(o)
        self.ohl.MoveDown(o)
        self.assertEqual(0, self.ohl.GetIndexOf(o))
예제 #10
0
class TestObjectHtmlViewAddRemove(unittest.TestCase):
    def setUp(self):
        app = wx.PySimpleApp()
        frame = wx.Frame(None)
        self.ohl = ObjectHtmlView(frame)
        frame.Show()

    def test_empty(self):
        self.assertEqual(0, self.ohl.GetObjectCount())

    def test_add_object(self):
        self.ohl.AddObject({'an': 'object'})
        self.assertEqual(1, self.ohl.GetObjectCount())

    def test_add_objects(self):
        self.ohl.AddObjects(OBJECTS)
        self.assertEqual(len(OBJECTS), self.ohl.GetObjectCount())

    def test_remove_object(self):
        o = {'an': 'object'}
        self.ohl.AddObject(o)
        self.assertEqual(1, self.ohl.GetObjectCount())
        self.ohl.RemoveObject(o)
        self.assertEqual(0, self.ohl.GetObjectCount())

    def test_remove_non_existing_object(self):
        self.assertRaises(ValueError, self.ohl.RemoveObject, {})

    def test_add_same_object(self):
        o = {'an': 'object'}
        self.ohl.AddObject(o)
        self.ohl.AddObject(o)
        self.assertEqual(1, self.ohl.GetObjectCount())
예제 #11
0
class TestObjectHtmlViewSelection(unittest.TestCase):
    def setUp(self):
        app = wx.PySimpleApp()
        frame = wx.Frame(None)
        self.ohl = ObjectHtmlView(frame)
        frame.Show()

        def render(obj):
            return '%s' % obj

        self.ohl.SetRenderer(render)

    def test_no_selection(self):
        self.assertEqual(None, self.ohl.GetSelectedObject())

    def test_select_non_existant_object(self):
        self.assertRaises(ValueError, self.ohl.SelectObject, {})

    def test_select_object_one(self):
        o = {'an': 'object'}
        self.ohl.AddObject(o)
        self.ohl.SelectObject(o)
        self.assertEqual(o, self.ohl.GetSelectedObject())

    def test_select_object_two(self):
        o, o2 = {'an': 'object'}, {'object': '2'}
        self.ohl.AddObjects((o, o2))
        self.ohl.SelectObject(o)
        self.assertEqual(o, self.ohl.GetSelectedObject())
        self.ohl.SelectObject(o2)
        self.assertEqual(o2, self.ohl.GetSelectedObject())

    def test_select_object_three(self):
        o, o2, o3 = {'an': 'object'}, {'object': '2'}, {'o': '2'}
        self.ohl.AddObjects((o, o2, o3))
        self.ohl.SelectObject(o)
        self.assertEqual(o, self.ohl.GetSelectedObject())
        self.ohl.SelectObject(o2)
        self.assertEqual(o2, self.ohl.GetSelectedObject())
        self.ohl.SelectObject(o3)
        self.assertEqual(o3, self.ohl.GetSelectedObject())
예제 #12
0
 def setUp(self):
     app = wx.PySimpleApp()
     frame = wx.Frame(None)
     self.ohl = ObjectHtmlView(frame)
     frame.Show()
예제 #13
0
class Frame(wx.Frame):
    def __init__(self, *args, **kw):
        wx.Frame.__init__(self, *args, **kw)
        self._init_panel()

    def _init_panel(self):
        main_sizer = wx.BoxSizer(orient=wx.HORIZONTAL)
        right_sizer = wx.BoxSizer(orient=wx.VERTICAL)

        self.ohl = ObjectHtmlView(self)
        self.ohl.SetRenderer(renderer)

        add_button = wx.Button(self, wx.ID_ANY, 'Add Object')
        self.Bind(wx.EVT_BUTTON, self._handle_add, id=add_button.GetId())

        add_same_button = wx.Button(self, wx.ID_ANY, 'Same Object')
        self.Bind(wx.EVT_BUTTON,
                  self._handle_add_same,
                  id=add_same_button.GetId())

        change_button = wx.Button(self, wx.ID_ANY, 'Change Object')
        self.Bind(wx.EVT_BUTTON, self._handle_change, id=change_button.GetId())

        move_down_button = wx.Button(self, wx.ID_ANY, 'Move Down Object')
        self.Bind(wx.EVT_BUTTON,
                  self._handle_move_down,
                  id=move_down_button.GetId())

        move_up_button = wx.Button(self, wx.ID_ANY, 'Move Up Object')
        self.Bind(wx.EVT_BUTTON,
                  self._handle_move_up,
                  id=move_up_button.GetId())

        main_sizer.Add(self.ohl, proportion=1, flag=wx.GROW)
        right_sizer.Add(add_button)
        right_sizer.Add(add_same_button)
        right_sizer.Add(change_button)
        right_sizer.Add(move_down_button)
        right_sizer.Add(move_up_button)

        main_sizer.AddSizer(right_sizer)

        self.SetSizer(main_sizer)

    def _handle_add(self, event):
        self.ohl.AddObject({
            'title':
            'A title',
            'text':
            'lots of text lots of text lots of text lots of text lots of text lots of text '
        })

    def _handle_add_same(self, event):
        self.ohl.AddObject(O)

    def _handle_change(self, event):
        o = self.ohl.GetClientData(1)
        o['text'] = 'Changed Text!'
        self.ohl.RefreshObject(o)

    def _handle_move_down(self, event):
        self.ohl.MoveDown(O)

    def _handle_move_up(self, event):
        self.ohl.MoveUp(O)