Created
August 18, 2015 17:34
-
-
Save achadwick/c826870d80034c881d07 to your computer and use it in GitHub Desktop.
gdk-screen-layout-tester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Draws the layout of the current GdkScreen. | |
# CC0 1.0 2014-12-15 Andrew Chadwick, all rights waived | |
# https://creativecommons.org/publicdomain/zero/1.0/ | |
import logging | |
from gi.repository import Gtk | |
from gi.repository import Gdk | |
APP_NAME = "mypaint-usertest-gdk-screens" | |
logger = logging.getLogger(APP_NAME) | |
class Tester (object): | |
MARGIN = 20 | |
def __init__(self): | |
super(Tester, self).__init__() | |
w = Gtk.Window() | |
w.set_title(APP_NAME) | |
w.connect("destroy", self._destroy_cb) | |
d = Gtk.DrawingArea() | |
d.set_size_request(600, 500) | |
d.connect("draw", self._draw_cb) | |
w.add(d) | |
self._main_window = w | |
self._drawing_area = d | |
screen = d.get_screen() | |
screen.connect("size-changed", self._screen_size_changed) | |
screen.connect("monitors-changed", self._screen_monitors_changed) | |
def run(self): | |
self._main_window.show_all() | |
Gtk.main() | |
def _destroy_cb(self, win): | |
Gtk.main_quit() | |
def _draw_cb(self, da, cr): | |
cr.set_source_rgb(1,1,1) | |
cr.paint() | |
dw = da.get_allocated_width() | |
dh = da.get_allocated_height() | |
cr.translate(self.MARGIN, self.MARGIN) | |
ew = dw - 2.0*self.MARGIN | |
eh = dh - 2.0*self.MARGIN | |
cr.translate(ew/2, eh/2) | |
screen = da.get_screen() | |
sw = screen.get_width() | |
sh = screen.get_height() | |
scale = min(ew/sw, eh/sh) | |
cr.scale(scale, scale) | |
cr.translate(-sw/2, -sh/2) | |
cr.set_source_rgba(0, 0, 0, 0.05) | |
cr.rectangle(0, 0, sw, sh) | |
cr.fill() | |
mpn = screen.get_primary_monitor() | |
for mn in range(screen.get_n_monitors()): | |
geom = screen.get_monitor_geometry(mn) | |
mx = geom.x | |
my = geom.y | |
mw = geom.width | |
mh = geom.height | |
cr.rectangle(mx, my, mw, mh) | |
if mn == mpn: | |
cr.set_source_rgba(0.8, 0, 0, 0.1) | |
cr.fill_preserve() | |
cr.set_source_rgb(0.8,0,0) | |
cr.set_line_width(5) | |
cr.stroke() | |
else: | |
cr.set_source_rgba(0, 0, 0, 0.05) | |
cr.fill_preserve() | |
cr.set_source_rgb(0,0,0) | |
cr.set_line_width(1) | |
cr.stroke() | |
def _screen_size_changed(self, *a): | |
self._drawing_area.queue_draw() | |
def _screen_monitors_changed(self, *a): | |
self._drawing_area.queue_draw() | |
if __name__ == '__main__': | |
logging.basicConfig(level=logging.DEBUG) | |
app = Tester() | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment