Esempio n. 1
0
class OccRevol(OccDependentShape, ProxyRevol):

    #: Update the class reference
    reference = set_default('https://dev.opencascade.org/doc/refman/html/'
                            'class_b_rep_prim_a_p_i___make_wedge.html')

    def update_shape(self, change=None):
        d = self.declaration

        if d.shape:
            shape = coerce_shape(d.shape)
            copy = True
        else:
            shape = self.get_shape().shape
            copy = False

        #: Build arguments
        args = [shape, gp_Ax1(d.position.proxy, d.direction.proxy)]
        if d.angle:
            args.append(d.angle)
        args.append(copy)
        revol = BRepPrimAPI_MakeRevol(*args)
        self.shape = revol.Shape()

    def get_shape(self):
        """ Get the first child shape """
        for child in self.children():
            if isinstance(child, OccShape):
                return child

    def set_shape(self, shape):
        self.update_shape()

    def set_angle(self, angle):
        self.update_shape()

    def set_copy(self, copy):
        self.update_shape()

    def set_direction(self, direction):
        self.update_shape()
Esempio n. 2
0
def test_set_default():
    """Test changing the default value of a member."""
    class Default1(Atom):
        i = Int()
        i2 = Int()

    sd = set_default(1)

    class Default2(Default1):
        i = sd
        i2 = sd

    # By setting the same default twice we should get a clone
    assert Default1.i is not Default2.i
    assert Default1().i == 0
    assert Default2().i == 1

    with pytest.raises(TypeError):

        class Check(Atom):
            a = set_default(1)
Esempio n. 3
0
class OccVertex(OccShape, ProxyVertex):
    #: Update the class reference
    reference = set_default('https://dev.opencascade.org/doc/refman/html/'
                            'class_b_rep_builder_a_p_i___make_vertex.html')

    #: A reference to the toolkit shape created by the proxy.
    shape = Typed(TopoDS_Vertex)

    def create_shape(self):
        d = self.declaration
        v = BRepBuilderAPI_MakeVertex(gp_Pnt(d.x, d.y, d.z))
        self.shape = v.Vertex()

    def set_x(self, x):
        self.create_shape()

    def set_y(self, y):
        self.create_shape()

    def set_z(self, z):
        self.create_shape()
Esempio n. 4
0
class OccWedge(OccShape, ProxyWedge):

    reference = set_default('https://dev.opencascade.org/doc/refman/html/'
                            'class_b_rep_prim_a_p_i___make_wedge.html')

    def create_shape(self):
        d = self.declaration
        self.shape = BRepPrimAPI_MakeWedge(coerce_axis(d.axis), d.dx, d.dy,
                                           d.dz, d.itx)

    def set_dx(self, dx):
        self.create_shape()

    def set_dy(self, dy):
        self.create_shape()

    def set_dz(self, dz):
        self.create_shape()

    def set_itx(self, itx):
        self.create_shape()
Esempio n. 5
0
class PSAGetSpectrumTask(InstrumentTask):
    """ Get the trace that is displayed right now

    """    
    database_entries = set_default({'sweep_data': {}})

    def perform(self):
        if not self.driver:
            self.start_driver()
            
        tr_data = self.get_trace()
        self.write_in_database('sweep_data',tr_data)
        
    def get_trace(self):
        """ Get the trace that is displayed right now (no new acquisition)

        """
        data = self.driver.read_raw_data((1,1))
        data_x = self.driver.get_x_data((1,1))
        aux = [data_x,data]
        return np.rec.fromarrays(aux,names=['Freq (GHz)','Spectrum'])
Esempio n. 6
0
class OccBSpline(OccLine, ProxyBSpline):
    #: Update the class reference
    reference = set_default('https://dev.opencascade.org/doc/refman/html/'
                            'class_geom___b_spline_curve.html')

    curve = Typed(Geom_BSplineCurve)

    def create_shape(self):
        d = self.declaration
        if not d.points:
            raise ValueError("Must have at least two points")
        # Poles and weights
        points = self.get_transformed_points()
        pts = TColgp_Array1OfPnt(1, len(points))
        set_value = pts.SetValue

        # TODO: Support weights
        for i, p in enumerate(points):
            set_value(i + 1, p)
        curve = self.curve = GeomAPI_PointsToBSpline(pts).Curve()
        self.shape = self.make_edge(curve)
Esempio n. 7
0
class AndroidPagerTitleStrip(AndroidViewGroup, ProxyPagerTitleStrip):
    """An Android implementation of an Enaml ProxyPagerTitleStrip."""

    #: A reference to the widget created by the proxy.
    widget = Typed(PagerTitleStrip)

    default_layout = set_default(  # type: ignore
        {
            "width": "match_parent",
            "height": "wrap_content",
            "gravity": "top"
        })

    # -------------------------------------------------------------------------
    # Initialization API
    # -------------------------------------------------------------------------
    def create_widget(self):
        """Create the underlying widget."""
        self.widget = PagerTitleStrip(self.get_context())

    def init_layout(self):
        # Make sure the layout always exists
        if not self.layout_params:
            self.set_layout({})
        super().init_layout()

    # -------------------------------------------------------------------------
    # ProxyPagerTitleStrip API
    # -------------------------------------------------------------------------
    def set_inactive_alpha(self, alpha):
        self.widget.setNonPrimaryAlpha(alpha)

    def set_text_color(self, color):
        self.widget.setTextColor(color)

    def set_text_size(self, size):
        self.widget.setTextSize(PagerTitleStrip.COMPLEX_UNIT_SP, size)

    def set_text_spacing(self, spacing):
        self.widget.setTextSpacing(spacing)
Esempio n. 8
0
class OccRevol(OccDependentShape, ProxyRevol):

    #: Update the class reference
    reference = set_default('https://dev.opencascade.org/doc/refman/html/'
                            'class_b_rep_prim_a_p_i___make_wedge.html')

    def update_shape(self, change):
        d = self.declaration

        c = d.shape if d.shape else self.get_shape()

        #: Build arguments
        args = [
            c.shape.Shape(),
            gp_Ax1(gp_Pnt(*d.position), gp_Dir(*d.direction))
        ]
        if d.angle:
            args.append(d.angle)
        args.append(d.copy)

        self.shape = BRepPrimAPI_MakeRevol(*args)

    def get_shape(self):
        """ Get the first child shape """
        for child in self.children():
            if isinstance(child, OccShape):
                return child

    def set_shape(self, shape):
        self.update_shape({})

    def set_angle(self, angle):
        self.update_shape({})

    def set_copy(self, copy):
        self.update_shape({})

    def set_direction(self, direction):
        self.update_shape({})
class AndroidLinearLayout(AndroidViewGroup, ProxyLinearLayout):
    """ An Android implementation of an Enaml ProxyLinearLayout.

    """
    #: A reference to the widget created by the proxy.
    widget = Typed(LinearLayout)

    layout_param_type = set_default(LinearLayoutLayoutParams)

    # -------------------------------------------------------------------------
    # Initialization API
    # -------------------------------------------------------------------------
    def create_widget(self):
        """ Create the underlying widget.

        """
        self.widget = LinearLayout(self.get_context())

    def init_widget(self):
        """ Initialize the underlying widget.

        """
        super(AndroidLinearLayout, self).init_widget()
        d = self.declaration
        self.set_orientation(d.orientation)
        if d.gravity:
            self.set_gravity(d.gravity)

    # -------------------------------------------------------------------------
    # ProxyLinearLayout API
    # -------------------------------------------------------------------------
    def set_orientation(self, orientation):
        """ Set the text in the widget.

        """
        self.widget.setOrientation(0 if orientation == 'horizontal' else 1)

    def set_gravity(self, gravity):
        self.widget.setGravity(gravity)
Esempio n. 10
0
class EditText(TextView):
    """A simple control for displaying read-only text."""

    #: Text selection
    selection = d_(Tuple(int))

    #: Make editable by default
    input_type = set_default("text")

    #: Placeholder text
    placeholder = d_(Str())

    #: Style (iOS)
    style = d_(Enum("", "line", "bezel", "rounded_rect"))

    #: A reference to the ProxyLabel object.
    proxy = Typed(ProxyEditText)

    @observe("selection", "placeholder", "style")
    def _update_proxy(self, change):

        super()._update_proxy(change)
Esempio n. 11
0
class RecylerView(ViewGroup):
    __nativeclass__ = set_default('%s.RecyclerView' % package)
    invalidate = JavaMethod()
    setHasFixedSize = JavaMethod('boolean')
    scrollTo = JavaMethod('int', 'int')
    scrollToPosition = JavaMethod('int')
    setItemViewCacheSize = JavaMethod('int')
    setAdapter = JavaMethod('%s.RecyclerView$Adapter' % package)
    setHasFixedSize = JavaMethod('boolean')
    setLayoutManager = JavaMethod('%s.RecyclerView$LayoutManager' % package)

    setRecyclerListener = JavaMethod('%s.RecyclerView$RecyclerListener' %
                                     package)

    class LayoutManager(JavaBridgeObject):
        __nativeclass__ = set_default('%s.RecyclerView$LayoutManager' %
                                      package)
        scrollToPosition = JavaMethod('int')
        setItemPrefetchEnabled = JavaMethod('boolean')

        HORIZONTAL = 0
        VERTICAL = 1
Esempio n. 12
0
class OccCone(OccShape, ProxyCone):
    reference = set_default('https://dev.opencascade.org/doc/refman/html/'
                            'class_b_rep_prim_a_p_i___make_cone.html')

    def create_shape(self):
        d = self.declaration
        args = [d.axis, d.radius, d.radius2, d.height]
        if d.angle:
            args.append(d.angle)
        self.shape = BRepPrimAPI_MakeCone(*args)

    def set_radius(self, r):
        self.create_shape()

    def set_radius2(self, r):
        self.create_shape()

    def set_height(self, height):
        self.create_shape()

    def set_angle(self, a):
        self.create_shape()
Esempio n. 13
0
class JavaBridgeObject(BridgeObject):
    """ A proxy to a class in java. This sends the commands over
    the bridge for execution.  The object is stored in a map
    with the given id and is valid until this object is deleted.
    
    Parameters
    ----------
    __id__: Int
        If an __id__ keyward argument is passed during creation,
        this will assume the object was already created and
        only a reference to the object with the given id is needed.

    """
    #: Java Class name
    __nativeclass__ = set_default('java.lang.Object')

    #: A callback with an implementation built in
    hashCode = JavaCallback(returns="int")

    def _impl_hashCode(self):
        #: Add a default callback for hashCode
        return self.__id__
class DrawerLayout(ViewGroup):
    __nativeclass__ = set_default('%s.DrawerLayout' % package)
    openDrawer = JavaMethod('android.view.View')
    closeDrawer = JavaMethod('android.view.View')
    addDrawerListener = JavaMethod('%s.DrawerLayout$DrawerListener' % package)
    onDrawerClosed = JavaCallback('android.view.View')
    onDrawerOpened = JavaCallback('android.view.View')
    onDrawerSlide = JavaCallback('android.view.View', 'float')
    onDrawerStateChanged = JavaCallback('int')

    setDrawerElevation = JavaMethod('float')
    setDrawerTitle = JavaMethod('int', 'java.lang.CharSequence')
    setDrawerLockMode = JavaMethod('int')
    setScrimColor = JavaMethod('android.graphics.Color')
    setStatusBarBackgroundColor = JavaMethod('android.graphics.Color')

    LOCK_MODES = {
        'unlocked': 0,
        'locked_closed': 1,
        'locked_open': 2,
        'undefined': 3,
    }
Esempio n. 15
0
class OccFillet(OccOperation, ProxyFillet):
    reference = set_default('https://dev.opencascade.org/doc/refman/html/'
                            'class_b_rep_fillet_a_p_i___make_fillet.html')

    shape_types = Dict(
        default={
            'rational': ChFi3d_Rational,
            'angular': ChFi3d_QuasiAngular,
            'polynomial': ChFi3d_Polynomial
        })

    def update_shape(self, change={}):
        d = self.declaration

        #: Get the shape to apply the fillet to
        children = [c for c in self.children()]
        if not children:
            raise ValueError("Fillet must have a child shape to operate on.")
        child = children[0]
        s = child.shape.Shape()
        shape = BRepFilletAPI_MakeFillet(s)  #,self.shape_types[d.shape])

        edges = d.edges if d.edges else child.topology.edges()
        for edge in edges:
            shape.Add(d.radius, edge)
        #if not shape.HasResult():
        #    raise ValueError("Could not compute fillet,
        # radius possibly too small?")
        self.shape = shape

    def set_shape(self, shape):
        self._queue_update({})

    def set_radius(self, r):
        self._queue_update({})

    def set_edges(self, edges):
        self._queue_update({})
Esempio n. 16
0
class Button(TextView):
    """ A simple control for displaying a button.

    """
    #: Button is clickable by default
    clickable = set_default(True)

    #: Styles
    style = d_(Enum('', 'borderless', 'inset', 'small'))

    #: A reference to the proxy object.
    proxy = Typed(ProxyButton)

    # -------------------------------------------------------------------------
    # Observers
    # -------------------------------------------------------------------------
    @observe('style')
    def _update_proxy(self, change):
        """ An observer which sends the state change to the proxy.

        """
        # The superclass implementation is sufficient.
        super(Button, self)._update_proxy(change)
Esempio n. 17
0
class OccLine(OccEdge, ProxyLine):
    #: Update the class reference
    reference = set_default('https://dev.opencascade.org/doc/refman/html/'
                            'classgp___lin.html')

    curve = Typed(Geom_Line)

    def get_transformed_points(self, points=None):
        d = self.declaration
        t = self.get_transform()
        return [p.proxy.Transformed(t) for p in points or d.points]

    def create_shape(self):
        d = self.declaration
        if len(d.points) == 2:
            curve = GC_MakeLine(*self.get_transformed_points()).Value()
        else:
            curve = GC_MakeLine(d.position.proxy, d.direction.proxy).Value()
        self.curve = curve
        self.shape = self.make_edge(curve)

    def set_points(self, points):
        self.create_shape()
Esempio n. 18
0
class SetDCFunctionTask(InterfaceableTaskMixin, InstrumentTask):
    """Set a DC source function to the specified value: VOLT or CURR

    """
    #: Target value for the source (dynamically evaluated)
    switch = Str('VOLT').tag(pref=True, feval=validators.SkipLoop())

    database_entries = set_default({'function': 'VOLT'})

    def i_perform(self, switch=None):
        """Default interface.

        """
        if switch is None:
            switch = self.format_and_eval_string(self.switch)

        if switch == 'VOLT':
            self.driver.function = 'VOLT'
            self.write_in_database('function', 'VOLT')

        if switch == 'CURR':
            self.driver.function = 'CURR'
            self.write_in_database('function', 'CURR')
Esempio n. 19
0
class UIButton(UIControl):
    """
    """
    __signature__ = set_default((dict(buttonWithType="enum"), ))
    #: Properties
    on = ObjcProperty('bool')
    onTintColor = ObjcProperty('UIColor')
    tintColor = ObjcProperty('UIColor')
    thumbTintColor = ObjcProperty('UIColor')
    onImage = ObjcProperty('UIImage')
    offImage = ObjcProperty('UIImage')

    #: Methods
    setTitle = ObjcMethod('NSString', dict(forState='enum'))

    #: Type Enum
    UIButtonTypeCustom = 0
    UIButtonTypeSystem = 1
    UIButtonTypeDetailDisclosure = 2
    UIButtonTypeInfoLight = 3
    UIButtonTypeInfoDark = 4
    UIButtonTypeContactAdd = 5
    UIButtonTypeRoundedRect = UIButtonTypeSystem
Esempio n. 20
0
class UsbManager(SystemService):
    """ Use UsbManger.get().then(on_ready) to get an instance.
    
    """
    SERVICE_TYPE = Context.USB_SERVICE
    __nativeclass__ = set_default('android.hardware.usb.UsbManager')

    getAccessoryList = JavaMethod(returns='android.hardware.usb.UsbAccessory[')
    getDeviceList = JavaMethod(returns='java.util.HashMap')
    openAccessory = JavaMethod('android.hardware.usb.UsbAccessory',
                               returns='android.os.ParcelFileDescriptor')
    openDevice = JavaMethod('android.hardware.usb.UsbDevice',
                            returns='android.hardware.usb.UsbDeviceConnection')
    hasPermission = JavaMethod('android.hardware.usb.UsbDevice',
                               returns='boolean')
    requestPermission = JavaMethod('android.hardware.usb.UsbDevice',
                                   'android.app.PendingIntent')

    #: These names are changed to support both signatures
    hasPermission_ = JavaMethod('android.hardware.usb.UsbAccessory',
                                returns='boolean')
    requestPermission_ = JavaMethod('android.hardware.usb.UsbAccessory',
                                    'android.app.PendingIntent')
Esempio n. 21
0
class PagerTitleStrip(ViewGroup):
    #: Top by default
    gravity = set_default("top")

    #: Set the alpha value used for non-primary page titles.
    inactive_alpha = d_(Float())

    # Set the color value used as the base color for all displayed page titles.
    text_color = d_(Str())

    #: Set the default text size to a given unit and value. Forced to DP
    text_size = d_(Int())

    #: Spacing pixels
    text_spacing = d_(Int())

    # -------------------------------------------------------------------------
    # Observers
    # -------------------------------------------------------------------------
    @observe("text_color", "text_size", "text_spacing")
    def _update_proxy(self, change):

        super()._update_proxy(change)
Esempio n. 22
0
class SetDCOutputTask(InterfaceableTaskMixin, InstrumentTask):
    """Set a DC source output to the specified value: ON or OFF

    """
    #: Target value for the source output
    switch = Unicode('OFF').tag(pref=True, feval=validators.SkipLoop())

    database_entries = set_default({'output': 'OFF'})

    def i_perform(self, switch=None):
        """Default interface.

        """
        if switch is None:
            switch = self.format_and_eval_string(self.switch)

        if switch == 'ON':
            self.driver.output = 'ON'
            self.write_in_database('output', 'ON')

        if switch == 'OFF':
            self.driver.output = 'OFF'
            self.write_in_database('output', 'OFF')
Esempio n. 23
0
class SleepTask(SimpleTask):
    """Simply sleeps for the specified amount of time.

    Wait for any parallel operation before execution by default.

    """
    #: Time during which to sleep.
    time = Float().tag(pref=True)

    wait = set_default({'activated': True})  # Wait on all pools by default.

    def perform(self):
        """ Sleep.

        """
        sleep(self.time)

    def check(self, *args, **kwargs):
        if self.time < 0:
            return False, {self.task_path + '/' + self.task_name:
                           'Sleep time must be positive.'}

        return True, {}
Esempio n. 24
0
class Button(TextView):
    """ A simple control for displaying a button.

    """
    #: Button is clickable by default
    clickable = set_default(True)

    #: Use a flat style
    flat = d_(Bool())

    #: A reference to the proxy object.
    proxy = Typed(ProxyButton)

    # -------------------------------------------------------------------------
    # Observers
    # -------------------------------------------------------------------------
    @observe('flat')
    def _update_proxy(self, change):
        """ An observer which sends the state change to the proxy.

        """
        # The superclass implementation is sufficient.
        super(Button, self)._update_proxy(change)
Esempio n. 25
0
class DummyMonitor(BaseMonitor):
    """Dummy monitor used for testing.

    """
    running = Bool()

    monitored_entries = set_default(['default_path'])

    received_news = List()

    def start(self):
        self.running = True

    def stop(self):
        self.running = False

    def refresh_monitored_entries(self, entries=None):
        """Do nothing when refreshing.

        """
        pass

    def handle_database_entries_change(self, news):
        """Add all entries to the monitored ones.

        """
        if news[0] == 'added':
            self.monitored_entries = self.monitored_entries + [news[1]]

    def handle_database_nodes_change(self, news):
        """Simply ignore nodes updates.

        """
        pass

    def process_news(self, news):
        self.received_news.append(news)
Esempio n. 26
0
class OccThickSolid(OccOffset, ProxyThickSolid):
    reference = set_default('https://dev.opencascade.org/doc/refman/html/'
                            'class_b_rep_offset_a_p_i___make_thick_solid.html')
    
    def get_faces(self, shape):
        d = self.declaration
        if d.closing_faces:
            return d.closing_faces
        for face in shape.topology.faces():
            return [face]
    
    def update_shape(self, change=None):

        d = self.declaration
        
        #: Get the shape to apply the fillet to
        s = self.get_shape()
        
        faces = TopTools_ListOfShape()
        for f in self.get_faces(s):
            faces.Append(f)
        if faces.IsEmpty():
            return
        
        self.shape = BRepOffsetAPI_MakeThickSolid(
            s.shape.Shape(),
            faces,
            d.offset,
            d.tolerance,
            self.offset_modes[d.offset_mode],
            d.intersection,
            False,
            self.join_types[d.join_type]
        )
        
    def set_closing_faces(self, faces):
        self._queue_update({})