MapInfo map control into Qt Python form

Tonight for a bit of fun, or shits and jiggles as we say here, I thought I would try and embed a MapInfo map control into a Qt python widget (although I should be studying, but it’s Saturday night) .

Turns out it is pretty easy!

pls send me teh codez? OK here you go.

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from win32com.client import Dispatch
import sys

app = QApplication(sys.argv)
wnd = QMainWindow()
wnd.resize(400, 400)
widget = QWidget()

handle = int(widget.winId())
mapinfo = Dispatch("MapInfo.Application")'Set Next Document Parent %s Style 1' % handle)'Open Table "D:\GIS\MAPS\Property.TAB"')'Map from Property')


The above code will load MapInfo and open the property layer into the Qt Widget control, with the result below.

MapInfo map in python Qt based form

So this means you don’t “always” have to write your MapInfo based apps in C# or C++; of course I already knew this as anything that can use OLE and provide a native window handle to MapInfo will work, I just never tried it.

6 thoughts on “MapInfo map control into Qt Python form

  1. Many many thanks!!! You opened a door to me. I had just to use “/” instead of “\”.
    Waiting for your next trick ;-)

    1. Glad someone found it useful :D Just a note: The only thing I haven’t worked out yet is how to do MapInfo callbacks but I’m working on it.

  2. Thanks Nathan.

    This is how I got it going in wxPython:

    #!/usr/bin/env python

    import wx
    import sys
    import win32com.client

    class MyApp(wx.App):

    def OnInit(self):
    return True

    def init_frame(self):
    self.frame = wx.Frame(None, wx.ID_ANY, “MapInfo window – compliments WxPython!”, (100,100), (640,480))

    def init_panel(self):
    self.panel = wx.Panel(self.frame, wx.ID_ANY,self.frame.GetPositionTuple(),self.frame.GetSizeTuple())

    def init_MapInfo(self):
    print self.panel.GetHandle()
    handle = int(self.panel.GetHandle())
    self.mapinfo = win32com.client.Dispatch(“MapInfo.Application”)‘Set Next Document Parent %s Style 1’ % handle)‘Open Table “W:\QM370642 MDF\_temp\mapping_test\”‘)‘Map from GroupLayer (“STATE_NAME_2006”,STE06aAUST)’)

    if __name__ == ‘__main__’:
    app = MyApp(False)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s