def __init__(self, document, width=0, height=0, is_fixed_size=False, background=False, font_size=13, font_name='Segoe UI', font_color=None, chat=False): Viewer.__init__(self, width, height) Controller.__init__(self) self.max_height = height if isinstance(document, str): self._document = pyglet.text.document.UnformattedDocument(document) else: self._document = document self.h1 = height self.w1 = width self.chat = chat self.fontSize = font_size self.fontName = font_name self.fontColor = font_color self._bgcolor = background self._bg = None self._content = None self.content_width = width self._scrollbar = None self.set_document_style = False self.firstTimeLoad = True self.is_fixed_size = is_fixed_size
def setUp(self): super(TestHorizontalContainer, self).setUp() self.container = HorizontalContainer([Viewer(width=50, height=50), Viewer(width=50, height=50)]) self.manager = Manager(self.container, window=self.window, batch=self.batch, theme=self.theme)
def __init__(self, label="", is_pressed=False, on_press=None,width=0,height=0,font_size=None,path=None,alternative=None,argument=None,outline=None,disabled=False,align=HALIGN_CENTER,font_color=None,texture=None,outlinePressingEnabled=True,font=None,font_valign=VALIGN_CENTER,on_right_press=None): TwoStateController.__init__(self, is_pressed=is_pressed, on_press=on_press) Viewer.__init__(self,width=width,height=height) self._width=width self._height=height self.label = label self._outlineGraphic=None # graphics self._label = None self._button = None self._fn=font if path is not None: self._path = [path] else: self._path = ['button'] self._alt=alternative self.font_size=font_size self.arg=argument self._outline=outline self.disabled=disabled self._al=align self._fl=font_color self._textureZ=texture self._olPressing=outlinePressingEnabled self._fontvalign=font_valign self.on_right_press=on_right_press
def __init__(self, value=0.0, min_value=0.0, max_value=1.0, on_set=None, steps=None, width=0, height=0): ContinuousStateController.__init__(self, value=value, min_value=min_value, max_value=max_value, on_set=on_set) Viewer.__init__(self, width, height) self._bar = None # a bar where the knob slides. self._knob = None # the knob that moves along the bar. self._offset = (0, 0 ) # offset of the knob image to its central position self._padding = (0, 0, 0, 0 ) # padding of the bar image to its central position self.steps = steps self._markers = [] # markers in case of discrete steps. self._step_offset = (0, 0)
def __init__(self, text="", length=20, max_length=None, padding=0, on_input=None): Viewer.__init__(self) FocusMixin.__init__(self) self._document = pyglet.text.document.UnformattedDocument(text) self._document_style_set = False # check if style of document was set. self._length = length # the length of the box in characters self._max_length = max_length # the max length allowed for writing. self._on_input = on_input self._padding = 4 + padding # graphics loaded in both states self._field = None # graphics loaded in state "writing" self._text_layout = None self._caret = None # graphics loaded in state "label" self._label = None
def test_add(self): """ Tests that we can add a new item. """ item = Viewer(width=50, height=50) self.container.add(item) self.assertEqual(item.has_manager(), True)
def __init__(self, label="", is_pressed=False, on_press=None): TwoStateController.__init__(self, is_pressed=is_pressed, on_press=on_press) Viewer.__init__(self) self.label = label # graphics self._label = None self._button = None
def __init__(self, path: str = None, binding: Binding = None): Viewer.__init__(self) Label.__init__(self) self.path = 'label' if path is None else path # ... if binding is not None: binding.setter = lambda value: self.set_text(value) # ... pass
def __init__(self, label="", is_pressed=False, on_press=None): TwoStateController.__init__(self, is_pressed=is_pressed, on_press=on_press) Viewer.__init__(self) if isinstance(label, str): self._document = pyglet.text.document.UnformattedDocument(label) else: self._document = label # graphics self._label = None self._button = None
def __init__(self, text="", bold=False, italic=False, font_name=None, font_size=None, color=None, path=None): Viewer.__init__(self) self.text = text self.bold = bold self.italic = italic self.font_name = font_name self.font_size = font_size self.color = color self.path = path self.label = None
def layout(self): Viewer.layout(self) # lays out graphics self._button.update(self.x, self.y, self.width, self.height) # centers the label on the middle of the button x, y, width, height = self._button.get_content_region() font = self._label.document.get_font() self._label.x = x + width/2 - self._label.content_width/2 self._label.y = y + height/2 - font.ascent/2 - font.descent self._label.update()
def __init__(self, text="", bold=False, italic=False, font_name=None, font_size=None, color=None, path=None,width=None,multiline=False): Viewer.__init__(self) self.text = text self.bold = bold self.italic = italic self.font_name = font_name self.font_size = font_size self.color = color self.path = path self.label = None self.multiline=multiline self.w=width
def __init__(self, document, width=0, height=0, is_fixed_size=False): Viewer.__init__(self, width, height) Controller.__init__(self) self.max_height = height if isinstance(document, str): self._document = pyglet.text.document.UnformattedDocument(document) else: self._document = document self._content = None self.content_width = width self._scrollbar = None self.set_document_style = False self.is_fixed_size = is_fixed_size
def __init__(self, path=None, is_expandable=False,alternative=None,outline=None,width=None,height=None,bgWidth=None,texture=None): Viewer.__init__(self) self._path = path self._expandable = is_expandable self._graphic = None self._outlineGraphic = None self.textureTmp = texture self._TextureGraphic = None self._alt=alternative self._outline=outline self._min_width = self._min_height = 0 self.w1=width self.h1=height self.bgWidth=bgWidth
def __init__(self, value=0.0, min_value=0.0, max_value=1.0, on_set=None, steps=None, width=0, height=0): ContinuousStateController.__init__(self, value=value, min_value=min_value, max_value=max_value, on_set=on_set) Viewer.__init__(self, width, height) self._bar = None # a bar where the knob slides. self._knob = None # the knob that moves along the bar. self._offset = (0, 0) # offset of the knob image to its central position self._padding = (0, 0, 0, 0) # padding of the bar image to its central position self.steps = steps self._markers = [] # markers in case of discrete steps. self._step_offset = (0, 0)
def test_add_column(self): """ Tests that if we add a column with 3 rows, we have the correct sizes. """ self.container.add_column([ Viewer(width=50, height=50), Viewer(width=50, height=50), Viewer(width=50, height=50) ]) self.assertEqual(self.container.width, 150 + 2 * self.container.padding) self.assertEqual(self.container.height, 150 + 2 * self.container.padding)
def test_add_widget(self): self.container.add(Viewer(width=50, height=50)) self.assertEqual(self.manager.width, 150 + 2*self.container.padding) self.assertEqual(self.manager.height, 50) self._test_content_position()
def layout(self): Viewer.layout(self) self._field.update(self.x, self.y, self.width, self.height) x, y, width, height = self._field.get_content_region() if self.is_focus(): self._text_layout.begin_update() self._text_layout.x = self.x + self._padding self._text_layout.y = self.y - self._padding self._text_layout.end_update() else: # Adjust the text for font's descent descent = self._document.get_font().descent self._label.begin_update() self._label.x = self.x + self._padding self._label.y = self.y + self._padding - descent self._label.width = width - self._padding * 2 self._label.end_update()
def __init__(self, on_press=None,width=0,height=0,hover=None,argument=None,outline=None,disabled=False,arguments=None,texture=None,hoveringType=None,path=None): TwoStateController.__init__(self, is_pressed=False, on_press=on_press) Viewer.__init__(self,width=width,height=height) self.disabled=disabled self._width=width self._height=height self._outlineGraphic=None self._button = None self.hover=hover self._path=path self.leaderGraphic=None self.arg=argument self.args=arguments self._outline=outline self._painting=None self._textureZ=texture self.pressing=False self.hovering=False self.hoveringType = hoveringType self.paintingLoaded=False
def __init__(self, label="", on_press=None,width=0,height=0,font_size=None,argument=None,outline=None,font_color=None,texture=None,font=None,font_valign=VALIGN_CENTER,leader=None): TwoStateController.__init__(self, is_pressed=False, on_press=on_press) Viewer.__init__(self,width=width,height=height) self._width=width self._height=height self.label = label self._outlineGraphic=None self._label = None self._button = None self._fn=font self._path = ['button'] self._leader=leader self.leaderGraphic=None self.font_size=font_size self.arg=argument self._outline=outline self._fl=font_color self._textureZ=texture self._fontvalign=font_valign
def __init__(self, text="", length=20, max_length=None, font=None, padding=0, on_input=None, width=None, height=None, font_size=None, font_color=None, multiline=False): Viewer.__init__(self) FocusMixin.__init__(self) self._document = pyglet.text.document.UnformattedDocument(text) self._document_style_set = False # check if style of document was set. self._length = length # the length of the box in characters self._max_length = max_length # the max length allowed for writing. self._on_input = on_input self.focused = False self._padding = 4 + padding # graphics loaded in both states self._field = None self.w1 = width self.h1 = height self._fs = font_size # graphics loaded in state "writing" self._text_layout = None self._caret = None self._font = font self._font_color = font_color # graphics loaded in state "label" self._label = None self.ml = multiline self._caret_height = 0
def setUp(self): TestPygletGUI.setUp(self) self.widgets = [] for i in range(2): self.widgets.append(Viewer(width=100, height=50)) for i in range(2): self.widgets.append(Viewer(width=20, height=50)) self.container = VerticalContainer([ HorizontalContainer([self.widgets[0], self.widgets[1]], padding=0), HorizontalContainer([ Spacer(), self.widgets[2], Spacer(), self.widgets[3], Spacer() ], padding=0) ], padding=0) self.manager = Manager(self.container, window=self.window, batch=self.batch, theme=self.theme)
def test_substitute_widget(self): """ Tests substitution of manager's content by other widget. """ self.new_widget = Viewer(width=60, height=50) self.manager.content = self.new_widget self.assertTrue(not self.widget.has_manager()) self.assertFalse(self.widget.is_loaded) self.assertTrue(self.new_widget.has_manager()) self.assertTrue(self.new_widget.is_loaded) # manager size was reset, new widget position is correct self.assertEqual(self.manager.width, self.new_widget.width) self.assertEqual(self.new_widget.x, self.window.width/2 - self.new_widget.width/2)
def __init__(self): Viewer.__init__(self) Controller.__init__(self) self._highlight = None self._highlight_flag = False
def __init__(self): Controller.__init__(self) Viewer.__init__(self) self._focus = None self._focus_flag = False
def delete(self): ContinuousStateController.delete(self) Viewer.delete(self)
def set_manager(self, manager): Viewer.set_manager(self, manager) for item in self._content: item.set_manager(self._manager) item.parent = self
def delete(self): FocusMixin.delete(self) Viewer.delete(self)
def delete(self): for item in self._content: item.delete() self._content = [] Viewer.delete(self)
def __init__(self, path, is_expandable=False): Viewer.__init__(self) self._path = path self._expandable = is_expandable self._graphic = None self._min_width = self._min_height = 0
def test_substitute_element(self): self.container.set(1, 1, Viewer(width=100, height=50)) self.assertEqual(self.container.width, 150 + self.container.padding) self.assertEqual(self.container.height, 100 + self.container.padding)
def __init__(self, min_width=0, min_height=0): Viewer.__init__(self) self._min_width, self._min_height = min_width, min_height
def setUp(self): super(TestDialog, self).setUp() self.widget = Viewer(width=50, height=50) self.manager = Manager(self.widget, window=self.window, batch=self.batch, theme=self.theme)
def delete(self): Viewer.delete(self) FocusMixin.delete(self)
class TestDialog(TestPygletGUI): """ This test case tests basic functionality of widget+manager. We use an empty widget for this. """ def setUp(self): super(TestDialog, self).setUp() self.widget = Viewer(width=50, height=50) self.manager = Manager(self.widget, window=self.window, batch=self.batch, theme=self.theme) def test_top_down_draw(self): """ Tests that the manager's size was set according to the child size. """ # manager size is correct self.assertEqual(self.manager.width, 50) self.assertEqual(self.manager.height, 50) # widget is centered in the window self.assertEqual(self.widget.x, self.window.width/2 - self.widget.width/2) self.assertEqual(self.widget.y, self.window.height/2 - self.widget.height/2) def test_bottom_up_draw(self): """ Tests that the manager's size is modified if we set a new size to the widget. """ self.widget.width = 60 self.widget.parent.reset_size() # manager size was reset self.assertEqual(self.manager.width, self.widget.width) # widget and manager were re-centered in the window self.assertEqual(self.widget.x, self.window.width/2 - self.widget.width/2) self.assertEqual(self.manager.x, self.window.width/2 - self.manager.width/2) def test_substitute_widget(self): """ Tests substitution of manager's content by other widget. """ self.new_widget = Viewer(width=60, height=50) self.manager.content = self.new_widget self.assertTrue(not self.widget.has_manager()) self.assertFalse(self.widget.is_loaded) self.assertTrue(self.new_widget.has_manager()) self.assertTrue(self.new_widget.is_loaded) # manager size was reset, new widget position is correct self.assertEqual(self.manager.width, self.new_widget.width) self.assertEqual(self.new_widget.x, self.window.width/2 - self.new_widget.width/2) def test_window_resize(self): self.window.width = 100 self.manager.on_resize(self.window.width, self.window.height) # manager size didn't changed. self.assertEqual(self.manager.width, 50) # manager is still centered. self.assertEqual(self.manager.x, self.window.width/2 - self.manager.width/2) def test_change_offset(self): self.manager.offset = (10, 0) # manager is centered with an offset. self.assertEqual(self.manager.x - 10, self.window.width/2 - self.manager.width/2) def test_change_anchor(self): self.manager.anchor = pyglet_gui.constants.ANCHOR_TOP_LEFT # manager is in correct position. self.assertEqual(self.manager.x, 0) def test_new_manager_is_on_top(self): other_manager = Manager(Viewer(width=50, height=50), window=self.window, batch=self.batch, theme=self.theme) # confirm that a new manager starts always on top self.assertTrue(other_manager.root_group.is_on_top()) def test_new_manager_without_window(self): other_manager = Manager(Viewer(width=50, height=50), batch=self.batch, theme=self.theme) # confirm that a new manager without window starts # with no size self.assertTrue(other_manager.width, 0) # change the manager's window other_manager.window = self.window # confirm it has a size. self.assertEqual(self.manager.width, 50) # confirm it is in the correct position self.assertEqual(self.manager.x, self.window.width/2 - self.manager.width/2) def test_deletion(self): self.manager.delete() # confirm that widget is also deleted self.assertTrue(not self.widget.has_manager()) def tearDown(self): self.manager.delete() super(TestDialog, self).tearDown()
def delete(self): Controller.delete(self) Viewer.delete(self)
def delete(self): TwoStateController.delete(self) Viewer.delete(self)