jhi2 / PyUi3

WinUI3 for Python!
GNU General Public License v3.0
5 stars 0 forks source link

Error on window init #1

Open jhi2 opened 3 months ago

jhi2 commented 3 months ago

@JPHutchins Hello again. As the title suggests, there is an error on window init. Can you please help me? continued from the conversation on toga.

JPHutchins commented 3 months ago

Hello! Can you post a code excerpt and the traceback? Thanks!

jhi2 commented 3 months ago

PS C:\Users\johnd\source\repos\PyUi3> & "C:/Program Files/Python312/python.exe" c:/Users/johnd/source/repos/PyUi3/PyUI3/test.py Traceback (most recent call last): File "c:\Users\johnd\source\repos\PyUi3\PyUI3\test.py", line 4, in window = PyUI3.ApplicationWindow() ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\johnd\AppData\Roaming\Python\Python312\site-packages\PyUI3__init.py", line 37, in init self.app = App() ^^^^^ File "C:\Users\johnd\AppData\Roaming\Python\Python312\site-packages\PyUI3__init.py", line 28, in init super().init() File "C:\Program Files\Python312\Lib\site-packages\win32more\xaml.py", line 36, in init__ self._provider = XamlControlsXamlMetaDataProvider() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Python312\Lib\site-packages\win32more\Microsoft\UI\Xaml\XamlTypeInfo__init.py", line 26, in init super().init__(move=win32more.Microsoft.UI.Xaml.XamlTypeInfo.XamlControlsXamlMetaDataProvider.CreateInstance(*args)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Python312\Lib\site-packages\win32more_winrt.py", line 722, in call__ return _ro_activate_instance(cls.classid, cls) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Python312\Lib\site-packages\win32more_winrt.py", line 785, in _ro_activate_instance raise WinError(hr) OSError: [WinError -2147221164] Class not registered

jhi2 commented 3 months ago

here is the code i used to test it(ai generated):

import PyUI3

# Create a window
window = PyUI3.ApplicationWindow()

# Add some widgets
label = PyUI3.Label(window, "Welcome to PyUI3!", pos=(150, 50))
button = PyUI3.Button(window, "Click Me!", pos=(150, 100))
entry = PyUI3.Entry(window, pos=(150, 150))

# Define a callback function for the button
def button_click():
    label.text = f"Hello, {entry.text}!"

# Bind the callback to the button
button.on_click = button_click

# Start the main loop
window.run()
jhi2 commented 3 months ago

I think @ynkdir would be helpful with this.

ynkdir commented 3 months ago

"Class not registered" means that WindowsAppSDK is not initialized. You need to initialize Com and WindowsAppSDK before using WinUI API. See win32more.xaml.XamlApplication.Start() for detail.

Typical application code is

from win32more.Microsoft.UI.Xaml import Window
from win32more.xaml import XamlApplication

class App(XamlApplication):
    def OnLaunched(self, args):
        # Now, Com and WindowsAppSDK were initialized.
        # You can use WinUI from here.
        win = Window()
        win.Activate()

XamlApplication.Start(App)
jhi2 commented 3 months ago

"Class not registered" means that WindowsAppSDK is not initialized. You need to initialize Com and WindowsAppSDK before using WinUI API. See win32more.xaml.XamlApplication.Start() for detail.

Typical application code is

from win32more.Microsoft.UI.Xaml import Window
from win32more.xaml import XamlApplication

class App(XamlApplication):
    def OnLaunched(self, args):
        # Now, Com and WindowsAppSDK were initialized.
        # You can use WinUI from here.
        win = Window()
        win.Activate()

XamlApplication.Start(App)

I will try that

jhi2 commented 3 months ago

No, Here is what i did in the run function:

 def run(self):
        for item in self.roster:
            self.win.Content = item
        XamlApplication.Start(self.app)
        self.win.Activate()

Please submit a PR to fix the issue.

jhi2 commented 1 month ago

So, I built a formatter, didint work AT ALL! I used it on this repo. I had to revert, so its fixed now

jhi2 commented 1 month ago

@ynkdir Did you see the post above the one above this one? There are a few mods to it, but still error

jhi2 commented 1 month ago

So, I built a formatter, didint work AT ALL! I used it on this repo. I had to revert, so its fixed now

I know, right? did you see, it look sorta-minified?

ynkdir commented 1 month ago

Did you try my example code? It show you an empty window. If I were you, I would start with a working code and gradually add my own code step by step, ensuring the program continues to work. I don't write your library.

jhi2 commented 1 month ago

i know how to use win32more, but can you please contribute and help me fix the code?