dialogs/DiscoveryDialog.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Sun, 06 Jan 2019 03:11:39 +0300
changeset 2501 eba2bbb2dd9a
parent 2432 dbc065a2f7a5
permissions -rw-r--r--
Make online debug optional

It could be useful for very small targets like Atmega (Arduino) and
for target bring-up there developer want to have running PLC program,
but has not implemented runtime communication yet.


TARGET_DEBUG_AND_RETAIN_DISABLE - completely disable debug and retain
functionality. Previously named TARGET_DEBUG_DISABLE.

TARGET_ONLINE_DEBUG_DISABLE - can be used to enable retain
functionality (no define TARGET_DEBUG_AND_RETAIN_DISABLE is used), but disable
online debug with corresponding RAM/FLASH overhead.

TARGET_LOGGING_DISABLE - disables logging functionality from runtime and PLC program

TARGET_EXT_SYNC_DISABLE - disables PLC program synchronization with
external events. For example, it could be used to synchronize several
PLCs that control motors for different axes.

By default all these options are off.

To test generate program for Generic target, put following files in
project files directory and run build.sh after generating PLC program.
This is very easy to integrate into makefile (Generic target).

[------------- build.sh --------------------------]
files=$(find $PWD/../build -iname '*.c' | grep -v POUS.c)
arm-none-eabi-gcc \
-DTARGET_DEBUG_AND_RETAIN_DISABLE \
-DTARGET_ONLINE_DEBUG_DISABLE \
-DTARGET_LOGGING_DISABLE \
-DTARGET_EXT_SYNC_DISABLE \
-flto -ffunction-sections -fdata-sections -I../../../../matiec/lib/C \
$files \
main.c \
-Wl,--Map=./program.map,--cref \
-nodefaultlibs --specs=nano.specs -Wl,--static -Wl,--gc-section -Wl,--start-group -lc -lm -lnosys -lgcc -Wl,--end-group
[------------------------------------------------]

[------------- main.c --------------------------]
#ifndef TARGET_DEBUG_AND_RETAIN_DISABLE
void Retain(void){}
void InValidateRetainBuffer(void){}
void ValidateRetainBuffer(void){}
#endif

extern void __run(void);
int main(void)
{
for(;;) {
__run();
// sleep common_ticktime__ ns
// add common_ticktime__ ns to __CURRENT_TIME
}
return 0;
}
[------------------------------------------------]
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
     1
#!/usr/bin/env python
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
     3
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
     6
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
     8
# Copyright (C) 2017: Andrey Skvortsov <andrej.skvortzov@gmail.com>
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
     9
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    10
# See COPYING file for copyrights details.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    11
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    12
# This program is free software; you can redistribute it and/or
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    13
# modify it under the terms of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    14
# as published by the Free Software Foundation; either version 2
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    15
# of the License, or (at your option) any later version.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    16
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    17
# This program is distributed in the hope that it will be useful,
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    20
# GNU General Public License for more details.
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    21
#
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    22
# You should have received a copy of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    23
# along with this program; if not, write to the Free Software
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1495
diff changeset
    24
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    25
1881
091005ec69c4 fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
    26
091005ec69c4 fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1850
diff changeset
    27
from __future__ import absolute_import
399
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 392
diff changeset
    28
import socket
2432
dbc065a2f7a5 python3 support: pylint, W1613 # (xrange-builtin) xrange built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1881
diff changeset
    29
from six.moves import xrange
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    30
import wx
1738
d2e979738700 clean-up: fix PEP8 E271 multiple spaces after keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1736
diff changeset
    31
import wx.lib.mixins.listctrl as listmix
1830
e598d1acf354 remove in-tree version of Zeroconf and use upstream from
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
    32
from zeroconf import ServiceBrowser, Zeroconf
399
77e23bf04c33 Merging some improvements from BCT
laurent
parents: 392
diff changeset
    33
2432
dbc065a2f7a5 python3 support: pylint, W1613 # (xrange-builtin) xrange built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1881
diff changeset
    34
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
    35
service_type = '_PYRO._tcp.local.'
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
    36
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    37
375
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
    38
class AutoWidthListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    39
    def __init__(self, parent, id, name, pos=wx.DefaultPosition,
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    40
                 size=wx.DefaultSize, style=0):
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    41
        wx.ListCtrl.__init__(self, parent, id, pos, size, style, name=name)
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    42
        listmix.ListCtrlAutoWidthMixin.__init__(self)
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    43
1749
d73b64672238 clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1746
diff changeset
    44
1773
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    45
[
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    46
    ID_DISCOVERYDIALOG, ID_DISCOVERYDIALOGSTATICTEXT1,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    47
    ID_DISCOVERYDIALOGSERVICESLIST, ID_DISCOVERYDIALOGREFRESHBUTTON,
38fde37c3766 clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1768
diff changeset
    48
    ID_DISCOVERYDIALOGLOCALBUTTON, ID_DISCOVERYDIALOGIPBUTTON,
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
    49
] = [wx.NewId() for _init_ctrls in range(6)]
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    50
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1734
diff changeset
    51
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
    52
class DiscoveryDialog(wx.Dialog, listmix.ColumnSorterMixin):
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    53
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    54
    def _init_coll_MainSizer_Items(self, parent):
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
    55
        parent.AddWindow(self.staticText1,    0, border=20, flag=wx.TOP | wx.LEFT | wx.RIGHT | wx.GROW)
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
    56
        parent.AddWindow(self.ServicesList,   0, border=20, flag=wx.LEFT | wx.RIGHT | wx.GROW)
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
    57
        parent.AddSizer(self.ButtonGridSizer, 0, border=20, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.GROW)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    58
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    59
    def _init_coll_MainSizer_Growables(self, parent):
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    60
        parent.AddGrowableCol(0)
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    61
        parent.AddGrowableRow(1)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    62
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    63
    def _init_coll_ButtonGridSizer_Items(self, parent):
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    64
        parent.AddWindow(self.RefreshButton, 0, border=0, flag=0)
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    65
        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
    66
        parent.AddWindow(self.IpButton, 0, border=0, flag=0)
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    67
        parent.AddSizer(self.ButtonSizer, 0, border=0, flag=0)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    68
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    69
    def _init_coll_ButtonGridSizer_Growables(self, parent):
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    70
        parent.AddGrowableCol(0)
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    71
        parent.AddGrowableCol(1)
1494
00910a8572d9 fix wrong Row number in DiscoveryDialog.py that caused following traceback:
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 814
diff changeset
    72
        parent.AddGrowableRow(0)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    73
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    74
    def _init_sizers(self):
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    75
        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
    76
        self.ButtonGridSizer = wx.FlexGridSizer(cols=4, hgap=5, rows=1, vgap=0)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    77
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    78
        self._init_coll_MainSizer_Items(self.MainSizer)
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    79
        self._init_coll_MainSizer_Growables(self.MainSizer)
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    80
        self._init_coll_ButtonGridSizer_Items(self.ButtonGridSizer)
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    81
        self._init_coll_ButtonGridSizer_Growables(self.ButtonGridSizer)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    82
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    83
        self.SetSizer(self.MainSizer)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
    84
1836
d42b6cf00fa6 fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
    85
    def _init_list_ctrl(self):
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
    86
        # Set up list control
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
    87
        self.ServicesList = AutoWidthListCtrl(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
    88
            id=ID_DISCOVERYDIALOGSERVICESLIST,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
    89
            name='ServicesList', parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 0),
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
    90
            style=wx.LC_REPORT | wx.LC_EDIT_LABELS | wx.LC_SORT_ASCENDING | wx.LC_SINGLE_SEL)
1495
078047c3ab85 add i18n for some strings in DiscoveryDialog, DurationEditDialog, ProjectDialog and CodeFileEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1494
diff changeset
    91
        self.ServicesList.InsertColumn(0, _('NAME'))
078047c3ab85 add i18n for some strings in DiscoveryDialog, DurationEditDialog, ProjectDialog and CodeFileEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1494
diff changeset
    92
        self.ServicesList.InsertColumn(1, _('TYPE'))
078047c3ab85 add i18n for some strings in DiscoveryDialog, DurationEditDialog, ProjectDialog and CodeFileEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1494
diff changeset
    93
        self.ServicesList.InsertColumn(2, _('IP'))
078047c3ab85 add i18n for some strings in DiscoveryDialog, DurationEditDialog, ProjectDialog and CodeFileEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1494
diff changeset
    94
        self.ServicesList.InsertColumn(3, _('PORT'))
392
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)
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
    99
        self.ServicesList.SetInitialSize(wx.Size(-1, 300))
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   100
        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
   101
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated, id=ID_DISCOVERYDIALOGSERVICESLIST)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   102
1836
d42b6cf00fa6 fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
   103
    def _init_ctrls(self, prnt):
d42b6cf00fa6 fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
   104
        self.staticText1 = wx.StaticText(
d42b6cf00fa6 fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
   105
            id=ID_DISCOVERYDIALOGSTATICTEXT1,
d42b6cf00fa6 fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
   106
            label=_('Services available:'), name='staticText1', parent=self,
d42b6cf00fa6 fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
   107
            pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   108
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   109
        self.RefreshButton = wx.Button(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   110
            id=ID_DISCOVERYDIALOGREFRESHBUTTON,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   111
            label=_('Refresh'), name='RefreshButton', parent=self,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   112
            pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   113
        self.Bind(wx.EVT_BUTTON, self.OnRefreshButton, id=ID_DISCOVERYDIALOGREFRESHBUTTON)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   114
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   115
        self.LocalButton = wx.Button(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   116
            id=ID_DISCOVERYDIALOGLOCALBUTTON,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   117
            label=_('Local'), name='LocalButton', parent=self,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   118
            pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   119
        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
   120
1768
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   121
        self.IpButton = wx.Button(
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   122
            id=ID_DISCOVERYDIALOGIPBUTTON,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   123
            label=_('Add IP'), name='IpButton', parent=self,
691083b5682a clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1762
diff changeset
   124
            pos=wx.Point(0, 0), size=wx.DefaultSize, style=0)
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
   125
        self.Bind(wx.EVT_BUTTON, self.OnIpButton, id=ID_DISCOVERYDIALOGIPBUTTON)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   126
1745
f9d32913bad4 clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1742
diff changeset
   127
        self.ButtonSizer = self.CreateButtonSizer(wx.OK | wx.CANCEL | wx.CENTER)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   128
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   129
        self._init_sizers()
1696
8043f32de7b8 make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   130
        self.Fit()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   131
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   132
    def __init__(self, parent):
1836
d42b6cf00fa6 fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
   133
        wx.Dialog.__init__(
d42b6cf00fa6 fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
   134
            self, id=ID_DISCOVERYDIALOG,
d42b6cf00fa6 fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
   135
            name='DiscoveryDialog', parent=parent,
d42b6cf00fa6 fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
   136
            style=wx.DEFAULT_DIALOG_STYLE,
d42b6cf00fa6 fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
   137
            title=_('Service Discovery'))
d42b6cf00fa6 fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
   138
d42b6cf00fa6 fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
   139
        self._init_list_ctrl()
d42b6cf00fa6 fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
   140
        listmix.ColumnSorterMixin.__init__(self, 4)
d42b6cf00fa6 fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1830
diff changeset
   141
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   142
        self._init_ctrls(parent)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   143
375
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   144
        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
   145
        self.nextItemId = 0
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   146
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   147
        self.URI = None
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
   148
        self.Browser = None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   149
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   150
        self.ZeroConfInstance = Zeroconf()
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   151
        self.RefreshList()
1742
92932cd370a4 clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1741
diff changeset
   152
        self.LatestSelection = None
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   153
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   154
    def __del__(self):
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   155
        if self.Browser is not None:
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   156
            self.Browser.cancel()
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   157
        self.ZeroConfInstance.close()
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   158
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   159
    def RefreshList(self):
1756
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   160
        if self.Browser is not None:
08e4394ff4fb clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1755
diff changeset
   161
            self.Browser.cancel()
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
   162
        self.Browser = ServiceBrowser(self.ZeroConfInstance, service_type, self)
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   163
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   164
    def OnRefreshButton(self, event):
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   165
        self.ServicesList.DeleteAllItems()
221
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   166
        self.RefreshList()
451bb2c1d157 Rewritten horrible discovery.py.
etisserant
parents: 203
diff changeset
   167
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   168
    def OnLocalButton(self, event):
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   169
        self.URI = "LOCAL://"
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   170
        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
   171
        event.Skip()
19db1076e93c close ZeroConf object when exiting the Service Discovery window.
btaylor@grond.willowglen.ab.ca
parents: 277
diff changeset
   172
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
   173
    def OnIpButton(self, event):
1762
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1758
diff changeset
   174
        def GetColText(col):
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1758
diff changeset
   175
            return self.getColumnText(self.LatestSelection, col)
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1758
diff changeset
   176
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
   177
        if self.LatestSelection is not None:
1762
fcc406143e5b clean-up: fix PEP8 E731 do not assign a lambda expression, use a def
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1758
diff changeset
   178
            self.URI = "%s://%s:%s" % tuple(map(GetColText, (1, 2, 3)))
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
   179
            self.EndModal(wx.ID_OK)
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
   180
        event.Skip()
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
   181
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   182
    # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   183
    def GetListCtrl(self):
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   184
        return self.ServicesList
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   185
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   186
    def getColumnText(self, index, col):
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   187
        item = self.ServicesList.GetItem(index, col)
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   188
        return item.GetText()
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   189
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   190
    def OnItemSelected(self, event):
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   191
        self.SetURI(event.m_itemIndex)
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   192
        event.Skip()
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   193
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   194
    def OnItemActivated(self, event):
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   195
        self.SetURI(event.m_itemIndex)
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   196
        self.EndModal(wx.ID_OK)
203
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   197
        event.Skip()
cb9901076a21 Added concepts :
etisserant
parents:
diff changeset
   198
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
   199
#    def SetURI(self, idx):
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
   200
#        connect_type = self.getColumnText(idx, 1)
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
   201
#        connect_address = self.getColumnText(idx, 2)
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
   202
#        connect_port = self.getColumnText(idx, 3)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   203
#
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
   204
#        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
   205
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   206
    def SetURI(self, idx):
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
   207
        self.LatestSelection = idx
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   208
        svcname = self.getColumnText(idx, 0)
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   209
        connect_type = self.getColumnText(idx, 1)
1734
750eeb7230a1 clean-up: fix some PEP8 E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1730
diff changeset
   210
        self.URI = "%s://%s" % (connect_type, svcname + '.' + service_type)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   211
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   212
    def GetURI(self):
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   213
        return self.URI
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   214
1830
e598d1acf354 remove in-tree version of Zeroconf and use upstream from
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
   215
    def remove_service(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
   216
        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
   217
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
   218
    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
   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
        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
   221
        '''
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   222
375
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   223
        # 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
   224
        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
   225
            # this is the unique identifier assigned to the item
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   226
            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
   227
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   228
            # 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
   229
            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
   230
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   231
            if item_name == name:
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   232
                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
   233
                break
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   234
1830
e598d1acf354 remove in-tree version of Zeroconf and use upstream from
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
   235
    def add_service(self, zeroconf, _type, name):
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
   236
        wx.CallAfter(self._addService, _type, name)
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
   237
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
   238
    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
   239
        '''
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   240
        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
   241
        '''
1830
e598d1acf354 remove in-tree version of Zeroconf and use upstream from
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
   242
        info = self.ZeroConfInstance.get_service_info(_type, name)
1758
845ca626db09 clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1756
diff changeset
   243
        svcname = name.split(".")[0]
763
c1104099c151 Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents: 726
diff changeset
   244
        typename = _type.split(".")[0][1:]
1830
e598d1acf354 remove in-tree version of Zeroconf and use upstream from
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
   245
        ip = str(socket.inet_ntoa(info.address))
e598d1acf354 remove in-tree version of Zeroconf and use upstream from
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1773
diff changeset
   246
        port = info.port
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
   247
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   248
        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
   249
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   250
        # display the new data in the list
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   251
        new_item = self.ServicesList.InsertStringItem(num_items, svcname)
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   252
        self.ServicesList.SetStringItem(new_item, 1, "%s" % typename)
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   253
        self.ServicesList.SetStringItem(new_item, 2, "%s" % ip)
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   254
        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
   255
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   256
        # 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
   257
        # 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
   258
        # are added or removed)
392
6617d3fb43e2 Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents: 379
diff changeset
   259
        self.ServicesList.SetItemData(new_item, self.nextItemId)
1730
64d8f52bc8c8 clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1696
diff changeset
   260
375
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   261
        # 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
   262
        # 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
   263
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   264
        # "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
   265
        # can access it.
1746
45d6f5fba016 clean-up: fix PEP8 E202 whitespace before ')'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1745
diff changeset
   266
        self.itemDataMap[self.nextItemId] = [svcname, typename, ip, port, 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
   267
b16bcfe531d7 fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents: 374
diff changeset
   268
        self.nextItemId += 1