legoEv3/ev3dev2/__pycache__/display.cpython-35.pyc




[_6@sddlZejdkr'edddlZddlZddlZddlZddlmZm    Z    ddl
mZddl
mZm
Z
dd    lmZejeZyddlZWn(ek
reje
d
dYnXGdd
d
eZGdddeZdS)Nz"Must be using Python 3.4 or higher)Image    ImageDraw)fonts)get_current_platformlibrary_load_warning_message)packfcntlDisplayc@seZdZdZdZdZdZdZd    ZGd
dde    j
ZGdd
d
e    j
ZdddZ
ddZedddZeddZeddZeddZeddZdS)FbMemzThe framebuffer memory object.

    Made of:
        - the framebuffer file descriptor
        - the fix screen info struct
        - the var screen info struct
        - the mapped memory
    fidfix_infovar_infommapiFiFrrc@seZdZdZdejdfdejfdejfdejfdejfdejfd    ejfd
ejfdejfdejfd
ejfdejfdejfdejdfgZ    dS)zFbMem.FixScreenInfoz The fb_fix_screeninfo from fb.h.Zid_nameZ
smem_startsmem_lentypeZtype_auxZvisualZxpanstepZypanstepZ    ywrapstepline_lengthZ
mmio_startZmmio_lenZaccelZreservedrN)
__name__
__module____qualname____doc__ctypesZc_charZc_ulongc_uint32Zc_uint16_fields_rr1/usr/lib/python3/dist-packages/ev3dev2/display.py
FixScreenInfoTsrc
@seZdZGdddejZdejfdejfdejfdejfdejfdejfd    ejfd
ejfdefdefd
efdefgZdS)zFbMem.VarScreenInfoc@s@eZdZdZdejfdejfdejfgZdS)zFbMem.VarScreenInfo.FbBitFieldz!The fb_bitfield struct from fb.h.offsetZlengthZ    msb_rightN)rrrrrrrrrrr
FbBitFieldksr!xresyresZxres_virtualZyres_virtualZxoffsetZyoffsetbits_per_pixelZ    grayscaleZredZgreenZblueZtranspN)rrrr    Structurer!rrrrrr
VarScreenInfois
            r&NcCsatj|}tj|}tj||}||_||_tj||_||_dS)z+Create the FbMem framebuffer memory object.N)    r
_open_fbdev
_get_fix_info_map_fb_memoryrr
_get_var_inforr)selffbdevrrZfbmmaprrr__init__s        zFbMem.__init__cCs!|jjtj|jdS)z*Close the FbMem framebuffer memory object.N)rcloser
_close_fbdevr)r+rrr__del__s
z
FbMem.__del__cCs1|ptjdd}tj|tj}|S)zReturn the framebuffer file descriptor.

        Try to use the FRAMEBUFFER
        environment variable if fbdev is not given. Use '/dev/fb0' by
        default.
        ZFRAMEBUFFERz/dev/fb0)osgetenvopenO_RDWR)r,Zdevfbfidrrrr'szFbMem._open_fbdevcCstj|dS)z&Close the framebuffer file descriptor.N)r1r.)r5rrrr/szFbMem._close_fbdevcCs&tj}tj|tj||S)z@Return the fix screen info from the framebuffer file descriptor.)r
rrioctlFBIOGET_FSCREENINFO)r5rrrrr(szFbMem._get_fix_infocCs&tj}tj|tj||S)z@Return the var screen info from the framebuffer file descriptor.)r
r&rr6FBIOGET_VSCREENINFO)r5rrrrr*szFbMem._get_var_infocCs,tj||jtjtjtjBddS)zMap the framebuffer memory.r r)rrZ
MAP_SHAREDZ    PROT_READZ
PROT_WRITE)r5rrrrr)szFbMem._map_fb_memory)rrrr)rrrr    __slots__r8r7ZFB_VISUAL_MONO01ZFB_VISUAL_MONO10rr%rr&r-r0staticmethodr'r/r(r*r)rrrrr
2s     
r
c    @seZdZdZdZdZdZdZdddZdd    Z    e
d
dZe
dd
Ze
ddZ
e
ddZe
ddZddZddZddZddZddddddd Zdddd!d!d"d#d$d%Zdd!d!d&d"d"d'd(Zdddd)d&d"d"d*d+Zdddd"d,d-Zdddd"dd.d/Zdddd"dd0d1Zd2d3ZdS)4rzz
    A convenience wrapper for the FbMem class.
    Provides drawing functions from the python imaging library (PIL).
    
cCstj|t|_|jjdkr4d}nQ|jjdkrOd}n6|jdkry|jjdkryd}ntdtj||j    j
d    |jj|jfd
|_t
j|j|_||_dS)Nr1rRGBev3 Lz
Not supportedr<white)r
r-rplatformrr$    Exceptionrnewrrr#_imgrZDraw_drawdesc)r+rJZim_typerrrr-s
        !     zDisplay.__init__cCs|jS)N)rJ)r+rrr__str__szDisplay.__str__cCs
|jjS)z.
        Horizontal screen resolution
        )rr")r+rrrr"szDisplay.xrescCs
|jjS)z,
        Vertical screen resolution
        )rr#)r+rrrr#szDisplay.yrescCs|j|jfS)z+
        Dimensions of the screen.
        )r"r#)r+rrrshapesz
Display.shapecCs|jS)z
        Returns a handle to PIL.ImageDraw.Draw class associated with the screen.

        Example::

            screen.draw.rectangle((10,10,60,20), fill='black')
        )rI)r+rrrdraws    zDisplay.drawcCs|jS)z
        Returns a handle to PIL.Image class that is backing the screen. This can
        be accessed for blitting images to the screen.

        Example::

            screen.image.paste(picture, (0, 0))
        )rH)r+rrrimages
z
Display.imagecCs#|jjd|jfdddS)z#
        Clears the screen
        rfillrDN)rr)rI    rectanglerL)r+rrrclearsz
Display.clearcCs |d@d>|d@d>B|d?BS)zuConvert red, green, blue components to a 16-bit 565 RGB value. Components
        should be values 0 to 255.
        r<rr)r+rgbrrr    _color565szDisplay._color565cs9fddjjD}tdt||S)Ncs.g|]$\}}}j|||qSr)rW).0rTrUrV)r+rr
<listcomp>s    z0Display._img_to_rgb565_bytes.<locals>.<listcomp>H)rHZgetdatar
len)r+Zpixelsr)r+r_img_to_rgb565_bytess"zDisplay._img_to_rgb565_bytescCs|jjdkrC|jjdd}||jdt|<n|jjdkrq|j|jdd<n[|jdkr|jjdkr|jjdjdd    |jdd<nt    d
dS)z
        Applies pending changes to the screen.
        Nothing will be drawn on the screen until this function is called.
        rrawz1;RNrrArBr@ZXRGBz
Not supported)
rr$rHtobytesrr[r\rEZconvertrF)r+rVrrrupdate"s!.zDisplay.updateTrNcCss|r|jtj|}|dk    rV|dk    rV|jj|||||fS|jj|||fSdS)N)rQrr3rHZpaste)r+filenameclear_screenx1y1x2y2Zfilename_imrrrimage_filename1s
zDisplay.image_filename2ZblackrcCs8|r|j|jj||||fd|d|S)z7
        Draw a line from (x1, y1) to (x2, y2)
        rOwidth)rQrMline)r+rarbrcrdreZ
line_colorrhrrrri=s
zDisplay.line(cCs`|r|j||}||}||}    ||}
|jj|||    |
fd|d|S)z>
        Draw a circle of 'radius' centered at (x, y)
        rOoutline)rQrMZellipse)r+raxyZradius
fill_color
outline_colorrbrcrdrerrrcircleGs




zDisplay.circlePcCs8|r|j|jj||||fd|d|S)zZ
        Draw a rectangle 'width x height' where the top left corner is at (x, y)
        rOrk)rQrMrP)r+rarlrmrhZheightrnrorrrrPVs
zDisplay.rectanglecCs,|r|j|jj||fd|S)z/
        Draw a single pixel at (x, y)
        rO)rQrMpoint)r+rarlrmZpoint_colorrrrrr`s
z
Display.pointcCs|r|j|dk    rl|tjks>td||jj||f|d|dtj|S|jj||f|d|SdS)a
        Display `text` starting at pixel (x, y).

        The EV3 display is 178x128 pixels
        - (0, 0) would be the top left corner of the display
        - (89, 64) would be right in the middle of the display

        'text_color' : PIL says it supports "common HTML color names". There
        are 140 HTML color names listed here that are supported by all modern
        browsers. This is probably a good list to start with.
        https://www.w3schools.com/colors/colors_names.asp

        'font' : can be any font displayed here
            http://ev3dev-lang.readthedocs.io/projects/python-ev3dev/en/ev3dev-stretch/other.html#bitmap-fonts
        Nz%s is an invalid fontrOfont)rQrZ    availableAssertionErrorrMtextload)r+rurarlrm
text_colorrsrrrtext_pixelsjs
".zDisplay.text_pixelscCsd|kotjkns<tdtjd|fd|koVtjknsxtdtjd|f|j|||tj|tj||S)a
        Display 'text' starting at grid (x, y)

        The EV3 display can be broken down in a grid that is 22 columns wide
        and 12 rows tall. Each column is 8 pixels wide and each row is 10
        pixels tall.

        'text_color' : PIL says it supports "common HTML color names". There
        are 140 HTML color names listed here that are supported by all modern
        browsers. This is probably a good list to start with.
        https://www.w3schools.com/colors/colors_names.asp

        'font' : can be any font displayed here
            http://ev3dev-lang.readthedocs.io/projects/python-ev3dev/en/ev3dev-stretch/other.html#bitmap-fonts
        rz7grid columns must be between 0 and %d, %d was requestedrz4grid rows must be between 0 and %d, %d was requested)rGRID_COLUMNSrt    GRID_ROWSrxGRID_COLUMN_PIXELSGRID_ROW_PIXELS)r+rurarlrmrwrsrrr    text_grids""

zDisplay.text_gridcCs|j|jdS)N)rQr_)r+rrrreset_screens
zDisplay.reset_screen)rrrrryr{rzr|r-rKpropertyr"r#rLrMrNrQrWr\r_rfrirprPrrrxr}r~rrrrrs0!
!

)rr)sysversion_infoSystemErrorr1rrZloggingZPILrrrrr    Zstructr
Z    getLoggerrlogrImportErrorZwarningobjectr
rrrrr<module>s"