discovery.py
author beremiz
Wed, 12 Aug 2009 15:21:00 +0200
branchcherry-pick
changeset 671 6de6d6958efd
parent 375 b16bcfe531d7
child 377 9db62e0280f5
permissions -rwxr-xr-x
forgoten branch now closed
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     2
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     3
#This file is part of Beremiz, a Integrated Development Environment for
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     4
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival. 
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     5
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     6
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     7
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     8
#See COPYING file for copyrights details.
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     9
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    10
#This library is free software; you can redistribute it and/or
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    11
#modify it under the terms of the GNU General Public
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    12
#License as published by the Free Software Foundation; either
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    13
#version 2.1 of the License, or (at your option) any later version.
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    14
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    15
#This library is distributed in the hope that it will be useful,
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    16
#but WITHOUT ANY WARRANTY; without even the implied warranty of
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    17
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    18
#General Public License for more details.
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    19
#
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    20
#You should have received a copy of the GNU General Public
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    21
#License along with this library; if not, write to the Free Software
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    22
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    23
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    24
import wx
357
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
    25
from Zeroconf import *
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    26
import socket
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    27
import  wx.lib.mixins.listctrl  as  listmix
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    28
375
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
    29
class AutoWidthListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    30
    def __init__(self, parent, ID, pos=wx.DefaultPosition,
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    31
                 size=wx.DefaultSize, style=0):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    32
        wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    33
        listmix.ListCtrlAutoWidthMixin.__init__(self)
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    34
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    35
class DiscoveryDialog(wx.Dialog, listmix.ColumnSorterMixin):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    36
    def __init__(self, parent, id=-1, title='Service Discovery'):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    37
        self.my_result=None
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    38
        wx.Dialog.__init__(self, parent, id, title, size=(600,600), style=wx.DEFAULT_DIALOG_STYLE)
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    39
375
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
    40
        # set up dialog sizer
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
    41
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    42
        sizer = wx.FlexGridSizer(2, 1, 2, 2)  # rows, cols, vgap, hgap
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    43
        sizer.AddGrowableRow(0)
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    44
        sizer.AddGrowableCol(0)
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    45
375
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
    46
        # set up list control
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
    47
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
    48
        self.list = AutoWidthListCtrl(self, -1,
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
    49
                                      #pos=(50,20), 
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
    50
                                      #size=(500,300),
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
    51
                                      style=wx.LC_REPORT 
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
    52
                                     | wx.LC_EDIT_LABELS
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
    53
                                     | wx.LC_SORT_ASCENDING
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
    54
                                     | wx.LC_SINGLE_SEL 
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
    55
                                     )
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    56
        sizer.Add(self.list, 1, wx.EXPAND)
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    57
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    58
        btsizer = wx.FlexGridSizer(1, 6, 2, 2)  # rows, cols, vgap, hgap
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    59
        
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    60
        sizer.Add(btsizer, 1, wx.EXPAND)
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    61
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    62
        self.PopulateList()
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    63
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    64
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list)
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    65
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated, self.list)
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    66
375
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
    67
        # set up buttons
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
    68
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    69
        local_id = wx.NewId()
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    70
        b = wx.Button(self, local_id, "Refresh")
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    71
        self.Bind(wx.EVT_BUTTON, self.OnRefreshButton, b)
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    72
        btsizer.Add(b)
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    73
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    74
        btsizer.AddSpacer(0)
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    75
        btsizer.AddGrowableCol(1)
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    76
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    77
        local_id = wx.NewId()
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    78
        b = wx.Button(self, local_id, "Local")
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    79
        self.Bind(wx.EVT_BUTTON, self.ChooseLocalID, b)
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    80
        btsizer.Add(b)
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    81
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    82
        btsizer.AddSpacer(0)
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    83
        btsizer.AddGrowableCol(3)
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    84
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    85
        b = wx.Button(self, wx.ID_CANCEL, "Cancel")
357
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
    86
        self.Bind(wx.EVT_BUTTON, self.OnCancel, b)
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    87
        btsizer.Add(b)
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    88
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    89
        b = wx.Button(self, wx.ID_OK, "OK")
357
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
    90
        self.Bind(wx.EVT_BUTTON, self.OnOk, b)
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    91
        b.SetDefault()
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    92
        btsizer.Add(b)
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    93
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    94
        self.SetSizer(sizer)
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    95
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    96
        listmix.ColumnSorterMixin.__init__(self, 4)
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
    97
375
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
    98
        # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
    99
        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
   100
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   101
        # a counter used to assign a unique id to each listctrl item
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   102
        self.nextItemId = 0
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   103
262
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 226
diff changeset
   104
        self.browser = None
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   105
        self.zConfInstance = Zeroconf()
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   106
        self.RefreshList()
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   107
357
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
   108
        self.Bind(wx.EVT_CLOSE, self.OnClose)
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
   109
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   110
    def RefreshList(self):
375
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   111
        type = "_WGPLC._tcp.local."
262
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 226
diff changeset
   112
        self.browser = ServiceBrowser(self.zConfInstance, type, self)        
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   113
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   114
    def OnRefreshButton(self, event):
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   115
        self.list.DeleteAllItems()
262
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 226
diff changeset
   116
        self.browser.cancel()
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   117
        self.RefreshList()
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   118
357
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
   119
    def OnClose(self, event):
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
   120
        self.zConfInstance.close()
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
   121
        event.Skip()
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
   122
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
   123
    def OnCancel(self, event):
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
   124
        self.zConfInstance.close()
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
   125
        event.Skip()
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
   126
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
   127
    def OnOk(self, event):
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
   128
        self.zConfInstance.close()
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
   129
        event.Skip()
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
   130
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   131
    # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   132
    def GetListCtrl(self):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   133
        return self.list
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   134
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   135
    def PopulateList(self):
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   136
        self.list.InsertColumn(0, 'NAME')
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   137
        self.list.InsertColumn(1, 'TYPE')
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   138
        self.list.InsertColumn(2, 'IP')
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   139
        self.list.InsertColumn(3, 'PORT')
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   140
        self.list.SetColumnWidth(0, 150)
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   141
        self.list.SetColumnWidth(1, 150)
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   142
        self.list.SetColumnWidth(2, 150)
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   143
        self.list.SetColumnWidth(3, 150)
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   144
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   145
    def getColumnText(self, index, col):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   146
        item = self.list.GetItem(index, col)
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   147
        return item.GetText()
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   148
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   149
    def OnItemSelected(self, event):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   150
        self.currentItem = event.m_itemIndex
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   151
        self.setresult()
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   152
        event.Skip()
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   153
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   154
    def OnItemActivated(self, event):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   155
        self.currentItem = event.m_itemIndex
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   156
        self.setresult()
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   157
        self.Close()
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   158
        event.Skip()
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   159
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   160
    def setresult(self):
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   161
        connect_type = self.getColumnText(self.currentItem, 1)
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   162
        connect_address = self.getColumnText(self.currentItem, 2)
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   163
        connect_port = self.getColumnText(self.currentItem, 3)
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   164
        
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   165
        uri = self.CreateURI(connect_type, connect_address, connect_port)
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   166
        self.my_result=uri
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   167
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   168
    def GetResult(self):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   169
        return self.my_result
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   170
        
357
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
   171
    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
   172
        '''
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   173
        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
   174
        '''
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   175
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   176
        # loop through the list items looking for the service that went offline
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   177
        for idx in xrange(self.list.GetItemCount()):
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   178
            # this is the unique identifier assigned to the item
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   179
            item_id = self.list.GetItemData(idx)
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   180
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   181
            # 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
   182
            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
   183
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   184
            if item_name == name:
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   185
                self.list.DeleteItem(idx)
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   186
                break
357
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
   187
262
141a7145c099 add taskbaricon to beremiz_service.
greg
parents: 226
diff changeset
   188
    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
   189
        '''
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   190
        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
   191
        '''
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   192
357
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
   193
        info = self.zConfInstance.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
   194
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
   195
        svcname  = name.split(".")[0]
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   196
        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
   197
        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
   198
        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
   199
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   200
        num_items = self.list.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
   201
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   202
        # display the new data in the list
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
   203
        new_item = self.list.InsertStringItem(num_items, svcname)
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
   204
        self.list.SetStringItem(new_item, 1, "%s" % typename)
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
   205
        self.list.SetStringItem(new_item, 2, "%s" % ip)
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
        self.list.SetStringItem(new_item, 3, "%s" % port)
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   207
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   208
        # 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
   209
        # 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
   210
        # are added or removed)
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   211
        self.list.SetItemData(new_item, self.nextItemId)
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   212
 
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   213
        # 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
   214
        # 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
   215
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   216
        # "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
   217
        # 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
   218
        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
   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
        self.nextItemId += 1
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   221
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   222
    def CreateURI(self, connect_type, connect_address, connect_port):
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   223
        uri = "%s://%s:%s"%(connect_type, connect_address, connect_port)
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   224
        return uri
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   225
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   226
    def ChooseLocalID(self, event):
277
73890551f021 Local PYRO connection is designated by LOCAL://, not PYRO://localhost:3000 anymore
etisserant
parents: 262
diff changeset
   227
        self.my_result = "LOCAL://"
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   228
        self.Close()