r0x0r / pywebview

Build GUI for your Python program with JavaScript, HTML, and CSS
https://pywebview.flowrl.com
BSD 3-Clause "New" or "Revised" License
4.64k stars 539 forks source link

add window object methods #624

Closed Ksengine closed 3 years ago

Ksengine commented 3 years ago

add this methods to use from javascript(from webpage side) this methods are not supported in most browsers

Practicalities

r0x0r commented 3 years ago

Good suggestion. I disagree with overloading the window object, but these could be placed into pywebview.window. The api and method names could be same or at least similar to the methods of the window.py.

Comments? Other ideas?

Ksengine commented 3 years ago

we can set pywebview.window methods to window eg: window.moveTo=pywebview.window.moveTo;

Ksengine commented 3 years ago

can u set suitable labels to this issue

Ksengine commented 3 years ago

can we add this methods to jsbridge class. please, explain it

Ksengine commented 3 years ago

can i make a pull

Ksengine commented 3 years ago

https://www.w3schools.com/jsref/obj_window.asp

r0x0r commented 3 years ago

Overwriting Javascript built-in functions is a bad practice. I would rather have these separately, for example under pywebview.window. The API could be

pywebview.window.createFileDialog(params) pywebview.window.destroy() pywebview.window.hide() pywebview.window.minimize() pywebview.window.move(x, y) pywebview.window.resize(width, height) pywebview.window.restore() pywebview.window.show() pywebview.window.toggleFullscreen()

I am not sure what to with properties.

Ksengine commented 3 years ago

Overwriting Javascript built-in functions is a bad practice why?

Ksengine commented 3 years ago

We can use ECMAScript5 (for properties)

Browser Support

chrome  IE/Edge  Firefox  Safari   Opera 
Chrome 23 IE10 / Edge Firefox 21 Safari 6 Opera 15
Sep 2012 Sep 2012 Apr 2013 Jul 2012 Jul 2013
Ksengine commented 3 years ago

example

// Define object
var obj = {counter : 0};

// Define setters
Object.defineProperty(obj, "reset", {
  get : function () {this.counter = 0;}
});
Object.defineProperty(obj, "increment", {
  get : function () {this.counter++;}
});
Object.defineProperty(obj, "decrement", {
  get : function () {this.counter--;}
});
Object.defineProperty(obj, "add", {
  set : function (value) {this.counter += value;}
});
Object.defineProperty(obj, "subtract", {
  set : function (value) {this.counter -= value;}
});

// Play with the counter:
obj.reset;
obj.add = 5;
obj.subtract = 1;
obj.increment;
obj.decrement;
Ksengine commented 3 years ago

if not supported;(older than IE10)

window.__defineGetter__('innerWidth', function() { return pywebview.window.getInnerWidth(); });

window.__defineSetter__('innerWidth', function(val) { pywebview.window.setInnerWidth(val); });

window.innerWidth = 5;
console.log(window.innerWidth); 
Ksengine commented 3 years ago

can i make a pull

kakksanthusa commented 3 years ago

Its good

r0x0r commented 3 years ago

can i make a pull

Please go ahead.

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] commented 3 years ago

The message to post on the issue when closing it. If none provided, will not comment when closing an issue.