def on_mouse_release(self, x, y, button, modifiers): Widget.on_mouse_release(self, x, y, button, modifiers) r = self.clip_rect() for c in self.children: if r.intersect(c.bounds()).hit_test(x, y): c.on_mouse_release(x, y, button, modifiers)
def _update_state(self): ''' Update state. ''' if self._deleted: return Widget._update_state(self) self._label.color = self._style.colors[self._state]
def refresh(self): """ Redraw border for EditBox and command an underlying window refresh. """ if self.__border: rectangle(self.window, self.y-1, self.x-1, self.y+1, self.x+self.cols) Widget.refresh(self)
def __init__(self, cfg): Widget.__init__(self, cfg) self.toggle_state = True self.cache_type = "dynamic" self.colour = None self.colours = {"default": cfg['globals']['colours']['default']} self.default_colour = None self.size = [0, 0] # Minimum size is c_size * 2 self.img_proto = pygame.image.load("./image/proto.png") self.proto_pos = cfg['globals']['proto_pos']['button'] self.alt_proto_pos = cfg['globals']['proto_pos']['small_button'] self.img_proto.convert_alpha() self.internal_surface = None self.widget_surface = None self.surfaces = {} self.surf_flags = SRCALPHA self.special_flags = BLEND_RGBA_MULT self.strings = {"default": "Default"} self.alterable = True self.c_size = 10 self.alt_c_size = 4 """ STATES """ self.clicked, self.hovered, self.idle = 0, 1, 2 self.held_down = 3
def __init__(self, surface): global root_widget Widget.__init__(self, surface.get_rect()) self.surface = surface root_widget = self widget.root_widget = self self.is_gl = surface.get_flags() & OPENGL != 0 self.idle_handlers = [] self.dont = False self.shiftClicked = 0 self.shiftPlaced = -2 self.ctrlClicked = 0 self.ctrlPlaced = -2 self.altClicked = 0 self.altPlaced = -2 self.shiftAction = None self.altAction = None self.ctrlAction = None self.editor = None self.selectTool = None self.movementMath = [-1, 1, 1, -1, 1, -1] self.movementNum = [0, 0, 2, 2, 1, 1] self.notMove = [False, False, False, False, False, False] self.usedKeys = [False, False, False, False, False, False] self.cameraMath = [-1., 1., -1., 1.] self.cameraNum = [0, 0, 1, 1] self.notMoveCamera = [False, False, False, False] self.usedCameraKeys = [False, False, False, False]
def __init__(self, **kwargs): '''Create a slider control Keyword arguments: name -- unique widget identifier min -- minimum value max -- maximum value value -- initial value action -- callback to be invoked when the slider is moved continuous -- if true, invoke action on every movement, else invoke action only when the user releases the mouse button ''' Widget.__init__(self, **kwargs) self._min = kwargs.get('min', 0.0) self._max = kwargs.get('max', 1.0) self._value = kwargs.get('value', 0.5) self.shapes['track'] = Rectangle() self.shapes['knob'] = Rectangle() self.action = kwargs.get('action', None) self._continuous = kwargs.get('continuous', True) self._focused = False
def __init__(self, width, upper=None, **kwds): Widget.__init__(self, **kwds) self.set_size_for_text(width) if upper is not None: self.upper = upper self.insertion_point = None self.root = self.get_root()
def __init__(self, id, parent): Widget.__init__(self, id, parent) self._add_widget('histogram_table', HistogramTable) self._add_widget('population_picker', PopulationPicker) self._add_widget('dim_picker', Select) self._add_widget('negative_values_picker', Select) self._add_widget('apply', ApplyButton)
def setUp(self): ''' 是父类TestCase中定义的函数 在setUp()方法中进行测试前的初始化工作 ''' # print "do something before test.Prepare environment." self.widget = Widget()
def __init__(self, x=0, y=0, z=0, width=300, height=300, anchor_x='left', anchor_y='bottom', elements=[]): fg = (.5,.5,.5, 1) bg = (.5,.5,.5,.5) Widget.__init__(self,x,y,z,width,height,anchor_x,anchor_y) self.margin = 3 self.ropen = 0 length = len(elements) for i in range(length): elements[i].height = height / length - 2 * self.margin elements[i].width = width - 2 * self.margin elements[i].x = self.margin elements[i].y = (height - self.margin) - (i + 2) * (elements[i].height + self.margin) self._elements[i] = elements[i] self._elements[i]._hidden = True chooselabel = Label(text='...', x=self.margin, y= (height - self.margin) - ( elements[i].height + self.margin), height = height / length - 2 * self.margin, width = width - 2 * self.margin) frame = Rectangle (x=chooselabel.x, y=chooselabel.y + chooselabel.height, z=z, width=chooselabel.width, height=-chooselabel.height, radius=0, foreground=fg, background=bg, anchor_x=anchor_x, anchor_y=anchor_y) self._elements['chooselabel'] = chooselabel self._elements['frame'] = frame
def __init__(self, container, x, y, frame_rate, text, size, color, type="normal", fill=True, anchor_type="topleft"): Widget.__init__(self, container, pygame.Rect(x, y, 0, 0), frame_rate) self.type = type self.lines = [] self.font = get_font(size) self.color = color self.parse_lines(text) self.size = size self.fill = fill self.anchor = (container[0] + x, container[1] + y) self.anchor_type = anchor_type if type == "tooltip": self.rect_absolute.bottomleft = (x, y) self.prepare_text_block()
def _move(self, x, y): dx, dy = x - self.x, y - self.y Widget._move(self, x, y) widget = self._label or self._layout if widget: widget.x = widget.x + dx widget.y = widget.y + dy
def setFocusHandler(self,focusHandler): Widget.setFocusHandler(self,focusHandler) if self.mInternalFocusHandler != None: return None for i in self.mWidgets: i.setFocusHandler(focusHandler)
def setInternalFocusHandler(self,focusHandler): Widget.setInternalFocusHandler(self,focusHandler) for i in self.mWidgets: if self.mInternalFocusHandler == None: i.setFocusHandler(self.getFocusHandler()) else: i.setFocusHandler(self.mInternalFocusHandler)
def __init__(self, cfg): Widget.__init__(self, cfg) self.size = [0, 0] self.bg_surface = None self.trace_surface = None self.dirty_traces = True # Positional self.position = 0 self.range = 1000.0 self.zoom_range = (0, 0) # Bg colour self.colour = [0, 0, 0] # Traces dict self.traces = {} # Viewrect self.view_colour = [0, 255, 0] # Parsing check self.currently_parsing = False self.progress = 0
def __init__(self, items, keysColumn=None, buttonsColumn=None, item_spacing=None): self.items = items self.item_spacing = item_spacing self.keysColumn = keysColumn self.buttonsColumn = buttonsColumn Widget.__init__(self) self.buildWidgets()
def update_elements(self): if self._dirty and self.theme: patch = self.theme['button'][('image_down' if self._down else 'image_up')] label = self.elements['label'] font = label.document.get_font() height = font.ascent - font.descent left = 0 if self.halign == 'center': left = self.w / 2 - self._pref_size[0] / 2 elif self.halign == 'right': left = self.w - self._pref_size[0] bottom = 0 if self.valign == 'center': bottom = self.h / 2 - self._pref_size[1] / 2 elif self.valign == 'top': bottom = self.h - self._pref_size[1] label.x = self._gx + left + patch.padding_left label.y = self._gy + bottom + patch.padding_bottom self.shapes['frame'].update( self._gx + left + patch.padding_left, self._gy + bottom + patch.padding_bottom, label.content_width, height) self.active_region = Rect(self._gx + left + patch.padding_left, self._gy + bottom + patch.padding_bottom, label.content_width, height) Widget.update_elements(self)
def load_widget(self, name, x=None, y=None): """ Load a widget with the given name at the specified coordinates (optional). :param name: The name of the widget. :param x: The x-coordinate. :param y: The y-coordinate. :type name: `str` :type x: `int` :type y: `int` """ x, y = int(x), int(y) self.messages.debug("Loading widget '%s'..." % name) # Initialize the widget... widget = Widget(self.available_widgets.get_by_name(name)._path, backref=self) widget.set_position(x, y) # Add the widget to the list of currently active widgets: self.widgets.add(widget, x, y) widget.show()
def get_content(my, request_type): web = WebContainer.get_web() # NOTE: is this needed anymore? if request_type in ["upload", "dynamic_file"]: print "DEPRECATED: dynamic file in app_server.py" widget = Widget() page = my.get_page_widget() widget.add(page) return widget # find hash of url my.custom_url = None if my.hash: hash = "/".join(my.hash) hash = "/%s" % hash from tactic.ui.panel import HashPanelWdg my.custom_url = HashPanelWdg.get_url_from_hash(hash) if my.custom_url: content_type = my.custom_url.get_value("content_type", no_exception=True) # TODO: we may want to handle this differently for content types # other that text/html return my.get_application_wdg()
def on_mouse_drag(self, x, y, dx, dy, button, modifiers): if self._focused: self.label.caret.on_mouse_drag(x, y, dx, dy, button, modifiers) return pyglet.event.EVENT_HANDLED Widget.on_mouse_drag(self, x, y, dx, dy, button, modifiers) return pyglet.event.EVENT_UNHANDLED
def on_mouse_scroll(self, x, y, scroll_x, scroll_y): Widget.on_mouse_scroll(self, x, y, scroll_x, scroll_y) r = self.clip_rect() for c in self.children: if r.intersect(c.bounds()).hit_test(x, y): c.on_mouse_scroll(x, y, scroll_x, scroll_y)
def on_mouse_scroll(self, x, y, scroll_x, scroll_y): if self._focused: self.label.caret.on_mouse_scroll(x, y, scroll_x, scroll_y) return pyglet.event.EVENT_HANDLED Widget.on_mouse_scroll(self, x, y, scroll_x, scroll_y) return pyglet.event.EVENT_UNHANDLED
def setcolor(self, color_pair): """ Set the curses color pair that should be used for drawing to the window. """ Widget.setcolor(self, color_pair) # refresh the data when we change the color self.setdata(self.data)
def on_text(self, text): if self._focused: self.label.caret.on_text(text) return pyglet.event.EVENT_HANDLED Widget.on_text(self, text) return pyglet.event.EVENT_UNHANDLED
def __init__(self, text='Label'): ''' Creates label. ''' self._text = text self._label = cached.Label(text=self._text) Widget.__init__(self) self.style = theme.Label
def on_text_motion(self, motion, select=False): if self._focused: self.label.caret.on_text_motion(motion, select) return pyglet.event.EVENT_HANDLED Widget.on_text_motion(self, motion, select) return pyglet.event.EVENT_UNHANDLED
def __init__(self, rows, row_spacing = 10, column_spacing = 10, **kwds): col_widths = [0] * len(rows[0]) row_heights = [0] * len(rows) for j, row in enumerate(rows): for i, widget in enumerate(row): if widget: col_widths[i] = max(col_widths[i], widget.width) row_heights[j] = max(row_heights[j], widget.height) row_top = 0 for j, row in enumerate(rows): h = row_heights[j] y = row_top + h // 2 col_left = 0 for i, widget in enumerate(row): if widget: w = col_widths[i] x = col_left widget.midleft = (x, y) col_left += w + column_spacing row_top += h + row_spacing width = max(1, col_left - column_spacing) height = max(1, row_top - row_spacing) r = Rect(0, 0, width, height) #print "albow.controls.Grid: r =", r ### #print "...col_widths =", col_widths ### #print "...row_heights =", row_heights ### Widget.__init__(self, r, **kwds) self.add(rows)
def main(argv): app = QApplication(argv) w = Widget() w.show() return app.exec_()
def addSettings(klass, s): '''Construct list of settings.''' Widget.addSettings(s) s.add( setting.Distance( 'leftMargin', '1.7cm', descr=_('Distance from left of graph to edge'), usertext=_('Left margin'), formatting=True) ) s.add( setting.Distance( 'rightMargin', '0.2cm', descr=_('Distance from right of graph to edge'), usertext=_('Right margin'), formatting=True) ) s.add( setting.Distance( 'topMargin', '0.2cm', descr=_('Distance from top of graph to edge'), usertext=_('Top margin'), formatting=True) ) s.add( setting.Distance( 'bottomMargin', '1.7cm', descr=_('Distance from bottom of graph to edge'), usertext=_('Bottom margin'), formatting=True) ) s.add( setting.GraphBrush( 'Background', descr = _('Background plot fill'), usertext=_('Background')), pixmap='settings_bgfill' ) s.add( setting.Line('Border', descr = _('Graph border line'), usertext=_('Border')), pixmap='settings_border')
def setcolor(self, color_pair): """ Set the curses color pair that should be used for drawing to the window. """ Widget.setcolor(self, color_pair) # refresh the data when we change the color Widget.setdata(self, data)
def draw(self, painter): if self.modal_child is None: Widget.draw(self, painter) else: painter.move(self.modal_child.pos) self.modal_child.draw(painter) painter.umove(self.modal_child.pos)
def testSize(self): expectedSize = (40,40) widget = Widget() if widget.getSize() == expectedSize: print "test[Widget}: getSize workds perfect!" else: print "test:Widget] getSize does not work!"
def __init__(self, x=0, y=0, z=0, width=200, height=10, font_size = 10, anchor_x='left', anchor_y='bottom', value=0.50): Widget.__init__(self,x,y,z,width,height,anchor_x,anchor_y) fg = (1,1,1,1) bg = (1,1,1,.5) frame = Rectangle (x=0, y=0, z=z, width=width, height=height, radius=(height-1)/2, foreground=fg, background=bg, anchor_x=anchor_x, anchor_y=anchor_y) cursor = Ellipse (x=0, y=-.5+height/2, z=z, width=height-1, height=height-1, foreground=fg, background=fg, anchor_x='center', anchor_y='center') label = pyglet.text.Label('0', font_name='Monaco', font_size=8, x=0, y=height+2, anchor_x='center', anchor_y='bottom') self._elements['frame'] = frame self._elements['cursor'] = cursor self._elements['label'] = label self.set_cursor(value) self._is_dragging = False
def _move(self, x, y): dx, dy = x-self.x, y-self.y Widget._move(self,x,y) widget = self._label or self._layout if widget: widget.x = widget.x+dx widget.y = widget.y+dy
def _build(self, batch=None, group=None): Widget._build(self, batch) #, group) if self._label: self._label.delete() self._label = None if self._layout: self._layout.delete() self._layout = None if self._caret: self._caret.delete() self._caret = None # Dummy layout creation and deletion seems to make rendering faster doc = pyglet.text.document.UnformattedDocument('dummy') pyglet.text.layout.IncrementalTextLayout(doc, 1, 1, batch=self._batch).delete() if not self._active: self._label = cached.Label(text = self._text, multiline=False, batch=self._batch, group=self._fg_group, anchor_x='left', anchor_y='top') else: doc = pyglet.text.document.UnformattedDocument(self._text or ' ') self._layout = pyglet.text.layout.IncrementalTextLayout( doc, 1, 1, multiline=False, batch=self._batch, group=self._fg_group) self._layout.anchor_x = 'left' self._layout.anchor_y = 'top' self._caret = pyglet.text.caret.Caret(self._layout) self._deleted = False self._update_style() self._update_state() self._update_size()
def __init__(self, rows, row_spacing=10, column_spacing=10, **kwds): col_widths = [0] * len(rows[0]) row_heights = [0] * len(rows) for j, row in enumerate(rows): for i, widget in enumerate(row): if widget: col_widths[i] = max(col_widths[i], widget.width) row_heights[j] = max(row_heights[j], widget.height) row_top = 0 for j, row in enumerate(rows): h = row_heights[j] y = row_top + h // 2 col_left = 0 for i, widget in enumerate(row): if widget: w = col_widths[i] x = col_left widget.midleft = (x, y) col_left += w + column_spacing row_top += h + row_spacing width = max(1, col_left - column_spacing) height = max(1, row_top - row_spacing) r = Rect(0, 0, width, height) #print "albow.controls.Grid: r =", r ### #print "...col_widths =", col_widths ### #print "...row_heights =", row_heights ### Widget.__init__(self, r, **kwds) self.add(rows)
def update_elements(self): if self._dirty and self.theme: patch = self.theme['button'][('image_down' if self._down else 'image_up')] label = self.elements['label'] font = label.document.get_font() height = font.ascent - font.descent left = 0 if self.halign == 'center': left = self.w/2 - self._pref_size[0]/2 elif self.halign == 'right': left = self.w - self._pref_size[0] bottom = 0 if self.valign == 'center': bottom = self.h/2 - self._pref_size[1]/2 elif self.valign == 'top': bottom = self.h - self._pref_size[1] label.x = self._gx + left + patch.padding_left label.y = self._gy + bottom + patch.padding_bottom self.shapes['frame'].update(self._gx + left + patch.padding_left, self._gy + bottom + patch.padding_bottom, label.content_width, height) self.active_region = Rect(self._gx + left + patch.padding_left, self._gy + bottom + patch.padding_bottom, label.content_width, height) Widget.update_elements(self)
def __init__(self, parent, name=None): '''Initialise plotter.''' Widget.__init__(self, parent, name=name) if type(self) == NonOrthFunction: self.readDefaults() self.checker = FunctionChecker()
def __init__(self, surface): global root_widget Widget.__init__(self, surface.get_rect()) self.surface = surface root_widget = self widget.root_widget = self self.is_gl = surface.get_flags() & OPENGL <> 0
def __init__(self, cfg): Widget.__init__(self, cfg) self.size = [0, 0] self.surface = None self.line_col = cfg['globals']['colours']['cha'] self.mode = "line" # line, lines, rectangle are valid self.scale = {"x": 1.0, "y": 1.0} self.offset = {"x": 0.0, "y": 0.0} self.start = {"x": 0, "y": 0} # Pluralities for multiple traces self.offsets = {} self.scales = {} self.line_cols = {} self.sources = {} self.slots = {"colour": False, "offset": False, "order": []} self.slots['colours'] = [[255, 255, 0], [0, 255, 0], [255, 0, 0], [0, 0, 255], [255, 0, 255], [0, 255, 255], [255, 255, 255], [128, 128, 255]] self.alpha = 255 self.markers = {}
def __init__(self, image_checked, image_unchecked, position=(0, 0), checked=0, callbacks=None): """Initializes the widget. Loads the icons from the passed filenamea.""" # firts call superclass constructor Widget.__init__(self, position, callbacks) # load the icons self.checked = image_checked self.unchecked = image_unchecked # store the default state self.state = checked # set the surface too, so that isInside() has something to check self.surface = self.checked # set our internal callbacks so that we can trap changes self.internal = {widget.MOUSEBUTTONUP: self.toggle} # set the original background to none, is used in the paint method self.original_background = None
def __init__(self, text='Label'): ''' Creates label. ''' self._text = text self._label = cached.Label(text = self._text) Widget.__init__(self) self.style = theme.Label
def __init__(self, client=None, responses=None, default=0, cancel=-1, **kwds): Widget.__init__(self, **kwds) if client or responses: rows = [] w1 = 0 w2 = 0 if client: rows.append(client) w1 = client.width if responses: buttons = Row([ Button(text, action=lambda t=text: self.dismiss(t)) for text in responses]) rows.append(buttons) w2 = buttons.width if w1 < w2: a = 'l' else: a = 'r' contents = Column(rows, align=a) m = self.margin contents.topleft = (m, m) self.add(contents) self.shrink_wrap() if responses and default is not None: self.enter_response = responses[default] if responses and cancel is not None: self.cancel_response = responses[cancel]
def update_layout(self): Widget.update_layout(self) if self.theme: patch = self.theme['text_input']['image'] self.elements['layout'].x = patch.padding_left self.elements['layout'].width = self.w - patch.padding_left - patch.padding_right