1

Im making a pyweview desktop stand alone app and I have 2 things I cant seem to find much on. Mainly how to get it to see local src files and how to implement the windows snap feature. By that I mean the windows key + direction to snap to that side of the screen. I found a potential JS option for resizeing but have yet to test it.

How to make frameless window draggable in pywebview?

This post gave me the answer to making it dragable.

All the examples I can find of it using things like images have to be done with a weblink and that works but the point of this particular project is to have it self contained so is there a way to have the html load local files?

The html is loaded through window.load_html() and in the html I have tried every file path I can think of but so far nothing works. Even using the full system path. Bellow is a simple example just replace dots.svg with any local image you have. if the html is loaded on its own it works just fine. If loaded though pyweview there is no image. I am still new to JS but is there maybe a way to use JS to load the image?

import webview

html = """
<!DOCTYPE html>
<html lang="en">
    <h1>This is dynamically loaded HTML</h1>
    <body>
        <img src="images/dots.svg"> image should be here
    </body>
</html>
"""

def load_html(window):
    window.load_html(html)


if __name__ == '__main__':
    window = webview.create_window('Load HTML Example', html=html)
    webview.start(load_html, window)
tokageKitayama
  • 551
  • 1
  • 4
  • 5

1 Answers1

0

I am a dunce and it was how I had my folders. I was editing a copy folder not the main one so when I ran it it wouldnt update. as for the resize I found a solution here

https://awesomeopensource.com/project/DizzyduckAR/pywebview-Frameless-boilerplate

it doesn't add the half screen snap but it does add the window resize. Here is the code from it that does the resize. Its not as smooth as I was wanting but it does work.

#Resize Window
    def resizedrag(self):
        c = 1
        state_left = win32api.GetAsyncKeyState(0x01)
        beforex, beforey = pyautogui.position()
        beforex= str(beforex).rjust(4)
        beforey=str(beforey).rjust(4)
        # print(beforex,beforey)
        winWbefore=window.width
        winHbefore=window.height
        while True:
            a = win32api.GetAsyncKeyState(0x01) & 0x8000
            if a != state_left:
                state_left = a
                print(a)
                if a != 0:
                    print('Left Button Pressed')
                else:
                    print('Left Button Released')
                    break

                
            print("running")
            afterx, aftery = pyautogui.position()
            afterx= str(afterx).rjust(4)
            aftery=str(aftery).rjust(4)
            try:
                totalx=int(beforex)-int(afterx)
                totaly=int(beforey)-int(aftery)
                print('totals',totalx,totaly)
            except:
                print('fail')
            if totalx > 0:
                print('reduce x')
              #  print(totalx*-1)
                changerx=winWbefore+(totalx*-1)
            else:
                print('expend x')
                changerx=winWbefore+(totalx*-1)
               # print(totalx*-1)
            
            if totaly > 0:
                print('reduce y')
               # print(totaly*-1)
                changerY=winHbefore+(totaly*-1)
            else:
                print('expend y')
                #print(totalx*-1)
                changerY=winHbefore+(totaly*-1)
            #
            print('changed',changerx, changerY)
            window.resize(changerx, changerY)
            time.sleep(0.1)
tokageKitayama
  • 551
  • 1
  • 4
  • 5