GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — updated libgio · leonhd/rpythonic@46c947b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • examples
    • libgio-helloworld.py
    • libgio
      • __init__.py
  • scripts
    • gen-gtk-wrappers.py
    • glibfooter.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎examples/libgio-helloworld.py‎

Copy file name to clipboardExpand all lines: examples/libgio-helloworld.py
+87-7Lines changed: 87 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,97 @@
33

44
import os, sys, time, ctypes
55
import libgio as gio
6-
print(gio)
6+
glib = gio
77
gio.g_type_init()
88

99
file = gio.file_new_for_path( '/tmp' )
1010
info = gio.file_query_info(file, "standard::*", gio.G_FILE_QUERY_INFO_NONE, None, None)
1111
print(info)
1212

13-
print( info.get_name() )
14-
print( info.get_size() )
15-
print( info.get_icon() )
16-
print( info.get_content_type() )
17-
#print( info.get_attribute_string() )
18-
#print( info.get_attribute_stringv() )
13+
print('info-name', info.get_name() )
14+
print('info-size', info.get_size() )
15+
print('info-icon', info.get_icon() )
16+
print('info-content-type', info.get_content_type() )
17+
18+
############## test Glib ################
19+
def Variant( *args ):
20+
gargs = ( ctypes.POINTER(glib.GVariant.CSTRUCT)*len(args) )()
21+
if type(args[0]) == str:
22+
for i,a in enumerate(args):
23+
gargs[i] = glib.variant_new_string( a ).POINTER
24+
return glib.variant_new_array( None, gargs, len(args) )
25+
26+
hello = 'hello'
27+
world = 'world'
28+
var = Variant( hello, world )
29+
assert var.n_children() == 2
30+
a = var.get_child_value(0)
31+
b = var.get_child_value(1)
32+
assert a.get_size() == len(hello)+1
33+
assert b.get_size() == len(world)+1
34+
35+
s = a.get_string()
36+
for i,char in enumerate(hello):
37+
assert s[i] == char
38+
39+
s = b.get_string()
40+
for i,char in enumerate(world):
41+
assert s[i] == char
42+
43+
t = var.get_type()
44+
assert t.is_array() and t.is_container() and t.is_definite()
45+
assert t.get_string_length() == 2
46+
s = t.peek_string()
47+
assert s[0] == 'a' # array
48+
assert s[1] == 's' # of string
49+
50+
############### test bus ##############
51+
bus = gio.bus_get_sync( gio.G_BUS_TYPE_SESSION, None )
52+
proxy = gio.dbus_proxy_new_sync(
53+
bus,
54+
gio.G_DBUS_PROXY_FLAGS_NONE,
55+
None,
56+
'org.freedesktop.DBus',
57+
'/org/freedesktop/DBus',
58+
'org.freedesktop.DBus',
59+
None,
60+
None
61+
)
62+
res = proxy.call_sync(
63+
'ListNames',
64+
None,
65+
gio.G_DBUS_CALL_FLAGS_NO_AUTO_START,
66+
500,
67+
None,
68+
None
69+
)
70+
## unbox ##
71+
assert res.n_children() == 1
72+
assert res.get_type().peek_string() == '(as)'
73+
a = res.get_child_value(0)
74+
for i in range( a.n_children() ):
75+
name = a.get_child_value(i).get_string()
76+
if not name.startswith(':'): #ignore private
77+
print( name )
78+
79+
80+
#########################################
81+
bus = gio.bus_get_sync( gio.G_BUS_TYPE_SESSION, None )
82+
83+
##Creates a proxy for accessing interface_name on the remote object at object_path owned by name at connection and synchronously loads D-Bus properties unless the G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag is used. ##
84+
proxy = gio.dbus_proxy_new_sync(
85+
bus, # GIOStream
86+
gio.G_DBUS_PROXY_FLAGS_NONE,
87+
None, # info : ctypes.POINTER(_GDBusInterfaceInfo)
88+
'org.something', # name
89+
'/org/something', # object path
90+
'org.freedesktop.DBus.Properties', # interface name
91+
None, # ctypes.POINTER(_GCancellable))
92+
None # ctypes.POINTER(ctypes.POINTER(_GError)))
93+
)
94+
print('proxy', proxy)
95+
96+
proxy.set_cached_property( 'someproperty', var )
97+
print('gio test complete')
98+
1999

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.