PiStorms  4.015
PiStorms Library Reference by mindsensors.com
 All Classes Namespaces Files Functions Variables
mindsensorsUI.mindsensorsUI Class Reference

mindsensorsUI: this class provides functions for touchscreen LCD on mindsensors.com products for read and write operations. More...

Public Member Functions

def __init__
 Initialize the UI device. More...
 
def dumpTerminal
 Dumps the screen buffer. More...
 
def setMode
 Sets the mode (Experienced users) More...
 
def getMode
 Returns the value of the mode (Experienced users) More...
 
def fillRoundRect
 Draw a rectangle with rounded edges on the screen (rotated to screen) More...
 
def screenXFromImageCoords
 Calculates the x-coordinate of the screen upon rotation (INTERNAL USE ONLY) More...
 
def screenYFromImageCoords
 Calculates the y-coordinate of the screen upon rotation (INTERNAL USE ONLY) More...
 
def TS_To_ImageCoords_X
 Calculates display x-coordinate from touchscreen values, adjusted for rotation (INTERNAL USE ONLY) More...
 
def TS_To_ImageCoords_Y
 Calculates display y-coordinate from touchscreen values, adjusted for rotation (INTERNAL USE ONLY) More...
 
def draw_rotated_text
 Displays rotated text (INTERNAL USE ONLY) More...
 
def screenWidth
 Determines the width of the screen based on rotation (Experienced users) More...
 
def screenHeight
 Determines the height of the screen based on rotation (Experienced users) More...
 
def drawDisplay
 Prints a large title, intended for terminal mode. More...
 
def drawArrows
 Draw forward and back arrows on the screen. More...
 
def checkArrows
 Determine if either on screen arrow button is pressed. More...
 
def hideArrows
 Hide the on screen arrow buttons. More...
 
def showArrows
 Show the on screen arrow buttons. More...
 
def TS_X
 Reads the x-coordinate of the touchscreen press. More...
 
def TS_Y
 Reads the y-coordinate of the touchscreen press. More...
 
def isTouched
 Detects touchscreen presses and prevents false positives, updates self.x and self.y if pressed. More...
 
def clearScreen
 Clears the LCD screen to defualt black. More...
 
def fillRect
 Draw a rectangle on the screen (rotated to screen) More...
 
def fillCircle
 Draw a filled circle on the screen (rotated to screen) More...
 
def drawCircle
 Draw a circle on the screen (rotated to screen) More...
 
def fillBmp
 Draw a bitmap image on the screen (.png files rcommended) More...
 
def fillImgArray
 Draw a image on the screen using supplied image data. More...
 
def rotateRight
 Rotates the screen orientation 90 degrees to the right (-90 degrees) More...
 
def rotateLeft
 Rotates the screen orientation 90 degrees to the left (90 degrees) More...
 
def drawAutoText
 Displays text on the screen with adjusted position and rotation. More...
 
def termGotoLine
 Set the cursor to a specific line of the of the screen. More...
 
def termPrintAt
 Print to a specific line of the screen. More...
 
def termPrint
 Print to the current line of the screen. More...
 
def termPrintln
 Print to the current line and then go to the next line. More...
 
def termReplaceLastLine
 Print new text in place of current line (Low Refresh Rate) More...
 
def refreshLine
 Refresh a screen line. More...
 
def drawButton
 Draw a labeled button on the screen (INTERNAL USE ONLY) More...
 
def refresh
 Refresh the screen (Slow) More...
 
def checkButton
 Determine if an on screen button is pressed. More...
 
def checkDialogButtons
 Determines if button in a pop-up window is pressed (Experienced users) More...
 
def askQuestion
 Display pop-up of a question on the screen. More...
 
def askYesOrNoQuestion
 Display Pop-up of 'Yes' or 'No' question on the screen, returning True or False. More...
 
def showMessage
 Display pop-up of a message on the screen with a single option "OK". More...
 
def forceMessage
 Display pop-up of a message on the screen with no exit options. More...
 
def drawLine
 Draw a line on the screen (rotated to screen) More...
 
def drawPolyLine
 Draw a polyline on the screen (rotated to screen) More...
 

Public Attributes

 comm
 
 currentRotation
 
 myname
 
 terminalBuffer
 
 terminalCursor
 
 currentMode
 
 drawArrowsbool
 
 x
 
 y
 
 popupText
 
 buttonText
 

Static Public Attributes

tuple PS_BLACK = (0,0,0)
 Constant to specify black color.
 
tuple PS_BLUE = (0,0,255)
 Constant to specify blue color.
 
tuple PS_RED = (255,0,0)
 Constant to specify red color.
 
tuple PS_GREEN = (0,255,0)
 Constant to specify green color.
 
tuple PS_CYAN = (0,255,255)
 Constant to specify cyan color.
 
tuple PS_MAGENTA = (255,0,255)
 Constant to specify magenta color.
 
tuple PS_YELLOW = (255,255,0)
 Constant to specify yellow color.
 
tuple PS_WHITE = (255,255,255)
 Constant to specify white color.
 
int PS_SCREENWIDTH = 240
 Constant to defualt screen width.
 
int PS_SCREENHEIGHT = 320
 Constant to defualt screen height.
 

Detailed Description

mindsensorsUI: this class provides functions for touchscreen LCD on mindsensors.com products for read and write operations.

There is no need to initialize this class unless using the LCD screen alone. Normal initialization will be performed automatically when instantiating a PiStorms object.

Constructor & Destructor Documentation

def mindsensorsUI.mindsensorsUI.__init__ (   self,
  name = "PiStorms",
  rotation = 3 
)

Initialize the UI device.

Parameters
selfThe object pointer.
nameThe display title that will appear at the top of the LCD touchscreen. Optional, defaults to "PiStorms" (unused).
rotationThe rotation of the LCD touchscreen. Optional, defaults to 3 (standard rotation).
Remarks
There is no need to use this function directly. To initialize the mindsensorsUI class in your program:
1 from mindsensorsUI import mindsensorsUI
2 ...
3 screen = mindsensorsUI()

Member Function Documentation

def mindsensorsUI.mindsensorsUI.askQuestion (   self,
  question,
  options,
  touch = True,
  goBtn = False,
  wrapText = False 
)

Display pop-up of a question on the screen.

Parameters
selfThe object pointer.
questionThe question that will pop-up on the screen. The first string will be the titlebar.
optionsThe possible answers to the question.
touchWhether to check if the on screen buttons are pressed. Optional, defaults to True.
goBtnWhether to check for the GO button to close the question. Optional, defaults to False.
wrapTextWhen True, long lines of text will be wrapped to fit in the popup. Optional, default to False.
1 question = ["Title", "This is a very long line of text which will be wrapped to fit in the dialog box.", "Here's a second line. It will be wrapped, too. What do you think?"]
2 options = ["No thanks", "Cool!"]
3 answer = screen.askQuestion(question, options, wrapText=True)
Note
If goBtn is True, pressing GO will close the dialog and return -1
Remarks
To use this function in your program:
1 ...
2 question = ["Color Picker", "Pick a color!"]
3 options = ["Red", "Green", "Blue"]
4 answer = screen.askQuestion(question, options)
def mindsensorsUI.mindsensorsUI.askYesOrNoQuestion (   self,
  question,
  touch = True,
  goBtn = False,
  wrapText = False 
)

Display Pop-up of 'Yes' or 'No' question on the screen, returning True or False.

Parameters
selfThe object pointer.
questionThe question that will pop-up on the screen.
touchWhether to check if on screen buttons are pressed. Optional, defaults to True.
goBtnWhether to check for the GO button to close the question. Optional, defaults to False.
wrapTextWhen True, long lines of text will be wrapped to fit in the popup. Optional, default to False.
1 question = ["Title", "This is a very long line of text which will be wrapped to fit in the dialog box.", "Cool?"]
2 response = screen.askYesOrNoQuestion(question, wrapText=True)
Note
If goBtn is True, pressing GO will close the dialog and return False
Remarks
To use this function in your program:
1 ...
2 question = ["Continue?", "Do you want to continue?"]
3 response = screen.askYesOrNoQuestion(question)
def mindsensorsUI.mindsensorsUI.checkArrows (   self)

Determine if either on screen arrow button is pressed.

Parameters
selfThe object pointer.
def mindsensorsUI.mindsensorsUI.checkButton (   self,
  x,
  y,
  width,
  height 
)

Determine if an on screen button is pressed.

Parameters
selfThe object pointer.
xThe upper left x-coordinate of the button.
yThe upper left y-coordinate of the button.
widthThe width of the button.
heightThe height of the button.
Remarks
To use this function in your program:
1 ...
2 button = screen.checkButton(0, 0, 50, 50)
def mindsensorsUI.mindsensorsUI.checkDialogButtons (   self,
  numButts 
)

Determines if button in a pop-up window is pressed (Experienced users)

Parameters
selfThe object pointer.
numButtsHow many buttons are being shown
def mindsensorsUI.mindsensorsUI.clearScreen (   self,
  display = True 
)

Clears the LCD screen to defualt black.

Parameters
selfThe object pointer.
displayChoose to immediately push the drawing to the screen. Optional, defaults to True. To use this function in your program:
1 ...
2 screen.clearScreen()
def mindsensorsUI.mindsensorsUI.draw_rotated_text (   self,
  image,
  text,
  position,
  angle,
  font,
  fill = (255,255,
  display = True 
)

Displays rotated text (INTERNAL USE ONLY)

Parameters
selfThe object pointer.
imageThe image used for creating text
textThe text to display on the screen
positionThe position of the text as a set of x and y-coordinates
angleThe angle at which to rotate the text
fontThe font of the text
fillThe color of the text. Optional, defaults to white.
displayChoose to immediately push the drawing to the screen. Optional, defaults to True.
def mindsensorsUI.mindsensorsUI.drawArrows (   self,
  display = True 
)

Draw forward and back arrows on the screen.

Parameters
selfThe object pointer.
displayChoose to immediately push the drawing to the screen. Optional, defaults to True.
def mindsensorsUI.mindsensorsUI.drawAutoText (   self,
  text,
  x,
  y,
  fill = (255,255,
  size = 20,
  align = "left",
  display = True 
)

Displays text on the screen with adjusted position and rotation.

Parameters
selfThe object pointer.
textThe text to display on the screen
xThe upper left x coordinate of the text. Optional, defaults to "left". Irrelevant if align is "center"
yThe upper left y coordinate of the text.
fillThe color of the text. Optional, defaults to white.
sizeThe pixel size of the text. Optional, defaults to 20.
alignThe text alignment, "left" or "center" or "right". Optional, defaults to "left".
displayChoose to immediately push the drawing to the screen. Optional, defaults to True.
Remarks
To use this function in your program:
1 ...
2 screen.drawAutoText("Wow!", 10, 20, fill = (255,255,255), size = 25)
def mindsensorsUI.mindsensorsUI.drawButton (   self,
  x,
  y,
  width,
  height,
  prefix = "btns_",
  text = "OK",
  display = True,
  align = "left",
  image = None,
  imageX = None,
  imageY = None 
)

Draw a labeled button on the screen (INTERNAL USE ONLY)

Parameters
selfThe object pointer.
xThe upper left x coordinate of the rectangle.
yThe upper left y coordinate of the rectangle.
widthThe width of the button.
heightThe height of the button.
prefixThe button images filename prefix. Optional, defaults to "btns_"
textThe button label. Defaults to "OK"
displayChoose to immediately push the drawing to the screen. Optional, defaults to True.
alignThe alignment for the button's text label.
imageAn optional image to be included on the button, should be 32x32.
imageXThe x-coordinate of the optional image icon.
imageYThe y-coordinate of the optional image icon.
def mindsensorsUI.mindsensorsUI.drawCircle (   self,
  x,
  y,
  radius,
  fill = None,
  outline = (0,0,
  display = True 
)

Draw a circle on the screen (rotated to screen)

Parameters
selfThe object pointer.
xThe center x coordinate of the circle.
yThe center y coordinate of the circle.
radiusThe radius of the circle.
fillThe color of the inside of the circle. Optional, defaults to None
outlineThe color of the outer edge of the circle. Optional, defaults to Black
displayChoose to immediately push the drawing to the screen. Optional, defaults to True.
Remarks
To use this function in your program:
1 ...
2 red circle with blue outline:
3 screen.drawCircle(100, 100, 15, fill = (255,0,0), outline=(0,0,255))
def mindsensorsUI.mindsensorsUI.drawDisplay (   self,
  name,
  display = True 
)

Prints a large title, intended for terminal mode.

Parameters
selfThe object pointer.
nameThe display title that will appear at the top of the LCD touchscreen in cyan.
displayChoose to immediately push the drawing to the screen. Optional, defaults to True.
def mindsensorsUI.mindsensorsUI.drawLine (   self,
  x1,
  y1,
  x2,
  y2,
  width = 0,
  fill = (255,255,
  display = True 
)

Draw a line on the screen (rotated to screen)

Parameters
selfThe object pointer.
x1,y1,x2,y2The x and y coordinates of each endpoint of the line.
widthThe width of the line. Optional, defaults to 0.
fillThe color of line. Optional, defaults to white.
displayChoose to immediately push the drawing to the screen. Optional, defaults to True.
Remarks
To use this function in your program:
1 ...
2 screen.drawLine(50, 50, 100, 100, width = 0, fill = (255,0,0))
def mindsensorsUI.mindsensorsUI.drawPolyLine (   self,
  endpoints,
  width = 0,
  fill = (255,255,
  display = True 
)

Draw a polyline on the screen (rotated to screen)

Parameters
selfThe object pointer.
endpoints[x1, y1, x2, y2...] The x and y coordinates of each endpoint of the polyline.
widthThe width of the polyline. Optional, defaults to 0.
fillThe color of polyline. Optional, defaults to white.
displayChoose to immediately push the drawing to the screen. Optional, defaults to True.
Remarks
To use this function in your program:
1 ...
2 screen.drawLine([50, 50, 100, 50, 100, 100], width = 0, fill = (255,0,0))
def mindsensorsUI.mindsensorsUI.dumpTerminal (   self)

Dumps the screen buffer.

Parameters
selfThe object pointer.
def mindsensorsUI.mindsensorsUI.fillBmp (   self,
  x,
  y,
  width,
  height,
  path = "/usr/local/mindsensors/images/Pane1.png",
  display = True 
)

Draw a bitmap image on the screen (.png files rcommended)

Parameters
selfThe object pointer.
xThe upper left x coordinate of the image.
yThe upper left y coordinate of the image.
widthThe width of the image.
heightThe width of the image.
pathThe image file path. Optional, defaults to the popup background image.
displayChoose to immediately push the drawing to the screen. Optional, defaults to True.
Remarks
To use this function in your program:
1 ...
2 screen.screen.fillBmp(30, 0, 240, 240, path = os.path.join(currentdir, "dog.png"))
def mindsensorsUI.mindsensorsUI.fillCircle (   self,
  x,
  y,
  radius,
  fill = (255,255,
  display = True 
)

Draw a filled circle on the screen (rotated to screen)

Parameters
selfThe object pointer.
xThe center x coordinate of the circle.
yThe center y coordinate of the circle.
radiusThe radius of the circle.
fillThe color of the inside of the circle. Optional, defaults to white.
displayChoose to immediately push the drawing to the screen. Optional, defaults to True.
Remarks
To use this function in your program:
1 ...
2 screen.fillCircle(100, 100, 15, fill = (255,0,0))
def mindsensorsUI.mindsensorsUI.fillImgArray (   self,
  x,
  y,
  width,
  height,
  image,
  display = True 
)

Draw a image on the screen using supplied image data.

Parameters
selfThe object pointer.
xThe upper left x coordinate of the image.
yThe upper left y coordinate of the image.
widthThe width of the image.
heightThe width of the image.
imagedata
displayChoose to immediately push the drawing to the screen. Optional, defaults to True.
Remarks
To use this function in your program:
1 ...
2 screen.screen.fillBmp(40, 0, 240, 240, image)
def mindsensorsUI.mindsensorsUI.fillRect (   self,
  x,
  y,
  width,
  height,
  fill = (255,255,
  outline = None,
  display = True 
)

Draw a rectangle on the screen (rotated to screen)

Parameters
selfThe object pointer.
xThe upper left x coordinate of the rectangle.
yThe upper left y coordinate of the rectangle.
widthThe width of the rectangle.
heightThe height of the rectangle.
fillThe color of inside of the rectangle. Optional, defaults to white.
outlineThe color of the outer edge of the rectangle. Optional, defaults to no outline.
displayChoose to immediately push the drawing to the screen. Optional, defaults to True.
Remarks
To use this function in your program:
1 ...
2 screen.fillRect(100, 100, 75, 75, fill = (255,0,0), outline = (0,0,0))
def mindsensorsUI.mindsensorsUI.fillRoundRect (   self,
  x,
  y,
  width,
  height,
  radius,
  fill = (255,255,
  display = True 
)

Draw a rectangle with rounded edges on the screen (rotated to screen)

Parameters
selfThe object pointer.
xThe upper left x coordinate of the rectangle.
yThe upper left y coordinate of the rectangle.
widthThe width of the rectangle.
heightThe height of the rectangle.
radiusThe arc of the rectangle corners.
fillThe color of the inside of the rectangle. Optional, defaults to white.
displayChoose to immediately push the drawing to the screen. Optional, defaults to True.
def mindsensorsUI.mindsensorsUI.forceMessage (   self,
  message 
)

Display pop-up of a message on the screen with no exit options.

This function will return right away. You may need to call screen.setMode(screen.PS_MODE_TERMINAL) to stop the popup later.

Parameters
selfThe object pointer.
messageThe message that will pop-up on the screen.
Remarks
To use this function in your program:
1 ...
2 message = ["Processing", "Processing, please wait..."]
3 screen.forceMessage(message)
def mindsensorsUI.mindsensorsUI.getMode (   self)

Returns the value of the mode (Experienced users)

Parameters
selfThe object pointer.
def mindsensorsUI.mindsensorsUI.hideArrows (   self,
  refresh = True 
)

Hide the on screen arrow buttons.

Parameters
selfThe object pointer.
refreshChoose to immediately refresh screen.
def mindsensorsUI.mindsensorsUI.isTouched (   self)

Detects touchscreen presses and prevents false positives, updates self.x and self.y if pressed.

Parameters
selfThe object pointer. To use this function in your program:
1 ...
2 if (screen.isTouched())
3  print "Touched at {},{}".format(screen.x, screen.y)
def mindsensorsUI.mindsensorsUI.refresh (   self)

Refresh the screen (Slow)

Parameters
selfThe object pointer.
Remarks
To use this function in your program:
1 ...
2 screen.refresh()
def mindsensorsUI.mindsensorsUI.refreshLine (   self,
  lineNum,
  display = True 
)

Refresh a screen line.

Parameters
selfThe object pointer.
lineNumThe line number to refresh.
displayChoose to immediately push the drawing to the screen.
Remarks
To use this function in your program:
1 ...
2 screen.refreshLine(1)
def mindsensorsUI.mindsensorsUI.rotateLeft (   self)

Rotates the screen orientation 90 degrees to the left (90 degrees)

Parameters
selfThe object pointer.
Remarks
To use this function in your program:
1 ...
2 screen.rotateLeft()
def mindsensorsUI.mindsensorsUI.rotateRight (   self)

Rotates the screen orientation 90 degrees to the right (-90 degrees)

Parameters
selfThe object pointer.
Remarks
To use this function in your program:
1 ...
2 screen.rotateRight()
def mindsensorsUI.mindsensorsUI.screenHeight (   self)

Determines the height of the screen based on rotation (Experienced users)

Parameters
selfThe object pointer.
def mindsensorsUI.mindsensorsUI.screenWidth (   self)

Determines the width of the screen based on rotation (Experienced users)

Parameters
selfThe object pointer.
def mindsensorsUI.mindsensorsUI.screenXFromImageCoords (   self,
  x,
  y 
)

Calculates the x-coordinate of the screen upon rotation (INTERNAL USE ONLY)

Parameters
selfThe object pointer.
xx value in the current rotation's coordinate system
yy value in the current rotation's coordinate system
Returns
x value for the corresponding point in the display's coordinate system (for writing to TFT)
def mindsensorsUI.mindsensorsUI.screenYFromImageCoords (   self,
  x,
  y 
)

Calculates the y-coordinate of the screen upon rotation (INTERNAL USE ONLY)

Parameters
selfThe object pointer.
xx value in the current rotation's coordinate system
yy value in the current rotation's coordinate system
Returns
y value for the corresponding point in the display's coordinate system (for writing to TFT)
def mindsensorsUI.mindsensorsUI.setMode (   self,
  mode = 0 
)

Sets the mode (Experienced users)

Parameters
selfThe object pointer.
modeThe new mode: PS_MODE_TERMINAL, PS_MODE_POPUP, or PS_MODE_DEAD. Optional, defaults to PS_MODE_TERMINAL.
def mindsensorsUI.mindsensorsUI.showArrows (   self,
  refresh = True 
)

Show the on screen arrow buttons.

Parameters
selfThe object pointer.
refreshChoose to immediately refresh screen.
def mindsensorsUI.mindsensorsUI.showMessage (   self,
  message,
  touch = True,
  goBtn = True,
  wrapText = False 
)

Display pop-up of a message on the screen with a single option "OK".

Parameters
selfThe object pointer.
messageThe message that will pop-up on the screen.
touchWhether to check if on screen buttons are pressed. Optional, defaults to True.
goBtnWhether to check for the GO button to close the question. Optional, defaults to True.
wrapTextWhen True, long lines of text will be wrapped to fit in the popup. Optional, default to False.
1 message = ["Title", "This is a very long line of text which will be wrapped to fit in the dialog box.", "Other lines will be wrapped, too. Press OK to close this popup."]
2 screen.showMessage(message, wrapText=True)
Note
If goBtn is True, pressing GO will close the dialog and return False
Remarks
To use this function in your program:
1 ...
2 message = ["Complete", "The process has completed.", "Status: success"]
3 screen.showMessage(message)
def mindsensorsUI.mindsensorsUI.termGotoLine (   self,
  lineno 
)

Set the cursor to a specific line of the of the screen.

Parameters
selfThe object pointer.
linenoThe line number at which to set the cursor.
Remarks
To use this function in your program:
1 ...
2 screen.termGotoLine(5)
def mindsensorsUI.mindsensorsUI.termPrint (   self,
  text 
)

Print to the current line of the screen.

Parameters
selfThe object pointer.
textThe text to print to the screen.
Remarks
To use this function in your program:
1 ...
2 screen.termPrint("Regular print, no newline")
def mindsensorsUI.mindsensorsUI.termPrintAt (   self,
  lineno,
  text 
)

Print to a specific line of the screen.

Parameters
selfThe object pointer.
linenoThe line number at which to set the cursor.
textThe text to print to the screen.
Remarks
To use this function in your program:
1 ...
2 screen.termPrintAt(5, "Printing at line 5")
def mindsensorsUI.mindsensorsUI.termPrintln (   self,
  text 
)

Print to the current line and then go to the next line.

Parameters
selfThe object pointer.
textThe text to print to the screen.
Remarks
To use this function in your program:
1 ...
2 screen.termPrintln("Hello, world!")
def mindsensorsUI.mindsensorsUI.termReplaceLastLine (   self,
  text 
)

Print new text in place of current line (Low Refresh Rate)

Parameters
selfThe object pointer.
textThe text to print to the screen.
Remarks
To use this function in your program:
1 ...
2 screen.termReplaceLastLine("Replaced!")
def mindsensorsUI.mindsensorsUI.TS_To_ImageCoords_X (   self,
  x,
  y 
)

Calculates display x-coordinate from touchscreen values, adjusted for rotation (INTERNAL USE ONLY)

Parameters
selfThe object pointer.
xx value in the touchscreen's coordinate system (read from registers)
yy value in the touchscreen's coordinate system (read from registers)
Returns
x value for the corresponding point in the current rotation's coordinate system
def mindsensorsUI.mindsensorsUI.TS_To_ImageCoords_Y (   self,
  x,
  y 
)

Calculates display y-coordinate from touchscreen values, adjusted for rotation (INTERNAL USE ONLY)

Parameters
selfThe object pointer.
xx value in the touchscreen's coordinate system (read from registers)
yy value in the touchscreen's coordinate system (read from registers)
Returns
y value for the corresponding point in the current rotation's coordinate system
def mindsensorsUI.mindsensorsUI.TS_X (   self)

Reads the x-coordinate of the touchscreen press.

Parameters
selfThe object pointer.
Remarks
To use this function in your program:
1 ...
2 x = screen.TS_X()
def mindsensorsUI.mindsensorsUI.TS_Y (   self)

Reads the y-coordinate of the touchscreen press.

Parameters
selfThe object pointer. To use this function in your program:
1 ...
2 y = screen.TS_Y()

The documentation for this class was generated from the following file: