picibucor picibucor - 9 days ago 6
Python Question

listening keys and fullscreen on second monitor

I have two monitors. If I run my project it appears on the main monitor. I can resize the window and make it full-screen by:
--> clicking on the full-screen button in the upper-right corner
--> pulling it to the top of the screen

As usual for Microsoft-Windows.

But this changes if I pull my App in the second window. By clicking on the full-screen icon, or pulling it to the top i will get the following error-message:

[INFO ] [Logger ] Record log in C:\Mirk\CETACal\logs\kivy_16-11-18_53.txt
[INFO ] [Kivy ] v1.9.2-dev0
[INFO ] [Python ] v3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 20:20:57) [MSC v.1600 64 bit (AMD64)]
[INFO ] [Factory ] 193 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_gif, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [OSC ] using <thread> for socket
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] GLEW initialization succeeded
[INFO ] [GL ] OpenGL version <b'4.3.0 - Build 10.18.14.4432'>
[INFO ] [GL ] OpenGL vendor <b'Intel'>
[INFO ] [GL ] OpenGL renderer <b'Intel(R) HD Graphics 4600'>
[INFO ] [GL ] OpenGL parsed version: 4, 3
[INFO ] [GL ] Shading version <b'4.30 - Build 10.18.14.4432'>
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <32>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [Base ] Start application main loop
[INFO ] [GL ] NPOT texture support is available
[INFO ] [Base ] Leaving application in progress...
Traceback (most recent call last):
File "C:\Mirk\CETACal\cls\test4.py", line 67, in <module>
ChildApp().run()
File "C:\Python34\lib\site-packages\kivy\app.py", line 828, in run
runTouchApp()
File "C:\Python34\lib\site-packages\kivy\base.py", line 487, in runTouchApp
EventLoop.window.mainloop()
File "C:\Python34\lib\site-packages\kivy\core\window\window_sdl2.py", line 637, in mainloop
self._mainloop()
File "C:\Python34\lib\site-packages\kivy\core\window\window_sdl2.py", line 390, in _mainloop
EventLoop.idle()
File "C:\Python34\lib\site-packages\kivy\base.py", line 327, in idle
Clock.tick()
File "C:\Python34\lib\site-packages\kivy\clock.py", line 581, in tick
self._process_events()
File "kivy\_clock.pyx", line 368, in kivy._clock.CyClockBase._process_events (kivy\_clock.c:7392)
File "kivy\_clock.pyx", line 398, in kivy._clock.CyClockBase._process_events (kivy\_clock.c:7269)
File "kivy\_clock.pyx", line 396, in kivy._clock.CyClockBase._process_events (kivy\_clock.c:7190)
File "kivy\_clock.pyx", line 168, in kivy._clock.ClockEvent.tick (kivy\_clock.c:3300)
File "C:\Python34\lib\site-packages\kivy\core\window\__init__.py", line 543, in _upd_kbd_height
self._keyboard_changed = not self._keyboard_changed
File "kivy\properties.pyx", line 423, in kivy.properties.Property.__set__ (kivy\properties.c:5212)
File "kivy\properties.pyx", line 461, in kivy.properties.Property.set (kivy\properties.c:5973)
File "kivy\properties.pyx", line 516, in kivy.properties.Property.dispatch (kivy\properties.c:6637)
File "kivy\_event.pyx", line 1225, in kivy._event.EventObservers.dispatch (kivy\_event.c:13521)
File "kivy\_event.pyx", line 1131, in kivy._event.EventObservers._dispatch (kivy\_event.c:12723)
File "kivy\properties.pyx", line 1394, in kivy.properties.AliasProperty.trigger_change (kivy\properties.c:22410)
File "kivy\properties.pyx", line 1400, in kivy.properties.AliasProperty.trigger_change (kivy\properties.c:22301)
File "kivy\properties.pyx", line 516, in kivy.properties.Property.dispatch (kivy\properties.c:6637)
File "kivy\_event.pyx", line 1225, in kivy._event.EventObservers.dispatch (kivy\_event.c:13521)
File "kivy\_event.pyx", line 1131, in kivy._event.EventObservers._dispatch (kivy\_event.c:12723)
File "C:\Python34\lib\site-packages\kivy\core\window\__init__.py", line 778, in <lambda>
keyboard_height=lambda *dt: self.update_viewport())
File "C:\Python34\lib\site-packages\kivy\core\window\__init__.py", line 1141, in update_viewport
targettop = max(0, target.to_window(0, target.y)[1]) if target else 0
AttributeError: 'ChildApp' object has no attribute 'to_window'


Here is a small sample just for demonstrating my problem:

from kivy.config import Config
Config.set('kivy', 'exit_on_escape', '0')
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.popup import Popup
from kivy.core.window import Window
from kivy.properties import ObjectProperty, ListProperty, StringProperty
from kivy.logger import Logger


class ChildApp(App):


def __init__(self, sys_path_list=None):
super(ChildApp, self).__init__()
# Hotkey
self.superkey = []
text = StringProperty()
keyboard = Window.request_keyboard(self._keyboard_released, self)
keyboard.bind(on_key_down=self._keyboard_on_key_down, on_key_up=self._keyboard_released)


def _keyboard_released(self, *args):
self.superkey = []


def _keyboard_on_key_down(self, window, keycode, text, super):
if 'lctrl' in self.superkey and keycode[1] == 's':
Logger.info('DO SOMETHING')
self.superkey = []
return False
elif 'lctrl' not in self.superkey and keycode[1] in ["lctrl"]:
self.superkey.append(keycode[1])
return False
else:
Logger.info("key {} pressed.".format(keycode))
return False


def build(self):
Window.bind(on_request_close=self.on_request_close)
return Label(text='Child')


def on_request_close(self, *args):
Logger.info('Are you sure?')
return True


if __name__ == '__main__':
ChildApp().run()


I was able to make it full-screen on both monitors before adding the key-listening feature.
Could you tell me how could I get it full-screen on both monitors?

Answer

I edited the line # 1141 of the following file:

C:\Python34\Lib\site-packages\kivy\core\window__init__.py

the line:

targettop = max(0, target.to_window(0, target.y)[1]) if target else 0

edited to:

if target and 'to_window' in dir(target):
    targettop = max(0, target.to_window(0, target.y)[1])
else:
    targettop = 0
Comments