示例#1
0
 def __init__(self, app, **kwargs):
     StencilView.__init__(self, **kwargs)
     self.app = app
     self.xx = 0
     self.scale = 1.0
     self.size_hint = (None, None)
     self.cursor_pos = (0, 0)
     self.fbo_size = DEFAULT_IMAGE_SIZE
     self.fbo = None
     self.fbo_rect = None
     self.tool_fbo = None
     self.tool_fbo_rect = None
     self.bg_rect = None
     self.rect = None
     self.fbo_clear_color = (1, 1, 1, 1)
     self.layer_undo_stack = []
     self.undo_layer_index = 0
     self.layer_rect = []
     self.fbo_create_on_canvas()
     self.touches = []
     self.move_image = False
     self.active_layer = None
     self.tool_buffer_enabled = True
     self.px = None
     self.py = None
     self.grid_texture = None
     self.active_layer_last_texture = None
示例#2
0
 def __init__(self,
              position=(0, 0, 0),
              heading=(0, 0, 0),
              meshes=(),
              fov=100,
              **keywords):
     """ 
     """
     StencilView.__init__(self, **keywords)
     CameraLogic.__init__(self, position, heading, meshes, fov)
示例#3
0
class SlideFrameParent(MpfWidget, FloatLayout):
    def __init__(self, mc, config, slide_frame):
        self.mc = mc
        self.name = slide_frame.name
        self.config = config
        self.slide_frame = slide_frame

        self.ready = False
        self.size_hint = (None, None)
        super().__init__(mc=mc, key=None, config=config)
        self.size = slide_frame.native_size

        self.stencil = StencilView(size_hint=(None, None), size=self.size)
        self.stencil.config = dict()
        self.stencil.config['z'] = 0
        super().add_widget(self.stencil)
        self.add_widget(slide_frame)

    def __repr__(self):
        return '<SlideFrameParent name={}, parent={}>'.format(
            self.name, self.parent)

    def on_pos(self, *args):

        # if this is the initial positioning, calculate it from the config
        # otherwise just update the slide frame and stencil

        if not self.slide_frame.pos:
            self.pos = set_position(self.parent.width, self.parent.height,
                                    self.width, self.height,
                                    self.slide_frame.config['x'],
                                    self.slide_frame.config['y'],
                                    self.slide_frame.config['anchor_x'],
                                    self.slide_frame.config['anchor_y'])

        self.stencil.pos = self.pos
        self.slide_frame.pos = self.pos

    def add_widget(self, widget, **kwargs):
        del kwargs

        widget.pos = set_position(self.width, self.height, widget.width,
                                  widget.height)

        self.stencil.add_widget(widget,
                                bisect_left(self.stencil.children, widget))

    def prepare_for_removal(self):
        """Remove slide frame from targets."""
        super().prepare_for_removal()
        self.mc.targets[self.name].prepare_for_removal()
        del self.mc.targets[self.name]
示例#4
0
文件: dmd.py 项目: vgrillot/mpf-mc
    def __init__(self, mc, config, key=None, **kwargs):
        super().__init__(mc=mc, config=config, key=key)

        self.source = self.mc.displays[self.config['source_display']]

        stencil = StencilView(size_hint=(None, None),
                              size=(self.source.config['width'],
                                    self.source.config['height']))

        # Add the effects to make this look like a DMD
        effect_list = list()

        if 'luminosity' in self.config:
            effect_list.append(Monochrome(r=self.config['luminosity'][0],
                                          g=self.config['luminosity'][1],
                                          b=self.config['luminosity'][2]))

        if self.config['shades']:
            effect_list.append(Reduce(shades=self.config['shades']))

        if self.config['pixel_color']:
            effect_list.append(Colorize(r=self.config['pixel_color'][0],
                                        g=self.config['pixel_color'][1],
                                        b=self.config['pixel_color'][2]))

        if self.config['gain'] != 1.0:
            effect_list.append(Gain(gain=self.config['gain']))

        effect = EffectWidget()
        effect.effects = effect_list

        stencil.add_widget(effect)

        self.add_widget(stencil)

        try:
            effect.add_widget(self.source)
        except WidgetException:
            self.source.parent = None
            effect.add_widget(self.source)

        effect.size = (self.config['width'], self.config['height'])

        effect.texture.mag_filter = 'nearest'
        effect.texture.min_filter = 'nearest'

        self.scale = min(self.width / self.source.width,
                         self.height / self.source.height)

        self.pos = (0, 0)
示例#5
0
 def illumniate_key(self, touch):
     # define a short name for the touch-specific and unique UserDictionary "ud"
     ud = touch.ud
     
     # bind all touch coordinates to real keyboard dimensions
     bounded_x = self.bind_x_on_keyboard(touch.x)
     bounded_y = self.bind_y_on_keyboard(touch.y)
     
     # TODO: port the whole calculation into "calculate_key"
     # find out on which x position to put the key
     x_to_keyboard = bounded_x - self.x;
     y_to_keyboard = bounded_y - self.y;
     keynumber_absolute = int(x_to_keyboard / self.key_width);
     keyposition_to_keyboard = keynumber_absolute * self.key_width;
     keyposition_absolute_x = keyposition_to_keyboard + self.x;
     keyposition_absolute_y = y_to_keyboard + self.y - 500;
     
     # create a stencilView with the dimension of one key
     stencil = StencilView(
         size=(self.key_width-2, self.height-2),
         pos=(keyposition_absolute_x+1, self.y+1))
     
     # first, add an image called "universal key" which is just a white image. This can be made more or less bright (changes with the y-position of the finger)
     stencil.add_widget(Image(
         color=(1, 1, 1, UNIVERSAL_KEY_IMAGE_TRANSPARENCY_MIN + (y_to_keyboard / self.height) * (UNIVERSAL_KEY_IMAGE_TRANSPARENCY_MAX - UNIVERSAL_KEY_IMAGE_TRANSPARENCY_MIN)),
         source=UNIVERSAL_KEY_IMAGE,
         allow_stretch=True,
         size=(100, 500),
         pos=(keyposition_absolute_x, self.y)))
     
     # then, add an image called "key image" which is basically a huge blob in a rectangle shape. It changes his position with the y-position of the finger
     stencil.add_widget(Image(
         color=KEY_IMAGE_COLOR,
         source=self.parent.app.config.get('Advanced', 'KeyImage'),
         allow_stretch=True,
         size=(100, 1000),
         pos=(keyposition_absolute_x-25, keyposition_absolute_y)))
     
     # if the user dictionary key 'keys' wasn't created yet, create it now.
     if not 'keys' in ud:
         ud['keys'] = [Widget()]
     
     # then add the key to the list of this touch AND to the keybaord widget
     ud['keys'].append(stencil)
     self.add_widget(stencil)
     
     # workaround for having the blob image IN FRONT of the key images
     self.remove_widget(ud['blob'])
     self.add_widget(ud['blob'])
示例#6
0
    def __init__(self, **kwargs):
        super(Graph, self).__init__(**kwargs)

        self._mesh = Mesh(mode='lines')
        self._mesh_rect = Mesh(mode='line_strip')
        val = 0.25
        self.canvas.add(Color(1 * val, 1 * val, 1 * val))
        self.canvas.add(self._mesh)
        self.canvas.add(Color(1, 1, 1))
        self.canvas.add(self._mesh_rect)
        mesh = self._mesh_rect
        mesh.vertices = [0] * (5 * 4)
        mesh.indices = [k for k in xrange(5)]

        self._plot_area = StencilView()
        self.add_widget(self._plot_area)

        self._trigger = Clock.create_trigger(self._redraw_all)
        self._trigger_size = Clock.create_trigger(self._redraw_size)

        self.bind(center=self._trigger_size, padding=self._trigger_size,
                  font_size=self._trigger_size, plots=self._trigger_size,
                  x_grid=self._trigger_size, y_grid=self._trigger_size,
                  draw_border=self._trigger_size)
        self.bind(xmin=self._trigger, xmax=self._trigger,
                  xlog=self._trigger, x_ticks_major=self._trigger,
                  x_ticks_minor=self._trigger,
                  xlabel=self._trigger, x_grid_label=self._trigger,
                  ymin=self._trigger, ymax=self._trigger,
                  ylog=self._trigger, y_ticks_major=self._trigger,
                  y_ticks_minor=self._trigger,
                  ylabel=self._trigger, y_grid_label=self._trigger)
        self._trigger()
 def handle_clip_rectangle(self, gc, x, y):
     '''It checks whether the point (x,y) collides with any already
        existent stencil. If so it returns the index position of the
        stencil it collides with. if the new clip rectangle bounds are
        None it draws in the canvas otherwise it finds the correspondent
        stencil or creates a new one for the new graphics instructions.
        The point x,y is given in matplotlib coordinates.
     '''
     x = self.widget.x + x
     y = self.widget.y + y
     collides = self.collides_with_existent_stencil(x, y)
     if collides > -1:
         return collides
     new_bounds = gc.get_clip_rectangle()
     if new_bounds:
         x = self.widget.x + int(new_bounds.bounds[0])
         y = self.widget.y + int(new_bounds.bounds[1])
         w = int(new_bounds.bounds[2])
         h = int(new_bounds.bounds[3])
         collides = self.collides_with_existent_stencil(x, y)
         if collides == -1:
             cliparea = StencilView(pos=(x, y), size=(w, h))
             self.clip_rectangles.append(cliparea)
             self.widget.add_widget(cliparea)
             return len(self.clip_rectangles) - 1
         else:
             return collides
     else:
         return -2
示例#8
0
    def __init__(self, mc, config, slide_frame):
        self.mc = mc
        self.name = slide_frame.name
        self.config = config
        self.slide_frame = slide_frame

        self.ready = False
        self.size_hint = (None, None)
        super().__init__(mc=mc, key=None, config=config)
        self.size = slide_frame.native_size

        self.stencil = StencilView(size_hint=(None, None), size=self.size)
        self.stencil.config = dict()
        self.stencil.config['z'] = 0
        super().add_widget(self.stencil)
        self.add_widget(slide_frame)
示例#9
0
文件: tab.py 项目: Modeful/poc
class Tab(TabbedPanelHeader):

    def __init__(self, file=None, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.view = StencilView()
        self.view.background_color = (255, 0, 0, .5)
        self.view.size = Window.size

        self.file = file
        self.text = os.path.basename(file.name)[:-len('.mdfl')] 

        if file:
            self.diagram = Diagram(file.model)
            self.diagram.size = Window.size
            self.view.add_widget(self.diagram)
            self.content = self.view
示例#10
0
    def __init__(self, **kwargs):
        super(Graph, self).__init__(**kwargs)

        with self.canvas:
            self._fbo = Fbo(size=self.size,
                            with_stencilbuffer=self._with_stencilbuffer)

        with self._fbo:
            self._background_color = Color(*self.background_color)
            self._background_rect = Rectangle(size=self.size)
            self._mesh_ticks_color = Color(*self.tick_color)
            self._mesh_ticks = Mesh(mode='lines')
            self._mesh_rect_color = Color(*self.border_color)
            self._mesh_rect = Mesh(mode='line_strip')

        with self.canvas:
            Color(1, 1, 1)
            self._fbo_rect = Rectangle(size=self.size,
                                       texture=self._fbo.texture)

        mesh = self._mesh_rect
        mesh.vertices = [0] * (5 * 4)
        mesh.indices = range(5)

        self._plot_area = StencilView()
        self.add_widget(self._plot_area)

        t = self._trigger = Clock.create_trigger(self._redraw_all)
        ts = self._trigger_size = Clock.create_trigger(self._redraw_size)
        tc = self._trigger_color = Clock.create_trigger(self._update_colors)

        self.bind(center=ts,
                  padding=ts,
                  precision=ts,
                  plots=ts,
                  x_grid=ts,
                  y_grid=ts,
                  draw_border=ts)
        self.bind(xmin=t,
                  xmax=t,
                  xlog=t,
                  x_ticks_major=t,
                  x_ticks_minor=t,
                  xlabel=t,
                  x_grid_label=t,
                  ymin=t,
                  ymax=t,
                  ylog=t,
                  y_ticks_major=t,
                  y_ticks_minor=t,
                  ylabel=t,
                  y_grid_label=t,
                  font_size=t,
                  label_options=t,
                  x_ticks_angle=t)
        self.bind(tick_color=tc, background_color=tc, border_color=tc)
        self._trigger()
示例#11
0
文件: tile.py 项目: TimSC/kivmap
	def __init__(self, **args):
		StencilView.__init__(self, **args)

		self.objs = []
		self.tileNum = (None, None)
		self.tileZoom = None
		self.randomBackgroundColour = False

		with self.canvas:
			if self.randomBackgroundColour:
				Color(random.random(), random.random(), random.random())
				self.objs.append(Rectangle(pos=(0., 0), size=(self.width, self.height)))
			#Color(0, 0.7, 0)
			#self.objs.append(Ellipse(pos=(0., 0), size=self.size))
			#Color(0, 0, 0.4)
			self.label = Label(pos=(0., 0), text="test")
			self.objs.append(self.label)

		self.bind(pos=self.update_graphics_pos,
			size=self.update_graphics_size)
示例#12
0
    def illumniate_key(self, touch):
        # define a short name for the touch-specific and unique UserDictionary "ud"
        ud = touch.ud

        # bind all touch coordinates to real keyboard dimensions
        bounded_x = self.bind_x_on_keyboard(touch.x)
        bounded_y = self.bind_y_on_keyboard(touch.y)

        # TODO: port the whole calculation into "calculate_key"
        # find out on which x position to put the key
        x_to_keyboard = bounded_x - self.x
        y_to_keyboard = bounded_y - self.y
        keynumber_absolute = int(x_to_keyboard / self.key_width)
        keyposition_to_keyboard = keynumber_absolute * self.key_width
        keyposition_absolute_x = keyposition_to_keyboard + self.x
        keyposition_absolute_y = y_to_keyboard + self.y - 500

        # create a stencilView with the dimension of one key
        stencil = StencilView(size=(self.key_width - 2, self.height - 2),
                              pos=(keyposition_absolute_x + 1, self.y + 1))

        # first, add an image called "universal key" which is just a white image. This can be made more or less bright (changes with the y-position of the finger)
        stencil.add_widget(
            Image(color=(1, 1, 1, UNIVERSAL_KEY_IMAGE_TRANSPARENCY_MIN +
                         (y_to_keyboard / self.height) *
                         (UNIVERSAL_KEY_IMAGE_TRANSPARENCY_MAX -
                          UNIVERSAL_KEY_IMAGE_TRANSPARENCY_MIN)),
                  source=UNIVERSAL_KEY_IMAGE,
                  allow_stretch=True,
                  size=(100, 500),
                  pos=(keyposition_absolute_x, self.y)))

        # then, add an image called "key image" which is basically a huge blob in a rectangle shape. It changes his position with the y-position of the finger
        stencil.add_widget(
            Image(color=KEY_IMAGE_COLOR,
                  source=self.parent.app.config.get('Advanced', 'KeyImage'),
                  allow_stretch=True,
                  size=(100, 1000),
                  pos=(keyposition_absolute_x - 25, keyposition_absolute_y)))

        # if the user dictionary key 'keys' wasn't created yet, create it now.
        if not 'keys' in ud:
            ud['keys'] = [Widget()]

        # then add the key to the list of this touch AND to the keybaord widget
        ud['keys'].append(stencil)
        self.add_widget(stencil)

        # workaround for having the blob image IN FRONT of the key images
        self.remove_widget(ud['blob'])
        self.add_widget(ud['blob'])
示例#13
0
    def __init__(self, **kwargs):
        super(Graph, self).__init__(**kwargs)

        with self.canvas:
            self._background_color = Color(*self.background_color)
            self._background_rect = Rectangle(size=self.size)
            self._plot_area = StencilView()
            self._mesh_ticks_color = Color(*self.tick_color)
            self._mesh_ticks = Mesh(mode='lines')
            self._frame_color = Color(*self.border_color)
            self._frame = Line(rectangle=(self.x, self.y, self.width,
                                          self.height),
                               width=1)

        t = self._trigger = Clock.create_trigger(self._redraw_all)
        ts = self._trigger_size = Clock.create_trigger(self._redraw_size)
        tc = self._trigger_color = Clock.create_trigger(self._update_colors)

        self.bind(center=ts,
                  padding=ts,
                  precision=ts,
                  plots=ts,
                  x_grid=ts,
                  y_grid=ts,
                  draw_border=ts)
        self.bind(xmin=t,
                  xmax=t,
                  xlog=t,
                  x_ticks_major=t,
                  x_ticks_minor=t,
                  xlabel=t,
                  x_grid_label=t,
                  ymin=t,
                  ymax=t,
                  ylog=t,
                  y_ticks_major=t,
                  y_ticks_minor=t,
                  ylabel=t,
                  y_grid_label=t,
                  font_size=t,
                  label_options=t)
        self.bind(tick_color=tc, background_color=tc, border_color=tc)
        self._trigger()
示例#14
0
文件: slide.py 项目: vgrillot/mpf-mc
class Slide(Screen):
    next_id = 0

    @classmethod
    def get_id(cls):
        Slide.next_id += 1
        return Slide.next_id

    # pylint: disable-msg=too-many-arguments
    def __init__(self, mc, name, config=None, target='default', key=None,
                 priority=0, play_kwargs=None):

        # config is a dict. widgets will be in a key
        # assumes config, if present, is validated.

        self.creation_order = Slide.get_id()

        if not name:
            name = 'Anon_{}'.format(self.creation_order)

        self.mc = mc
        self.name = name
        self.priority = priority
        self.pending_widgets = set()
        self.key = key

        if not config:
            config = self.mc.config_validator.validate_config('slides', dict())

        self.transition_out = config.get('transition_out', None)
        self.expire = config.get('expire', None)

        target = mc.targets[target]

        self.size_hint = (None, None)
        super().__init__()
        self.size = target.native_size
        self.orig_w, self.orig_h = self.size

        self.stencil = StencilView(size_hint=(None, None),
                                   size=self.size)
        self.stencil.config = dict()
        self.stencil.config['z'] = 0
        super().add_widget(self.stencil)

        if 'widgets' in config:  # don't want try, swallows too much

            widgets = create_widget_objects_from_config(
                mc=self.mc,
                config=config['widgets'], key=self.key,
                play_kwargs=play_kwargs)

            self.add_widgets(widgets)

        self.mc.active_slides[name] = self
        target.add_widget(self)
        self.mc.slides[name] = config

        bg = config.get('background_color', [0.0, 0.0, 0.0, 1.0])
        if bg != [0.0, 0.0, 0.0, 0.0]:
            with self.canvas.before:
                Color(*bg)
                Rectangle(size=self.size, pos=(0, 0))

        self.opacity = config.get('opacity', 1.0)

        self.mc.post_mc_native_event(
            'slide_{}_created'.format(self.name))

        """event: slide_(name)_created

        desc: A slide called (name) has just been created.

        This means that this slide now exists, but it's not necessarily the
        active (showing) slide, depending on the priorities of the other slides
        and/or what else is going on.

        This is useful for things like the widget_player where you want to
        target a widget for a specific slide, but you can only do so if
        that slide exists.

        Slide names do not take into account what display or slide frame
        they're playing on, so be sure to create machine-wide unique names
        when you're naming your slides.

        """

    def __repr__(self):
        return '<Slide name={}, priority={}, id={}>'.format(self.name,
            self.priority, self.creation_order)

    def add_widgets_from_library(self, name, key=None, widget_settings=None, play_kwargs=None,
                                 **kwargs):
        if name not in self.mc.widgets:
            raise ValueError("Widget %s not found", name)

        return self.add_widgets_from_config(config=self.mc.widgets[name],
                                            key=key,
                                            widget_settings=widget_settings,
                                            play_kwargs=play_kwargs)

    def add_widgets_from_config(self, config, key=None, play_kwargs=None,
                                widget_settings=None):

        if not isinstance(config, list):
            config = [config]
        widgets_added = list()

        if not play_kwargs:
            play_kwargs = dict()  # todo

        for widget in config:

            if widget_settings:
                widget_settings = self.mc.config_validator.validate_config(
                    'widgets:{}'.format(widget['type']), widget_settings,
                    base_spec='widgets:common', add_missing_keys=False)

                widget.update(widget_settings)

            configured_key = widget.get('key', None)

            if (configured_key and key and "." not in key and
                    configured_key != key):
                raise KeyError("Widget has incoming key '{}' which does not "
                               "match the key in the widget's config "
                               "'{}'.".format(key, configured_key))

            if configured_key:
                this_key = configured_key
            else:
                this_key = key

            widget_obj = self.mc.widgets.type_map[widget['type']](
                mc=self.mc, config=widget, slide=self, key=this_key, play_kwargs=play_kwargs)

            top_widget = widget_obj

            # some widgets (like slide frames) have parents, so we need to make
            # sure that we add the parent widget to the slide
            while top_widget.parent:
                top_widget = top_widget.parent

            self.add_widget(top_widget)

            widget_obj.pos = set_position(self.width,
                                          self.height,
                                          widget_obj.width,
                                          widget_obj.height,
                                          widget_obj.config['x'],
                                          widget_obj.config['y'],
                                          widget_obj.config['anchor_x'],
                                          widget_obj.config['anchor_y'],
                                          widget_obj.config['adjust_top'],
                                          widget_obj.config['adjust_right'],
                                          widget_obj.config['adjust_bottom'],
                                          widget_obj.config['adjust_left'])
            widgets_added.append(widget_obj)

        return widgets_added

    def add_widgets(self, widgets):
        for w in widgets:
            self.add_widget(w)

    def add_widget(self, widget, **kwargs):
        """Adds a widget to this slide.

        Args:
            widget: An MPF-enhanced widget (which will include details like z
                order and removal keys.)

        This method respects the z-order of the widget it's adding and inserts
        it into the proper position in the widget tree. Higher numbered z order
        values will be inserted after (so they draw on top) of existing ones.

        If the new widget has the same priority of existing widgets, the new
        one is inserted after the widgets of that priority, meaning the newest
        widget will be displayed on top of existing ones with the same
        priority.

        """
        del kwargs

        if widget.config['z'] < 0:
            self.add_widget_to_parent_frame(widget)
            return

        self.stencil.add_widget(widget, bisect(self.stencil.children, widget))

        widget.pos = set_position(self.size[0],
                                  self.size[1],
                                  widget.width,
                                  widget.height,
                                  widget.config['x'],
                                  widget.config['y'],
                                  widget.config['anchor_x'],
                                  widget.config['anchor_y'],
                                  widget.config['adjust_top'],
                                  widget.config['adjust_right'],
                                  widget.config['adjust_bottom'],
                                  widget.config['adjust_left'])

    def remove_widgets_by_key(self, key):
        for widget in self.get_widgets_by_key(key):
            self.stencil.remove_widget(widget)

    def get_widgets_by_key(self, key):
        return [x for x in self.stencil.children if x.key == key]

    def remove_widget(self, widget):
        self.stencil.remove_widget(widget)

    def add_widget_to_parent_frame(self, widget):
        """Adds this widget to this slide's parent frame instead of to this
        slide.

        Args:
            widget:
                The widget object.

        Widgets added to the parent slide_frame stay active and visible even
        if the slide in the frame changes.

        """
        self.manager.parent.parent.add_widget(widget)

    def schedule_removal(self, secs):
        self.mc.clock.schedule_once(self.remove, secs)

    def remove(self, dt=None):
        del dt

        try:
            self.manager.remove_slide(slide=self,
                                      transition_config=self.transition_out)

        except AttributeError:
            # looks like slide was already removed, but let's clean it up just
            # in case

            self.prepare_for_removal()
            self.mc.active_slides.pop(self.name, None)

    def prepare_for_removal(self):
        self.mc.clock.unschedule(self.remove)

        for widget in self.stencil.children:
            if hasattr(widget, 'prepare_for_removal'):  # try swallows too much
                widget.prepare_for_removal()

        self.mc.post_mc_native_event('slide_{}_removed'.format(self.name))

        """event: slide_(name)_removed

        desc: A slide called (name) has just been removed.

        This event is posted whenever a slide is removed, regardless of
        whether or not that slide was active (showing).

        Note that even though this event is called "removed", it's actually
        posted as part of the removal process. (e.g. there are still some
        clean-up things that happen afterwards.)

        Slide names do not take into account what display or slide frame
        they're playing on, so be sure to create machine-wide unique names
        when you're naming your slides.

        """

    def on_pre_enter(self, *args):
        del args
        for widget in self.stencil.children:
            widget.on_pre_show_slide()

    def on_enter(self, *args):
        del args
        for widget in self.stencil.children:
            widget.on_show_slide()

    def on_pre_leave(self, *args):
        del args
        for widget in self.stencil.children:
            widget.on_pre_slide_leave()

    def on_leave(self, *args):
        del args
        for widget in self.stencil.children:
            widget.on_slide_leave()

    def on_slide_play(self):
        for widget in self.stencil.children:
            widget.on_slide_play()
示例#15
0
文件: blackCockpit.py 项目: dddist/pd
    def __init__(self, **kwargs):
        super(Dashboard, self).__init__(**kwargs)

        # Background
        self.background_image = Image(source='bg.png')
        self.add_widget(self.background_image)

        # RPM
        self.rpm = Gauge(file_gauge="gauge512.png",
                         do_rotation=False,
                         do_scale=False,
                         do_translation=False,
                         value=0,
                         size_gauge=512,
                         pos=(72, -16))
        self.add_widget(self.rpm)
        self.rpm.value = 1

        # Speedometer
        self.speedometer = Label(text='0',
                                 font_size=80,
                                 font_name='hemi_head_bd_it.ttf',
                                 pos=(274, 194))
        self.rpm.add_widget(self.speedometer)

        # BOTTOM BAR
        self.bottom_bar = Image(source='bottomBar.png', pos=(0, -209))
        self.add_widget(self.bottom_bar)

        # KM LEFT
        self.km_left_label = Label(text='000',
                                   font_name='Avenir.ttc',
                                   halign="right",
                                   text_size=self.size,
                                   font_size=32,
                                   pos=(260, 234))
        self.add_widget(self.km_left_label)

        # CLOCK
        self.clock = Label(text='00:00',
                           font_name='Avenir.ttc',
                           halign="right",
                           text_size=self.size,
                           font_size=32,
                           pos=(-130, -180))
        self.add_widget(self.clock)

        # OUTDOOR TEMPERATURE
        self.outdoor_temperature_label = Label(text='00.0',
                                               font_name='Avenir.ttc',
                                               halign="right",
                                               text_size=self.size,
                                               font_size=32,
                                               pos=(95, -180))
        self.add_widget(self.outdoor_temperature_label)
        self.unitC = Label(text='°C',
                           font_name='Avenir.ttc',
                           halign="left",
                           text_size=self.size,
                           font_size=24,
                           pos=(200, -172))
        self.add_widget(self.unitC)

        # OIL TEMPERATURE
        self.oil_label = Label(text='00',
                               font_name='Avenir.ttc',
                               halign="right",
                               text_size=self.size,
                               font_size=27,
                               pos=(-390, -180))
        self.add_widget(self.oil_label)

        # DISTANCE
        self.distance_label = Label(text='000000',
                                    font_name='Avenir.ttc',
                                    halign="right",
                                    text_size=self.size,
                                    font_size=27,
                                    pos=(305, -180))
        self.add_widget(self.distance_label)

        # FUEL CONSUMPTION
        self.fuel_consumption_label = Label(text='00.0',
                                            font_name='Avenir.ttc',
                                            halign="right",
                                            text_size=self.size,
                                            font_size=32,
                                            pos=(-290, 234))
        self.add_widget(self.fuel_consumption_label)

        # COOLANT TEMPERATURE
        self.coolant_bar = StencilView(size_hint=(None, None),
                                       size=(94, 256),
                                       pos=(15, 112))
        self.coolant_image = Image(source='coolantScaleFull.png',
                                   size=(94, 256),
                                   pos=(15, 112))
        self.coolant_bar.add_widget(self.coolant_image)
        self.add_widget(self.coolant_bar)
        self.coolant_bar.height = 0

        # FUEL LEFT
        self.fuel_bar = StencilView(size_hint=(None, None),
                                    size=(94, 256),
                                    pos=(686, 112))
        self.fuel_image = Image(source='fuelScaleFull.png',
                                size=(94, 256),
                                pos=(686, 112))
        self.fuel_bar.add_widget(self.fuel_image)
        self.add_widget(self.fuel_bar)
        self.fuel_bar.height = 0

        # CAR DOORS
        self.car = Car(pos=(257, 84))
        self.add_widget(self.car)
        self.minimize_car()
示例#16
0
文件: slide.py 项目: vgrillot/mpf-mc
    def __init__(self, mc, name, config=None, target='default', key=None,
                 priority=0, play_kwargs=None):

        # config is a dict. widgets will be in a key
        # assumes config, if present, is validated.

        self.creation_order = Slide.get_id()

        if not name:
            name = 'Anon_{}'.format(self.creation_order)

        self.mc = mc
        self.name = name
        self.priority = priority
        self.pending_widgets = set()
        self.key = key

        if not config:
            config = self.mc.config_validator.validate_config('slides', dict())

        self.transition_out = config.get('transition_out', None)
        self.expire = config.get('expire', None)

        target = mc.targets[target]

        self.size_hint = (None, None)
        super().__init__()
        self.size = target.native_size
        self.orig_w, self.orig_h = self.size

        self.stencil = StencilView(size_hint=(None, None),
                                   size=self.size)
        self.stencil.config = dict()
        self.stencil.config['z'] = 0
        super().add_widget(self.stencil)

        if 'widgets' in config:  # don't want try, swallows too much

            widgets = create_widget_objects_from_config(
                mc=self.mc,
                config=config['widgets'], key=self.key,
                play_kwargs=play_kwargs)

            self.add_widgets(widgets)

        self.mc.active_slides[name] = self
        target.add_widget(self)
        self.mc.slides[name] = config

        bg = config.get('background_color', [0.0, 0.0, 0.0, 1.0])
        if bg != [0.0, 0.0, 0.0, 0.0]:
            with self.canvas.before:
                Color(*bg)
                Rectangle(size=self.size, pos=(0, 0))

        self.opacity = config.get('opacity', 1.0)

        self.mc.post_mc_native_event(
            'slide_{}_created'.format(self.name))

        """event: slide_(name)_created
示例#17
0
class Dashboard(FloatLayout):
    def __init__(self, **kwargs):
        super(Dashboard, self).__init__(**kwargs)

        # Background
        self.backgroundImage = Image(source='bg.png')
        self.add_widget(self.backgroundImage)

        # RPM
        self.rpm = Gauge(file_gauge="gauge512.png",
                         do_rotation=False,
                         do_scale=False,
                         do_translation=False,
                         value=0,
                         size_gauge=512,
                         pos=(72, -16))
        self.add_widget(self.rpm)
        self.rpm.value = 1

        # Bottom Bar
        self.bottomBar = Image(source='bottomBar.png', pos=(0, -209))
        self.add_widget(self.bottomBar)

        # Speedometer
        self.speedometer = Label(text='0',
                                 font_size=80,
                                 font_name='hemi_head_bd_it.ttf',
                                 pos=(0, 0))
        self.add_widget(self.speedometer)

        # KM LEFT
        self.kmLeftLabel = Label(text='000',
                                 font_name='Avenir.ttc',
                                 halign="right",
                                 text_size=self.size,
                                 font_size=32,
                                 pos=(260, 234))
        self.add_widget(self.kmLeftLabel)

        # CLOCK
        self.clock = Label(text='00:00',
                           font_name='Avenir.ttc',
                           halign="right",
                           text_size=self.size,
                           font_size=32,
                           pos=(-130, -180))
        self.add_widget(self.clock)

        # OUTDOOR TEMPERATURE
        self.outDoorTemperatureLabel = Label(text='00.0',
                                             font_name='Avenir.ttc',
                                             halign="right",
                                             text_size=self.size,
                                             font_size=32,
                                             pos=(95, -180))
        self.add_widget(self.outDoorTemperatureLabel)
        self.unitC = Label(text='°C',
                           font_name='Avenir.ttc',
                           halign="left",
                           text_size=self.size,
                           font_size=24,
                           pos=(200, -172))
        self.add_widget(self.unitC)

        # OIL TEMPERATURE
        self.oilLabel = Label(text='00',
                              font_name='Avenir.ttc',
                              halign="right",
                              text_size=self.size,
                              font_size=27,
                              pos=(-390, -180))
        self.add_widget(self.oilLabel)

        # DISTANCE
        self.distanceLabel = Label(text='000000',
                                   font_name='Avenir.ttc',
                                   halign="right",
                                   text_size=self.size,
                                   font_size=27,
                                   pos=(305, -180))
        self.add_widget(self.distanceLabel)

        # FUEL CONSUMPTION
        self.fuelConsLabel = Label(text='00.0',
                                   font_name='Avenir.ttc',
                                   halign="right",
                                   text_size=self.size,
                                   font_size=32,
                                   pos=(-285, 234))
        self.add_widget(self.fuelConsLabel)

        # COOLANT TEMPERATURE
        self.coolantBar = StencilView(size_hint=(None, None),
                                      size=(94, 256),
                                      pos=(15, 112))
        self.coolantImage = Image(source='coolantScaleFull.png',
                                  size=(94, 256),
                                  pos=(15, 112))
        self.coolantBar.add_widget(self.coolantImage)
        self.add_widget(self.coolantBar)
        self.coolantBar.height = 160

        # FUEL LEFT
        self.fuelBar = StencilView(size_hint=(None, None),
                                   size=(94, 256),
                                   pos=(686, 112))
        self.fuelImage = Image(source='fuelScaleFull.png',
                               size=(94, 256),
                               pos=(686, 112))
        self.fuelBar.add_widget(self.fuelImage)
        self.add_widget(self.fuelBar)
        self.fuelBar.height = 220

        # CAR DOORS
        self.car = Car(pos=(257, 84))
        self.add_widget(self.car)
        self.minimizeCar()

    def minimizeCar(self, *args):
        anim = Animation(scale=0.5, opacity=0, t='linear', duration=0.5)
        anim.start(self.car)

        animRpm = Animation(scale=1, opacity=1, t='linear', duration=0.5)
        animRpm.start(self.rpm)

    def maximizeCar(self, *args):
        anim = Animation(scale=1, opacity=1, t='linear', duration=0.5)
        anim.start(self.car)

        animRpm = Animation(scale=0.5, opacity=0, t='linear', duration=0.5)
        animRpm.start(self.rpm)