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) app.setAttribute(Qt.AA_NativeWindows,True) wnd = QMainWindow() wnd.resize(400, 400) widget = QWidget() wnd.setCentralWidget(widget) wnd.show() handle = int(widget.winId()) mapinfo = Dispatch("MapInfo.Application") mapinfo.do('Set Next Document Parent %s Style 1' % handle) mapinfo.do('Open Table "D:\GIS\MAPS\Property.TAB"') mapinfo.do('Map from Property') app.exec_()
The above code will load MapInfo and open the property layer into the Qt Widget control, with the result below.
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.
[…] QGIS and GIS blog" montre comment afficher un couche .TAB de MapInfo dans Python avec pyQT4 https://woostuff.wordpress.com/2011/0…t-python-form/ Code: from PyQt4.QtCore import * from PyQt4.QtGui import * from win32com.client import Dispatch […]
Many many thanks!!! You opened a door to me. I had just to use “/” instead of “\”.
Waiting for your next trick ;-)
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.
[…] other day I posted an entry about using MapInfo with Python and Qt (see https://woostuff.wordpress.com/2011/03/05/mapinfo-map-control-into-qt-python-form/), one big thing that I missed was support for callbacks, which if you want to do […]
How to automate a running instance of a MapInfo application (by Qt)?
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):
self.init_frame()
return True
def init_frame(self):
self.frame = wx.Frame(None, wx.ID_ANY, “MapInfo window – compliments WxPython!”, (100,100), (640,480))
self.init_panel()
self.frame.Show()
self.SetTopWindow(self.frame)
def init_panel(self):
self.panel = wx.Panel(self.frame, wx.ID_ANY,self.frame.GetPositionTuple(),self.frame.GetSizeTuple())
self.init_MapInfo()
def init_MapInfo(self):
print self.panel.GetHandle()
handle = int(self.panel.GetHandle())
self.mapinfo = win32com.client.Dispatch(“MapInfo.Application”)
self.mapinfo.do(‘Set Next Document Parent %s Style 1’ % handle)
self.mapinfo.do(‘Open Table “W:\QM370642 MDF\_temp\mapping_test\STE06aAUST.tab”‘)
self.mapinfo.do(‘Map from GroupLayer (“STATE_NAME_2006”,STE06aAUST)’)
if __name__ == ‘__main__’:
app = MyApp(False)
app.MainLoop()