1. Trang chủ
  2. » Công Nghệ Thông Tin

Perl in a Nutshell phần 10 ppsx

72 284 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề The Canvas Widget
Trường học University of California, Berkeley
Chuyên ngành Computer Science
Thể loại Tài liệu
Năm xuất bản 2001
Thành phố Berkeley
Định dạng
Số trang 72
Dung lượng 6,45 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Chapter 18 Perl/Tk18.13 The Scale Widget Create a "slider" widget representing a numeric value with the Scale method.. For example: 'command' type, and we use the -command option for eac

Trang 1

The height of the printed page.

[Chapter 18] 18.12 The Canvas Widget

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_12.htm (10 of 12) [2/7/2001 10:38:00 PM]

Trang 2

Changes the scaling of the canvas or any individual items For example, to scale the entire canvas

to half its dimensions:

Manipulates the canvas in view With no arguments, returns a list of two numbers between 0 and

1, defining what portion of the canvas is currently hidden on the top and bottom, respectively.With arguments, its function changes:

moveto

[Chapter 18] 18.12 The Canvas Widget

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_12.htm (11 of 12) [2/7/2001 10:38:00 PM]

Trang 3

Moves the specified fraction of the canvas area to the top of the visible portion.

scroll

Scrolls the canvas up or down by the specified number of units or pages Used primarily as acallback to a scrollbar; pressing on an arrow would move by units (lines), and pressing onthe trough would move by pages The number is either 1 or -1, to move forwards or

backwards, respectively

[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl

Programming | Perl Cookbook ]

[Chapter 18] 18.12 The Canvas Widget

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_12.htm (12 of 12) [2/7/2001 10:38:00 PM]

Trang 4

Chapter 18 Perl/Tk

18.13 The Scale Widget

Create a "slider" widget representing a numeric value with the Scale method

$parent->Scale(options);

The standard configuration options that apply to Scale are: -activebackground, -background,-bg, -borderwidth, -bw, -cursor, -font, -foreground, -fg, -highlightbackground,-highlightcolor, -highlightthickness, -relief, -state, -takefocus, and -width.Other options are:

Trang 6

[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl Programming | Perl Cookbook ]

[Chapter 18] 18.13 The Scale Widget

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_13.htm (3 of 3) [2/7/2001 10:38:02 PM]

Trang 7

Chapter 18 Perl/Tk

18.14 The Menubutton Widget

Create a menubutton with the Menubutton method For example:

'command' type, and we use the -command option for each item to point to the callback to execute when the menu item is selected We also use the -underline option to enable the user to select a menu item using keystrokes (The \[quotedbl]-" represents a separator between menu items.)

In addition to 'command' , other types of menus are:

Treats the menu item as a radiobutton.

[Chapter 18] 18.14 The Menubutton Widget

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_14.htm (1 of 4) [2/7/2001 10:38:06 PM]

Trang 8

You can configure both the menu itself and the individual menu items The configuration options that apply to

Menubutton are: -activebackground , -activeforeground , -anchor , -background , -bg ,

-bitmap , -borderwidth , -bw , -cursor , -disabledforeground , -font , -foreground , -fg ,

-height , -highlightbackground , -highlightcolor , -highlightthickness , -image ,

-justify , -padx , -pady , -relief , -state , -takefocus , -underline , -width , and

18.14.1 Menu Item Options

In addition to the menu itself, each individual menu item can be configured The widget configuration options that apply to menu items are: -activebackground , -background , -bg , -bitmap , -font ,

-foreground , -fg , -image , -state , and -underline Other options are:

Trang 9

For a checkbutton, specifies the value used when the checkbutton is "off."

For a checkbutton or radiobutton, defines the image to be displayed instead of text when the radiobutton is

"on" Ignored if -image is not used.

"-command" => \&exitclean ]);

command

Adds a command item to the end of the menu The above example could have read:

$menubutton->command(-label => "Print", -command => \&printscreen);

$menubutton->command(-label => "Exit", -command => \&exitclean); checkbutton

Adds a checkbutton item to the end of the menu.

$menubutton->checkbutton(-label => "Show Toolbar", [-variable => \$toolbar");

radiobutton

Adds a radiobutton item to the end of the menu.

$menubutton->radiobutton(-label => "Red", -variable => \$color");

$menubutton->radiobutton(-label => "Blue", -variable => \$color"); separator

Adds a separator line to the end of a menu.

cascade

[Chapter 18] 18.14 The Menubutton Widget

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_14.htm (3 of 4) [2/7/2001 10:38:06 PM]

Trang 10

Adds a cascade item to the end of the menu.

Changes information on a specific menu item given an index.

18.13 The Scale Widget 18.15 The Menu Widget

[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl Programming | Perl Cookbook ]

[Chapter 18] 18.14 The Menubutton Widget

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_14.htm (4 of 4) [2/7/2001 10:38:06 PM]

Trang 11

Chapter 18 Perl/Tk

18.15 The Menu Widget

Create a menu with the Menu method, to be displayed later with the post method

$menu = $parent->Menu(options)

The standard configuration options that apply to Menu are: -activebackground,

-activeforeground, -background, -bg, -borderwidth, -bw, -cursor,

-disabledforeground, -font, -foreground, -fg, -relief, and -takefocus

Other options are:

The last menu item

[Chapter 18] 18.15 The Menu Widget

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_15.htm (1 of 3) [2/7/2001 10:38:13 PM]

Trang 13

Returns the type of menu item at the specified index.

Trang 14

Chapter 18 Perl/Tk

18.16 The Optionmenu Widget

Use the Optionmenu method to create an option menu, in which the selected item is the value

displayed For example:

$mainwindow->OptionMenu(-textvariable => \$platform,

-options => [ [ "UNIX", "unix" ],

[ "Windows NT", "winnt" ],

[ "Macintosh", "mac" ] ]) -> pack;

The -options argument takes a list of menu items If the description of the menu items that aredisplayed are different from the values stored, the menu items are themselves written as two-item lists.The standard configuration options that apply to Optionmenu are: -activebackground,

-activeforeground, -background, -bg, -bitmap, -borderwidth, -bw, -cursor,-disabledforeground, -font, -foreground, -fg, -highlightbackground,

-highlightcolor, -highlightthickness, -image, -justify, -relief, -state,-takefocus, -underline, -width, and -wraplength

Other options are:

Trang 15

Specifies the text to display as a label for the option menu.

-textvariable =>\$variable

Points to the variable containing text to be displayed in the option menu

-variable =>\$variable

Points to a variable containing a stored value, distinct from the value shown in the option menu

[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl Programming | Perl Cookbook ]

[Chapter 18] 18.16 The Optionmenu Widget

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_16.htm (2 of 2) [2/7/2001 10:38:15 PM]

Trang 16

Chapter 18 Perl/Tk

18.17 The Frame Widget

Create a frame for enclosing other widgets using the Frame method For example:

$parent->Frame( options )

The standard configuration options that apply to Frame are: -background, -bg, -borderwidth,-bw, -cursor, -height, -highlightbackground, -highlightcolor,

-highlightthickness, -relief, -takefocus, and -width

Other options are:

18.18 The Toplevel Widget

[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl

[Chapter 18] 18.17 The Frame Widget

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_17.htm (1 of 2) [2/7/2001 10:38:17 PM]

Trang 17

Programming | Perl Cookbook ]

[Chapter 18] 18.17 The Frame Widget

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_17.htm (2 of 2) [2/7/2001 10:38:17 PM]

Trang 18

Chapter 18 Perl/Tk

18.18 The Toplevel Widget

Create a toplevel widget, displayed independently from the main window with the same decoration as thewindow system, using the Toplevel method

The standard configuration options that apply to Toplevel are: -background, -bg,

-borderwidth, -bw, -cursor, -height, -highlightbackground, -highlightcolor,-highlightthickness, -relief, -takefocus, and -width

Other options are:

Assigns a name to the toplevel window

[Chapter 18] 18.18 The Toplevel Widget

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_18.htm (1 of 3) [2/7/2001 10:38:20 PM]

Trang 20

Specifies the smallest size for the window.

Makes the window non-visible

[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl

Programming | Perl Cookbook ]

[Chapter 18] 18.18 The Toplevel Widget

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch18_18.htm (3 of 3) [2/7/2001 10:38:20 PM]

Trang 21

Part VIII

Part VIII: Win32

Chapter 19: Win32 Modules and Extensions

Trang 22

If you use Perl on a Win32 system, a number of extension modules are available to provide

Windows-specific functionality Extension modules consist of a regular module written in Perl and alibrary written in C or C++ that can implement native Windows calls The core of available modules is

bundled together as lib-win32 on CPAN, and with ActivePerl, Activestate's version of Perl for Win32.

They provide such functionality as managing Windows processes, NT user administration, registrymodification, and OLE automation

The Win32 modules were originally written for Windows NT systems, so much of the functionality ofthe Win32 library is only applicable to Perl running on Windows NT Many modules check to see whichsystem they are on before installing Many of the NT-specific modules such as NetAdmin and EventLog

do not install at all on Windows 95 Modules like Registry do their best to work on both systems, despite

[Chapter 19] Win32 Modules and Extensions

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch19_01.htm (1 of 3) [2/7/2001 10:38:25 PM]

Trang 23

the differences in their registries.

This chapter covers most of the modules and extensions included in lib-win32 and distributed with

ActivePerl Additional Windows modules are available at CPAN

The following modules are described in this chapter:

Create and use semaphores

[Chapter 19] Win32 Modules and Extensions

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch19_01.htm (2 of 3) [2/7/2001 10:38:25 PM]

Trang 24

Manage Windows NT services

Win32::Shortcut

Provide shell link interface

The reference material for the Clipboard, Console, Internet, and Shortcut modules was graciously

provided by Aldo Capini, author and maintainer of many Win32 modules

(http://www.divinf.it/dada/perl/)

The final section of this chapter describes OLE automation in Perl programs and details the Win32::OLEmodules

19.1 Win32::Clipboard

The Win32::Clipboard module allows you to manipulate the Windows clipboard You can use the

clipboard as an object with the following syntax:

$clip = Win32::Clipboard();

This functions as an implicit constructor If you include a text string as an argument, that text will beplaced on the clipboard You can just use the package-qualified method names instead of the objectsyntax, since the clipboard is a single entity

[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl

Programming | Perl Cookbook ]

[Chapter 19] Win32 Modules and Extensions

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch19_01.htm (3 of 3) [2/7/2001 10:38:25 PM]

Trang 25

Chapter 19 Win32 Modules and Extensions

19.2 Win32::Console

Win32::Console implements the Win32 console and character mode functions They give you full control

on the console input and output, including: support of off-screen console buffers (e.g., multiple screenpages); reading and writing of characters, attributes, and whole portions of the screen; and completeprocessing of keyboard and mouse events

The new constructor is used to create a console object It can take two forms:

$con = Win32::Console->new(standard_handle);

$con = Win32::Console->new(accessmode, sharemode);

The first form creates a handle to a standard channel standard_handle can be one of

STD_OUTPUT_HANDLE, STD_ERROR_HANDLE, or STD_INPUT_HANDLE

The second form creates a console screen buffer in memory, which you can access for reading and

writing as a normal console, and then redirect on the standard output (the screen) with Display In thiscase, you can specify accessmode to be GENERIC_READ, GENERIC_WRITE, or both, determiningthe permissions you will have on the created buffer

sharemode affects the way the console can be shared It can be specified either as

FILE_SHARE_READ, FILE_SHARE_WRITE, or both If you don't specify any of those parameters, allfour flags will be used

Methods supported by the Win32::Console module are:

Trang 28

Chapter 19 Win32 Modules and Extensions

19.3 Win32::ChangeNotification

This module provides access to Win32 change-notification objects, letting you monitor events relating tofiles and directory trees The constructor for this class is new, which creates a ChangeNotification objectfor a specified directory and indicates how it should be monitored:

$ntfy = Win32::ChangeNotification->new(directory, subtree, filter);

The function returns a reference to the object as $ntfy directory is the pathname of the directory tomonitor subtree is a Boolean value that, if true, forces the object to monitor all subdirectories of theobject's path The filter parameter indicates what type of events will trigger a notification It can beone of the following string values:

ATTRIBUTES Any attribute change

DIR_NAME Any directory name change

FILE_NAME Any filename change (creating/deleting/renaming)

LAST_WRITE Any change to a file's last write time

SECURITY Any security descriptor change

SIZE Any change in a file's size

The following methods are used on notification objects created by new:

[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl

Programming | Perl Cookbook ]

[Chapter 19] 19.3 Win32::ChangeNotification

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch19_03.htm [2/7/2001 10:38:31 PM]

Trang 29

Chapter 19 Win32 Modules and Extensions

19.4 Win32::Eventlog

This module makes the Windows NT event log accessible to your Perl programs It allows you to createnew records, read records, and create backup logfiles The new constructor opens a server's event log as

an object

$log = Win32::EventLog->new(source, [server]);

This function opens an event log and returns an object reference source specifies the name of thesource event, and server specifies the name of the server (local is assumed if no server name isgiven)

Many of the methods for this module require a reference to an empty variable as an argument This iswhere the return value of the method will be placed, whether it is a hash or a scalar The followingmethods can be used on event log objects:

[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl

Programming | Perl Cookbook ]

[Chapter 19] 19.4 Win32::Eventlog

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch19_04.htm [2/7/2001 10:38:34 PM]

Trang 30

Chapter 19 Win32 Modules and Extensions

19.5 Win32::File

The Win32::File module allows you to view or set the attributes for files There are two functions thatallow you to do this, which must be explicitly imported to your namespace:

use Win32::File qw/GetAttributes SetAttributes/;

The constant values for the attributes are exported by default

GetAttributes (filename, \$atts)

Returns the attribute settings for file filename and saves them as the variable referenced by $atts,

which will contain an ORed combination of one or more of the following values:

ARCHIVE DIRECTORY HIDDEN NORMAL READONLY SYSTEMSetAttributes (filename, atts)

Set the attributes for the file filename to the values contained in atts The attributes are given as an

ORed combination of one or more of the attribute values shown above

[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl

Programming | Perl Cookbook ]

[Chapter 19] 19.5 Win32::File

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch19_05.htm [2/7/2001 10:38:36 PM]

Trang 31

Chapter 19 Win32 Modules and Extensions

19.6 Win32::FileSecurity

The Win32::FileSecurity module allows you to work with NT File System (NTFS) file permissions Filepermissions are stored as Discretionary Access Control Lists (DACLs) for each file or directory Theselists contain a bitmask specifying the permission rights for users on the file or directory This module

implements a DACL as a permissions hash in which each key is a username and the value is the bitmask

for the permissions

The FileSecurity module exports the following constants to describe user permissions:

Using the constant function on one of these constants gives its value, and bitmasks or multiple

permissions settings can be made by supplying a list of these constants to the MakeMask function.The functions exported by the Win32::FileSecurity module are:

Trang 32

[ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl Programming | Perl Cookbook ]

[Chapter 19] 19.6 Win32::FileSecurity

http://www.crypto.nc1uw1aoi420d85w1sos.de/documents/oreilly/perl/perlnut/ch19_06.htm (2 of 2) [2/7/2001 10:38:38 PM]

Trang 33

Chapter 19 Win32 Modules and Extensions

19.7 Win32::Internet

The Win32::Internet extension implements the Win32 Internet APIs (found in WININET.DLL), providing

support for HTTP, FTP, and Gopher connections.

All types of connections start as a basic Internet connection that must be opened with the following command:

You can achieve the same result with this series of commands, which is what FetchURL actually does:

$inet = new Win32::Internet();

Trang 34

19.7.1 General Internet Methods

The methods described in this section are used on Internet connection objects created with new :

Additional flags affecting the behavior of the function Default is none.

If you pass a hash reference to the function, the following values are taken from the hash:

Trang 35

$inet = new Win32::Internet();

$inet->FTP($FTP, "hostname", "username", "password");

The following methods are used on FTP session objects:

Trang 36

$inet = new Win32::Internet();

$inet->HTTP($http, "hostname", "username", "password");

This opens the session and creates the HTTP session object $http The following methods can be used on HTTP session objects:

Ngày đăng: 12/08/2014, 21:21