Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exe genereted by ipyc says "the calling thread must be sta because many ui components require" #1310

Closed
retsyo opened this issue Jan 23, 2022 · 3 comments · Fixed by #1316
Closed

Comments

@retsyo
Copy link

retsyo commented Jan 23, 2022

I used the following code with latest ironpython2 and ironpython3 release.
no matter IronPython.2.7.12\net45\ipy.exe gui_wpf.py or IronPython.3.4.0-alpha1\net46\ipy.exe gui_wpf.py can run without problem.

Then I use ipyc to create exe file with

ipyc.exe /embed  /target:exe gui_wpf.py

I copy gui_wpf.exe, form.xaml, IronPython.2.7.12\lib to IronPython.2.7.12\net45\
or
copy gui_wpf.exe, form.xaml, IronPython.3.4.0-alpha1\lib to IronPython.3.4.0-alpha1\net46\.

However when I run gui_wpf.exe in the dos prompt, I get

gui_wpf.exe
Error occurred: the calling thread must be sta because many ui components require

how to fix it? Thanks

the following code is actually copied from https://stackoverflow.com/questions/47953638/button-click-event-on-ironpython-wpf

# gui_wpf.py

import clr
import wpf

from System.Windows import Application, Window

class MyWindow(Window):
    def __init__(self):
        self.ui = wpf.LoadComponent(self, 'form.xaml')

    def Button_Click(self, sender, e):
        print('Button has clicked')

if __name__ == '__main__':
    Application().Run(MyWindow())

and form.xaml is

<Window 
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
       Title="WpfApplication1" Height="300" Width="300"> 
       <Grid>
        <Button x:Name="BUTTON" Content="Button" HorizontalAlignment="Left" Margin="101,82,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click" Background="#FFFF1616"/>
    </Grid>
</Window> 
@slozier
Copy link
Contributor

slozier commented Jan 24, 2022

You probably need to use /target:winexe for a WPF application:

ipyc.exe /embed  /target:winexe gui_wpf.py

@retsyo
Copy link
Author

retsyo commented Jan 24, 2022

winexe works. Thanks

but for the original code, the event prints text in dos windows. If GUI+console window are desired, how can we modify the code to let both exe and py work?

@slozier
Copy link
Contributor

slozier commented Jan 24, 2022

Hmm, I'm not seeing any command-line arguments that would enable this. I guess ipyc would need to be modified to add the STAThread attirbute to the entry point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants