Merge pull request #2 from markochk/main

A few small improvements
This commit is contained in:
Taiko2k
2022-02-25 10:46:40 +13:00
committed by GitHub

View File

@@ -261,7 +261,7 @@ A label is like a basic line of text
```python ```python
self.label = Gtk.Label(label="A switch") self.label = Gtk.Label(label="A switch")
self.switch_box.append(self.switch) self.switch_box.append(self.label)
self.switch_box.set_spacing(5) # Add some spacing self.switch_box.set_spacing(5) # Add some spacing
``` ```
@@ -414,18 +414,18 @@ To draw with Cairo we use the [***DrawingArea***](https://docs.gtk.org/gtk4/clas
```python ```python
dw = Gtk.DrawingArea() self.dw = Gtk.DrawingArea()
# Make it fill the available space (It will stretch with the window) # Make it fill the available space (It will stretch with the window)
dw.set_hexpand(True) self.dw.set_hexpand(True)
dw.set_vexpand(True) self.dw.set_vexpand(True)
# Instead, If we didn't want it to fill the available space but wanted a fixed size # Instead, If we didn't want it to fill the available space but wanted a fixed size
#dw.set_content_width(100) #self.dw.set_content_width(100)
#dw.set_content_height(100) #self.dw.set_content_height(100)
dw.set_draw_func(self.draw, None) self.dw.set_draw_func(self.draw, None)
self.box3.append(dw) self.box3.append(self.dw)
def draw(self, area, c, w, h, data): def draw(self, area, c, w, h, data):
# c is a Cairo context # c is a Cairo context
@@ -514,6 +514,7 @@ See also: [EventControllerMotion](https://docs.gtk.org/gtk4/class.EventControlle
```python ```python
evk = Gtk.EventControllerMotion.new() evk = Gtk.EventControllerMotion.new()
evk.connect("motion", self.mouse_motion) evk.connect("motion", self.mouse_motion)
self.add_controller(evk)
def mouse_motion(self, motion, x, y): def mouse_motion(self, motion, x, y):
print(f"Mouse moved to {x}, {y}") print(f"Mouse moved to {x}, {y}")
``` ```
@@ -525,7 +526,7 @@ See also: [EventControllerKey](https://docs.gtk.org/gtk4/class.EventControllerKe
evk.connect("key-pressed", self.key_press) evk.connect("key-pressed", self.key_press)
self.add_controller(evk) # add to window self.add_controller(evk) # add to window
def key_press(self, event, keyval, keycode, state): def key_press(self, event, keyval, keycode, state):
if keyval == Gdk.KEY_q and state & Gdk.ModifierType.CONTROL_MASK: if keyval == Gdk.KEY_q and state & Gdk.ModifierType.CONTROL_MASK: # Add Gdk to your imports. i.e. from gi import Gdk
self.close() self.close()
``` ```