Hello World



Yüklə 281,82 Kb.
Pdf görüntüsü
tarix11.10.2017
ölçüsü281,82 Kb.
#4283


Pythics Documentation

Release 0.5.2

Brian R. D’Urso

July 14, 2015





Contents

1

Getting started



3

1.1


Requirements

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3

1.2


Installation

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4

1.3


Running

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4

2

Programming



7

2.1


Overview

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

7

2.2


XML/HTML File Format

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

9

2.3


Controls

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

10

3

Examples



13

4

Pythics API



15

4.1


Controls

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

15

4.2


Matplotlib Controls

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

15

4.3


PyQwt Controls

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

15

4.4


Deprecated Controls

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

15

5

GNU General Public License



17

6

GNU Free Documentation License



29

7

Indices and Tables



39

i


ii


Pythics Documentation, Release 0.5.2

This document is Copyright (C) 2008 - 2013 Brian R. D’Urso

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation

License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no

Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled ‘GNU Free

Documentation License’.

Pythics is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License

as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Pythics is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied

warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public

License for more details.

You should have received a copy of the GNU General Public License along with Pythics.

If not, see

<

http://www.gnu.org/licenses/

>.

Pythics is based in part on the work of the Qwt project (



http://qwt.sf.net

).

Contents:



Contents

1


Pythics Documentation, Release 0.5.2

2

Contents


CHAPTER

1

Getting started

This is the primary documentation for the Python Instrument Control System, also known as Pythics.

Pythics is an application for running Python code intended to be used for simple interfaces to laboratory instruments

or numerical simulations. It features a simple system for making graphical user interfaces (GUIs) with useful controls

and indicators, including plotting functionality. There is a clean separation between the GUI and application code with

multithreading and multiprocessing support. In this way backend code does not interfere with the functionality of the

GUI. Pythics attempts to robustly handle all of the complex details of writing a program with a GUI for you, allowing

you to concentrate on the functionality of your program.

The key goals of Pythics are:

• Provide a framework which provides a highly multiprocessing environment without requiring any extra effort

by the user/developer.

• Provide a simple method for specifying a GUI for typical scientific applications.

• Be as Pythonic as possible.

– Use standard library functions whenever possible.

– Minimize introduction of new special keywords, functions, or calling conventions.

1.1 Requirements

The following programs and libraries are required for Pythics to run:

Python 2.6



2.6.2 or later preferred; earlier versions lack the multiprocessing package

PyQt



widget toolkit for GUI, version 4.5.4 or later

The following libraries are strongly recommended for basic functionality in Pythics:

NumPy


array support

matplotlib



plotting library

The following libraries are optional for full functionality in Pythics:

PIL


python Imaging Library - for image display support, (1.1.7 or later preferred)

PyQwt



widgets for scientific and engineering applications

The following additional packages may be helpful for writing scientific code for Pythics:

PyVISA


for communicating with VISA laboratory instruments

pySerial



for communicating with laboratory instruments by RS-232

3


Pythics Documentation, Release 0.5.2

SciPy



for additional numerical processing routines

1.2 Installation

Pythics uses Python Distutils for installation. Installers are available for some platforms.

On Windows, run the installer (.exe). It will install Pythics and place a shortcut on your desktop to launch Pythics.

If an installer is not available for your platform, you can install from a source distribution (.tar.gz or .zip):

• Unpack the archive file.

• run python setup.py install



1.3 Running

To start Pythics:

• On Linux, go to the pythics/pythics directory and type python pythics-run.py.

• On Windows, double-click on the shortcut created on your desktop by the installer or go to the pythics/pythics

directory and double-click on pythics-run.py.

• You can also start pythics from the command line with options as: Usage: pythics-run.py [options]

Options:

-h

show help text then exit



-a

selects startup html file

-v

selects verbose mode



-d

selects debug mode

--help

same as -h



--app

same as -a

--verbose

same as -v

--debug

same as -d



1.3.1 Using Pythics

Once Pythics is running, virtual instruments (VIs) can be opened and controlled though a combination of the Pythics

menus and the VI’s GUI. Interaction with an individual VI’s GUI is not covered here, because it depends on the details

of VI. Here we describe the operation of Pythics through the menus, which provide basic control of VI operations.

File Menu

• Open...

• Close

• Close All



• Reload

• Open Workspace...



4

Chapter 1. Getting started


Pythics Documentation, Release 0.5.2

• Save Workspace

• Save Workspace As...

• Page Setup...

• Print Preview

• Print...

• Exit

Edit Menu



• Cut

• Copy


• Paste

• Delete


Parameters

• Load Defaults

• Load..._pySerial

• Save As Defaults

• Save As...

1.3. Running

5



Pythics Documentation, Release 0.5.2

6

Chapter 1. Getting started


CHAPTER

2

Programming

2.1 Overview

While the underlying architecture of Pythics is generally hidden from the user, some knowledge of the structure may

be helpful in understanding how to build and run programs under Pythics. When running user code, Pythics runs as a

primary process which controls the GUI, and an additional process for each loaded user program, which we will refer

to as a virtual instrument (VI). The GUI process itself uses multiple threads to handle the GUI and communication

with the VI subprocess, while each VI has one primary thread and possibly additional timer threads in a subprocess.

Each VI subprocess is actually a true separate process handled with the Python multiprocessing package. As a result,

the VI subprocesses and GUI can generally run without blocking each other, and the VI subprocesses can even be

distributed over multiple processors or cores as supported by the operating system. Additionally, even if one VI

subprocess crashes, for example due to an error accessing low-level hardware, the Pythics GUI and other VIs should

be undisturbed. Pythics handles all communication between the VI subprocesses and the GUI process, and provides

means of sharing data between VIs.

Writing code for a new VI in Pythics generally consists of writing two components:

1. A single XML file (a subset of XHTML) to layout the graphical user interface.

2. One or more text files containing Python code. These give functionality to the VI.

The XML file is loaded by the GUI process in order to set up the interface, while the Python code files are loaded and

ultimately executed in a VI subprocess. For each XML file loaded a new tab will be created in the Pythics window

which holds the corresponding VI GUI and a VI subprocess which handles the associated functionality.

The XML file specifies the layout for the controls in the GUI with a structure very similar to that used to describe

the layout of a web page. Simple tables, styles, alignments, etc. of text and controls are supported. In the XML file,

parameters may also be passed to controls to setup the behavior of the controls. The XML file can also direct Pythics

to load files which contain Python code, for example in order to respond to a button press.

The second VI component is one or more text files which contain Python code and are loaded based on requests in

the XML file. The Python code typically takes the form of a series of Python functions with a particular format. Each

function to be called from the GUI should take an indefinite number of keyword arguments. In practice, when a GUI

control calls a function from one of these files, Pythics passes the function an object for each control in the GUI with

a id attribute. The id attribute is used as the name of the corresponding keyword argument. Additional functions or

other code may be included in the Python code files for use within a VI subprocess. It may sound complex, but the

examples show that this actually a simple and effective protocol.

7



Pythics Documentation, Release 0.5.2

Fig. 2.1: Data flow betweeen processes and threads in Pythics.



8

Chapter 2. Programming


Pythics Documentation, Release 0.5.2

2.2 XML/HTML File Format

The file format which describes the GUI layout in Pythics is an XML-compliant HTML format, similar to a subset of

XHTML. Elements (text, controls, etc.) within the XML file are controlled by up to three sources within the XML

file in addition to the document structure itself: a cascading style sheet (CSS) which specifies element properties and

element attributes. The CSS is located in a  element in the document  , and will be

described in the section below.

A nearly minimal XML document for Pythics has a head with title and style elements, and a body which contains the

controls and other GUI layout elements:







Hello World









Hello World

: surrounds the main body of the html document (everything but the document header)

• 

, ... 

: text placed on its own line, typically used for VI or section names

• 
: text which is not on its own line

• 


: insert a horizontal line, typeically as a separator between sections (no closing tag needed)

• 
: insert a line break to start the next elements on a new line (no closing tag needed)

• 

: use a table to arrange elements

• : used to insert a control object into a VI interface, see details below



2.2.2 Cascading Style Sheets (CSS)

A VI’s appearance can be specified in a Cascading Style Sheet (CSS), enclosed between  and



tags within the document head. The style sheet consist of a series of entries separated by white space (new

lines or spaces) of the form: selector{property1:value1; property2:value2} where there may be an arbitrary number of

property:value

pairs separated by semicolons. The available properties and example values are given below.

2.2. XML/HTML File Format

9



Pythics Documentation, Release 0.5.2

The selector in a CSS entry may take one of five forms. In order of increasing specificity, these are: tag, .*class*,

tag

.*class*, #id, and tag#id. When Pythics encounter an Pythics encounters an XML element in the body of the



document, it searches for a style property of a given element as follows, where the first match encountered is used:

1. If the element has a id attribute: An entry in the style sheet of the form tag#id, where tag is replaced with the

element’s tag, and id is replaced with the element’s id attribute.

2. If the element has a id attribute: An entry in the style sheet of the form #id, where id is replaced with the

element’s id attribute.

3. If the element has a class attribute: An entry in the style sheet of the form tag.class, where tag is replaced with

the element’s tag, and class is replaced with the element’s class attribute.

4. If the element has a class attribute: An entry in the style sheet of the form .class, where class is replaced with

the element’s class attribute.

5. An entry matching the element tag.

6. If no entry has been found, the process stated above is repeated for the parent element containing the original

element. As long as no entry is found, the search keeps proceeding to parent elements until the body tag is

reached, which contains a default value for every property.

The following properties can be set in style sheets. Not all properties have meaning for all element types.

Property

Description

Default

Applies to



align

Alignment of element

left

all elements



background-color

RGB background color

#eeeeee

body only



margin

Margin on left and right side

10px

body only



padding

Space around element

5px

all elements



color

Text color

black

text elements



font-size

Text size

12pt

text elements



font-family

Family


default

text elements

font-style

Style


normal

text elements

font-weight

Weight


normal

text elements

Here is an example style sheet:

body {background-color: #eeeeee; margin: 10px; padding: 5px}

a {align: left; color: black; font-size: 8pt; font-family: default; font-style: normal; font-weight: normal}

p {align: left; color: black; font-size: 8pt; font-family: default; font-style: normal; font-weight: normal}

h1 {align: center; font-size: 22pt; font-family: default; font-style: normal; font-weight: bold}

h2 {align: left; font-size: 18pt; font-family: default; font-style: normal; font-weight: normal}

h3 {align: left; font-size: 14pt; font-family: default; font-style: normal; font-weight: normal}

h4 {align: left; font-size: 12pt; font-family: default; font-style: normal; font-weight: normal}

h5 {align: left; font-size: 10pt; font-family: default; font-style: normal; font-weight: normal}

h6 {align: left; font-size: 8pt; font-family: default; font-style: normal; font-weight: normal}

object {align: left}

table {align: center}

.cells {align: left; padding: 1px}

.compact {padding: 0px}





2.3 Controls

object parameters (for controls (object) elements only)

A quick example illustrates the differences between object attributes and parameters:

10

Chapter 2. Programming



Pythics Documentation, Release 0.5.2



In this case, we refer to id, classid, width as attributes of object, while we refer to digits and read_only as parameters

of object, since they are in param elements. Note that param elements can only be present inside of object elements.

2.3.1 Common Attributes

Attributes:

• classid: A string indicating the type of control to be inserted. For standard controls, only the name of the control

is needed. For custom controls, it should be of the form ‘module.class’, where module is the name of the module

to be imported to find the control class.

• id: A string used for identifying the control in the html style sheet and used as the name of the keyword argument

when the control is passed to VI Python code.

• width: A string giving the width of the control in pixels (default) or in percent of the window width if the string

ends in %.

• height: A string giving the height of the control in pixels. Many controls have a reasonable default height so

this attribute may not be needed for all controls.

2.3.2 Parameters and Python API

See automatically generated API documetation, which lists parameters for specifying the behavior of each control



from the html file as well as the methods and properties of the control accessible from a VI’s Python code.

2.3. Controls

11


Pythics Documentation, Release 0.5.2

12

Chapter 2. Programming


CHAPTER

3

Examples



Hello World



Hello World











Yüklə 281,82 Kb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə