当前位置:文档之家› Tkexampl tcltk的一个经典例子

Tkexampl tcltk的一个经典例子

Tkexampl tcltk的一个经典例子
Tkexampl tcltk的一个经典例子

315C H A P T E R III. Tk Basics

22Tk by Example This chapter introduces Tk through a series of short examples. The ExecLog

runs a program in the background and displays its output. The Example

Browser displays the Tcl examples from the book. The T cl Shell lets you

type Tcl commands and execute them in a slave interpreter.

This chapter is from Practical Programming in Tcl and Tk , 3rd Ed.

? 1999, Brent Welch

https://www.doczj.com/doc/b718251592.html,/book/

Tk provides a quick and fun way to gen-erate user interfaces. In this chapter we will go through a series of short example programs to give you a feel for what you can do. Some details are glossed over in this chapter and considered in more detail later. In particular, the pack geometry manager is covered in Chapter 23 and event bindings are discussed in Chapter

26. The Tk widgets are discussed in more detail in later chapters.

ExecLog

Our first example provides a simple user interface to running another program with the exec command. The interface consists of two buttons, Run it and Quit ,an entry widget in which to enter a command, and a text widget in which to log the results of running the program. The script runs the program in a pipeline and uses the fileevent command to wait for output. This structure lets the user interface remain responsive while the program executes. You could use this to run make , for example, and it would save the results in the log. The complete example is given first, and then its commands are discussed in more detail.

316 Tk by Example Chap. 22 Example 22–1Logging the output of a program run with exec.

#!/usr/local/bin/wish

# execlog - run a program with exec and log the output

# Set window title

wm title . ExecLog

# Create a frame for buttons and entry.

frame .top -borderwidth 10

pack .top -side top -fill x

# Create the command buttons.

button .top.quit -text Quit -command exit

set but [button .top.run -text "Run it" -command Run]

pack .top.quit .top.run -side right

# Create a labeled entry for the command

label .top.l -text Command: -padx 0

entry .top.cmd -width 20 -relief sunken \

-textvariable command

pack .top.l -side left

pack .top.cmd -side left -fill x -expand true

# Set up key binding equivalents to the buttons

bind .top.cmd Run

bind .top.cmd Stop

focus .top.cmd

# Create a text widget to log the output

frame .t

set log [text .t.log -width 80 -height 10 \

-borderwidth 2 -relief raised -setgrid true \

ExecLog 317

III. Tk Basics

-yscrollcommand {.t.scroll set}]

scrollbar .t.scroll -command {.t.log yview}

pack .t.scroll -side right -fill y

pack .t.log -side left -fill both -expand true

pack .t -side top -fill both -expand true

# Run the program and arrange to read its input

proc Run {} {

global command input log but

if [catch {open "|$command |& cat"} input] {

$log insert end $input\n

} else {

fileevent $input readable Log

$log insert end $command\n

$but config -text Stop -command Stop

}

}

# Read and log output from the program

proc Log {} {

global input log

if [eof $input] {

Stop

} else {

gets $input line

$log insert end $line\n

$log see end

}

}

# Stop the program and fix up the button

proc Stop {} {

global input but

catch {close $input}$but config -text "Run it" -command Run

}

Window Title

The first command sets the title that appears in the title bar implemented by the window manager. Recall that dot (i.e., .) is the name of the main window:

wm title . ExecLog

The wm command communicates with the window manager. The window manager is the program that lets you open, close, and resize windows. It imple-ments the title bar for the window and probably some small buttons to close or resize the window. Different window managers have a distinctive look; the figure shows a title bar from twm , a window manager for X.

318 Tk by Example Chap. 22

A Frame for Buttons

A frame is created to hold the widgets that appear along the top of the interface. The frame has a border to provide some space around the widgets: frame .top -borderwidth 10

The frame is positioned in the main window. The default packing side is the top, so -side top is redundant here, but it is used for clarity. The -fill x packing option makes the frame fill out to the whole width of the main window: pack .top -side top -fill x

Command Buttons

Two buttons are created: one to run the command, the other to quit the pro-gram. Their names, .top.quit and .top.run, imply that they are children of the .top frame. This affects the pack command, which positions widgets inside their parent by default:

button .top.quit -text Quit -command exit

set but [button .top.run -text "Run it" \

-command Run]

pack .top.quit .top.run -side right

A Label and an Entry

The label and entry are also created as children of the .top frame. The label is created with no padding in the X direction so that it can be positioned right next to the entry. The size of the entry is specified in terms of characters. The relief attribute gives the entry some looks to set it apart visually on the display. The contents of the entry widget are linked to the Tcl variable command: label .top.l -text Command: -padx 0

entry .top.cmd -width 20 -relief sunken \

-textvariable command

The label and entry are positioned to the left inside the .top frame. The additional packing parameters to the entry allow it to expand its packing space and fill up that extra area with its display. The difference between packing space and display space is discussed in Chapter 23 on page 337:

pack .top.l -side left

pack .top.cmd -side left -fill x -expand true

Key Bindings and Focus

Key bindings on the entry widget provide an additional way to invoke the functions of the application. The bind command associates a Tcl command with an event in a particular widget. The event is generated when the user presses the Return key on the keyboard. The event is generated when the letter c is typed while the Control key is already held down. For the

ExecLog 319III. Tk Basics

events to go to the entry widget, .top.cmd , input focus must be given to the wid-get. By default, an entry widget gets the focus when you click the left mouse but-ton in it. The explicit focus command is helpful for users with the focus-follows-mouse model. As soon as the mouse is over the main window the user can type into the entry:

bind .top.cmd Run

bind .top.cmd Stop

focus .top.cmd

A Resizable Text and Scrollbar

A text widget is created and packed into a frame with a scrollbar. The width and height of the text widget are specified in characters and lines, respec-tively . The setgrid attribute of the text widget is turned on. This restricts the resize so that only a whole number of lines and average-sized characters can be displayed.

The scrollbar is a separate widget in Tk, and it can be connected to different widgets using the same setup as is used here. The text’s yscrollcommand updates the display of the scrollbar when the text widget is modified, and the scrollbar’s command scrolls the associated widget when the user manipulates the scrollbar:

frame .t

set log [text .t.log -width 80 -height 10 \

-borderwidth 2 -relief raised -setgrid true\

-yscrollcommand {.t.scroll set}]

scrollbar .t.scroll -command {.t.log yview}

pack .t.scroll -side right -fill y

pack .t.log -side left -fill both -expand true

pack .t -side top -fill both -expand true

A side effect of creating a Tk widget is the creation of a new Tcl command that operates on that widget. The name of the Tcl command is the same as the Tk pathname of the widget. In this script, the text widget command, .t.log , is needed in several places. However, it is a good idea to put the Tk pathname of an important widget into a variable because that pathname can change if you reor-ganize your user interface. The disadvantage of this is that you must declare the variable with global inside procedures. The variable log is used for this purpose in this example to demonstrate this style.

The Run Procedure

The Run procedure starts the program specified in the command entry . That value is available in the global command variable because of the textvariable attribute of the entry . The command is run in a pipeline so that it executes in the background. The leading | in the argument to open indicates that a pipeline is being created. The catch command guards against bogus commands. The vari-able input is set to an error message, or to the normal open return that is a file

320 Tk by Example Chap. 22

descriptor. The program is started like this:

if [catch {open "|$command |& cat"} input] {

Trapping errors from pipelines.

The pipeline diverts error output from the command through the cat pro-gram. If you do not use cat like this, then the error output from the pipeline, if any, shows up as an error message when the pipeline is closed. In this example it turns out to be awkward to distinguish between errors generated from the pro-gram and errors generated because of the way the Stop procedure is imple-mented. Furthermore, some programs interleave output and error output, and you might want to see the error output in order instead of all at the end.

If the pipeline is opened successfully, then a callback is set up using the fileevent command. Whenever the pipeline generates output, then the script can read data from it. The Log procedure is registered to be called whenever the pipeline is readable:

fileevent $input readable Log

The command (or the error message) is inserted into the log. This is done using the name of the text widget, which is stored in the log variable, as a Tcl command. The value of the command is appended to the log, and a newline is added so that its output will appear on the next line.

$log insert end $command\n

The text widget’s insert function takes two parameters: a mark and a string to insert at that mark. The symbolic mark end represents the end of the contents of the text widget.

The run button is changed into a stop button after the program begins. This avoids a cluttered interface and demonstrates the dynamic nature of a Tk inter-face. Again, because this button is used in a few different places in the script, its pathname has been stored in the variable but:

$but config -text Stop -command Stop

The Log Procedure

The Log procedure is invoked whenever data can be read from the pipeline, and when end of file has been reached. This condition is checked first, and the Stop procedure is called to clean things up. Otherwise, one line of data is read and inserted into the log. The text widget’s see operation is used to position the view on the text so that the new line is visible to the user:

if [eof $input] {

Stop

} else {

gets $input line

$log insert end $line\n

$log see end

}

ExecLog 321

III. Tk Basics

The Stop Procedure

The Stop procedure terminates the program by closing the pipeline. The close is wrapped up with a catch . This suppresses the errors that can occur when the pipeline is closed prematurely on the process. Finally , the button is restored to its run state so that the user can run another command:

catch {close $input}

$but config -text "Run it" -command Run

In most cases, closing the pipeline is adequate to kill the job. On UNIX, this results in a signal, SIGPIPE , being delivered to the program the next time it does a write to its standard output. There is no built-in way to kill a process, but you can exec the UNIX kill program. The pid command returns the process IDs from the pipeline:

foreach pid [pid $input] {

catch {exec kill $pid}

}

If you need more sophisticated control over another process, you should check out the expect Tcl extension, which is described in the book Exploring Expect (Don Libes, O’Reilly & Associates, Inc., 1995). Expect provides powerful control over interactive programs. You can write Tcl scripts that send input to interactive programs and pattern match on their output. Expect is designed to automate the use of programs that were designed for interactive use.

Cross-Platform Issues

This script will run on UNIX and Windows, but not on Macintosh because there is no exec command. One other problem is the binding for to cancel the job. This is UNIX-like, while Windows users expect to cancel a job, and Macintosh users expect . Platform_CancelEvent defines a virtual event, <>, and Stop is bound to it:

Example 22–2A platform-specific cancel event.

proc Platform_CancelEvent {} {

global tcl_platform

switch $tcl_platform(platform) {

unix {

event add <>

}

windows {

event add <>

}

macintosh {

event add <>

}

}}

bind .top.entry <> Stop

322 Tk by Example Chap. 22 There are other virtual events already defined by Tk. The event command and virtual events are described on page 378.

The Example Browser

Example 22–3 is a browser for the code examples that appear in this book. The basic idea is to provide a menu that selects the examples, and a text window to display the examples. Before you can use this sample program, you need to edit it to set the proper location of the exsource directory that contains all the exam-ple sources from the book. Example 22–4 on page 327 extends the browser with a shell that is used to test the examples.

Example 22–3A browser for the code examples in the book.

#!/usr/local/bin/wish

#Browser for the Tcl and Tk examples in the book.

# browse(dir) is the directory containing all the tcl files

# Please edit to match your system configuration.

switch $tcl_platform(platform) {

"unix" {set browse(dir) /cdrom/tclbook2/exsource}

"windows" {set browse(dir) D:/exsource}

"macintosh" {set browse(dir) /tclbook2/exsource}

}

wm minsize . 30 5

wm title . "Tcl Example Browser"

# Create a row of buttons along the top

set f [frame .menubar]

pack $f -fill x

button $f.quit -text Quit -command exit

button $f.next -text Next -command Next

button $f.prev -text Previous -command Previous

# The Run and Reset buttons use EvalEcho that

# is defined by the Tcl shell in Example 22–4 on page 327

button $f.load -text Run -command Run

button $f.reset -text Reset -command Reset

pack $f.quit $f.reset $f.load $f.next $f.prev -side right

# A label identifies the current example

label $https://www.doczj.com/doc/b718251592.html,bel -textvariable browse(current)

pack $https://www.doczj.com/doc/b718251592.html,bel -side right -fill x -expand true

# Create the menubutton and menu

The Example Browser 323

III. Tk Basics

menubutton $f.ex -text Examples -menu $f.ex.m

pack $f.ex -side left

set m [menu $f.ex.m]

# Create the text to display the example

# Scrolled_Text is defined in Example 30–1 on page 428

set browse(text) [Scrolled_Text .body \

-width 80 -height 10\

-setgrid true]

pack .body -fill both -expand true

# Look through the example files for their ID number.

foreach f [lsort -dictionary [glob [file join $browse(dir) *]]] {

if [catch {open $f} in] {

puts stderr "Cannot open $f: $in"

continue

}

while {[gets $in line] >= 0} {

if [regexp {^# Example ([0-9]+)-([0-9]+)} $line \

x chap ex] {

lappend examples($chap) $ex

lappend browse(list) $f

# Read example title

gets $in line

set title($chap-$ex) [string trim $line "# "]

set file($chap-$ex) $f

close $in

break

}

}

}

# Create two levels of cascaded menus.

# The first level divides up the chapters into chunks.

# The second level has an entry for each example.

option add *Menu.tearOff 0

set limit 8

set c 0; set i 0

foreach chap [lsort -integer [array names examples]] {

if {$i == 0} {

$m add cascade -label "Chapter $chap..." \

-menu $m.$c

set sub1 [menu $m.$c]

incr c

}

set i [expr ($i +1) % $limit]

$sub1 add cascade -label "Chapter $chap" -menu $sub1.sub$i

set sub2 [menu $sub1.sub$i ]

foreach ex [lsort -integer $examples($chap)] {

$sub2 add command -label "$chap-$ex $title($chap-$ex)" \

-command [list Browse $file($chap-$ex)]

324 Tk by Example Chap. 22 }

}

# Display a specified file. The label is updated to

# reflect what is displayed, and the text is left

# in a read-only mode after the example is inserted.

proc Browse { file } {

global browse

set browse(current) [file tail $file]

set browse(curix) [lsearch $browse(list) $file]

set t $browse(text)

$t config -state normal

$t delete 1.0 end

if [catch {open $file} in] {

$t insert end $in

} else {

$t insert end [read $in]

close $in

}

$t config -state disabled

}

# Browse the next and previous files in the list

set browse(curix) -1

proc Next {} {

global browse

if {$browse(curix) < [llength $browse(list)] - 1} {

incr browse(curix)

}

Browse [lindex $browse(list) $browse(curix)]

}

proc Previous {} {

global browse

if {$browse(curix) > 0} {

incr browse(curix) -1

}

Browse [lindex $browse(list) $browse(curix)]

}

# Run the example in the shell

proc Run {} {

global browse

EvalEcho [list source \

[file join $browse(dir) $browse(current)]]

}

# Reset the slave in the eval server

proc Reset {} {

EvalEcho reset

}

The Example Browser 325

III. Tk Basics

More about Resizing Windows

This example uses the wm minsize command to put a constraint on the min-imum size of the window. The arguments specify the minimum width and height.These values can be interpreted in two ways. By default they are pixel values.However, if an internal widget has enabled geometry gridding , then the dimen-sions are in grid units of that widget. In this case the text widget enables grid-ding with its setgrid attribute, so the minimum size of the window is set so that the text window is at least 30 characters wide by five lines high:

wm minsize . 30 5

In older versions of Tk, Tk 3.6, gridding also enabled interactive resizing of the window. Interactive resizing is enabled by default in Tk 4.0 and later.

Managing Global State

The example uses the browse array to collect its global variables. This makes it simpler to reference the state from inside procedures because only the array needs to be declared global. As the application grows over time and new features are added, that global command won’t have to be adjusted. This style also serves to emphasize what variables are important. The browse array holds the name of the example directory (dir ), the Tk pathname of the text display (text ), and the name of the current file (current ). The list and curix elements are used to implement the Next and Previous procedures.

Searching through Files

The browser searches the file system to determine what it can display . The tcl_platform(platform) variable is used to select a different example directory on different platforms. You may need to edit the on-line example to match your system. The example uses glob to find all the files in the exsource directory . The file join command is used to create the file name pattern in a platform-inde-pendent way . The result of glob is sorted explicitly so the menu entries are in the right order. Each file is read one line at a time with gets , and then regexp is used to scan for keywords. The loop is repeated here for reference:

foreach f [lsort -dictionary [glob [file join $browse(dir) *]]] {

if [catch {open $f} in] {

puts stderr "Cannot open $f: $in"

continue

}

while {[gets $in line] >= 0} {

if [regexp {^# Example ([0-9]+)-([0-9]+)} $line \

x chap ex] {

lappend examples($chap) $ex

lappend browse(list) $f

# Read example title

gets $in line

set title($chap-$ex) [string trim $line "# "]

set file($chap-$ex) $f

326 Tk by Example Chap. 22 close $in

break

}

}

}

The example files contain lines like this:

# Example 1-1

# The Hello, World! program

The regexp picks out the example numbers with the ([0-9]+)-([0-9]+) part of the pattern, and these are assigned to the chap and ex variables. The x variable is assigned the value of the whole match, which is more than we are interested in. Once the example number is found, the next line is read to get the description of the example. At the end of the foreach loop the examples array has an element defined for each chapter, and the value of each element is a list of the examples for that chapter.

Cascaded Menus

The values in the examples array are used to build up a cascaded menu structure. First a menubutton is created that will post the main menu. It is asso-ciated with the main menu with its menu attribute. The menu must be a child of the menubutton for its display to work properly:

menubutton $f.ex -text Examples -menu $f.ex.m

set m [menu $f.ex.m]

There are too many chapters to put them all into one menu. The main menu has a cascade entry for each group of eight chapters. Each of these submenus has a cascade entry for each chapter in the group, and each chapter has a menu of all its examples. Once again, the submenus are defined as a child of their par-ent menu. Note the inconsistency between menu entries and buttons. Their text is defined with the -label option, not -text. Other than this they are much like buttons. Chapter 27 describes menus in more detail. The code is repeated here: set limit 8 ; set c 0 ; set i 0

foreach key [lsort -integer [array names examples]] {

if {$i == 0} {

$m add cascade -label "Chapter $key..." \

-menu $m.$c

set sub1 [menu $m.$c]

incr c

}

set i [expr ($i +1) % $limit]

$sub1 add cascade -label "Chapter $key" -menu $sub1.sub$i

set sub2 [menu $sub1.sub$i]

foreach ex [lsort -integer $examples($key)] {

$sub2 add command -label "$key-$ex $title($key-$ex)" \

-command [list Browse $file($key-$ex)]

}

}

A Tcl Shell 327

III. Tk Basics

A Read-Only Text Widget

The Browse procedure is fairly simple. It sets browse(current) to be the name of the file. This changes the main label because of its textvariable attribute that links it to this variable. The state attribute of the text widget is manipulated so that the text is read-only after the text is inserted. You have to set the state to normal before inserting the text; otherwise, the insert has no effect. Here are a few commands from the body of Browse :

global browse

set browse(current) [file tail $file]

$t config -state normal

$t insert end [read $in]

$t config -state disabled

A Tcl Shell

This section demonstrates the text widget with a simple Tcl shell application. It uses a text widget to prompt for commands and display their results. It uses a second Tcl interpreter to evaluate the commands you type. This dual interpreter structure is used by the console built into the Windows and Macintosh versions of wish . The TkCon application written by Jeff Hobbs is an even more elaborate console that has many features to support interactive Tcl use.

Example 22–4 is written to be used with the browser from Example 22–3 in the same application. The browser’s Run button runs the current example in the shell. An alternative is to have the shell run as a separate process and use the send command to communicate Tcl commands between separate applications.That alternative is shown in Example 40–2 on page 563.

Example 22–4A Tcl shell in a text widget.

#!/usr/local/bin/wish

# Simple evaluator. It executes Tcl in a slave interpreter

set t [Scrolled_Text .eval -width 80 -height 10]

pack .eval -fill both -expand true

# Text tags give script output, command errors, command

# results, and the prompt a different appearance

$t tag configure prompt -underline true

$t tag configure result -foreground purple

$t tag configure error -foreground red

$t tag configure output -foreground blue

# Insert the prompt and initialize the limit mark

set eval(prompt) "tcl> "

$t insert insert $eval(prompt) prompt

$t mark set limit insert

328 Tk by Example Chap. 22 $t mark gravity limit left

focus $t

set eval(text) $t

# Key bindings that limit input and eval things. The break in

# the bindings skips the default Text binding for the event.

bind $t {EvalTypein ; break}

bind $t {

if {[%W tag nextrange sel 1.0 end] != ""} {

%W delete sel.first https://www.doczj.com/doc/b718251592.html,st

} elseif {[%W compare insert > limit]} {

%W delete insert-1c

%W see insert

}

break

}

bind $t {

if [%W compare insert < limit] {

%W mark set insert end

}

}

# Evaluate everything between limit and end as a Tcl command

proc EvalTypein {} {

global eval

$eval(text) insert insert \n

set command [$eval(text) get limit end]

if [info complete $command] {

$eval(text) mark set limit insert

Eval $command

}

}

# Echo the command and evaluate it

proc EvalEcho {command} {

global eval

$eval(text) mark set insert end

$eval(text) insert insert $command\n

Eval $command

}

# Evaluate a command and display its result

proc Eval {command} {

global eval

$eval(text) mark set insert end

if [catch {$eval(slave) eval $command} result] {

$eval(text) insert insert $result error

} else {

$eval(text) insert insert $result result

}

if {[$eval(text) compare insert != "insert linestart"]} {

A Tcl Shell 329

III. Tk Basics

$eval(text) insert insert \n

}

$eval(text) insert insert $eval(prompt) prompt

$eval(text) see insert

$eval(text) mark set limit insert

return

}

# Create and initialize the slave interpreter

proc SlaveInit {slave} {

interp create $slave

load {} Tk $slave

interp alias $slave reset {} ResetAlias $slave

interp alias $slave puts {} PutsAlias $slave

return $slave

}

# The reset alias deletes the slave and starts a new one

proc ResetAlias {slave} {

interp delete $slave

SlaveInit $slave

}

# The puts alias puts stdout and stderr into the text widget

proc PutsAlias {slave args} {

if {[llength $args] > 3} {

error "invalid arguments"

}

set newline "\n"

if {[string match "-nonewline" [lindex $args 0]]} {

set newline ""

set args [lreplace $args 0 0]

}

if {[llength $args] == 1} {

set chan stdout

set string [lindex $args 0]$newline

} else {

set chan [lindex $args 0]

set string [lindex $args 1]$newline

}

if [regexp (stdout|stderr) $chan] {

global eval

$eval(text) mark gravity limit right

$eval(text) insert limit $string output

$eval(text) see limit

$eval(text) mark gravity limit left

} else {

puts -nonewline $chan $string

}}

set eval(slave) [SlaveInit shell]

330 Tk by Example Chap. 22 Text Marks, Tags, and Bindings

The shell uses a text mark and some extra bindings to ensure that users only type new text into the end of the text widget. A mark represents a position in the text that is updated as characters are inserted and deleted. The limit mark keeps track of the boundary between the read-only area and the editable area. The insert mark is where the cursor is displayed. The end mark is always the end of the text. The EvalTypein procedure looks at all the text between limit and end to see if it is a complete Tcl command. If it is, it evaluates the com-mand in the slave interpreter.

The binding checks to see where the insert mark is and bounces it to the end if the user tries to input text before the limit mark. The puts alias sets right gravity on limit, so the mark is pushed along when program output is inserted right at limit. Otherwise, the left gravity on limit means that the mark does not move when the user inserts right at limit.

Text tags are used to give different regions of text difference appearances. A tag applies to a range of text. The tags are configured at the beginning of the script and they are applied when text is inserted.

Chapter 33 describes the text widget in more detail.

Multiple Interpreters

The SlaveInit procedure creates another interpreter to evaluate the com-mands. This prevents conflicts with the procedures and variables used to imple-ment the shell. Initially, the slave interpreter only has access to Tcl commands. The load command installs the Tk commands, and it creates a new top-level win-dow that is "." for the slave interpreter. Chapter 20 describes how you can embed the window of the slave within other frames.

The shell interpreter is not created with the -safe flag, so it can do any-thing. For example, if you type exit, it will exit the whole application. The SlaveInit procedure installs an alias, reset, that just deletes the slave inter-preter and creates a new one. You can use this to clean up after working in the shell for a while. Chapter 19 describes the interp command in detail.

Native Look and Feel

When you run a Tk script on different platforms, it uses native buttons, menus, and scrollbars. The text and entry widgets are tuned to give the applica-tion the native look and feel. The following screen shots show the combined browser and shell as it looks on Macintosh, Windows, and UNIX.

A Tcl Shell 331III. Tk Basics

Example 22–5Macintosh look and feel.

Example 22–6

Windows look and feel.

332 Tk by Example Chap. 22 Example 22–7UNIX look and feel.

发散思维案例

发散思维案例 案例1 有一个古老的智力题:“树上有10只鸟,打死1只,还有几只?”最笨的回答是:“打死1只,还有9只。”最聪明的,也是被认为 唯一正确的答案是:“打死1只,就一只也没有了,因为它们都被 吓跑了。”在一次教学实践中,我还听到学生们说出了下面一些答案: 1、还有1只死鸟挂在树上; 2、还有9只,因为是用无声手枪击中的; 3、还有2只,树上鸟窝里有2只不会飞的雏鸟; 4、还有9只,在风雨交加的天气,枪声被掩盖了; 5、还有1只,这只鸟是聋子; 6、还有10只,因为它们受伤飞不起来了; 案例2 有一只猪四百斤,一座桥承重两百斤,猪怎么过桥?条件: 1.猪是活猪,任何解决方案都不得切割猪 2.故事发生在猪王国,不要引入人的因素 3.是过桥,不是过河,不要说是游泳过去 4.是过桥,不是过涧,不要说是飞过去丫 5.桥是承重两百斤的桥,把桥挪到平地上抑或过另一座承重超过四百斤的桥都属改变性状 6.不是文字游戏,不要说“猪晕过去了” 1、立体思维

思考问题时跳出点、线、面的限制,立体式进行思维。 立体绿化:屋顶花园增加绿化面积、减少占地改善环境、净化空气。 立体农业、间作:如玉米地种绿豆、高粱地里种花生等 立体森林:高大乔木下种灌木、灌木下种草,草下种食用菌。 立体渔业:网箱养鱼充分利用水面、水体 立体开发资源:煤、石头、开发产品 你还能想出什么样的立体思维形式? 2、平面思维 以构思二维平面图形为特点的发散思维形式如用一支笔一张纸一笔画出圆心和圆周。 这种不连续的图形是难以一笔画出的 发散思维 3、逆向思维 背逆通常的思考方法。从相反方向思考问题的方法,也叫做反向思维。因为客观世界上许多事物之间甲能产生乙,乙也能产生甲。如:化学能能产生电能据此意大利科学家伏特1800年发明了伏打电池。反过来电能也能产生化学能,通过电解,英国化学家戴维1807年发现了钾、钠、钙、镁、锶、钡、硼等七种元素。 如说话声音高低能引起金属片相应的振动,相反金属片的振动也可以引起声音高低的变化。爱迪生在对电话的改进中,发明制造了世界上第一台留声机。 那么如何进行逆向思维呢? 1)就事物依存的条件逆向思考,如小孩掉进水里,把人从水中救起,是使人脱离水,司马光救人是打破缸,使水脱离人,这就是逆向思维。

互联网思维落地十大法则 超多案例(3)

互联网思维落地十大法则超多案例(3) 360的创始人周鸿祎先生,他说:“假设说,华夏银行请我吃饭,我打开一瓶矿泉水,喝完之后,它确实是矿泉水,这叫体验吗?这不叫体验。只有把一个东西做到极致,超出 预期才叫体验。我开个玩笑:比如有人递过一个矿泉水瓶子,我一喝里面全是50度的茅台——这个就超出我的体验嘛。 假设它是一个体验,我(作为用户)就会到处讲“我到哪儿吃饭,我以为是矿泉水,结果里面是茅台”,如果我就这个经历写一个微博发出来,绝对能转发500次以上。” 法则六:Iterative 快速迭代——边开枪,边瞄准这里的迭代思维,对传统企 业而言,更侧重在迭代的意识,意味着我们必须要及时乃至实时关注消费者需求,把握消费者需求的变化。要从细微的用户需求入手,贴近用户心理,在用户参与和反馈中逐步改进。“敏捷开发”是互联网产品开发的典型方法论,是一种以 人为核心、迭代、循序渐进的开发方法,允许有所不足,不断试错,在持续迭代中完善产品。乔布斯曾举了一个例,强调商业伦理和细节的重要性,“如果你是个正在打造漂亮衣柜的木匠,你不会在背面使用胶合板,即使它冲着墙壁,没有人会看见。但你自己心知肚明,所以你依然会在背面使用一块漂亮的木料。为了能在晚上睡个安稳觉,美观和质量必须贯穿始终。” “天下武功,唯快不破”,只有快速地对消费者需

求做出反应,产品才更容易贴近消费者。Zynga游戏公司每周对游戏进行数次更新,小米MIUI系统坚持每周迭代,就连雕爷牛腩的菜单也是每月更新。微信在推出后1年内迭代开发44次,小米手机每周都有四五十个BUG(漏洞)要修改。边开枪,边瞄准,精益求精。做到快速失败(fail fast),廉价地失败(fail cheap),同时整个组织要有一种包容失败的文化(Inclusive Culture) 传统的商业思维则讲究大而全、讲究周密控制,做决策时往往要通盘考虑各方面的影响,调动各方面的资源,很难快得起来。传统企业的产品从研发到投放到更新按年来算,对消费者的影响方式也是投一轮广告,卖一轮产品,几个运动下来才有可能让消费者记住你。但互联网时代讲究小步快跑、快速迭代,节奏是按周算的。法则七:My favorite给我想要的——知我,懂我在一次论坛上,当当网CEO李国庆先生曾跟我讲过这样一件“尴尬”的事情:有位女顾客在当当网上买了一些怀孕方面的书籍,此后一年多她几乎每次都收到类似的书籍推荐,不堪其扰的她一怒之下直接向李国庆投诉,此事才宣告结束。比我更懂我,通过大数据推荐我想要的。我们可以通过移动互联网,加速推进自己的数字化进程,建立对消费者的洞察,无论何时何地,我们都要尽可能及时的、精确的收集到每个顾客所有购物活动相关涉及到的顾客的所有的数据,数字化每一个顾客,每一件商品和他们的每一个购物活动,最终还原每个顾客的原

发散思维

发散思维 平阴县第二中学张树峰第八周 目标: 让学生了解发散思维的概念、特征及其应用,学会有效运用发散思维思考问题、分析问题、解决问题,培养发散思维能力。 重点:学会有效运用发散思维思考问题、分析问题、解决问题。 难点:运用发散思维解决实际问题。 教学过程 第一课时 一、导入 1、师:同学们一定都听过龟兔赛跑的故事,故事中兔子为什么失败? 因为它在途中睡了一觉。 2、师:假如故事中没写明原因,让你来猜,你会想到什么原因? …… 3、展示课本中“龟兔赛跑、兔子为什么落后”的发散思维图: 根据图示,引出发散思维概念。 二、了解发散思维的概念 1、Ppt打出发散思维的概念:发散思维又称辐射思维、放射思维、扩散思维或求异思维,是指大脑在思维时呈现的一种扩散状态的思维模式。 图示:

2、通过对“铅笔的用途”进行发散思维,加深对概念的理解: (1)让学生不看书,在P23页横线上写出铅笔除书写、画画以外的用途; (2)看书上例举的铅笔的用途。 小结:这就是典型的发散思维解决问题的方法,这种方法可以做到一题多解、一事多写、一物多用。有不少心理学家认为,发散思维是创造性思维的一个最主要的特点,是测定一个人或一个团队的创造力的主要指标之一。所以学会这种思维方法对任何一个人都非常重要。 三、发散思维的特征 Ppt显示发散思维的三个特征:流畅性、变通性和独特性。 下面通过一些例子帮助学生理解发散思维的三个特征: (一)流畅性 1、Ppt显示什么是流畅性: 流畅性指在尽可能短的时间内生成尽可能多的思维火花,产生心可能多的方式和方法,表达出尽可能多的思想和观念。 2、让学生看书上的例子:如果你有了钱可以干什么? 儿童A答:买可乐、买玩具车;

管理学经典案例20篇.docx

管理学经典案例 20 篇 1.安通公司的投资决策 安通公司是一家特种机械制造公司。该公司下设10个专业工厂,分布在全国 10 个省市,拥有 20 亿资产, 8 万员工,其中本部员工200 人。本部员工中60%以上技术管理人员,基本都是学特种机械专业的。该公司所属企业所生产的产品 由政府有关部门集中采购,供应全国市场。 改革开放以来,安通公司的生产经营呈现较好的局面,在机械行业普遍不景气的 情况下,该公司仍保持各厂都有较饱和的产品。但是,进入90 年代以后,国内市场开始呈现供大于求的趋势。政府有关部门的负责人曾透露,如果三年不买安通公司的产品,仍可维持正常生产经营。面对这样的新形势,安通公司领导连续 召开两次会议,分析形势,研究对策。 第一次会议专门分析形势。刘总经理主持会议,他说,安通公司要保持良好的发 展趋势,取得稳定的效益,首先必须分析形势,认清形势,才能适应形势。我们 的产品在全国市场已经趋于饱和。如果不是有政府主管部门干预和集中采购,我们的生产能力一下子就过剩30%,甚至更多。我们应该对此有清醒的认识负责经 营的李副总经理说,改革开放以来,全公司的资金利润率达到了8%左右,局全国机械行业平均水平之上。但是现在产品单一,又出现供大于求的趋势,今后再 保持这样的发展水平很难。目前,公司本部和各厂都有富裕资金和富余人员,应该做出新的选择。分管技术工作的赵副总经理说,总公司和各厂的产品特别是有 一部分产品通过近几年引进国外先进技术,基本是能满足国内市场目前的需要, 总公司和各厂的专业技术力量很强,如果没有新产品持续不断开发出来,单靠现有老产品很难使本行业有较大发展,专业人员也要流失。其他的副总们也都从各 自的角度分析了安通公司所面临的形势,大家都感到这次会议开得及时,开得必要。 第二次会议仍有刘总主持。他说,我们上次会议全面分析了形势,使我们大家头脑更清醒,认识更加一至,这就是总公司要适应新形势,必须研究自己的发展战略。分管经营的李副总说,我们应该充分利用富余人员和富余资金,寻找新的门路,发展多种经营。要敢于进入机械行业外的产品。现在,国家不是提倡发展第 三产业吗,我们应该利用国家的优惠政策,开展多种经营,取得更好的经济效益。分管技术的赵总谈到,安通公司的产品虽然经过引进国外先进技术,已经升级换代,但是和国际先进水平比还有相当差距。我们现在应该充分利用技术力量和资 金,进一步引进技术,开发新产品,为国内市场作一些储备,以适应未来市场的需要,同时争取把产品打到国际市场上去。其他各位老总也都一致认为,安通公司必须发展,不能停滞不前。大家认为,安通公司是一个专业化很强的企业,虽 然现在主产品是供大于求的趋势,但现在特别是将来还是有比较稳定的市场的, 这个主业绝不能放松,但是单靠这个主业要想过得富裕是不行的,要不断地开辟

发散思维的例子

发散思维的例子 发散思维的例子一: 心理学家曾做过这样的试验:在黑板上画一个圆圈,问在座学生这是什么?其中大学生回答很一致:“这是一个圆。”而幼儿园的小朋友则给出了各种各样的答案:“太陽”、“皮球”、“镜子”……可谓五花八门。或许大学生的答案更加符合所画的图形,但是比起幼儿园孩子来说他们的答案是不是显得有些单调呆板呢? 发散思维的例子二: 1987年,我国在广西省南宁市召开了我国“创造学会”第一次学术研讨会。这次会议集中了全国许多在科学、技术、艺术等方面众多的杰出人才。为扩大与会者的创造视野,也聘请了国外某些著名的专家、学者。 其中有日本的村上幸雄先生。在会议中请村上幸雄先生为与会者讲学。他讲了三个半天,讲的很新奇,很有魅力,也深受大家的欢迎。其间,村上幸雄先生拿出一把曲别针,请大家动动脑筋,打破框框,想想曲别针都有什么用途?比一比看谁的发散性思维好。会议上一片哗然,七嘴八舌,议论纷纷。有的说可以别胸卡、挂日历、别文件,有的说可以挂窗帘、钉书本,大约说出了二十余种,大家问村上幸雄,“你能说出多少种”?村上幸雄轻轻地伸出三个指头。 有人问:“是三十种吗”?他摇摇头,“是三百种吗?”他仍然摇头,他说:“是三千种”,大家都异常惊讶,心里说:“这日本人果真聪明”。

然而就在此时,坐在台下的一位先生,他是中国魔球理论的创始人、著名的许国泰先生心里一阵紧缩,他想,我们中华民族在历史上就是以高智力著称世界的民族,我们的发散性思维绝不会比日本人差。于是他给村上幸雄写了个条子说:“幸雄先生,对于曲别针的用途我可 以说出三千种、三万种”。幸雄十分震惊,大家也都不十分相信。 许先生说:“幸雄所说曲别针的用途我可以简单地用四个字加以概括,即钩、挂、别、联。我认为远远不止这些。接着他把曲别针分解为铁质、重量、长度、截面、弹性、韧性、硬度、银白色等十个要素,用一条直线连起来形成信息的栏轴,然后把要动用的曲别针的各种要素用直线连成信息标的竖轴。再把两条轴相交垂直延伸,形成一个信息反应场,将两条轴上的信息依次“相乘”,达到信息交合……” 于是曲别针的用途就无穷无尽了。例如可加硫酸可制氢气,可加工 成弹簧、做成外文字母、做成数学符号进行四则运算等等,为中国人民在大会上创出了奇迹,使许多外国人十分惊讶!故事告诉我们发散性思维对于一个人的智力、创造力多么重要。 发散思维的例子三:一片叶子 一、在孩子、男人、女人、老人看来会有不同的认识,而在不同的 孩子、不同的老人看来又会不同,在不同的职业看来也会不同,还有不同的阶层、不同的地域…… 一片叶子,是绿色、是椭圆、是希望、是好心情…… 画家看来是一幅美丽的画

OpenLayers二维地图使用教程

OpenLayers 1 OpenLayers简介 OpenLayers是由MetaCarta公司开发的,用于WebGIS客户端的JavaScript包。它实现访问地理空间数据的方法都符合行业标准,比如OpenGIS的WMS和WFS规范,OpenLayers 采用纯面向对象的JavaScript方式开发,同时借用了Prototype框架和Rico库的一些组件。采用OpenLayers作为客户端不存在浏览器依赖性。由于OpenLayers采用JavaScript语言实 现,而应用于Web浏览器中的DOM(文档对 象模型)由JavaScript实现,同时,Web浏览 器(比如IE,FF等)都支持DOM。OpenLayers APIs采用动态类型脚本语言JavaScript编写, 实现了类似与Ajax功能的无刷新更新页面, 能够带给用户丰富的桌面体验(它本身就有一 个Ajax类,用于实现Ajax功能)。 目前,OpenLayers所能够支持的Format有:XML、GML、GeoJSON、GeoRSS、JSON、KML、WFS、WKT(Well-Known Text)。在OPenlayers.Format名称空间下的各个类里,实现了具体读/写这些Format的解析器。OpenLayers所能够利用的地图数据资源“丰富多彩”,在这方面提供给拥护较多的选择,比如WMS、WFS、GoogleMap、KaMap、MSVirtualEarth、WorldWind等等。当然,也可以用简单的图片作为源。 在操作方面,OpenLayers 除了可以在浏览器中帮助开发者实现地图浏览的基本效果,比如放大(Zoom In)、缩小(Zoom Out)、平移(Pan)等常用操作之外,还可以进行选取面、选取线、要素选择、图层叠加等不同的操作,甚至可以对已有的OpenLayers 操作和数据支持类型进行扩充,为其赋予更多的功能。例如,它可以为OpenLayers 添加网络处理服务WPS 的操作接口,从而利用已有的空间分析处理服务来对加载的地理空间数据进行计算。同时,在OpenLayers提供的类库当中,它还使用了类库Prototype.js 和Rico 中的部分组件,为地图浏览操作客户端增加Ajax效果。 2 Openlayers基本使用方法 Openlayers是使用Javascript编写的脚本,与网页设计技术密切相关,因此在使用之前需要掌握一定得相关知识,例如html、css、javascript等。编辑工具推荐使用:EditPlus。 1)下载并拷贝源代码即相关文件 到Openlayers官方网站https://www.doczj.com/doc/b718251592.html,下载源代码压缩包,解压后可以看到其中的一些目录和文件。需要拷贝的文件和目录有:根目录下的【OpenLayer.js】文件、根目录下的【lib】目录、根目录下的【img】目录、根目录下的【theme】目录。将这4项内容拷贝到你网站的Scripts目录下(当然,这个只是例子,自己的网站程序目录结构自己说了算,只要保证OpenLayers.js,/lib,/img,/theme在同一目录中即可)。

中国最经典的七大人才案例

;中国历史悠久,各种人才智慧的学说纷呈,而人才智慧的典范更是举不胜举。中国是一个智慧大成的民族,人才智慧的经典案例,让人拍案叫绝,下面精选几例,供大家借鉴。引才案例:秦昭王五跪得范睢。引才纳贤是国家强盛的根本,而人才,尤其是高才,并不那么容易引得到,纳得着。秦昭王雄心勃勃,欲一统天下,在引才纳贤方面显示了非凡的气度。范睢原为一隐士,熟知兵法,颇有远略。秦昭王驱车前往拜访范睢,见到他便屏退左右,跪而请教:“请先生教我?”但范睢支支吾吾,欲言又止。于是,秦昭王“第二次跪地请教”,且态度上更加恭敬,可范睢仍不语。秦昭王又跪,说:“先生卒不幸教寡人邪?”这第三跪打动了范睢,道出自己不愿进言的重重顾虑。秦昭王听后,第四次下跪,说道:“先生不要有什么顾虑,更不要对我怀有疑虑,我是真心向您请教。”范睢还是不放心,就试探道:“大王的用计也有失败的时候。”秦昭王对此责并没有发怒,并领悟到范睢可能要进言了,于是,第五次跪下,说:“我愿意听先生说其详”。言辞更加恳切,态度更加恭敬。这一次范睢也觉得时机成熟,便答应辅佐秦昭王,帮他统一六国。后来,范睢鞠躬尽瘁地辅佐秦昭王成就霸业,而秦昭王五跪得范睢的典故,千百年来被人们所称誉,成为引才纳贤的楷模。今天的企业老板做何感想,将如何引才纳贤?秦昭王五跪得范睢的典故,是否有老板们来做续呢?识才案例:一双筷子放弃了周亚夫。如果说引才,只需要态度友好就够了,识才却是很神秘的工作。所谓识才不只是看看谁是人才,谁不是人才这么简单。而要从小的方面推断大的方面,从今天的行为推断以后的行为,得出用人策略。周亚夫是汉景帝的重臣,在平定七国之乱时,立下了赫赫战功,官至丞相,为汉景帝献言献策,忠心耿耿。一天汉景帝宴请周亚夫,给他准备了一块大肉。但是没有切开,也没有准备筷子。周亚夫很不高兴,就向内侍官员要了双筷子。汉景帝笑着说:“丞相,我赏你这么大块肉吃,你还不满足吗?还向内侍要筷子,很讲究啊!”周亚夫闻言,急忙跪下谢罪。汉景帝说:“既然丞相不习惯不用筷子吃肉,也就算了,宴席到此结束。”于是,周亚夫只能告退,但心理很郁闷。这一切汉景帝都看在眼里,叹息到:“周亚夫连我对他的不礼貌都不能忍受,如何能忍受少主年轻气盛呢”。汉景帝通过吃肉这件小事,试探出周亚夫不适合做太子的辅政大臣。汉景帝认为,周亚夫应把赏他的肉,用手拿着吃下去,才是一个臣子安守本分的品德,周亚夫要筷子是非分的做法。汉景帝依此推断,周亚夫如果辅佐太子,肯定会生出些非分的要求,趁早放弃了他做太子辅政大臣的打算。识才的策略与传说贯穿中国五行年历史,汉景帝只是其中的一个代表。今天的企业老板们是否也要向汉景帝学点什么?识才的奥妙深着呢!用才案例:神偷请战。用人之道,最重要的,是要善于发现、发掘、发挥属下的一技之长。用人得当,事半功倍。楚将子发爱结交有一技之长的人,并把他们招揽到麾下。有个人其貌不扬,号称“神偷”的人,也被子发待为上宾。有一次,齐国进犯楚国,子发率军迎敌。交战三次,楚军三次败北。子发旗下不乏智谋之士、勇悍之将,但在强大的齐军面前,简直无计可施了。这时神偷请战,在夜幕的掩护下,他将齐军主帅的睡帐偷了回来。第二天,子发派使者将睡帐送还给齐军主帅,并对他说:“我们出去打柴的士兵捡到您的帷帐,特地赶来奉还。”当天晚上,神偷又去将齐军主帅的枕头偷来,再由子发派人送还。第三天晚上,神偷连齐军主帅头上的发簪子都偷来了,子发照样派人送还。齐军上下听说此事,甚为恐惧,主帅惊骇地对幕僚们说:“如果再不撤退,恐怕子发要派人来取我的人头了。”于是,齐军不战而退。人不可能每一方面都出色,但也不可能每一方面都差劲,再逊的人总有一方面较他人一日之长。企业老板们要能很清楚地了解每个下属的优缺点,千万不能夹杂个人喜好,也许你今天看不起的某个人,他日正是你事业转机的干将。育才案例:纪浪子训鸡喻育才。一般情况下,人才到位须进行培训,并且育才是企业永久的工程,用才而不育才,人才便没有持续竞争力。据传,周宣王爱好斗鸡,纪浪子是一个有名的斗鸡专家,被命去负责饲养斗鸡。10天后,宣王催问道:训练成了吗?纪浪子说:还不行,它一看见别的鸡,或听到别的鸡叫,就跃跃欲试。又过了10天,宣王问训练好了没有,纪浪子说:还不行,心神还相当活跃,火气还没有消退。再过了10天,宣王又说道:怎么样?难

八大思维的经典案例

一、创新思维 1、在一个专门收集世界名画的美术馆,每幅画都投了一份巨额保险。可是美术馆新购进一副非常有名的画家的代表作,却没给这幅画投保险。 你知道这是为什么吗? 解答:那是一幅壁画 有六个小朋友要平均吃五块蛋糕,但不能切碎,而且任何一块蛋糕切成三块以上,你知道怎么分切这5块蛋糕吗? 解答:先把三块蛋糕各切成平均的两半,然后分给6个小朋友。然后把另外两块蛋糕分别切成三等份,再分给6个小朋友,这样每个人就得到了一个半块和1/3块。 二、发散思维 1、尽可能想象“△”和什么东西相似或相近? 解答:和“△”相似或相近的东西有:馒头、涵洞、峭石、山峰、堡垒、城门、隧道口、喷水池、橱窗、问讯窗口、尼龙秧棚、坟墓、萌芽、彩虹、乌篷船、抛物红、仙鹤戏水、镜片、电视机屏幕、枪洞、子弹头、树荫、海上日出、跳水、弯腰、插秧、拱桥、盾牌、活页木铁夹、天边浮云、英文字母“D”等等。回答得越多,发散思维的流畅程度越高。 2、古时候,有兄弟三人。大哥、二哥好吃懒做,三弟勤劳聪明。三人长大后都成了家。有一天,三兄弟在一起喝酒,大哥、二哥提议:“从现在起,我们三人说话,互相不准怀疑,否则罚米一斗。”酒后,大哥说:“你们总说我好吃懒做,现在家里那只母鸡一报晓,我就起床了……”三弟直摇头说:“哪有母鸡报晓之理?”大哥嘿嘿一笑说:“好!你不信我的话,罚米一斗。”二哥接下去说:“我没有大哥这么勤快,因此家里穷得老鼠撵得猫吱吱叫……”三弟又连连摇头,二哥得意地说:“你不信,也罚米一斗。”后来…… 三、收敛思维

1、高尔基童年在食品店干杂活,曾碰到过一位刁钻的顾客,“订九块蛋糕,但要装在四个盒子里,而且每个盒子里至少要装三块蛋糕”。 解答:高尔基的办法是:先将九个蛋糕分装在三个盒子里,每盒三块;然后再把这三个盒子一起装在一个大盒子里,用包装袋扎好。 2、你的面前摆着四种物品: 一本平装书; 一瓶百事可乐; 一根纯金项链; 一台彩色电视机。 请从上述四种物品中找出一种“与众不同”的物品;然后,再找出两两物品之间的共同之处。 解答: 平装书是唯一用纸做成的、供人阅读的物品; 可乐是唯一由液体构成、供人饮用的物品; 项链是唯一用纯金制作的、戴在身上的装饰品; 电视是唯一能把无线电波转换成声音和图像的物品。 平装书与可乐属于“价格低廉品”;平装书与电视属于“信息用品”;可乐与电视属于“诞生于现代的物品”;项链与电视属于“贵重物品”······ 四、类比思维 1、棒球:投手 篮球:得分手 B.拳击:对手 C.足球:射手 D.橄榄球:四分卫

openlayers经典例子

Openlayers经典例子 案例地址 (2) 一. Popup (2) 二、图层叠加 (3) 三、编辑功能 (5) 四、鹰眼 (7) 五、书签及样式 (7) 六、改变显示内容 (9) 七、SLD (9) 八、动画效果 (10) 九、获得属性 (11) 十、局部放大 (12) 十一、记录上次操作历史 (12) 十二、鼠标滚轮 (13) 十三、鼠标坐标 (13) 十四、标签 (14) 十五、全屏 (14) 十六、显示缩放比例 (15)

案例地址 https://www.doczj.com/doc/b718251592.html,/releases/OpenLayers-2.10/examples/ https://www.doczj.com/doc/b718251592.html,/dev/examples/ 一.Popup https://www.doczj.com/doc/b718251592.html,/dev/examples/sundials.html https://www.doczj.com/doc/b718251592.html,/dev/examples/sundials-spherical-mercator.html

https://www.doczj.com/doc/b718251592.html,/dev/examples/select-feature-openpopup.html 二、图层叠加 https://www.doczj.com/doc/b718251592.html,/dev/examples/layerswitcher.html

https://www.doczj.com/doc/b718251592.html,/dev/examples/wmts-getfeatureinfo.html https://www.doczj.com/doc/b718251592.html,/dev/examples/wmts-capabilities.html

古代最经典的七个人才案例

古代最经典的七个人才案例 中国历史悠久,各种人才智慧的学说纷呈,而人才智慧的典范更是举不胜举。中国是一个智慧大成的民族,人才智慧的经典案例,让人拍案叫绝,下面精选几例,供大家借鉴。 引才案例:秦昭王五跪得范睢。 引才纳贤是国家强盛的根本,而人才,尤其是高才,并不那么容易引得到,纳得着。秦昭王雄心勃勃,欲一统天下,在引才纳贤方面显示了非凡的气度。范睢原为一隐士,熟知兵法,颇有远略。秦昭王驱车前往拜访范睢,见到他便屏退左右,跪而请教:“请先生教我?”但范睢支支吾吾,欲言又止。于是,秦昭王“第二次跪地请教”,且态度上更加恭敬,可范睢仍不语。秦昭王又跪,说:“先生卒不幸教寡人邪?”这第三跪打动了范睢,道出自己不愿进言的重重顾虑。秦昭王听后,第四次下跪,说道:“先生不要有什么顾虑,更不要对我怀有疑虑,我是真心向您请教。”范睢还是不放心,就试探道:“大王的用计也有失败的时候。”秦昭王对此责并没有发怒,并领悟到范睢可能要进言了,于是,第五次跪下,说:“我愿意听先生说其详”。言辞更加恳切,态度更加恭敬。这一次范睢也觉得时机成熟,便答应辅佐秦昭王,帮他统一六国。后来,范睢鞠躬尽瘁地辅佐秦昭王成就霸业,而秦昭王五跪得范睢的典故,千百年来被人们所称誉,成为引才纳贤的楷模。 今天的企业老板做何感想,将如何引才纳贤?秦昭王五跪得范睢的典故,是否有老板们来做续尼? 识才案例:一双筷子放弃了周亚夫。 如果说引才,只需要态度友好就够了,识才却是很神秘的工作。所谓识才不只是看看谁是人才,谁不是人才这么简单。而要从小的方面推断大的方面,从今天的行为推断以后的行为,得出用人策略。周亚夫是汉景帝的重臣,在平定七国之乱时,立下了赫赫战功,官至丞相,为汉景帝献言献策,忠心耿耿。一天汉景帝宴请周亚夫,给他准备了一块大肉。但是没有切开,也没有准备筷子。周亚夫很不高兴,就向内侍官员要了双筷子。汉景帝笑着说:“丞相,我赏你这么大块肉吃,你还不满足吗?还向内侍要筷子,很讲究啊!”周亚夫闻言,急忙跪下谢罪。汉景帝说:“既然丞相不习惯不用筷子吃肉,也就算了,宴席到此结束。”于是,周亚夫只能告退,但心理很郁闷。这一切汉景帝都看在眼里,叹息到:“周亚夫连我对他的不礼貌都不能忍受,如何能忍受少主年轻气盛呢”。汉景帝通过吃肉这件小事,试探出周亚夫不适合做太子的辅政大臣。汉景帝认为,周亚夫应把赏他的肉,用手拿着吃下去,才是一个臣子安守本分的品德,周亚夫要筷子是非分的做法。汉景帝依此推断,周亚夫如果辅佐太子,肯定会生出些非分的要求,趁早放弃了他做太子辅政大臣的打算。 识才的策略与传说贯穿中国五行年历史,汉景帝只是其中的一个代表。今天的企业老板们是否也要向汉景帝学点什么?识才的奥妙深着呢! 用才案例:神偷请战。 用人之道,最重要的,是要善于发现、发掘、发挥属下的一技之长。用人得当,事半功倍。楚将子发爱结交有一技之长的人,并把他们招揽到麾下。有个人其貌不扬,号称“神偷”的人,

Openlayers教程

OpenLayers教程 1开始使用openlayers 1.1设置 先到它的官方网站https://www.doczj.com/doc/b718251592.html,下载他的压缩包,解压。 拷贝目录下的OpenLayer.js、根目录下的lib目录、根目录下的img目录到你网站的Scripts目录下(当然,这个只是例子,您网站的目录结构您自己说得算,只要保证OpenLayers.js,/lib,/img在同一目录中即可)。然后,创建一个****.html作为查看地图的页面。 2试验openlayers 环境:geoserver1.7 Openlayers2.4 Dreamviever8 2.1第一个地图窗口 目标:用openlayers加载geoserver wms。 步骤: (1)空白html文件 (2)插入div-map (3)为div付风格 以上为未加载地图的静态页面 代码为: 效果为: (4)插入openlayers代码引用 (5)写js代码,主要是init() 第一个地图窗口就完成了 注1.js中defer的作用是页面加载完成后,执行脚本。

注2.222 2.2控制地图与div的占据区域 目标:让地图默认占满展现区 方法: 设置map的options,由其中两个因素决定:maxExtent-最大地图边界;maxResolution-最大解析度。 当maxExtent设置为地图的最大边界后,maxResolution设置为auto,那地图就占满DIV。 var options = { controls: [], maxExtent: bounds, maxResolution: "auto", projection: "EPSG:4326", numZoomLevels: 7, units: 'degrees' }; map = new OpenLayers.Map('map',options); 2.3地图控制-尺度缩放 目标:填加尺度缩放控件 步骤: (1)map初始化赋参数 var options = { controls: [], //scales: [50000000, 30000000, 10000000, 5000000], maxExtent: bounds, maxResolution: "auto", projection: "EPSG:4326", numZoomLevels: 7, (表示有几个缩放级别) units: 'degrees' }; map = new OpenLayers.Map('map',options); (2)填加控件,代码 map.addControl(new OpenLayers.Control.PanZoomBar({ position: new OpenLayers.Pixel(2, 15)(右边距,上边距) })); 思考:级别的计算,个人推测由(maxResolution- minResolution)/ numZoomLevels,但是默认值是书面日后再细究。

博弈论66个经典例子(9)不会令人后悔的纳什均衡

不会令人后悔的均衡 在纳什均衡中,你不一定满意其他的策略,但你的策略是回馈对手招数的最佳策略。 从囚徒困境中我们会发现,作为博弈各方的行动就是针对对方行动而确定的最佳对策,而一旦知道对方在做什么,就没人愿意改变自己的做法。博弈论学把这么一个结果称为均衡。这个概念是有普林斯顿大学数学家约翰·纳什提出的,因此被称为纳什均衡。 诺贝尔经济学奖获得者萨缪尔森有句名言,你可以将一只鹦鹉训练成经济学家,因为它所需要学习的只有两个词,供给与需求。博弈论专家坎多瑞引申说:“要成为现代经济学家,这只鹦鹉必须再多学一个词,这个词就是纳什均衡”。 1950年,还是一名研究生的纳什写了一篇论文,题为《n人博弈的均衡问题》,该文只有短短一页纸,可就这短短一页纸成了博弈论的经典文献。 纳什的贡献是,他证明了在这一类的竞争中,在很广泛的条件下是有稳定解存在的,只要是别人的行为确定下来,竞争者就可以有最佳的策略。 那么,什么纳什均衡呢?简单说,就是一策略组合中,所有的参与者面临这样的一种情况:给定你的策略,我的策略是我最好的策略。给定我的策略,你的策略也是你最好的策略,即双方在对方给定的策略下不愿意调整自己的策略。 纳什均衡从此成为经济学家用来分析商业竞争到贸易谈判现象的有力工具,所以纳什均衡是对冯诺依曼和摩根斯坦的合作博弈论的重大发展,甚至说是一场革命。 纳什均衡首先对亚当斯密“看不见的手”的原理提出挑战,按照斯密的理论,在市场经济中,每一个人都从利己的目的出发,而最终全社会达到利他的效果,

从纳什均衡引出一个悖论:从利己的目的触发,结果损人不利己。“囚徒困境”就是如此,从这个意义说,纳什均衡提出的悖论实际上动摇了西方经济学的基石。 纳什的想法成为我们指导“同时行动博弈”的最后一个法则的基础。这个法则如下:走完寻找优势策略和剔除劣势策略的捷径之后,下一步就是寻找这个博弈的均衡。所谓博弈均衡,它是一稳定的博弈结果。均衡是博弈的一结果,但不是说博弈的结果都能成为均衡。博弈的均衡是稳定的,因而是可以预测的。 在囚徒困境中存在唯一的纳什均衡点,即两个囚犯均选择“招认”,这是唯一稳定的结果。 有些博弈的纳什均衡点不止一个,如下述夫妻博弈中有两个纳什均衡点。 丈夫和妻子商量晚上的活动,丈夫喜欢看拳击,而妻子喜欢欣赏歌剧,但两个人都希望在一起度过夜晚。在这个夫妻博弈中有两个纳什均衡点:要么一同去看歌剧,要么一同去看拳击。在有两个或两个以上纳什均衡点的博弈中,其最后的结果难以预测。在夫妻博弈中,我们无法知道,最后结果是一同欣赏歌剧还是一同看拳击。 是不是所有的博弈均存在纳什均衡点呢?不一定存在纯策略纳什均衡点,但至少存在一个混合策略均衡点。 这里所谓纯策略是指参与者在他的策略空间中选取唯一确定的策略,所谓混合策略是指参与者采取的不是唯一的策略,而是其策略空间上的概率分布。 我们下面将在警察与小偷的博弈中给出混合策略的说明。 在西部片里,我们常能看到这样的故事:某个小镇上只有一名警察,他要负责整个镇的治安,现在我们假定,小镇的一头有一家酒馆,另一头有一家银行,再假定该地有一个小偷,要实施偷盗。因为分身乏术,警察一次只能在一个地方

经典的10个逆向思维故事

经典的10个逆向思维故事 它是思维中较高级别的一种方法。 你听过哪些跟逆向思维有关的故事?接下来,跟你分享逆向思维的经典故事和案例。 经典逆向思维的小故事1、如何得到美女的电话号码傍晚陪爷爷在公园散步,不远处有一个气质美女,忍不住多看了两眼。 爷爷问我:喜欢吗?我不好意思的笑笑点点头。 爷爷又问:想要她的电话号码吗?。 我瞬间脸红了。 爷爷说看我的,然后转身向美女走去。 几分钟后我的电话响了,里面传来一个甜美的声音:你好,你是***吗?你爷爷迷路了,赶紧过来吧,我们在公园***处。 我对爷爷简直佩服的五体投地,然后默默的把这个电话存了下了。 经典逆向思维的小故事2、如何让孩子做作业孩子不愿意做爸爸留的课外作业,于是爸爸灵机一动说:儿子,我来做作业,你来检查如何?孩子高兴的答应了,并且把爸爸的“作业认真的检查了一遍,还列出算式给爸爸讲解了一遍。 只是他可能不明白为什么爸爸所有作业都做错了。 经典逆向思维的小故事3、惹不起的大爷大爷买西红柿挑了3个到秤盘,摊主秤了下:“一斤半3块7。 大爷:“做汤不用那么多。

去掉了最大的西红柿。 摊主,“一斤二两,3块。 正当我想提醒大爷注意秤子时,大爷从容的掏出了七毛钱,拿起刚刚去掉的那个大的西红柿,扭头就走。 摊主当场无风凌乱。 。 至午夜十分,打电话到美女房间问:需服务否?答然。 男奋而前往,并得一千而返。 经典逆向思维的小故事5、换个角度看问题海阔天空小伙子站在天台上要自杀,众人围观。 不一会警察来了,问其原因,小伙回答:谈了八年的女朋友跟土豪跑了,明天要结婚了,感觉活着没意思!旁边一老者答:睡了别人的老婆八年,你还有脸在这里自杀?小伙想了想,也对啊,笑了笑,就走下来了。 经典逆向思维的小故事6、大爷损失了多少钱王老板花30元进了一双鞋,零售价40元。 一个小伙子来买鞋,拿一张100元人民币,王老板找不开,只能去找邻居换了这100,然后找给了小伙子60元。 后来邻居发现这个100是假币,没办法王老板又还了邻居50。 问这场交易里,王大爷一共损失了多少钱?在数据化管理的培训中经常用这个题测试学员的数据思维,结果是只有约20%的人能算出准

geoserver

●利用具有地理空间位置信息的数据制作地图。其中将地图定义为地理数据可视的表现。 这个规范定义了三个操作: ?GetCapabitities 返回服务级元数据,它是对服务信息内容和要求参数的一种描述; ?GetMap 返回一个地图影像,其地理空间参考和大小参数是明确定义了的; ?GetFeatureInfo(可选)返回显示在地图上的某些特殊要素的信息 WFS: Web Feature Service(Web要素服务) ●Web 地图服务返回的是图层级的地图影像, ●Web要素服务(WFS)返回的是要素级的GML编码,并提供对要素的增加、修改、删 除等事务操作,是对Web地图服务的进一步深入。OGC Web要素服务允许客户端从多个Web要素服务中取得使用地理标记语言(GML)编码的地理空间数据,定义了五个操作: ?GetCapabilites 返回Web要素服务性能描述文档(用XML描述); ?DescribeFeatureType 返回描述可以提供服务的任何要素结构的XML文档; ?GetFeature 一个获取要素实例的请求提供服务; ?Transaction 为事务请求提供服务; ?LockFeature 处理在一个事务期间对一个或多个要素类型实例上锁的请求。 WFS-T: Web Map Service-Transactional. 允许用户以可传输的块编辑地理数据。 WCS:Web Coverage Service(Web覆盖服务) Web 覆盖服务(WCS)面向空间影像数据,它将包含地理位置值的地理空间数据作为“覆盖(Coverage)”在网上相互交换。 ●网络覆盖服务由三种操作组成:GetCapabilities,GetCoverage和DescribeCoverageType: ?GetCapabilities 操作返回描述服务和数据集的XML文档。 ?GetCoverage操作是在GetCapabilities确定什么样的查询可以执行、什么样的数据能 够获取之后执行的,它使用通用的覆盖格式返回地理位置的值或属性。 ?DescribeCoverageType 操作允许客户端请求由具体的WCS服务器提供的任一覆盖层 的完全描述。 GML: Geography Markup Language. 一种用于描述地理数据的XML。OGC——Open Geospatial Consortium——开放地理信息联盟 总之,GeoServer 是您需要显示地图在网页的那些工具的当中一个,用户可以缩放并且移动。可以与一些客户端联合使用,比如:MapBuilder (for web pages), UDig, GVSig,等等。对标准的使用允许信息从GeoServer 到其它地理信息可以很容易地被结合。

墨菲定律的经典故事

最近看了一般书就叫墨菲定律,世界上那些最有趣的定律,作者是李原,书名虽然叫做墨菲定律,但是他介绍了很多生活中有趣又用得着的定律法则,这些法则世界闻名,里面蕴含了,很多大智慧,了解它才能利用它,会对我们工作生活带来裨益。 我们看几个例子: 案例一:“今天出门忘带伞了,可千万不要下雨呀,结果下雨了”, 案例二:“上班快迟到了,千万别堵车呀,结构堵车了。”, 案例三:“刚买的股票,希望它大涨,结果,刚买完就下跌了,” 你遇到过上面的事情,或类似的事情,恭喜你,你见过墨菲定律了。 看看,原来墨菲是怎么说的: 1949年,一位名叫爱德华·墨菲的空军上尉工程师,对他的某位运气不太好的同事随口开了句玩笑:“如果一件事有可能被做坏,让他去做就一定会更坏。” 但是这只是我们肤浅地了解,怪运气不好,但是往往事情的发生在偶然中尤其必然的原因:

一、任何事都没有表面看起来那么简单; 二、所有的事都会比你预计的时间长; 三、会出错的事总会出错; 四、如果你担心某种情况发生,那么它就更有可能发生。 我们光知道墨菲定律没有用,有用的是我们知道如何利用墨菲定律,改变我们的生活 我们看上面的案例,和墨菲定律的那4点,我们能总结出什么来: 对,就是不要存在侥幸心理,你担心的事情一定会发生,但要从错误中汲取教训。 所以我们针对上面要说两点, 第一不要侥幸心理,做任何事情都尽量做到完全的准备。 第二正视错误,汲取教训,让墨菲定律不在同一件事情上发生。

举个投资的例子 我听过太多的人说,自己买的股票,一买就跌,已卖就涨,这就是墨菲定律在起作用,自己祈祷上苍的保佑是没有用的,你必须有保证错误不发生或不在发生的办法才行,当你提前组好了所有的准备,你心里就踏实,就不会说出一买就跌,已卖就涨的话,所以总结就是,当你不去为错误做准备的时候,错误就会让你损失惨重。而一旦你做好了准备,你就能够坦然面对错误,并通过修正错误,走上更正确的道路。对错对于成年人来说,没有意义,小孩子才挣对错。

环境法经典10个案例

案例 1 征收排污费制度 【案情】 某市机器厂(甲)家属楼与棉纺厂(乙)纺织车间仅一墙之隔。纺织车间1993年4月新上一生产线,扩大生产规模鼓风机日夜运作,致使楼房的居民无法入睡严重影响其正常生活秩序和身心健康。甲厂职工多次反映,要求环保部门予以处理。1993年9月市环境监理总站经调查、监测证实,该车间厂界噪声为74.2分贝,所处区域为Ⅱ类混合区。为此市环保局向乙厂下达书面通知, 要求缴纳超标排污费, 但乙厂置之不理。1993年11月,市环保局对乙厂作出行政处罚:(1) 征收噪声超标排污费25000元;(2)追缴滞纳金1500元;(3)罚款5000 元。乙厂不服,提出几点理由:(1) 污染源所在地建在先,甲厂住宅楼建在后,责任在甲厂选址不当;(2) 主要污染源鼓风机系国家定点厂家生产,低噪音符合排放标准,出现高噪音应属厂家产品质量问题。 【问题】 1 、你认为乙厂的理由成立吗?为什么?依据环境法,请具体分析说明乙厂有无违法行为? 2 、环保部门的处理是否正确?为什么? 3 、如果你是甲厂的代理人, 你将如何维护自身的合法权益, 解决该案的问题? 【分析】 1 、乙厂的理由不成立。就环境法律关系而言,征收排污费制度的对象是超标排污单位即乙厂,至于鼓风机生产厂家的产品不合格,属于乙厂与鼓风机厂之间的民事法律关系。因此,依照我国环境噪声污染防治法律规定,乙厂超标排放噪声应当缴纳超标排污费。乙厂的违法行为包括:乙厂纺织车间是在1993年4月新上的,未执行环境影响评价、“三同时”、排污申报登记以及征收排污费制度。 2 、环保部门的处理是正确的。根据我国环境保护法律法规的规定,特别是依照《征收排污费暂行办法》,超标排放噪声应当按标准缴纳超标排污费,对逾期不缴者,可以处以罚款,并追缴滞纳金。 3 、作为甲厂的代理人,应当从处理好相邻关系的角度出发,请求乙厂按照国家环境噪声标准规定E 类混合区的要求,达标排放噪声以及根据时限要求定时排放噪声。也可以向人民法院起诉,请求法院判令乙厂消除影响、排除危害。如果有人身或者财产损害者,还可以请求赔偿损害。 案例 2 被告人曹保章1988年承包了张家港市港口乡泗安村向阳化工厂。为牟取暴利,在明知该厂无能力处理含氰化钠、氰化钾等剧毒工业废渣的情况下,于1989年1月与上海锯条总厂签定了处理该厂含氰废渣的协议。协议约定向阳化工厂必须要按当地环保部门的规定处理含氰废渣,杜绝二次污染,不能存放在露天场所等等。从1989年1月至1991年8月,曹保章等人先后25次将294吨含氰废渣直接抛人宝山区、嘉定县及江苏太仓县的水域中。造成严重水域污染,大量鱼及生物死亡、自来水厂停止供水,部分企业停产,直接经济损失210万元,水域中的氰化物难以消除,给环境和水生生物及人体健康造成的潜在危害更难以估量。 案例 3 环境噪声污染 【案情】 1996 年8 月, 某市举行一级方程式摩托艇世界锦标赛。甲公司与世摩赛组委会签订协议: 在世摩赛期间, 由世摩赛组委会委托甲公司在赛场及青少年宫上空进行飞艇放飞。 10 月26 日, 甲公司在青少年宫上空进行试放飞, 该市环保局测得飞艇试放噪声为81 分贝, 超过排放标准。市环保局向世摩赛组委会和甲公司发出停止放飞的紧急通知,

相关主题
文本预览
相关文档 最新文档