BonjourBrowser.pm 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # A tiny dialog to select an OctoPrint device to print to.
  2. package Slic3r::GUI::BonjourBrowser;
  3. use strict;
  4. use warnings;
  5. use utf8;
  6. use Wx qw(:dialog :id :misc :sizer :choicebook wxTAB_TRAVERSAL);
  7. use Wx::Event qw(EVT_CLOSE);
  8. use base 'Wx::Dialog';
  9. sub new {
  10. my $class = shift;
  11. my ($parent, $devices) = @_;
  12. my $self = $class->SUPER::new($parent, -1, "Device Browser", wxDefaultPosition, [350,700], wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
  13. $self->{devices} = $devices;
  14. # label
  15. my $text = Wx::StaticText->new($self, -1, "Choose an OctoPrint device in your network:", wxDefaultPosition, wxDefaultSize);
  16. # selector
  17. $self->{choice} = my $choice = Wx::Choice->new($self, -1, wxDefaultPosition, wxDefaultSize,
  18. [ map $_->name, @{$self->{devices}} ]);
  19. my $main_sizer = Wx::BoxSizer->new(wxVERTICAL);
  20. $main_sizer->Add($text, 1, wxEXPAND | wxALL, 10);
  21. $main_sizer->Add($choice, 1, wxEXPAND | wxALL, 10);
  22. $main_sizer->Add($self->CreateButtonSizer(wxOK | wxCANCEL), 0, wxEXPAND);
  23. $self->SetSizer($main_sizer);
  24. $self->SetMinSize($self->GetSize);
  25. $main_sizer->SetSizeHints($self);
  26. # needed to actually free memory
  27. EVT_CLOSE($self, sub {
  28. $self->EndModal(wxID_OK);
  29. $self->Destroy;
  30. });
  31. return $self;
  32. }
  33. sub GetValue {
  34. my ($self) = @_;
  35. return $self->{devices}[ $self->{choice}->GetSelection ]->address;
  36. }
  37. sub GetPort {
  38. my ($self) = @_;
  39. return $self->{devices}[ $self->{choice}->GetSelection ]->port;
  40. }
  41. 1;