author | laurent |
Fri, 04 Jun 2010 11:27:00 +0200 | |
changeset 551 | d18e86b603bc |
parent 399 | 77e23bf04c33 |
child 644 | b511cab580eb |
permissions | -rwxr-xr-x |
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 |
357
19db1076e93c
close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents:
277
diff
changeset
|
27 |
from Zeroconf import * |
399 | 28 |
|
29 |
import connectors |
|
203 | 30 |
|
375
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
31 |
class AutoWidthListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin): |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
32 |
def __init__(self, parent, id, name, pos=wx.DefaultPosition, |
203 | 33 |
size=wx.DefaultSize, style=0): |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
34 |
wx.ListCtrl.__init__(self, parent, id, pos, size, style, name=name) |
203 | 35 |
listmix.ListCtrlAutoWidthMixin.__init__(self) |
36 |
||
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
37 |
[ID_DISCOVERYDIALOG, ID_DISCOVERYDIALOGSTATICTEXT1, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
38 |
ID_DISCOVERYDIALOGSERVICESLIST, ID_DISCOVERYDIALOGREFRESHBUTTON, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
39 |
ID_DISCOVERYDIALOGLOCALBUTTON, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
40 |
] = [wx.NewId() for _init_ctrls in range(5)] |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
41 |
|
203 | 42 |
class DiscoveryDialog(wx.Dialog, listmix.ColumnSorterMixin): |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
43 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
44 |
def _init_coll_MainSizer_Items(self, parent): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
45 |
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
|
46 |
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
|
47 |
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
|
48 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
49 |
def _init_coll_MainSizer_Growables(self, parent): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
50 |
parent.AddGrowableCol(0) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
51 |
parent.AddGrowableRow(1) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
52 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
53 |
def _init_coll_ButtonGridSizer_Items(self, parent): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
54 |
parent.AddWindow(self.RefreshButton, 0, border=0, flag=0) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
55 |
parent.AddWindow(self.LocalButton, 0, border=0, flag=0) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
56 |
parent.AddSizer(self.ButtonSizer, 0, border=0, flag=0) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
57 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
58 |
def _init_coll_ButtonGridSizer_Growables(self, parent): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
59 |
parent.AddGrowableCol(0) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
60 |
parent.AddGrowableCol(1) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
61 |
parent.AddGrowableRow(1) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
62 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
63 |
def _init_sizers(self): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
64 |
self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
65 |
self.ButtonGridSizer = wx.FlexGridSizer(cols=3, hgap=5, rows=1, vgap=0) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
66 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
67 |
self._init_coll_MainSizer_Items(self.MainSizer) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
68 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
69 |
self._init_coll_ButtonGridSizer_Items(self.ButtonGridSizer) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
70 |
self._init_coll_ButtonGridSizer_Growables(self.ButtonGridSizer) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
71 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
72 |
self.SetSizer(self.MainSizer) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
73 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
74 |
def _init_ctrls(self, prnt): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
75 |
wx.Dialog.__init__(self, id=ID_DISCOVERYDIALOG, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
76 |
name='DiscoveryDialog', parent=prnt, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
77 |
size=wx.Size(600, 600), style=wx.DEFAULT_DIALOG_STYLE, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
78 |
title='Service Discovery') |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
79 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
80 |
self.staticText1 = wx.StaticText(id=ID_DISCOVERYDIALOGSTATICTEXT1, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
81 |
label=_('Services available:'), name='staticText1', parent=self, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
82 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
83 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
84 |
# Set up list control |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
85 |
self.ServicesList = AutoWidthListCtrl(id=ID_DISCOVERYDIALOGSERVICESLIST, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
86 |
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
|
87 |
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
|
88 |
self.ServicesList.InsertColumn(0, 'NAME') |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
89 |
self.ServicesList.InsertColumn(1, 'TYPE') |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
90 |
self.ServicesList.InsertColumn(2, 'IP') |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
91 |
self.ServicesList.InsertColumn(3, 'PORT') |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
92 |
self.ServicesList.SetColumnWidth(0, 150) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
93 |
self.ServicesList.SetColumnWidth(1, 150) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
94 |
self.ServicesList.SetColumnWidth(2, 150) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
95 |
self.ServicesList.SetColumnWidth(3, 150) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
96 |
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
|
97 |
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
|
98 |
|
203 | 99 |
listmix.ColumnSorterMixin.__init__(self, 4) |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
100 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
101 |
self.RefreshButton = wx.Button(id=ID_DISCOVERYDIALOGREFRESHBUTTON, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
102 |
label=_('Refresh'), name='RefreshButton', parent=self, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
103 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
104 |
self.Bind(wx.EVT_BUTTON, self.OnRefreshButton, id=ID_DISCOVERYDIALOGREFRESHBUTTON) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
105 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
106 |
self.LocalButton = wx.Button(id=ID_DISCOVERYDIALOGLOCALBUTTON, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
107 |
label=_('Local'), name='LocalButton', parent=self, |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
108 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
109 |
self.Bind(wx.EVT_BUTTON, self.OnLocalButton, id=ID_DISCOVERYDIALOGLOCALBUTTON) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
110 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
111 |
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTER) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
112 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
113 |
self._init_sizers() |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
114 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
115 |
def __init__(self, parent): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
116 |
self._init_ctrls(parent) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
117 |
|
375
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
118 |
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
|
119 |
self.nextItemId = 0 |
392
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.URI = None |
399 | 122 |
self.Browsers = [] |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
123 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
124 |
self.ZeroConfInstance = Zeroconf() |
221 | 125 |
self.RefreshList() |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
126 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
127 |
def __del__(self): |
399 | 128 |
for browser in self.Browsers: |
129 |
browser.cancel() |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
130 |
self.ZeroConfInstance.close() |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
131 |
|
221 | 132 |
def RefreshList(self): |
399 | 133 |
for browser in self.Browsers: |
134 |
browser.cancel() |
|
135 |
||
136 |
self.Browsers = [] |
|
137 |
for t in connectors.dnssd_connectors.keys(): |
|
138 |
self.Browsers.append(ServiceBrowser(self.ZeroConfInstance, t, self)) |
|
221 | 139 |
|
140 |
def OnRefreshButton(self, event): |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
141 |
self.ServicesList.DeleteAllItems() |
221 | 142 |
self.RefreshList() |
143 |
||
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
144 |
def OnLocalButton(self, event): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
145 |
self.URI = "LOCAL://" |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
146 |
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
|
147 |
event.Skip() |
19db1076e93c
close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents:
277
diff
changeset
|
148 |
|
203 | 149 |
# Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py |
150 |
def GetListCtrl(self): |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
151 |
return self.ServicesList |
203 | 152 |
|
153 |
def getColumnText(self, index, col): |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
154 |
item = self.ServicesList.GetItem(index, col) |
203 | 155 |
return item.GetText() |
156 |
||
157 |
def OnItemSelected(self, event): |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
158 |
self.SetURI(event.m_itemIndex) |
203 | 159 |
event.Skip() |
160 |
||
161 |
def OnItemActivated(self, event): |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
162 |
self.SetURI(event.m_itemIndex) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
163 |
self.EndModal(wx.ID_OK) |
203 | 164 |
event.Skip() |
165 |
||
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
166 |
def SetURI(self, idx): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
167 |
connect_type = self.getColumnText(idx, 1) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
168 |
connect_address = self.getColumnText(idx, 2) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
169 |
connect_port = self.getColumnText(idx, 3) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
170 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
171 |
self.URI = "%s://%s:%s"%(connect_type, connect_address, connect_port) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
172 |
|
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
173 |
def GetURI(self): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
174 |
return self.URI |
203 | 175 |
|
357
19db1076e93c
close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents:
277
diff
changeset
|
176 |
def removeService(self, zeroconf, 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
|
177 |
''' |
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
178 |
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
|
179 |
''' |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
180 |
|
375
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
181 |
# 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
|
182 |
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
|
183 |
# this is the unique identifier assigned to the item |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
184 |
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
|
185 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
186 |
# 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
|
187 |
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
|
188 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
189 |
if item_name == name: |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
190 |
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
|
191 |
break |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
192 |
|
262 | 193 |
def addService(self, zeroconf, 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
|
194 |
''' |
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
195 |
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
|
196 |
''' |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
197 |
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
|
198 |
|
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
|
199 |
svcname = name.split(".")[0] |
203 | 200 |
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
|
201 |
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
|
202 |
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
|
203 |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
204 |
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
|
205 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
206 |
# display the new data in the list |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
207 |
new_item = self.ServicesList.InsertStringItem(num_items, svcname) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
208 |
self.ServicesList.SetStringItem(new_item, 1, "%s" % typename) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
209 |
self.ServicesList.SetStringItem(new_item, 2, "%s" % ip) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
210 |
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
|
211 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
212 |
# 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
|
213 |
# 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
|
214 |
# are added or removed) |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
215 |
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
|
216 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
217 |
# 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
|
218 |
# 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
|
219 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
220 |
# "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
|
221 |
# 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
|
222 |
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
|
223 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
224 |
self.nextItemId += 1 |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
225 |