From 64f455cc4508183bbacc65ab6afb03b822c301ab Mon Sep 17 00:00:00 2001 From: thladnik Date: Tue, 10 Sep 2019 16:58:33 +0200 Subject: [PATCH 01/19] Added option to select screen for backend_pyglet.set_fullscreen; Added setter/getter for fullscreen in backend_qt5 --- glumpy/app/window/backends/backend_pyglet.py | 17 +++++++++++++---- glumpy/app/window/backends/backend_qt5.py | 13 ++++++++++++- glumpy/app/window/window.py | 2 +- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/glumpy/app/window/backends/backend_pyglet.py b/glumpy/app/window/backends/backend_pyglet.py index a8ef2548..c0bf94cc 100644 --- a/glumpy/app/window/backends/backend_pyglet.py +++ b/glumpy/app/window/backends/backend_pyglet.py @@ -241,18 +241,27 @@ def show(self): def hide(self): self._native_window.set_visible(False) - def set_fullscreen(self, state): - self._native_window.set_fullscreen(state) + def set_fullscreen(self, state, screen=None): + if screen is not None: + if not(isinstance(screen, pyglet.canvas.Screen)) and isinstance(screen, int): + screens = self._native_window.canvas.display.get_screens() + screen = screens[screen] + + self._native_window.set_fullscreen(state, screen=screen) + self._fullscreen = state + + def get_fullscreen(self): + return self._fullscreen def set_title(self, title): self._native_window.set_caption(title) self._title = title - def get_title(self, title): + def get_title(self): return self._title def set_size(self, width, height): - self._window.set_size(width, height) + self._native_window.set_size(width, height) self._width = self._native_window.width self._height = self._native_window.height diff --git a/glumpy/app/window/backends/backend_qt5.py b/glumpy/app/window/backends/backend_qt5.py index c37ac1d4..942e925e 100644 --- a/glumpy/app/window/backends/backend_qt5.py +++ b/glumpy/app/window/backends/backend_qt5.py @@ -357,7 +357,7 @@ def set_title(self, title): self._native_window.setWindowTitle(self._title) self._title = title - def get_title(self, title): + def get_title(self): return self._title def set_size(self, width, height): @@ -370,6 +370,17 @@ def get_size(self): self._height = self._native_window.geometry().height() return self._width, self._height + def set_fullscreen(self, fullscreen): + if fullscreen: + self._native_window.showFullScreen() + else: + self._native_window.showNormal() + self._fullscreen = fullscreen + self.get_size() + + def get_fullscreen(self): + return self._fullscreen + def set_position(self, x, y): self._native_window.move(x,y) self._x = self._native_window.geometry().x() diff --git a/glumpy/app/window/window.py b/glumpy/app/window/window.py index 826eabf5..56fb0196 100644 --- a/glumpy/app/window/window.py +++ b/glumpy/app/window/window.py @@ -283,7 +283,7 @@ def get_position(self): """ Get window position """ log.warn('%s backend cannot get position' % self._backend.name()) - def set_fullscreen(self, fullsrceen): + def set_fullscreen(self, fullscreen): """ Set window fullscreen mode """ log.warn('%s backend cannot set fullscreen mode' % self._backend.name()) From 34731e2a21b8820aa65cc30651dbeba2219df086 Mon Sep 17 00:00:00 2001 From: thladnik Date: Wed, 11 Sep 2019 08:39:26 +0200 Subject: [PATCH 02/19] Added screen setter/getter for qt5 backend and opt. screen argument for set_fullscreen --- glumpy/app/window/backends/backend_qt5.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/glumpy/app/window/backends/backend_qt5.py b/glumpy/app/window/backends/backend_qt5.py index 942e925e..1e1fc22c 100644 --- a/glumpy/app/window/backends/backend_qt5.py +++ b/glumpy/app/window/backends/backend_qt5.py @@ -370,7 +370,10 @@ def get_size(self): self._height = self._native_window.geometry().height() return self._width, self._height - def set_fullscreen(self, fullscreen): + def set_fullscreen(self, fullscreen, screen=None): + if screen is not None: + self.set_screen(screen) + if fullscreen: self._native_window.showFullScreen() else: @@ -381,6 +384,14 @@ def set_fullscreen(self, fullscreen): def get_fullscreen(self): return self._fullscreen + def set_screen(self, screen): + if isinstance(screen, int): + screen = self._native_app.screens()[screen] + self._native_window.windowHandle().setScreen(screen) + + def get_screen(self): + return self._native_window.windowHandle().screen() + def set_position(self, x, y): self._native_window.move(x,y) self._x = self._native_window.geometry().x() From 53bdc42f54c0d2acc91505dbb5f0c84b7ab2253d Mon Sep 17 00:00:00 2001 From: memery-imb Date: Wed, 17 Jun 2020 11:20:42 -0700 Subject: [PATCH 03/19] Added fetch_build_eggs to setup.py for isolated builds --- setup.py | 6 +++++- tox.ini | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 tox.ini diff --git a/setup.py b/setup.py index 6fca4b75..8d11b9f3 100755 --- a/setup.py +++ b/setup.py @@ -5,9 +5,13 @@ # the file COPYING, distributed as part of this software. #----------------------------------------------------------------------------- import os +from setuptools import dist, setup, Extension + +dist.Distribution().fetch_build_eggs(['Cython>=0.15.1', 'numpy>=1.10']) + import numpy from Cython.Distutils import build_ext -from setuptools import setup, Extension + if __name__ == "__main__": diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..b3f63489 --- /dev/null +++ b/tox.ini @@ -0,0 +1,5 @@ +[tox] +envlist = py36 + +commands = + python setup.py install \ No newline at end of file From 79f63fcba780886e67309c52fc1538e4c5584cc4 Mon Sep 17 00:00:00 2001 From: Ivo Ihrke Date: Fri, 24 Jul 2020 18:34:31 +0200 Subject: [PATCH 04/19] imgui_demo added --- examples/imgui_demo.py | 443 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 443 insertions(+) create mode 100644 examples/imgui_demo.py diff --git a/examples/imgui_demo.py b/examples/imgui_demo.py new file mode 100644 index 00000000..5f794662 --- /dev/null +++ b/examples/imgui_demo.py @@ -0,0 +1,443 @@ +# -*- coding: utf-8 -*- +""" + +imgui_demo.py + +A glumpy demo using imgui. + +The demo is structured as follows: + * there are 3 classes: + * ImGuiPlayer implements the main rendering loop; it is design to + play "Apps" + * ImGuiPlayerApp is the abstract base class of Render "Apps" + * DemoApp is the concrete demo application + * everything is kept in one file for convenience, in a real application, + this may be split up for clarity + +Authors: + github user mlviz + Ivo Ihrke + +""" + +import os +from typing import List +import numpy as np + +from glumpy.app import configuration +from glumpy import app, gloo, gl + +import OpenGL.GL as gl +import glfw + +import imgui +from imgui.integrations.glfw import GlfwRenderer + +#------------------------------------------------------------------------------ +#--------------------- abstract base class ------------------------------------ +#------------------------------------------------------------------------------ +class ImGuiPlayerApp: + + def __init__( self, name, window_size ): + pass + + def initialize_program( self ): + pass + + def key_callback( self, window, key, scancode, action, mods): + pass + + def mouse_cursor_pos_callback( self, window, xpos, ypos ): + pass + + def mouse_button_callback( self, window, button, action, mods ): + pass + + def mouse_scroll_callback( self, window, xoffset, yoffset ): + pass + + def window_size_callback( self, window, width, height ): + gl.glViewport(0, 0, width, height); + + def on_draw(self): + pass + + def menu(self): + pass + +#------------------------------------------------------------------------------ +#---------------------------- demo app ---------------------------------------- +#------------------------------------------------------------------------------ + +class DemoApp( ImGuiPlayerApp ): + + # --------------------------------------------------------------------------- + # ------------------------- internal classes ------------------------------- + # --------------------------------------------------------------------------- + + + class UI(): + """ + This class contains the variables that are communicated + to the vertex and fragment programs + """ + + mouse_pos : np.array = None; #mouse position; used for translating the view + zoom : float = None; #zoom value + gamma : float = None; #contrast + blue : float = None; #value of blue compponent for interaction demo + animate : bool = None; #toggle animation + speed : float = None; #speed of animation + theta : float = None; #rotation angle + + prev_mouse : np.array = None; #previous mouse position to implement drag; maybe move to ImGuiPlayer + + def __init__(self): + + + self.mouse_pos = np.array( [0,0] ).astype('float'); + self.zoom = 1.0; + self.gamma = 1.0; + self.blue = 0.0; + self.animate = False; + self.speed = 2.0 * np.pi / 100; + self.theta = 0.0; + + self.prev_mouse = np.array( [-1, -1] ).astype('float'); + + # --------------------------------------------------------------------------- + # --------------------------- class variables ------------------------------- + # --------------------------------------------------------------------------- + + ui : UI = None; + quad : gloo.Program = None; + + def __init__( self ): + + + + self.ui = DemoApp.UI(); + + self.quad = self.quad_init() + + + def quad_init( self ): + ''' + Initializes the rendering geometry (a quad) and the shader programs. + ''' + + + vertex = """ + //note that this is ineffective, I keep it here as a reminder, + //the actual glsl version request must be made to the + //gloo.Program(..., version=130) constructor + #version 130 + + in vec2 position; // do not use layout(location = 0) syntax; glumpy appears to use some magic + in vec3 color; + uniform vec2 mouse_pos; + uniform float zoom; + uniform float blue; + uniform float theta; + + out vec4 frag_color; + + void main() + { + vec2 p = zoom * (position + mouse_pos); + vec2 q = vec2( p.x * cos( theta ) + p.y * sin( theta ), -p.x * sin( theta ) + p.y * cos( theta ) ); + gl_Position = vec4( q, 0.0, 1.0); + frag_color = vec4( color.rg, blue, 1.0 ); + } + """ + + fragment = """ + //note that this is ineffective, I keep it here as a reminder, + //the actual glsl version request must be made to the + //gloo.Program(..., version=130) constructor + #version 130 + + uniform float gamma; + + in vec4 frag_color; // from vertex shader + + out vec4 color; // this is the output color, going to GL_COLOR_ATTACHEMENT0 + + void main() + { + vec3 gamma_col = pow( frag_color.rgb, vec3(1.0/gamma) ); + color = vec4( gamma_col, 1 ); + } + """ + + + #create a shader program for count vertices + quad = gloo.Program(vertex, fragment, count=4, version=130); + + #geometry and texure coordinates for the quad + quad['position'] = [(-1,-1), (-1,+1), (+1,-1), (+1,+1)]; + quad['color'] = [( 0, 0, 0), ( 1, 0, 0), ( 1, 1, 0), ( 0, 1, 0)]; + + #initial values + quad['mouse_pos'] = self.ui.mouse_pos; + quad['zoom'] = self.ui.zoom; + quad['gamma'] = self.ui.gamma; + + return quad + + # --------------------------------------------------------------------------- + # --------------------------- class methods - gui and menu ---------------- + # --------------------------------------------------------------------------- + + + def key_callback( self, window, key, scancode, action, mods): + + + if key == glfw.KEY_SPACE and action == glfw.RELEASE: + self.ui.animate = not self.ui.animate; + + pass + + def mouse_cursor_pos_callback( self, window, xpos, ypos ): + io = imgui.get_io(); + + mouse_pos = np.array( [xpos, ypos] ).astype('float'); + + if io.mouse_down[0]: + + + _, _, w, h = gl.glGetIntegerv(gl.GL_VIEWPORT) + + if not np.all( self.ui.prev_mouse == np.array([-1,-1]) ): + dmouse = self.ui.prev_mouse - mouse_pos; + + self.ui.mouse_pos -= np.array( [ dmouse[0]/w, -dmouse[1]/h] ) / self.ui.zoom * 2; + self.quad["mouse_pos"] = self.ui.mouse_pos; + + print("mouse_pos: {}, dmouse: {}".format( mouse_pos, dmouse ) ); + + self.ui.prev_mouse = mouse_pos; + + + def mouse_button_callback( self, window, button, action, mods ): + pass + + def mouse_scroll_callback( self, window, xoffset, yoffset ): + + self.ui.zoom += yoffset * 0.05; + + if self.ui.zoom < 0.1: + self.ui.zoom = 0.1; + + self.quad["zoom"] = self.ui.zoom; + + + + def on_draw(self): + ''' + called for every rendered frame + ''' + + if self.ui.animate: + self.ui.theta += self.ui.speed; + + if self.ui.theta > 2.0 * np.pi: + self.ui.theta -= 2.0 * np.pi; + + #move variable values to shader program + self.quad['theta'] = self.ui.theta; + + + self.quad.draw(gl.GL_TRIANGLE_STRIP); + + def menu( self ): + + imgui.new_frame() + + #menu bar + if imgui.begin_main_menu_bar(): + if imgui.begin_menu("File", True): + + clicked_quit, selected_quit = imgui.menu_item( + "Quit", 'Ctrl+Q', False, True + ) + + if clicked_quit: + glfw.set_window_should_close( self.window, True ); + + imgui.end_menu() + imgui.end_main_menu_bar() + + imgui.show_test_window() + + imgui.begin("Demo window", True); + imgui.text('ImGuiDemo'); + imgui.text_colored("* hold Left Mouse Button and drag to translate", 0.2, 1., 0.); + imgui.text_colored("* use scroll wheel to zoom", 0.4, 1., 0.); + imgui.text_colored("* press SPACE to toggle animation", 0.6, 1., 0.); + + changed, self.ui.animate = imgui.checkbox("Animate", self.ui.animate ); + changed, self.ui.gamma = imgui.slider_float("Gamma",self.ui.gamma, 0.3, 3.3 ); + changed, self.ui.blue = imgui.slider_float("Blue",self.ui.blue, 0.0, 1.0 ); + imgui.text("Animation Angle: {:0.2f}".format( self.ui.theta / (2.0 * np.pi) * 360.0 ) ); + changed, self.ui.speed = imgui.slider_float("Speed",self.ui.speed, 0.0, np.pi/2.0 ); + + #transfer changed variables to shader programs + self.quad['blue'] = self.ui.blue; + self.quad['gamma'] = self.ui.gamma; + + imgui.end() + +#------------------------------------------------------------------------------ +#------------------------ generic player class ------------------------------- +#------------------------------------------------------------------------------ + +class ImGuiPlayer: + + # --------------------------------------------------------------------------- + # --------------------------- class variables ------------------------------- + # --------------------------------------------------------------------------- + + window = None; + impl : GlfwRenderer = None; + + app : ImGuiPlayerApp = None; + + quit_requested : bool = None; + + def __init__( self, app : ImGuiPlayerApp ): + + self.app = app; + + #initialize window and GUI + imgui.create_context(); + + self.window = self.impl_glfw_init() + self.impl = GlfwRenderer(self.window) + + self.quit_requested = False; + + + + def impl_glfw_init(self): + width, height = 1200, 1200 + window_name = "RefocusApp" + + + if not glfw.init(): + print("Could not initialize OpenGL context") + exit(1) + + glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3) + glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 2) + + # the OPENGL_COMPAT_PROFILE enables the mix between pyimgui and glumpy + glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_COMPAT_PROFILE) + glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, gl.GL_TRUE) + + window = glfw.create_window( int(width), int(height), window_name, None, None ); + glfw.make_context_current( window ) + + if not window: + glfw.terminate() + print("Could not initialize Window") + sys.exit(1) + + self.app.window_size_callback( window, 1200, 1200 ); + + + return window + + # --------------------------------------------------------------------------- + # --------------------------- class methods - gui and menu ---------------- + # --------------------------------------------------------------------------- + + + def key_callback( self, window, key, scancode, action, mods): + + io = imgui.get_io(); + self.impl.keyboard_callback( window, key, scancode, action, mods ); + + if io.want_capture_keyboard: + print("imgui handles") + else: + #print("processed by app: key pressed") + + if key == glfw.KEY_ESCAPE and action == glfw.RELEASE: + self.quit_requested = True; + + if key == glfw.KEY_Q and np.bitwise_and( mods, glfw.MOD_CONTROL ): + self.quit_requested = True; + + self.app.key_callback( window, key, scancode, action, mods ); + + def mouse_cursor_pos_callback( self, window, xpos, ypos ): + io = imgui.get_io(); + + if not io.want_capture_mouse: + self.app.mouse_cursor_pos_callback( window, xpos, ypos ) + + def mouse_button_callback( self, window, button, action, mods ): + io = imgui.get_io(); + + if io.want_capture_mouse: + print("imgui handles") + else: + self.app.mouse_button_callback( window, button, action, mods ); + + def mouse_scroll_callback( self, window, xoffset, yoffset ): + io = imgui.get_io(); + + if io.want_capture_mouse: + print("imgui handles") + else: + #print( "processed by app: scroll: {},{}".format( xoffset, yoffset )); + + self.app.mouse_scroll_callback(window, xoffset, yoffset); + + + def window_size_callback( self, window, width, height ): + self.app.window_size_callback(window, width, height); + + + def run(self): + + glfw.set_key_callback(self.window, self.key_callback ); + glfw.set_cursor_pos_callback( self.window, self.mouse_cursor_pos_callback ); + glfw.set_mouse_button_callback( self.window, self.mouse_button_callback ); + glfw.set_scroll_callback( self.window, self.mouse_scroll_callback ); + glfw.set_window_size_callback( self.window, self.window_size_callback ); + + while not glfw.window_should_close(self.window) and not self.quit_requested: + self.app.on_draw(); + + glfw.poll_events() + self.impl.process_inputs() + + + self.app.menu(); + + gl.glClearColor(0., 0., 0.2, 1) + gl.glClear(gl.GL_COLOR_BUFFER_BIT) + + self.app.on_draw(); + + imgui.render() + self.impl.render(imgui.get_draw_data()) + glfw.swap_buffers(self.window) + + self.impl.shutdown() + glfw.terminate() + + +# --------------------------------------------------------------------------- +# ---------------- main fct - run as app if used from cmd-line ------------ +# --------------------------------------------------------------------------- + + +if __name__ == "__main__": + app = DemoApp(); + + player = ImGuiPlayer( app ) + + player.run(); \ No newline at end of file From 580a1e80fae7862c4680cf45bc0a7b3361c8b5c4 Mon Sep 17 00:00:00 2001 From: Aaron Dargel Date: Sat, 25 Jul 2020 01:38:58 -0500 Subject: [PATCH 05/19] Fix syntax error in translate.glsl Problem: - The translate.glsl file has an errant ')' in two methods that prevents the shader from compiling. Solution: - Remove the ')'. --- glumpy/library/transforms/translate.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/glumpy/library/transforms/translate.glsl b/glumpy/library/transforms/translate.glsl index 25631395..c50abf87 100644 --- a/glumpy/library/transforms/translate.glsl +++ b/glumpy/library/transforms/translate.glsl @@ -11,7 +11,7 @@ vec2 forward(vec2 P) { return P + translate_translate.xy; } vec3 forward(float x, float y, float z) -{ return vec3(x,y,z) + translate_translate); } +{ return vec3(x,y,z) + translate_translate; } vec3 forward(vec3 P) { return P + translate_translate; } @@ -26,7 +26,7 @@ vec2 inverse(vec2 P) { return P - translate_translate.xy; } vec3 inverse(float x, float y, float z) -{ return vec3(x,y,z) - translate_translate); } +{ return vec3(x,y,z) - translate_translate; } vec3 inverse(vec3 P) { return P - translate_translate; } From 4d02458936fa7bb511e734a815fb4a20e578da7e Mon Sep 17 00:00:00 2001 From: thladnik Date: Wed, 19 Aug 2020 17:59:03 +0200 Subject: [PATCH 06/19] Changes to fullscreen/screen on qt5 and pyglet --- glumpy/app/window/backends/backend_glfw.py | 5 +++++ glumpy/app/window/backends/backend_pyglet.py | 16 ++++++++++++---- glumpy/app/window/backends/backend_qt5.py | 5 ++++- glumpy/app/window/window.py | 11 ++++++++++- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/glumpy/app/window/backends/backend_glfw.py b/glumpy/app/window/backends/backend_glfw.py index 3ecbafbd..8e0067d9 100644 --- a/glumpy/app/window/backends/backend_glfw.py +++ b/glumpy/app/window/backends/backend_glfw.py @@ -366,6 +366,11 @@ def close(self): def destroy(self): glfw.glfwDestroyWindow(self._native_window) + + def get_screen(self): + + glfw.glfwGetWindowMonitor() + def set_title(self, title): glfw.glfwSetWindowTitle( self._native_window, title) self._title = title diff --git a/glumpy/app/window/backends/backend_pyglet.py b/glumpy/app/window/backends/backend_pyglet.py index c0bf94cc..27efb04c 100644 --- a/glumpy/app/window/backends/backend_pyglet.py +++ b/glumpy/app/window/backends/backend_pyglet.py @@ -242,10 +242,9 @@ def hide(self): self._native_window.set_visible(False) def set_fullscreen(self, state, screen=None): - if screen is not None: - if not(isinstance(screen, pyglet.canvas.Screen)) and isinstance(screen, int): - screens = self._native_window.canvas.display.get_screens() - screen = screens[screen] + if isinstance(screen, int): + screens = self._native_window.canvas.display.get_screens() + screen = screens[screen] self._native_window.set_fullscreen(state, screen=screen) self._fullscreen = state @@ -260,6 +259,15 @@ def set_title(self, title): def get_title(self): return self._title + def set_screen(self, screen): + if isinstance(screen, int): + self._screen = screen + else: + self._screen = pyglet.canvas.get_display().get_screens().index(screen) + + def get_screen(self): + return pyglet.canvas.get_display().get_screens()[self._screen] + def set_size(self, width, height): self._native_window.set_size(width, height) self._width = self._native_window.width diff --git a/glumpy/app/window/backends/backend_qt5.py b/glumpy/app/window/backends/backend_qt5.py index 1e1fc22c..f45e3da7 100644 --- a/glumpy/app/window/backends/backend_qt5.py +++ b/glumpy/app/window/backends/backend_qt5.py @@ -379,14 +379,17 @@ def set_fullscreen(self, fullscreen, screen=None): else: self._native_window.showNormal() self._fullscreen = fullscreen - self.get_size() def get_fullscreen(self): return self._fullscreen def set_screen(self, screen): if isinstance(screen, int): + self._screen = screen screen = self._native_app.screens()[screen] + else: + self._screen = self._native_app.screens().index(screen) + self._native_window.windowHandle().setScreen(screen) def get_screen(self): diff --git a/glumpy/app/window/window.py b/glumpy/app/window/window.py index 56fb0196..dabfecb1 100644 --- a/glumpy/app/window/window.py +++ b/glumpy/app/window/window.py @@ -130,7 +130,7 @@ def on_idle(self, dt): """ def __init__(self, width=256, height=256, title=None, visible=True, aspect=None, - decoration=True, fullscreen=False, config=None, context=None, color=(0,0,0,1)): + decoration=True, fullscreen=False, screen=None, config=None, context=None, color=(0,0,0,1)): """ Create a window. """ @@ -145,6 +145,7 @@ def __init__(self, width=256, height=256, title=None, visible=True, aspect=None, self._height = height self._title = (title or sys.argv[0]) self._visible = visible + self._screen = screen self._fullscreen = fullscreen self._decoration = decoration self._clock = None @@ -283,6 +284,14 @@ def get_position(self): """ Get window position """ log.warn('%s backend cannot get position' % self._backend.name()) + def set_screen(self, screen): + """ Set window screen """ + log.warn('%s backend cannot set screen' % self._backend.name()) + + def get_screen(self): + """ Get window screen """ + log.warn('%s backend cannot get screen' % self._backend.name()) + def set_fullscreen(self, fullscreen): """ Set window fullscreen mode """ log.warn('%s backend cannot set fullscreen mode' % self._backend.name()) From f3e7117dce92c18ab949381b72aade2d030b99f5 Mon Sep 17 00:00:00 2001 From: thladnik Date: Fri, 21 Aug 2020 11:31:34 +0200 Subject: [PATCH 07/19] Fix glfwGetVideoMode binding; --- glumpy/app/window/backends/backend_glfw.py | 34 ++++++++++++++++------ glumpy/app/window/backends/backend_qt5.py | 5 +++- glumpy/app/window/window.py | 2 +- glumpy/ext/glfw.py | 15 +++++----- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/glumpy/app/window/backends/backend_glfw.py b/glumpy/app/window/backends/backend_glfw.py index 8e0067d9..c6c0134c 100644 --- a/glumpy/app/window/backends/backend_glfw.py +++ b/glumpy/app/window/backends/backend_glfw.py @@ -33,7 +33,7 @@ Fullscreen ✓ Scroll event ✓ ========================== ======== ======================== ======== """ -import os, sys +import os, sys, platform from glumpy import gl from glumpy.log import log from glumpy.app import configuration @@ -190,7 +190,7 @@ def set_configuration(config): class Window(window.Window): def __init__( self, width=512, height=512, title=None, visible=True, aspect=None, - decoration=True, fullscreen=False, config=None, context=None, color=(0,0,0,1), vsync=False): + decoration=True, fullscreen=False, screen=None, config=None, context=None, color=(0,0,0,1), vsync=False): window.Window.__init__(self, width=width, height=height, @@ -199,6 +199,7 @@ def __init__( self, width=512, height=512, title=None, visible=True, aspect=None aspect=aspect, decoration=decoration, fullscreen=fullscreen, + screen=screen, config=config, context=context, color=color) @@ -222,9 +223,14 @@ def on_error(error, message): config = configuration.Configuration() set_configuration(config) - monitor = glfw.glfwGetMonitors()[0] if fullscreen else None - self._native_window = glfw.glfwCreateWindow( self._width, self._height, - self._title, monitor, None) + monitor = glfw.glfwGetMonitors()[self._screen] if fullscreen else None + if fullscreen: + mode = glfw.glfwGetVideoMode(monitor) + self._width, self._height = mode[:2] + + self._native_window = glfw.glfwCreateWindow(self._width, self._height, + self._title, monitor, None) + if not self._native_window: log.critical("Window creation failed") @@ -238,7 +244,7 @@ def on_error(error, message): # can be different so we try to correct window size such as having # the framebuffer size of the right size w,h = glfw.glfwGetFramebufferSize(self._native_window) - if w != width or h!= height: + if platform == 'darwin' and (w!= width or h!= height): width, height = width//2, height//2 glfw.glfwSetWindowSize(self._native_window, width, height) log.info("HiDPI detected, fixing window size") @@ -366,10 +372,20 @@ def close(self): def destroy(self): glfw.glfwDestroyWindow(self._native_window) - def get_screen(self): - - glfw.glfwGetWindowMonitor() + return glfw.glfwGetWindowMonitor(self._native_window) + + def set_fullscreen(self, fullscreen, screen=None): + screen = 0 if screen is None else screen + mode = glfw.glfwGetVideoMode(glfw.glfwGetMonitors()[screen]) + + if fullscreen: + glfw.glfwSetWindowMonitor(self._native_window, screen, 0, 0, mode[0], mode[1], mode[-1]) + else: + glfw.glfwSetWindowMonitor(self._native_window, screen, 0, 0, 256, 256, mode[-1]) + + def get_fullscreen(self): + return self._fullscreen def set_title(self, title): glfw.glfwSetWindowTitle( self._native_window, title) diff --git a/glumpy/app/window/backends/backend_qt5.py b/glumpy/app/window/backends/backend_qt5.py index 874ffe81..54236db5 100644 --- a/glumpy/app/window/backends/backend_qt5.py +++ b/glumpy/app/window/backends/backend_qt5.py @@ -201,7 +201,7 @@ def set_configuration(config): # ------------------------------------------------------------------ Window --- class Window(window.Window): def __init__( self, width=256, height=256, title=None, visible=True, aspect=None, - decoration=True, fullscreen=False, config=None, context=None, color=(0,0,0,1), vsync=False): + decoration=True, fullscreen=False, screen=None, config=None, context=None, color=(0,0,0,1), vsync=False): window.Window.__init__(self, width=width, height=height, @@ -210,6 +210,7 @@ def __init__( self, width=256, height=256, title=None, visible=True, aspect=None aspect=aspect, decoration=decoration, fullscreen=fullscreen, + screen=screen, config=config, context=context, color=color) @@ -236,6 +237,8 @@ def __init__( self, width=256, height=256, title=None, visible=True, aspect=None self._native_window.setMouseTracking(True) self._native_window.setWindowTitle(self._title) + self.set_fullscreen(fullscreen, screen) + def paint_gl(): self.dispatch_event("on_draw", 0.0) self._native_window.paintGL = paint_gl diff --git a/glumpy/app/window/window.py b/glumpy/app/window/window.py index dabfecb1..c39a1f92 100644 --- a/glumpy/app/window/window.py +++ b/glumpy/app/window/window.py @@ -145,7 +145,7 @@ def __init__(self, width=256, height=256, title=None, visible=True, aspect=None, self._height = height self._title = (title or sys.argv[0]) self._visible = visible - self._screen = screen + self._screen = 0 if screen is None else screen self._fullscreen = fullscreen self._decoration = decoration self._clock = None diff --git a/glumpy/ext/glfw.py b/glumpy/ext/glfw.py index 65840c33..64577eae 100644 --- a/glumpy/ext/glfw.py +++ b/glumpy/ext/glfw.py @@ -541,6 +541,7 @@ class GLFWmonitor(Structure): pass glfwRestoreWindow = _glfw.glfwRestoreWindow glfwShowWindow = _glfw.glfwShowWindow glfwHideWindow = _glfw.glfwHideWindow +glfwSetWindowMonitor = _glfw.glfwSetWindowMonitor glfwGetWindowMonitor = _glfw.glfwGetWindowMonitor glfwGetWindowAttrib = _glfw.glfwGetWindowAttrib glfwSetWindowUserPointer = _glfw.glfwSetWindowUserPointer @@ -705,13 +706,13 @@ def glfwGetMonitorPhysicalSize(monitor): def glfwGetVideoMode(monitor): _glfw.glfwGetVideoMode.restype = POINTER(GLFWvidmode) - c_modes = _glfw.glfwGetVideoModes(monitor) - return (c_modes.width, - c_modes.height, - c_modes.redBits, - c_modes.blueBits, - c_modes.greenBits, - c_modes.refreshRate ) + c_mode = _glfw.glfwGetVideoMode(monitor) + return (c_mode.contents.width, + c_mode.contents.height, + c_mode.contents.redBits, + c_mode.contents.blueBits, + c_mode.contents.greenBits, + c_mode.contents.refreshRate) def GetGammaRamp(monitor): From 264cb30c55fcbf49859b4cf84f5375e965dd3ab0 Mon Sep 17 00:00:00 2001 From: QiuJiangkun Date: Thu, 26 Nov 2020 00:02:18 +0800 Subject: [PATCH 08/19] BUGFIX: https://github.com/glumpy/glumpy/issues/268 --- glumpy/graphics/text/sdf_font.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/glumpy/graphics/text/sdf_font.py b/glumpy/graphics/text/sdf_font.py index c31ac813..d801d068 100644 --- a/glumpy/graphics/text/sdf_font.py +++ b/glumpy/graphics/text/sdf_font.py @@ -42,8 +42,8 @@ def zoom(Z, ratio): """ Bilinear image zoom """ nrows, ncols = Z.shape - x,y = np.meshgrid(np.linspace(0, ncols, (ratio*ncols), endpoint=False), - np.linspace(0, nrows, (ratio*nrows), endpoint=False)) + x,y = np.meshgrid(np.linspace(0, ncols, round(ratio*ncols), endpoint=False), + np.linspace(0, nrows, round(ratio*nrows), endpoint=False)) return bilinear_interpolate(Z, x, y) From 7122a17ea2d24d04d69138220a67a88eeff5bc9a Mon Sep 17 00:00:00 2001 From: QiuJiangkun Date: Sat, 28 Nov 2020 23:37:31 +0800 Subject: [PATCH 09/19] int() after round() --- glumpy/graphics/text/sdf_font.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/glumpy/graphics/text/sdf_font.py b/glumpy/graphics/text/sdf_font.py index d801d068..287c3be0 100644 --- a/glumpy/graphics/text/sdf_font.py +++ b/glumpy/graphics/text/sdf_font.py @@ -42,8 +42,8 @@ def zoom(Z, ratio): """ Bilinear image zoom """ nrows, ncols = Z.shape - x,y = np.meshgrid(np.linspace(0, ncols, round(ratio*ncols), endpoint=False), - np.linspace(0, nrows, round(ratio*nrows), endpoint=False)) + x,y = np.meshgrid(np.linspace(0, ncols, int(round(ratio*ncols)), endpoint=False), + np.linspace(0, nrows, int(round(ratio*nrows)), endpoint=False)) return bilinear_interpolate(Z, x, y) From 5583c8a80168278a39cef557ed490a6b1355fe3a Mon Sep 17 00:00:00 2001 From: Le minaw Date: Fri, 12 Feb 2021 13:35:48 +0200 Subject: [PATCH 10/19] Remove GTK from install docs --- doc/installation.rst | 90 ++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/doc/installation.rst b/doc/installation.rst index 488c5baf..65fb8c6a 100644 --- a/doc/installation.rst +++ b/doc/installation.rst @@ -50,60 +50,60 @@ Backends requirements Glumpy requires at least one toolkit for opening a window and creates an OpenGL context. This can be done using one of the standard C/C++ toolkits (Qt, GLFW, -glut, pygame, SDL2, Wx, GTK2 or GTK3) and requires the corresponding python +glut, pygame, SDL2, or Wx) and requires the corresponding python bindings or a pure python toolkit such as pyglet. .. warning:: You only need to have one of these packages, no need to install them all ! -===================== === ==== ====== ==== ==== === -**Modern Backends** Qt GLFW Pyglet SDL2 GTK3 Wx3 ---------------------- --- ---- ------ ---- ---- --- -Multiple windows ✓ ✓ ✓ ✓ ✓ ✓ ---------------------- --- ---- ------ ---- ---- --- -Non-decorated windows ✓ ✓ ✓ ✓ ✓ ✓ ---------------------- --- ---- ------ ---- ---- --- -Resize windows ✓ ✓ ✓ ✓ ✓ ✓ ---------------------- --- ---- ------ ---- ---- --- -Move windows ✓ ✓ ✓ ✓ ✓ ✓ ---------------------- --- ---- ------ ---- ---- --- -Set GL API ✓ ✓ — ✓ ✓ ✓ ---------------------- --- ---- ------ ---- ---- --- -Set GL Profile ✓ ✓ — ✓ ✓ ✓ ---------------------- --- ---- ------ ---- ---- --- -Share GL Context ✓ ✓ ✓ ✓ ✓ ✓ ---------------------- --- ---- ------ ---- ---- --- -Fullscreen ✓ ✓ ✓ ✓ ✓ ✓ ---------------------- --- ---- ------ ---- ---- --- -Unicode handling ✓ ✓ ✓ ✓ ✓ ✓ -===================== === ==== ====== ==== ==== === +===================== === ==== ====== ==== === +**Modern Backends** Qt GLFW Pyglet SDL2 Wx3 +--------------------- --- ---- ------ ---- --- +Multiple windows ✓ ✓ ✓ ✓ ✓ +--------------------- --- ---- ------ ---- --- +Non-decorated windows ✓ ✓ ✓ ✓ ✓ +--------------------- --- ---- ------ ---- --- +Resize windows ✓ ✓ ✓ ✓ ✓ +--------------------- --- ---- ------ ---- --- +Move windows ✓ ✓ ✓ ✓ ✓ +--------------------- --- ---- ------ ---- --- +Set GL API ✓ ✓ — ✓ ✓ +--------------------- --- ---- ------ ---- --- +Set GL Profile ✓ ✓ — ✓ ✓ +--------------------- --- ---- ------ ---- --- +Share GL Context ✓ ✓ ✓ ✓ ✓ +--------------------- --- ---- ------ ---- --- +Fullscreen ✓ ✓ ✓ ✓ ✓ +--------------------- --- ---- ------ ---- --- +Unicode handling ✓ ✓ ✓ ✓ ✓ +===================== === ==== ====== ==== === | -======================== === ==== ======== ====== ======= -**Old school backends** Wx2 Glut Freeglut Pygame GTK 2.x ------------------------- --- ---- -------- ------ ------- -Multiple windows ✓ — — — ✓ ------------------------- --- ---- -------- ------ ------- -Non-decorated windows ✓ ✓ ✓ ✓ ✓ ------------------------- --- ---- -------- ------ ------- -Resize windows ✓ ✓ ✓ — ✓ ------------------------- --- ---- -------- ------ ------- -Move windows ✓ ✓ ✓ — ✓ ------------------------- --- ---- -------- ------ ------- -Set GL API — — — — — ------------------------- --- ---- -------- ------ ------- -Set GL Profile — — — — — ------------------------- --- ---- -------- ------ ------- -Share GL Context — — — — ✓ ------------------------- --- ---- -------- ------ ------- -Fullscreen ✓ ✓ ✓ ✓ ✓ ------------------------- --- ---- -------- ------ ------- -Unicode handling ✓ — — ✓ ✓ ------------------------- --- ---- -------- ------ ------- -Scroll event ✓ — ✓ — ✓ -======================== === ==== ======== ====== ======= +======================== === ==== ======== ====== +**Old school backends** Wx2 Glut Freeglut Pygame +------------------------ --- ---- -------- ------ +Multiple windows ✓ — — — +------------------------ --- ---- -------- ------ +Non-decorated windows ✓ ✓ ✓ ✓ +------------------------ --- ---- -------- ------ +Resize windows ✓ ✓ ✓ — +------------------------ --- ---- -------- ------ +Move windows ✓ ✓ ✓ — +------------------------ --- ---- -------- ------ +Set GL API — — — — +------------------------ --- ---- -------- ------ +Set GL Profile — — — — +------------------------ --- ---- -------- ------ +Share GL Context — — — — +------------------------ --- ---- -------- ------ +Fullscreen ✓ ✓ ✓ ✓ +------------------------ --- ---- -------- ------ +Unicode handling ✓ — — ✓ +------------------------ --- ---- -------- ------ +Scroll event ✓ — ✓ — +======================== === ==== ======== ====== From 319f02aa4309183e669692a66e4fb5f32cc0c59c Mon Sep 17 00:00:00 2001 From: Le minaw Date: Fri, 12 Feb 2021 13:38:06 +0200 Subject: [PATCH 11/19] remove gtk from docs --- doc/tutorial/hardway.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tutorial/hardway.rst b/doc/tutorial/hardway.rst index 4467bed7..3130accc 100644 --- a/doc/tutorial/hardway.rst +++ b/doc/tutorial/hardway.rst @@ -3,7 +3,7 @@ The hard way ============ Before even using OpenGL, we need to open a window with a valid GL -context. This can be done using toolkit such as Gtk, Qt or Wx or any native +context. This can be done using toolkit such as Qt or Wx, or any native toolkit (Windows, Linux, OSX). Note there also exists dedicated toolkits such as GLFW or GLUT and the advantage of GLUT is that it's already installed alongside OpenGL. Even if it is now deprecated, we'll use GLUT since it's a From 70b83a338873e6988731acd7e9c6b496bf59e4b0 Mon Sep 17 00:00:00 2001 From: David Matthews Date: Sat, 27 Feb 2021 20:17:23 -0500 Subject: [PATCH 12/19] adding key mapping of shift keys to glfw backend --- glumpy/app/window/backends/backend_glfw.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/glumpy/app/window/backends/backend_glfw.py b/glumpy/app/window/backends/backend_glfw.py index c6c0134c..03070d5b 100644 --- a/glumpy/app/window/backends/backend_glfw.py +++ b/glumpy/app/window/backends/backend_glfw.py @@ -107,6 +107,8 @@ def __exit__(): glfw.GLFW_KEY_HOME: window.key.HOME, glfw.GLFW_KEY_END: window.key.END, glfw.GLFW_KEY_CAPS_LOCK: window.key.CAPSLOCK, + glfw.GLFW_KEY_LEFT_SHIFT: window.key.LSHIFT, + glfw.GLFW_KEY_RIGHT_SHIFT: window.key.RSHIFT, glfw.GLFW_KEY_PRINT_SCREEN: window.key.PRINT, glfw.GLFW_KEY_PAUSE: window.key.PAUSE, glfw.GLFW_KEY_F1: window.key.F1, From 5d98bd9077c97db72f0e48d3c493cd6f59737fdd Mon Sep 17 00:00:00 2001 From: David Matthews Date: Sat, 27 Feb 2021 20:19:44 -0500 Subject: [PATCH 13/19] modifying trackball pan to pan when shift key is pressed --- glumpy/transforms/trackball_pan.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/glumpy/transforms/trackball_pan.py b/glumpy/transforms/trackball_pan.py index 891dc674..5a14f258 100644 --- a/glumpy/transforms/trackball_pan.py +++ b/glumpy/transforms/trackball_pan.py @@ -1,7 +1,7 @@ import numpy as np from . import _trackball from . transform import Transform -from glumpy import gl, glm, library +from glumpy import gl, glm, library, app class TrackballPan(Transform): @@ -217,8 +217,7 @@ def on_mouse_scroll(self, x, y, dx, dy): self._znear, self._zfar) def on_key_press(self, k, m): - #print('p', k, m) - if m == 1: + if k == app.window.key.LSHIFT or k == app.window.key.RSHIFT: self._shift = True def on_key_release(self, k, m): From 735a57582e46a532f475dcfbddc118e9c6c0ddaf Mon Sep 17 00:00:00 2001 From: David Matthews Date: Sun, 28 Feb 2021 01:26:28 -0500 Subject: [PATCH 14/19] updating trackball pan to have settters / properties for the view_x and view_y variables --- glumpy/transforms/trackball_pan.py | 43 ++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/glumpy/transforms/trackball_pan.py b/glumpy/transforms/trackball_pan.py index 5a14f258..8a32c9b4 100644 --- a/glumpy/transforms/trackball_pan.py +++ b/glumpy/transforms/trackball_pan.py @@ -146,7 +146,7 @@ def zoom(self): return self._zoom - @phi.setter + @zoom.setter def zoom(self, value): """ Zoom level (aperture angle in degrees) """ @@ -162,6 +162,8 @@ def aspect(self): return self._aspect + + @aspect.setter def aspect(self, value): """ Projection aspect """ @@ -171,6 +173,40 @@ def aspect(self, value): self._znear, self._zfar) + @property + def view_x(self): + """ + Pan X + """ + return self._view_x + + @view_x.setter + def view_x(self, value): + """ + Set pan X + """ + self._view_x = value + self.update_pan() + + + @property + def view_y(self): + """ + Pan y + """ + return self._view_y + + @view_y.setter + def view_y(self, value): + """ + Set pan y + """ + self._view_y = value + self.update_pan() + + def update_pan(self): + self["pan"] = self._view_x, self._view_y + def on_attach(self, program): self["view"] = self._view self["model"] = self._trackball.model @@ -186,17 +222,14 @@ def on_resize(self, width, height): self._znear, self._zfar) Transform.on_resize(self, width, height) - - def on_mouse_drag(self, x, y, dx, dy, button): if self._shift: # shift button is currently pressed # print(self._znear, self._zfar) dx = 2 * (dx / self._width) dy = -2 * (dy / self._height) - self['pan'] = self._view_x, self._view_y self._view_x += dx self._view_y += dy - aspect = self._window_aspect * self._aspect + self.update_pan() else: width = self._width height = self._height From 80a0aee83a55e9a7ab72aedb9ad44be304e9f084 Mon Sep 17 00:00:00 2001 From: eyllanesc Date: Mon, 15 Mar 2021 23:31:12 -0500 Subject: [PATCH 15/19] Expose native window as property --- glumpy/app/window/window.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/glumpy/app/window/window.py b/glumpy/app/window/window.py index c39a1f92..9224b849 100644 --- a/glumpy/app/window/window.py +++ b/glumpy/app/window/window.py @@ -153,6 +153,7 @@ def __init__(self, width=256, height=256, title=None, visible=True, aspect=None, self._timer_date = [] self._backend = None self._color = color + self._native_window = None self._clearflags = gl.GL_COLOR_BUFFER_BIT if config._depth_size: @@ -209,6 +210,10 @@ def clear(self,color=None, clearflags=None): gl.glClearColor(*self._color) if clearflags is not None: gl.glClear(clearflags) else: gl.glClear(self._clearflags) + + @property + def native_window(self): + return self._native_window def on_init(self): """ Window initialization """ From c67ce07d0101b33b931636419dbf6f009fdcc9bc Mon Sep 17 00:00:00 2001 From: Carlos Bergillos Date: Sun, 21 Mar 2021 20:57:57 +0100 Subject: [PATCH 16/19] Activate window on resize --- glumpy/app/window/window.py | 1 + 1 file changed, 1 insertion(+) diff --git a/glumpy/app/window/window.py b/glumpy/app/window/window.py index 9224b849..7b411d37 100644 --- a/glumpy/app/window/window.py +++ b/glumpy/app/window/window.py @@ -223,6 +223,7 @@ def on_init(self): def on_resize(self, width, height): """" Default resize handler that set viewport """ + self.activate() gl.glViewport(0, 0, width, height) self.dispatch_event('on_draw', 0.0) self.swap() From f646c7ce5b0230bb9cc1841de2814384b14ba016 Mon Sep 17 00:00:00 2001 From: Carlos Bergillos Date: Fri, 2 Apr 2021 20:56:01 +0200 Subject: [PATCH 17/19] Fixes to window get_title & set_title --- glumpy/app/window/backends/backend_freeglut.py | 2 +- glumpy/app/window/backends/backend_glfw.py | 2 +- glumpy/app/window/backends/backend_osxglut.py | 2 +- glumpy/app/window/backends/backend_pyside.py | 2 +- glumpy/app/window/backends/backend_pyside2.py | 2 +- glumpy/app/window/backends/backend_template.py | 2 +- glumpy/ext/glfw.py | 10 ++++++++-- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/glumpy/app/window/backends/backend_freeglut.py b/glumpy/app/window/backends/backend_freeglut.py index ba2650d0..a6a320bf 100644 --- a/glumpy/app/window/backends/backend_freeglut.py +++ b/glumpy/app/window/backends/backend_freeglut.py @@ -368,7 +368,7 @@ def set_title(self, title): glut.glutSetWindowTitle( title ) self._title = title - def get_title(self, title): + def get_title(self): return self._title def set_size(self, width, height): diff --git a/glumpy/app/window/backends/backend_glfw.py b/glumpy/app/window/backends/backend_glfw.py index 03070d5b..66413814 100644 --- a/glumpy/app/window/backends/backend_glfw.py +++ b/glumpy/app/window/backends/backend_glfw.py @@ -393,7 +393,7 @@ def set_title(self, title): glfw.glfwSetWindowTitle( self._native_window, title) self._title = title - def get_title(self, title): + def get_title(self): return self._title def set_size(self, width, height): diff --git a/glumpy/app/window/backends/backend_osxglut.py b/glumpy/app/window/backends/backend_osxglut.py index cc2e43db..c90ccb0b 100644 --- a/glumpy/app/window/backends/backend_osxglut.py +++ b/glumpy/app/window/backends/backend_osxglut.py @@ -367,7 +367,7 @@ def set_title(self, title): glut.glutSetWindowTitle( title ) self._title = title - def get_title(self, title): + def get_title(self): return self._title def set_size(self, width, height): diff --git a/glumpy/app/window/backends/backend_pyside.py b/glumpy/app/window/backends/backend_pyside.py index c2cdc809..5acf3467 100644 --- a/glumpy/app/window/backends/backend_pyside.py +++ b/glumpy/app/window/backends/backend_pyside.py @@ -356,7 +356,7 @@ def set_title(self, title): self._native_window.setWindowTitle(self._title) self._title = title - def get_title(self, title): + def get_title(self): return self._title def set_size(self, width, height): diff --git a/glumpy/app/window/backends/backend_pyside2.py b/glumpy/app/window/backends/backend_pyside2.py index 7aa6198f..54d3c6c9 100644 --- a/glumpy/app/window/backends/backend_pyside2.py +++ b/glumpy/app/window/backends/backend_pyside2.py @@ -354,7 +354,7 @@ def set_title(self, title): self._native_window.setWindowTitle(self._title) self._title = title - def get_title(self, title): + def get_title(self): return self._title def set_size(self, width, height): diff --git a/glumpy/app/window/backends/backend_template.py b/glumpy/app/window/backends/backend_template.py index 95444ec6..8d1d2cc7 100644 --- a/glumpy/app/window/backends/backend_template.py +++ b/glumpy/app/window/backends/backend_template.py @@ -142,7 +142,7 @@ def set_title(self, title): """ Set window title """ raise(NotImplemented) - def get_title(self, title): + def get_title(self): """ Get window title """ raise(NotImplemented) diff --git a/glumpy/ext/glfw.py b/glumpy/ext/glfw.py index 64577eae..f258df05 100644 --- a/glumpy/ext/glfw.py +++ b/glumpy/ext/glfw.py @@ -531,7 +531,7 @@ class GLFWmonitor(Structure): pass # glfwDestroyWindow = _glfw.glfwDestroyWindow glfwWindowShouldClose = _glfw.glfwWindowShouldClose glfwSetWindowShouldClose = _glfw.glfwSetWindowShouldClose -glfwSetWindowTitle = _glfw.glfwSetWindowTitle +# glfwSetWindowTitle = _glfw.glfwSetWindowTitle # glfwGetWindowPos = _glfw.glfwGetWindowPos glfwSetWindowPos = _glfw.glfwSetWindowPos # glfwGetWindowSize = _glfw.glfwGetWindowSize @@ -611,7 +611,7 @@ def glfwCreateWindow(width=640, height=480, title="GLFW Window", monitor=None, share=None): _glfw.glfwCreateWindow.restype = POINTER(GLFWwindow) if not isinstance(title,bytes): - title = title.encode("ascii") + title = title.encode('utf-8') window = _glfw.glfwCreateWindow(width,height,title,monitor,share) __windows__.append(window) __destroyed__.append(False) @@ -646,6 +646,12 @@ def glfwDestroyWindow(window): __destroyed__[index] = True +def glfwSetWindowTitle(window, title): + if not isinstance(title, bytes): + title = title.encode('utf-8') + _glfw.glfwSetWindowTitle(window, title) + + def glfwGetWindowPos(window): xpos, ypos = c_int(0), c_int(0) _glfw.glfwGetWindowPos(window, byref(xpos), byref(ypos)) From 1e42eb25e78d3418506d36b059c175921d8ae7e5 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Tue, 4 May 2021 13:53:57 +0200 Subject: [PATCH 18/19] Fix math of quadric filter function The comment above it clearly indicates that this constant should be 0.5, not 0.75. The use of 0.75 in its place seems to have been a simple mistake, perhaps due to the 0.75 constant after it. The corrected value of 0.5 matches the implementation in AGG, ImageMagick, and elsewhere. cf. https://sourceforge.net/p/agg/svn/HEAD/tree/agg-2.4/include/agg_image_filters.h cf. https://github.com/ImageMagick/ImageMagick/blob/main/MagickCore/resize.c#L415 --- glumpy/library/build-spatial-filters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glumpy/library/build-spatial-filters.py b/glumpy/library/build-spatial-filters.py index 995d36b3..4574d45b 100644 --- a/glumpy/library/build-spatial-filters.py +++ b/glumpy/library/build-spatial-filters.py @@ -274,7 +274,7 @@ def __init__(self): SpatialFilter.__init__(self, radius=1.5) def weight(self, x): - if x < 0.75: + if x < 0.5: return 0.75 - x * x elif x < 1.5: t = x - 1.5 From 2cc91b6859d14dcbad89d6877c213e3f7aeb9807 Mon Sep 17 00:00:00 2001 From: hesom Date: Wed, 5 May 2021 12:26:51 +0200 Subject: [PATCH 19/19] Fix deprecated Python 2 attribute naming --- glumpy/app/window/event.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/glumpy/app/window/event.py b/glumpy/app/window/event.py index 409ce895..d4f9223f 100644 --- a/glumpy/app/window/event.py +++ b/glumpy/app/window/event.py @@ -438,9 +438,9 @@ def _raise_dispatch_exception(self, event_type, args, handler): if n_handler_args != n_args: if inspect.isfunction(handler) or inspect.ismethod(handler): descr = '%s at %s:%d' % ( - handler.func_name, - handler.func_code.co_filename, - handler.func_code.co_firstlineno) + handler.__name__, + handler.__code__.co_filename, + handler.__code__.co_firstlineno) else: descr = repr(handler)