Python Forum
win32com Events not catching
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
win32com Events not catching
#1
Hello,
I have a custom COM component that fires events and that exposes objects.

This code opens this COM component and it connects to the database and shows the form.

But, when I scroll and click through the grid it doesn't catch the events. It should catch the EditChange event that is fired from this COM component.

Here is the CODE1:

class VFEventsClass(object):
    def EditChange(self, EditChangeFunction, VirtualFormName, IdDetail, EditState):
        print("Edit Change Event")

    def EditBeforeSave(self, Cancel, BeforeSaveFunctionName, VirtualFormName, TableName, IdDetail, EditFlag):
        print("Before Save Event")


if __name__ == '__main__':

    #################################################################
    # with this code I'm able to comunicate with the textboxes on the virtual form, but can't catch events
    import win32com.client as win32
    import pythoncom
    import time

    vf1 = win32.DispatchWithEvents('VirtualForm2.VirtualForm', VFEventsClass)

    vf1.VFFile = r'C:\Users\WinPIS\Desktop\VFPython\VFFilePython.vf'
    vf1.DatabaseType = 2
    vf1.ConnectionString = r"DRIVER={MySQL ODBC 5.3 Unicode Driver};" \
                           "Port=3306;" \
                           "SERVER=virtualforms.a2hosted.com;" \
                           "DATABASE=virtua51_oms;" \
                           "USER=virtua51_student;" \
                           "PASSWORD=Ksq6cXWUXou];" \
                           "OPTION=3;"

    # vf1.OpenVirtualFormDesigner()

    vf1.ShowVirtualForm("VF2")

    # in the opened VF2 form change the TextBox that is bound to database field customerid
    vf1.TextBox("VF2", "[customerid]")[0].Text = "888"

while True:
    # Trigger the event handlers if we have anything.
    pythoncom.PumpWaitingMessages()
    # pythoncom.PumpMessages()
    time.sleep(0.1)  # Don't use up all our CPU checking constantly
With this code (CODE1) I can communicate with the textbox that is on this COM component with this line of code:
vf1.TextBox("VF2", "[customerid]")[0].Text = "888"
But as I have said, this code (CODE1) doesn't catch the events.

#######################################

And this code (CODE2) catches the events, but can't figure out how to communicate with the textboxes and how to loop PumpEvents so that we can use in practically indefinitely and not only for a number of seconds.
Here is the CODE2:

class VFEventsClass(object):
    def EditChange(self, EditChangeFunction, VirtualFormName, IdDetail, EditState):
        print("Edit Change Event")

    def EditBeforeSave(self, Cancel, BeforeSaveFunctionName, VirtualFormName, TableName, IdDetail, EditFlag):
        print("Before Save Event")


if __name__ == '__main__':
    #################################################################
    # with this code I'm able to get the events from virtual forms,
    # but can't comunicate with the textboxes on the virtual form
    # and PumpEvents is not in a indefinite loop

    # https://pythonhosted.org/comtypes/
    from comtypes.client import CreateObject
    from comtypes.client import ShowEvents
    from comtypes.client import PumpEvents
    from comtypes.client import GetEvents
    import gc

    virtualformcontrol = CreateObject("VirtualForm2.VirtualForm")
    virtualformcontrol.VFFile = r'C:\Users\WinPIS\Desktop\VFPython\VFFilePython.vf'
    virtualformcontrol.DatabaseType = "2"
    virtualformcontrol.ConnectionString = r"DRIVER={MySQL ODBC 5.3 Unicode Driver};" \
                           "Port=3306;" \
                           "SERVER=virtualforms.a2hosted.com;" \
                           "DATABASE=virtua51_oms;" \
                           "USER=virtua51_student;" \
                           "PASSWORD=Ksq6cXWUXou];" \
                           "OPTION=3;"

    # OpenVirtualFormDesigner opens the designer
    # virtualformcontrol.OpenVirtualFormDesigner()

    virtualformcontrol.ShowVirtualForm("VF2")

    # this doesn't work
    # virtualformcontrol.TextBox("VF2", "[customerid]")[0].Text = "888"

    # connection = ShowEvents(virtualformcontrol)
    sink = VFEventsClass()
    connection = GetEvents(virtualformcontrol, sink)

    # how to make that this PumpEvents be used in a loop so that we can use in practically indefinitely
    #   and not only for a specific number of seconds
    PumpEvents(20)

    del connection
    del virtualformcontrol
    gc.collect()
Here is the COM component (VFSetupBeta2.0.0.31.exe):
https://www.virtual-forms.com/sharing/Vi...0.0.31.zip

and the VFFilePython.vf:
https://www.virtual-forms.com/sharing/VFFilePython.vf

Do you have any possible ideas for a solution?

Thanks, Davor
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  wait for the first of these events Skaperen 4 1,870 Mar-07-2022, 08:46 PM
Last Post: Gribouillis
  Catching a crash within a library code ebolisa 9 3,068 Nov-22-2021, 11:02 AM
Last Post: bowlofred
  win32com — How to resolve “AttributeError: xlUp” for Excel files? JaneTan 2 4,129 Aug-18-2021, 05:27 AM
Last Post: snippsat
Exclamation win32com: How to pass a reference object into a COM server class Alfalfa 3 4,801 Jul-26-2021, 06:25 PM
Last Post: Alfalfa
  Python with win32com and EXIF renaming files. Amrcodes 4 3,596 Apr-03-2021, 08:51 PM
Last Post: DeaD_EyE
  Python win32com.client: What are the syntax to open exe file & activate its window? JaneTan 0 4,130 Oct-14-2020, 09:09 AM
Last Post: JaneTan
  Alternate package of win32com.client manigandanpro 0 3,704 Aug-19-2020, 07:38 AM
Last Post: manigandanpro
  Catching Errors Alienspecimen 1 2,146 May-18-2019, 11:07 PM
Last Post: Larz60+
  Pexpect not catching embeded ssh response luchoArg32 0 2,288 Feb-08-2019, 08:45 AM
Last Post: luchoArg32
  catching / handle index out of range 3Pinter 3 2,631 Feb-04-2019, 01:19 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020