using mapbasic to modify your user interface

40
Peter H. Møller Senior Systems Engineer Pitney Bowes Software

Upload: peter-horsboll-moller

Post on 15-Jan-2015

641 views

Category:

Technology


6 download

DESCRIPTION

This is the presentation I used at a sessions at the Insights Conference in June 2012

TRANSCRIPT

Page 1: Using MapBasic to modify your user interface

Peter H. MøllerSenior Systems Engineer

Pitney Bowes Software

Page 2: Using MapBasic to modify your user interface

Using MapBasic to modify your user interface

2

Peter Horsbøll MøllerPitney Bowes Software

Page 3: Using MapBasic to modify your user interface

What is MapBasic?

• MapBasic is a scripting language that makes it easy to automate MapInfo Professional

• MapBasic is also a freely available compiler (and editor) to compile MapBasic source code into MapBasic applications (MBX)

• MapBasic is also the text that you see when you open a workspace in a text editor

• MapBasic is all over within MapInfo Professional!

3

Page 4: Using MapBasic to modify your user interface

What is C#?

• C# is a Windows programming language developed by Microsoft.

• C# does require a .NET Framework to be able to run• Since MapInfo Professional v9.5 you can call/access

methods within C# (and other .NET language) assemblies

4

Page 5: Using MapBasic to modify your user interface

What is the user interface?

• The user interface is what you use to make MapInfo Professional do what you want it to do

• The user interface is – the toolbars and the buttons– the menus and the menu items– the Layer Control and the Table List windows– the different dialogs that pops up within MapInfo Professional

5

Page 6: Using MapBasic to modify your user interface

Modifying the MapInfo menu file

Adding shortcut keys using a MapBasic application

Building your own dialogs

Using .NET languages to build good looking user interfaces

1

2

3

4

Rearranging and creating shortcut keys

6

Using MapBasic to modify your user interface

Page 7: Using MapBasic to modify your user interface

What is the MapInfo menu file?

• The menu file - mapinfow.mnu - is used by MapInfo Professional to build the menus and toolbars

• It contains a number of MapBasic statements for doing this

• The menu file is plain ascii and can be edited in a text editor, like NotePad

7

Page 8: Using MapBasic to modify your user interface

Create Menu statements

Let’s look at the content• Defining a new menu• Defining a new menu item• Ending a menu defintion (no

comma)• Defining a sub menu in a menu• Defining a separator

8

Page 9: Using MapBasic to modify your user interface

Create ButtonPad statements

Let’s look at the content• Defining a new buttonpad/toolbar• Defining a new button (push)• Defining a new button (toggle)• Defining a new button (tool)• Setting initial state and width• Defining a separator

9

Page 10: Using MapBasic to modify your user interface

Some notes

• Make a copy of your mapinfow.mnu before you start modifying it!

• You mapinfow.mnu is normally found in the directory where you installed MapInfo Professional. I can however be read from other places. Use this statement in the MapBasic window to locate the correct file, see path in the message window afterwards:– Print LocateFile$(7)

• Do remember the menu file i version specific, so you will need to modify the file for each new version of MapInfo Professional

10

Page 11: Using MapBasic to modify your user interface

Modifying the MapInfo menu file

Page 12: Using MapBasic to modify your user interface

Demo

12

Page 13: Using MapBasic to modify your user interface

Modifying the MapInfo menu file

Adding shortcut keys using a MapBasic application

Building your own dialogs

Using .NET languages to build good looking user interfaces

1

2

3

4

Static shortcut keys in an application

13

Using MapBasic to modify your user interface

Page 14: Using MapBasic to modify your user interface

What is a shortcut key?

• A shortcut key makes it possible to access a feature thru a key combination on your keyboard

• Only menu items can have shortcut keys – buttons can not ...

• ... but you can create menu items that ”call” the same handler as the button

14

Page 15: Using MapBasic to modify your user interface

How do you define a shortcut key?

• Create Menu statement:Create Menu newmenuname [ ID menu_id ] As menuitem [ ID menu_item_id ] [ HelpMsg help ] { Calling handler | As menuname } [ , menuitem ... ]

• You specify the shortcut key as part of the menu item title:

15

Page 16: Using MapBasic to modify your user interface

Examples

16

• ”/W^N” is the shortcut for Ctrl + N• ”\tCtrl+N” adds the text ”Ctrl+N” at

the right side of the menu• That is not necessay after v10 –

just create the shortcut and the matching text will appear by default

Page 17: Using MapBasic to modify your user interface

Special keys

• It’s easy to assign ”normal” keys like a, b and z to menu items using their character.

• But you can also use special key like F1, F2 and Home by referring to their number

• Here is list of virtual key codes: http://www.kbdedit.com/manual/low_level_vk_list.html

• For example Home has the numeric value 0x24 (hex). You need to convert this to a decimal number. Use for instance: http://www.statman.info/conversions/hexadecimal.html

• Now you can assign the value to a menu item like this:“Zoom entire layer.../W#%36"

HelpMsg "Display an individual or all map layer(s)." calling 807

17

Page 18: Using MapBasic to modify your user interface

Adding shortcut keys using a MapBasic application

Page 19: Using MapBasic to modify your user interface

Demo

19

• Defined in the Menu.def

Page 20: Using MapBasic to modify your user interface

Modifying the MapInfo menu file

Adding shortcut keys using a MapBasic application

Building your own dialogs

Using .NET languages to build good looking user interfaces

1

2

3

4

Custom made dialogs to make things easier

20

Using MapBasic to modify your user interface

Page 21: Using MapBasic to modify your user interface

21

Custom dialogs

• With MapBasic you can build applications containing custom dialogs designed for your specific need

• These dialogs can be designed to access data, analyse data, update attribute information and a number of other use cases

• MapBasic dialogs are modal (like the old Layer Control prior to MapInfo Pro 10.0). They can’t be floating (like the new Layer Control added in MapInfo Pro 10.0)

Page 22: Using MapBasic to modify your user interface

Some examples

22

Page 23: Using MapBasic to modify your user interface

Control types

23

OKButton CancelButton

CheckBox

RadioGroup

PenPicker BrushPicker SymbolPicker FontPicker

EditText

StaticText

StaticText

ListBox MultiListBox

PopupMenuStaticText

GroupBox

StaticText

Page 24: Using MapBasic to modify your user interface

Let’s look at some MapBasic code

24

Page 25: Using MapBasic to modify your user interface

Handlers

• A handler is a subprocedure, called from the dialog

• A handler on the dialog itself is called when the dialog is created and is being loaded

• You can use it to insert default values

• A handler on a control is called when the user ”uses” the control

• It can be used to react to the actions/choices of the user, like updating other control

25

Page 26: Using MapBasic to modify your user interface

Handler on the dialog

26

• Creates a list of map windows

• Refreshes the control with the list of windows

• Activates the handler for this control

Page 27: Using MapBasic to modify your user interface

Handler on a control

27

• Reads which windows is selected in the control

• Creates a list of layers

• Refreshes the control with the list of layers

Page 28: Using MapBasic to modify your user interface

Building your own dialogs

Page 29: Using MapBasic to modify your user interface

Modifying the MapInfo menu file

Adding shortcut keys using a MapBasic application

Building your own dialogs

Using .NET languages to build good looking user interfaces

1

2

3

4

Fancy looking windows, not dialogs

29

Using MapBasic to modify your user interface

Page 30: Using MapBasic to modify your user interface

Using .NET

• From MapInfo Professional 9.5 you have been able to call .NET methods from your MapBasic applications

• This has given a wide range of new possibilities when building applications to run inside MapInfo Professional

30

Page 31: Using MapBasic to modify your user interface

How is this done?

31

• Create a class with one or more static method

• Compile it into an assembly (.dll)

• Make the assembly accessible for your MapBasic app (copy it to the same folder as the app)

• Run your app

• Use the Declare Method statement to declare your .NET method to MapBasic

• Call/use the method in your MapBasic app• Compile (and link) your application

Page 32: Using MapBasic to modify your user interface

Create a new project in Visual Studio

• Choose the type ”Class Library”• Name your project, here ”MapInfoDialog”

Page 33: Using MapBasic to modify your user interface

Add a static method

• Here we have added the method ShowDialog

Page 34: Using MapBasic to modify your user interface

Compile your .NET assembly

• Compiler your project thru Build > Build MapInfoDialog– Or hit Shift + F6

• Note if there were any compile errors

Page 35: Using MapBasic to modify your user interface

Make the assembly accessible

• Copy the assembly to the folder where your compiled MapBasic application will be located:– MapInfoDialog.dll: The assembly– MapInfoDialog.pdb: Debug information

Page 36: Using MapBasic to modify your user interface

Build your MapBasic application

• Declare Method– Class: including Namesspaces– Lib: without path but with ”.dll”

• Declare Sub Main• Call ShowDialog(”some title”, ”some text to show in dialog”)

Page 37: Using MapBasic to modify your user interface

Compile and run your MapBasic application

• Compile– Check for errors

• Run the application in MapInfo Pro

Page 38: Using MapBasic to modify your user interface

Some examples

38

Page 39: Using MapBasic to modify your user interface

Open the MapBasic window. Look at the statements MapInfo Pro write here when you do certain tasks

Try to open a workspace in a text editor Look at the statements here

Have a look at the tools site, like MapInfoTools.com. Some tools do come with source code.

Have a look at these and try to modify them to fit your needs

Signup for MapInfo-L on Google Groups: groups.google.com/group/mapinfo-l Follow and learn from the conversation here and start asking questions

Use the MapBasic window

Look at your workspaces

Find tools with source code

Sign up for MapInfo-L

39

Getting started with MapBasic?

Page 40: Using MapBasic to modify your user interface

Thank You

Peter Horsbøll Mø[email protected]