From d42492ced5ce05271623fbedaf0095f27fa27471 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 13 Mar 2019 15:38:08 -0400 Subject: [PATCH] rind: Add gtk Application and Builder I also add a basic UI file that contains the main window. I'll add on to the gui from here. Signed-off-by: Anna Schumaker --- .gitignore | 1 + emmental.py | 4 ++++ emmental.ui | 21 +++++++++++++++++++++ rind/__init__.py | 4 ++++ rind/gtk.py | 20 ++++++++++++++++++++ rind/test_gtk.py | 28 ++++++++++++++++++++++++++++ test_emmental.py | 4 ++++ 7 files changed, 82 insertions(+) create mode 100644 emmental.ui create mode 100644 rind/__init__.py create mode 100644 rind/gtk.py create mode 100644 rind/test_gtk.py diff --git a/.gitignore b/.gitignore index cf3c4c7..a978261 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *__pycache__* *.ogg *.coverage +*.ui~ diff --git a/emmental.py b/emmental.py index 740b8c9..7374798 100755 --- a/emmental.py +++ b/emmental.py @@ -1,3 +1,7 @@ #!/usr/bin/python # Copyright 2019 (c) Anna Schumaker. import curds +import rind +import sys + +rind.Application.run(sys.argv) diff --git a/emmental.ui b/emmental.ui new file mode 100644 index 0000000..9632916 --- /dev/null +++ b/emmental.ui @@ -0,0 +1,21 @@ + + + + + + False + Emmental + 1280 + 800 + + + + + + True + False + label + + + + diff --git a/rind/__init__.py b/rind/__init__.py new file mode 100644 index 0000000..27aabec --- /dev/null +++ b/rind/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2019 (c) Anna Schumaker. +from . import gtk + +Application = gtk.Application diff --git a/rind/gtk.py b/rind/gtk.py new file mode 100644 index 0000000..babf4bf --- /dev/null +++ b/rind/gtk.py @@ -0,0 +1,20 @@ +# Copyright 2019 (c) Anna Schumaker. +import gi +gi.require_version("Gtk", "3.0") +from gi.repository import Gtk + +Builder = Gtk.Builder() +Builder.add_from_file("emmental.ui") + +class EmmentalApplication(Gtk.Application): + def __init__(self, *args, **kwargs): + super().__init__(*args, application_id="org.gtk.emmental", **kwargs) + self.window = None + + def do_activate(self): + if self.window == None: + self.window = Builder.get_object("window") + self.add_window(self.window) + self.window.present() + +Application = EmmentalApplication() diff --git a/rind/test_gtk.py b/rind/test_gtk.py new file mode 100644 index 0000000..6a3705b --- /dev/null +++ b/rind/test_gtk.py @@ -0,0 +1,28 @@ +# Copyright 2019 (c) Anna Schumaker. +from . import gtk +import curds +import time +import unittest +from gi.repository import Gtk + +class TestGtk(unittest.TestCase): + def test_builder(self): + self.assertIsInstance(gtk.Builder, Gtk.Builder) + self.assertIsInstance(gtk.Builder.get_object("window"), Gtk.ApplicationWindow) + + def test_window(self): + window = gtk.Builder.get_object("window") + self.assertIsInstance(window, Gtk.ApplicationWindow) + self.assertIsNone(gtk.Application.window) + self.assertEqual(window.get_title(), "Emmental") + + thread = curds.ThreadQueue() + thread.push(gtk.Application.run) + while gtk.Application.window == None: + time.sleep(0.1) + self.assertTrue(window.is_visible()) + gtk.Application.quit() + thread.stop() + + def test_application(self): + self.assertIsInstance(gtk.Application, Gtk.Application) diff --git a/test_emmental.py b/test_emmental.py index 44fc7ae..2097e61 100644 --- a/test_emmental.py +++ b/test_emmental.py @@ -1,5 +1,6 @@ # Copyright 2019 (c) Anna Schumaker. import curds +import rind import unittest class TestEmmental(unittest.TestCase): @@ -10,3 +11,6 @@ class TestEmmental(unittest.TestCase): self.assertEqual(curds.Playlist, curds.playlist.playlist.Playlist) self.assertEqual(curds.ThreadQueue, curds.threadqueue.ThreadQueue) self.assertEqual(curds.Track, curds.tags.Track) + + def test_import_rind(self): + self.assertEqual(rind.Application, rind.gtk.Application)