Skip to content

Commit

Permalink
manual connect: Use a glade file, tweak some more.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtwebster committed Nov 30, 2023
1 parent aeaf4a7 commit 49a719c
Show file tree
Hide file tree
Showing 4 changed files with 385 additions and 146 deletions.
233 changes: 233 additions & 0 deletions resources/manual-connect.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface domain="warpinator">
<requires lib="gtk+" version="3.24"/>
<object class="GtkBox" id="top_box">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="border-width">10</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">4</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-bottom">6</property>
<property name="label" translatable="yes" comments="manual-connect dialog: first main section header (bold, big)">On this computer:</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="1.3"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes" comments="The user enters an IP address and port in an entry below this">Enter the address of the device you want to connect to</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-start">10</property>
<property name="margin-end">10</property>
<child>
<object class="GtkEntry" id="ip_entry">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="progress-pulse-step">0.25</property>
<property name="placeholder-text">192.168.0.1:42001</property>
<style>
<class name="monospace"/>
</style>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="connect_button">
<property name="label" translatable="yes">Connect</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<style>
<class name="linked"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="status_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="use-markup">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-top">4</property>
<property name="margin-bottom">4</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">4</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-bottom">6</property>
<property name="label" translatable="yes" comments="manual-connect dialog: second main section header (bold, big)">Alternatively, on the other device:</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="1.3"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes" comments="A qr code is displayed below this">Scan this QR code</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="margin-bottom">6</property>
<property name="label-xalign">0</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkAlignment">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkBox" id="qr_holder">
<property name="width-request">300</property>
<property name="height-request">300</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes" comments="The user's ip address and port are displayed here">Or connect to the address below</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="our_ip_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label">192.168.0.50:42001</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="1.8"/>
</attributes>
<style>
<class name="monospace"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</interface>
1 change: 1 addition & 0 deletions resources/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
data = [
'group-code.ui',
'main-window.ui',
'manual-connect.ui',
'op-item.ui',
'overview-button.ui',
'prefs-window.ui'
Expand Down
69 changes: 16 additions & 53 deletions src/warpinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,68 +1169,31 @@ def __init__(self, parent:WarpWindow):
self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
self.set_type_hint(Gdk.WindowTypeHint.DIALOG)

vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6, margin=6)
self.add(vbox)
self.builder = Gtk.Builder.new_from_file(os.path.join(config.pkgdatadir, "manual-connect.ui"))
top_box = self.builder.get_object("top_box")
self.add(top_box)

label = Gtk.Label(label=_("Scan this QR code on your mobile device to connect"), halign=Gtk.Align.CENTER)
label.set_max_width_chars(45)
label.set_line_wrap(True)
vbox.add(label)
self.entry = self.builder.get_object("ip_entry")
self.connect_button = self.builder.get_object("connect_button")
self.status_label = self.builder.get_object("status_label")
ip_label = self.builder.get_object("our_ip_label")
qr_holder = self.builder.get_object("qr_holder")

qr_frame = Gtk.Frame(halign=Gtk.Align.CENTER, margin_bottom=20)
vbox.add(qr_frame)
self.entry.connect("changed", self.validate_address)
self.connect_button.connect("clicked", self.on_connecting)

qrbytes = BytesIO()
qr = qrcode.make("warpinator://%s:%d" % (parent.current_ip, parent.current_auth_port))
qr.save(qrbytes, "BMP")
stream = Gio.MemoryInputStream.new_from_bytes(GLib.Bytes.new(qrbytes.getvalue()))
pixbuf = GdkPixbuf.Pixbuf.new_from_stream_at_scale(stream, -1, -1, True, None)
img = Gtk.Image.new_from_pixbuf(pixbuf)
qr_frame.add(img)

label2 = Gtk.Label(label=_("You can also share your IP address and port number"), halign=Gtk.Align.CENTER)
label2.set_max_width_chars(50)
label2.set_line_wrap(True)
vbox.add(label2)

label3 = Gtk.Label(label="<tt><span size='xx-large'><b>%s:%d</b></span></tt>" % (parent.current_ip, parent.current_auth_port), use_markup=True, selectable=True, margin_bottom=20)
vbox.add(label3)

label4 = Gtk.Label(label=_("Or enter the other device's address"), halign=Gtk.Align.CENTER)
label4.set_max_width_chars(50)
label4.set_line_wrap(True)
vbox.add(label4)

entry_hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, margin_start=20, margin_end=20)
entry_hbox.get_style_context().add_class("linked")
self.entry = Gtk.Entry(placeholder_text="192.168.0.1:42001")
self.entry.connect("changed", self.validate_address)
self.entry.get_style_context().add_class("monospace")
self.entry.set_progress_pulse_step(0.25)
entry_hbox.pack_start(self.entry, True, True, 0)

self.connect_button = Gtk.Button(_("Connect"), sensitive=False, always_show_image=True)
self.connect_button.connect("clicked", self.on_connecting)

entry_hbox.pack_end(self.connect_button, False, False, 0)
vbox.add(entry_hbox)

self.status_label = Gtk.Label(label="", use_markup=True, margin_bottom=10)
vbox.add(self.status_label)

bbox = Gtk.ButtonBox(layout_style=Gtk.ButtonBoxStyle.EXPAND)
vbox.add(bbox)

close_button = Gtk.Button(label=_("Close"))
close_button.connect("clicked", lambda b: self.close())
bbox.add(close_button)
pixbuf = GdkPixbuf.Pixbuf.new_from_stream_at_scale(stream, 370 * self.get_scale_factor(), -1, True, None)
surface = Gdk.cairo_surface_create_from_pixbuf(pixbuf, self.get_scale_factor(), None)
img = Gtk.Image.new_from_surface(surface)
qr_holder.add(img)

vbox.set_margin_bottom(10)
vbox.set_margin_top(10)
vbox.set_margin_start(10)
vbox.set_margin_end(10)
ip_label.set_label("%s:%d" % (parent.current_ip, parent.current_auth_port))

self.set_focus(None)
self.set_focus(qr_holder)
self.show_all()

def on_connecting(self, _btn):
Expand Down
Loading

0 comments on commit 49a719c

Please sign in to comment.