-
-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1755 from freakboy3742/gtk-probe
Add GTK probe.
- Loading branch information
Showing
14 changed files
with
201 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
A GTK GUI test probe was added. |
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
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
Empty file.
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from pytest import skip | ||
|
||
from toga_gtk.libs import Gtk | ||
|
||
|
||
class SimpleProbe: | ||
def __init__(self, widget): | ||
self.widget = widget | ||
self.impl = widget._impl | ||
self.native = widget._impl.native | ||
assert isinstance(self.native, self.native_class) | ||
|
||
def assert_container(self, container): | ||
container_native = container._impl.native | ||
for control in container_native.get_children(): | ||
if control == self.native: | ||
break | ||
else: | ||
raise ValueError(f"cannot find {self.native} in {container_native}") | ||
|
||
async def redraw(self): | ||
"""Request a redraw of the app, waiting until that redraw has completed.""" | ||
# Refresh the layout | ||
self.widget.window.content.refresh() | ||
|
||
# Force a repaint | ||
while Gtk.events_pending(): | ||
Gtk.main_iteration_do(blocking=False) | ||
|
||
@property | ||
def enabled(self): | ||
skip("enabled probe not implemented") | ||
|
||
@property | ||
def hidden(self): | ||
skip("hidden probe not implemented") | ||
|
||
@property | ||
def width(self): | ||
return self.native.get_allocation().width | ||
|
||
@property | ||
def height(self): | ||
return self.native.get_allocation().height | ||
|
||
def press(self): | ||
skip("Press probe not implemented") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from pytest import skip | ||
|
||
from toga_gtk.libs import Gtk | ||
|
||
from .base import SimpleProbe | ||
|
||
|
||
class ButtonProbe(SimpleProbe): | ||
native_class = Gtk.Button | ||
|
||
@property | ||
def text(self): | ||
return self.native.get_label() | ||
|
||
@property | ||
def color(self): | ||
skip("color probe not implemented") | ||
|
||
@property | ||
def font(self): | ||
skip("font probe not implemented") | ||
|
||
@property | ||
def background_color(self): | ||
skip("background color probe not implemented") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from pytest import skip | ||
|
||
from toga_gtk.libs import Gtk | ||
|
||
from .base import SimpleProbe | ||
|
||
|
||
class LabelProbe(SimpleProbe): | ||
native_class = Gtk.Label | ||
|
||
@property | ||
def text(self): | ||
return self.native.get_label() | ||
|
||
@property | ||
def color(self): | ||
skip("color probe not implemented") | ||
|
||
@property | ||
def background_color(self): | ||
skip("background color probe not implemented") | ||
|
||
@property | ||
def font(self): | ||
skip("font probe not implemented") | ||
|
||
@property | ||
def alignment(self): | ||
skip("alignment probe not implemented") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from dataclasses import dataclass | ||
|
||
from toga.fonts import NORMAL | ||
from toga.style.pack import CENTER, JUSTIFY, LEFT, RIGHT | ||
from toga_gtk.libs import Gtk, Pango | ||
|
||
|
||
def toga_color(color): | ||
return color | ||
|
||
|
||
@dataclass | ||
class Font: | ||
family: str | ||
size: int | ||
style: str = NORMAL | ||
variant: str = NORMAL | ||
weight: str = NORMAL | ||
|
||
|
||
def toga_font(font): | ||
return Font( | ||
family=font.get_family(), | ||
size=font.get_size() / Pango.SCALE, | ||
) | ||
|
||
|
||
def toga_alignment(alignment): | ||
return { | ||
(0.0, Gtk.Justification.LEFT): LEFT, | ||
(1.0, Gtk.Justification.RIGHT): RIGHT, | ||
(0.5, Gtk.Justification.CENTER): CENTER, | ||
(0.0, Gtk.Justification.FILL): JUSTIFY, | ||
}[alignment] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from toga_gtk.libs import Gtk | ||
|
||
from .base import SimpleProbe | ||
|
||
|
||
class SliderProbe(SimpleProbe): | ||
native_class = Gtk.Scale | ||
|
||
@property | ||
def position(self): | ||
return (self.native.get_value() - self._min) / (self._max - self._min) | ||
|
||
def change(self, position): | ||
self.native.set_value(self._min + round(position * (self._max - self._min))) | ||
|
||
@property | ||
def _min(self): | ||
return self.impl.adj.get_lower() | ||
|
||
@property | ||
def _max(self): | ||
return self.impl.adj.get_upper() |
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
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
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
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