Code Monkey home page Code Monkey logo

Comments (10)

ffreemt avatar ffreemt commented on May 25, 2024 2

I see. I look forward to the possible new api. In the meantime, I use a somewhat alright workwround: limit the directories to load a file, for example in home directory and current work directory, the filename itselft can be obtained from <input type="file"... > in html (e.g., C:\fakepath\tmp.txt).

from webui.

hassandraga avatar hassandraga commented on May 25, 2024 1

If your data is bigger than ~250Kb it won't work actually using WebUI v2.4.0. But will be fixed soon in 2.4.1.

from webui.

hassandraga avatar hassandraga commented on May 25, 2024

For security reasons, all web browsers hide the real absolute file path. But you can easily use the native OS APIs instead. For example, you call your Python function that opens a file dialog and returns the absolute path to the UI.

import win32gui, win32con, os

filter='Python Scripts\0*.py;*.pyw;*.pys\0Text files\0*.txt\0'
customfilter='Other file types\0*.*\0'
fname, customfilter, flags=win32gui.GetOpenFileNameW(
    InitialDir=os.environ['temp'],
    Flags=win32con.OFN_ALLOWMULTISELECT|win32con.OFN_EXPLORER,
    File='somefilename', DefExt='py',
    Title='GetOpenFileNameW',
    Filter=filter,
    CustomFilter=customfilter,
    FilterIndex=0)

print 'open file names:', repr(fname)
print 'filter used:', repr(customfilter)
print 'Flags:', flags
for k,v in win32con.__dict__.items():
    if k.startswith('OFN_') and flags & v:
        print '\t'+k

Or use a third-party module

import easygui
path = easygui.fileopenbox()

from webui.

hassandraga avatar hassandraga commented on May 25, 2024

JavaScript

var result = webui_fn('MyPythonFunction');
alert('Path is: ' + result);

from webui.

ffreemt avatar ffreemt commented on May 25, 2024

Thanks very much for the reply and for the detailed alternatives.

I am aware of the security reasons for all web browsers to hide the real absolute file path.

But since this webui package is intended for processing local content, I wonder whether there is a way to directly access the real absolute file path like electron.js does.

from webui.

hassandraga avatar hassandraga commented on May 25, 2024

Electron uses an entirely modified embedded web browser (Chromium), that's why the final result is +100 MB. While WebUI uses only the already installed real web browser. Perhaps, probably we should add an API for opening a file, something like var path = webui_fopen('*.txt');

from webui.

OwOday avatar OwOday commented on May 25, 2024

Hey, if you aren't using the browsers file selector I'm not sure this workaround is guaranteed to work on some platforms. For example I am using golang and I'm not sure how to guarantee a file selector will actually open on linux; they could be using firefox on i3 with no installed file browser for all I know... I am new to the project and notice the api just switched, did the file thing ever get explicitly worked out?

from webui.

OwOday avatar OwOday commented on May 25, 2024

It sounds stupid when I think about it too long and I'm not a web dev but could you stream the data over the browser like uploading/downloading a file from a website? I have no idea how to code this on webui

from webui.

AlbertShown avatar AlbertShown commented on May 25, 2024

I already saw the file handling using HTML5/JS in the text editor example.

Another way to do this is by making the backend use OS native APIs to open the file selector, then send the file content to UI using webui_send_raw().

ScreenShot

from webui.

OwOday avatar OwOday commented on May 25, 2024

I already saw the file handling using HTML5/JS in the text editor example.

Another way to do this is by making the backend use OS native APIs to open the file selector, then send the file content to UI using webui_send_raw().

ScreenShot

I think that using the OS native APIs was hassandraga's first suggestion, but I'm planning to support platforms without native file browsers. I'm interested in this text editor example I haven't seen before. I'm using golang currently, I was able to modify the code of the text editor example to transfer the data of the file. This actually works for me at the moment, though it's kind of a stupid workaround for what I'm doing (loading/saving configs/databases). Next I have to figure out how to save the config to a new file (using the web file browser).

from webui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.