author | Laurent Bessard |
Wed, 29 May 2013 09:42:25 +0200 | |
changeset 1188 | 63afb5833bd8 |
parent 814 | 5743cbdff669 |
child 1494 | 00910a8572d9 |
permissions | -rw-r--r-- |
203 | 1 |
# -*- coding: utf-8 -*- |
2 |
||
3 |
#This file is part of Beremiz, a Integrated Development Environment for |
|
4 |
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
|
5 |
# |
|
6 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
|
7 |
# |
|
8 |
#See COPYING file for copyrights details. |
|
9 |
# |
|
10 |
#This library is free software; you can redistribute it and/or |
|
11 |
#modify it under the terms of the GNU General Public |
|
12 |
#License as published by the Free Software Foundation; either |
|
13 |
#version 2.1 of the License, or (at your option) any later version. |
|
14 |
# |
|
15 |
#This library is distributed in the hope that it will be useful, |
|
16 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
18 |
#General Public License for more details. |
|
19 |
# |
|
20 |
#You should have received a copy of the GNU General Public |
|
21 |
#License along with this library; if not, write to the Free Software |
|
22 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
||
399 | 24 |
import socket |
203 | 25 |
import wx |
399 | 26 |
import wx.lib.mixins.listctrl as listmix |
726 | 27 |
from util.Zeroconf import * |
399 | 28 |
|
29 |
import connectors |
|
203 | 30 |
|
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
31 |
service_type = '_PYRO._tcp.local.' |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
32 |
|
375
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
33 |
class AutoWidthListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin): |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
34 |
def __init__(self, parent, id, name, pos=wx.DefaultPosition, |
203 | 35 |
size=wx.DefaultSize, style=0): |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
36 |
wx.ListCtrl.__init__(self, parent, id, pos, size, style, name=name) |
203 | 37 |
listmix.ListCtrlAutoWidthMixin.__init__(self) |
38 |
||
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
39 |
[ID_DISCOVERYDIALOG, ID_DISCOVERYDIALOGSTATICTEXT1, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
40 |
ID_DISCOVERYDIALOGSERVICESLIST, ID_DISCOVERYDIALOGREFRESHBUTTON, |
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
41 |
ID_DISCOVERYDIALOGLOCALBUTTON, ID_DISCOVERYDIALOGIPBUTTON, |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
42 |
] = [wx.NewId() for _init_ctrls in range(6)] |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
43 |
|
203 | 44 |
class DiscoveryDialog(wx.Dialog, listmix.ColumnSorterMixin): |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
45 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
46 |
def _init_coll_MainSizer_Items(self, parent): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
47 |
parent.AddWindow(self.staticText1, 0, border=20, flag=wx.TOP|wx.LEFT|wx.RIGHT|wx.GROW) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
48 |
parent.AddWindow(self.ServicesList, 0, border=20, flag=wx.LEFT|wx.RIGHT|wx.GROW) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
49 |
parent.AddSizer(self.ButtonGridSizer, 0, border=20, flag=wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.GROW) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
50 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
51 |
def _init_coll_MainSizer_Growables(self, parent): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
52 |
parent.AddGrowableCol(0) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
53 |
parent.AddGrowableRow(1) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
54 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
55 |
def _init_coll_ButtonGridSizer_Items(self, parent): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
56 |
parent.AddWindow(self.RefreshButton, 0, border=0, flag=0) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
57 |
parent.AddWindow(self.LocalButton, 0, border=0, flag=0) |
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
58 |
parent.AddWindow(self.IpButton, 0, border=0, flag=0) |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
59 |
parent.AddSizer(self.ButtonSizer, 0, border=0, flag=0) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
60 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
61 |
def _init_coll_ButtonGridSizer_Growables(self, parent): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
62 |
parent.AddGrowableCol(0) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
63 |
parent.AddGrowableCol(1) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
64 |
parent.AddGrowableRow(1) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
65 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
66 |
def _init_sizers(self): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
67 |
self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) |
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
68 |
self.ButtonGridSizer = wx.FlexGridSizer(cols=4, hgap=5, rows=1, vgap=0) |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
69 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
70 |
self._init_coll_MainSizer_Items(self.MainSizer) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
71 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
72 |
self._init_coll_ButtonGridSizer_Items(self.ButtonGridSizer) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
73 |
self._init_coll_ButtonGridSizer_Growables(self.ButtonGridSizer) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
74 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
75 |
self.SetSizer(self.MainSizer) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
76 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
77 |
def _init_ctrls(self, prnt): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
78 |
wx.Dialog.__init__(self, id=ID_DISCOVERYDIALOG, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
79 |
name='DiscoveryDialog', parent=prnt, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
80 |
size=wx.Size(600, 600), style=wx.DEFAULT_DIALOG_STYLE, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
81 |
title='Service Discovery') |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
82 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
83 |
self.staticText1 = wx.StaticText(id=ID_DISCOVERYDIALOGSTATICTEXT1, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
84 |
label=_('Services available:'), name='staticText1', parent=self, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
85 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
86 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
87 |
# Set up list control |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
88 |
self.ServicesList = AutoWidthListCtrl(id=ID_DISCOVERYDIALOGSERVICESLIST, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
89 |
name='ServicesList', parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 0), |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
90 |
style=wx.LC_REPORT|wx.LC_EDIT_LABELS|wx.LC_SORT_ASCENDING|wx.LC_SINGLE_SEL) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
91 |
self.ServicesList.InsertColumn(0, 'NAME') |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
92 |
self.ServicesList.InsertColumn(1, 'TYPE') |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
93 |
self.ServicesList.InsertColumn(2, 'IP') |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
94 |
self.ServicesList.InsertColumn(3, 'PORT') |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
95 |
self.ServicesList.SetColumnWidth(0, 150) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
96 |
self.ServicesList.SetColumnWidth(1, 150) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
97 |
self.ServicesList.SetColumnWidth(2, 150) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
98 |
self.ServicesList.SetColumnWidth(3, 150) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
99 |
self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, id=ID_DISCOVERYDIALOGSERVICESLIST) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
100 |
self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated, id=ID_DISCOVERYDIALOGSERVICESLIST) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
101 |
|
203 | 102 |
listmix.ColumnSorterMixin.__init__(self, 4) |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
103 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
104 |
self.RefreshButton = wx.Button(id=ID_DISCOVERYDIALOGREFRESHBUTTON, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
105 |
label=_('Refresh'), name='RefreshButton', parent=self, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
106 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
107 |
self.Bind(wx.EVT_BUTTON, self.OnRefreshButton, id=ID_DISCOVERYDIALOGREFRESHBUTTON) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
108 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
109 |
self.LocalButton = wx.Button(id=ID_DISCOVERYDIALOGLOCALBUTTON, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
110 |
label=_('Local'), name='LocalButton', parent=self, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
111 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
112 |
self.Bind(wx.EVT_BUTTON, self.OnLocalButton, id=ID_DISCOVERYDIALOGLOCALBUTTON) |
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
113 |
|
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
114 |
self.IpButton = wx.Button(id=ID_DISCOVERYDIALOGIPBUTTON, |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
115 |
label=_('Add IP'), name='IpButton', parent=self, |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
116 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
117 |
self.Bind(wx.EVT_BUTTON, self.OnIpButton, id=ID_DISCOVERYDIALOGIPBUTTON) |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
118 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
119 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTER) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
120 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
121 |
self._init_sizers() |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
122 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
123 |
def __init__(self, parent): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
124 |
self._init_ctrls(parent) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
125 |
|
375
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
126 |
self.itemDataMap = {} |
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
127 |
self.nextItemId = 0 |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
128 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
129 |
self.URI = None |
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
130 |
self.Browser = None |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
131 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
132 |
self.ZeroConfInstance = Zeroconf() |
221 | 133 |
self.RefreshList() |
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
134 |
self.LatestSelection=None |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
135 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
136 |
def __del__(self): |
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
137 |
if self.Browser is not None : self.Browser.cancel() |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
138 |
self.ZeroConfInstance.close() |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
139 |
|
221 | 140 |
def RefreshList(self): |
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
141 |
if self.Browser is not None : self.Browser.cancel() |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
142 |
self.Browser = ServiceBrowser(self.ZeroConfInstance, service_type, self) |
221 | 143 |
|
144 |
def OnRefreshButton(self, event): |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
145 |
self.ServicesList.DeleteAllItems() |
221 | 146 |
self.RefreshList() |
147 |
||
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
148 |
def OnLocalButton(self, event): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
149 |
self.URI = "LOCAL://" |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
150 |
self.EndModal(wx.ID_OK) |
357
19db1076e93c
close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents:
277
diff
changeset
|
151 |
event.Skip() |
19db1076e93c
close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents:
277
diff
changeset
|
152 |
|
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
153 |
def OnIpButton(self, event): |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
154 |
if self.LatestSelection is not None: |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
155 |
l = lambda col : self.getColumnText(self.LatestSelection,col) |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
156 |
self.URI = "%s://%s:%s"%tuple(map(l,(1,2,3))) |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
157 |
self.EndModal(wx.ID_OK) |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
158 |
event.Skip() |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
159 |
|
203 | 160 |
# Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py |
161 |
def GetListCtrl(self): |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
162 |
return self.ServicesList |
203 | 163 |
|
164 |
def getColumnText(self, index, col): |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
165 |
item = self.ServicesList.GetItem(index, col) |
203 | 166 |
return item.GetText() |
167 |
||
168 |
def OnItemSelected(self, event): |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
169 |
self.SetURI(event.m_itemIndex) |
203 | 170 |
event.Skip() |
171 |
||
172 |
def OnItemActivated(self, event): |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
173 |
self.SetURI(event.m_itemIndex) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
174 |
self.EndModal(wx.ID_OK) |
203 | 175 |
event.Skip() |
176 |
||
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
177 |
# def SetURI(self, idx): |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
178 |
# connect_type = self.getColumnText(idx, 1) |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
179 |
# connect_address = self.getColumnText(idx, 2) |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
180 |
# connect_port = self.getColumnText(idx, 3) |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
181 |
# |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
182 |
# self.URI = "%s://%s:%s"%(connect_type, connect_address, connect_port) |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
183 |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
184 |
def SetURI(self, idx): |
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
185 |
self.LatestSelection = idx |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
186 |
svcname = self.getColumnText(idx, 0) |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
187 |
connect_type = self.getColumnText(idx, 1) |
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
188 |
self.URI = "%s://%s"%(connect_type, svcname + '.' + service_type) |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
189 |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
190 |
def GetURI(self): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
191 |
return self.URI |
203 | 192 |
|
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
193 |
def removeService(self, zeroconf, _type, name): |
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
399
diff
changeset
|
194 |
wx.CallAfter(self._removeService, name) |
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
399
diff
changeset
|
195 |
|
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
399
diff
changeset
|
196 |
|
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
399
diff
changeset
|
197 |
def _removeService(self, name): |
375
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
198 |
''' |
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
199 |
called when a service with the desired type goes offline. |
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
200 |
''' |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
201 |
|
375
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
202 |
# loop through the list items looking for the service that went offline |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
203 |
for idx in xrange(self.ServicesList.GetItemCount()): |
375
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
204 |
# this is the unique identifier assigned to the item |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
205 |
item_id = self.ServicesList.GetItemData(idx) |
375
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
206 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
207 |
# this is the full typename that was received by addService |
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
208 |
item_name = self.itemDataMap[item_id][4] |
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
209 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
210 |
if item_name == name: |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
211 |
self.ServicesList.DeleteItem(idx) |
375
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
212 |
break |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
213 |
|
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
214 |
def addService(self, zeroconf, _type, name): |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
215 |
wx.CallAfter(self._addService, _type, name) |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
216 |
|
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
217 |
def _addService(self, _type, name): |
375
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
218 |
''' |
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
219 |
called when a service with the desired type is discovered. |
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
220 |
''' |
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
221 |
info = self.ZeroConfInstance.getServiceInfo(_type, name) |
374
8787fa8c6792
bugfix: On Windows, sometimes the the wrong line in the service discovery list control is updated when multiple services are displayed and a new service is discovered.
b.taylor@willowglen.ca
parents:
357
diff
changeset
|
222 |
|
8787fa8c6792
bugfix: On Windows, sometimes the the wrong line in the service discovery list control is updated when multiple services are displayed and a new service is discovered.
b.taylor@willowglen.ca
parents:
357
diff
changeset
|
223 |
svcname = name.split(".")[0] |
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
224 |
typename = _type.split(".")[0][1:] |
374
8787fa8c6792
bugfix: On Windows, sometimes the the wrong line in the service discovery list control is updated when multiple services are displayed and a new service is discovered.
b.taylor@willowglen.ca
parents:
357
diff
changeset
|
225 |
ip = str(socket.inet_ntoa(info.getAddress())) |
8787fa8c6792
bugfix: On Windows, sometimes the the wrong line in the service discovery list control is updated when multiple services are displayed and a new service is discovered.
b.taylor@willowglen.ca
parents:
357
diff
changeset
|
226 |
port = info.getPort() |
8787fa8c6792
bugfix: On Windows, sometimes the the wrong line in the service discovery list control is updated when multiple services are displayed and a new service is discovered.
b.taylor@willowglen.ca
parents:
357
diff
changeset
|
227 |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
228 |
num_items = self.ServicesList.GetItemCount() |
375
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
229 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
230 |
# display the new data in the list |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
231 |
new_item = self.ServicesList.InsertStringItem(num_items, svcname) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
232 |
self.ServicesList.SetStringItem(new_item, 1, "%s" % typename) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
233 |
self.ServicesList.SetStringItem(new_item, 2, "%s" % ip) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
234 |
self.ServicesList.SetStringItem(new_item, 3, "%s" % port) |
375
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
235 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
236 |
# record the new data for the ColumnSorterMixin |
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
237 |
# we assign every list item a unique id (that won't change when items |
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
238 |
# are added or removed) |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
239 |
self.ServicesList.SetItemData(new_item, self.nextItemId) |
375
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
240 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
241 |
# the value of each column has to be stored in the itemDataMap |
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
242 |
# so that ColumnSorterMixin knows how to sort the column. |
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
243 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
244 |
# "name" is included at the end so that self.removeService |
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
245 |
# can access it. |
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
246 |
self.itemDataMap[self.nextItemId] = [ svcname, typename, ip, port, name ] |
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
247 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
248 |
self.nextItemId += 1 |
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
399
diff
changeset
|
249 |