author | Edouard Tisserant <edouard@beremiz.fr> |
Fri, 30 Aug 2024 11:50:23 +0200 | |
changeset 4008 | f30573e98600 |
parent 3935 | bc51b5a2daa9 |
child 4039 | 9ff455817691 |
permissions | -rw-r--r-- |
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 | 2 |
# -*- coding: utf-8 -*- |
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 | 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 |
|
399 | 27 |
import socket |
3935
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
28 |
import weakref |
203 | 29 |
import wx |
1738
d2e979738700
clean-up: fix PEP8 E271 multiple spaces after keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
30 |
import wx.lib.mixins.listctrl as listmix |
2477
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
31 |
from zeroconf import ServiceBrowser, Zeroconf, get_all_addresses |
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
32 |
|
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
33 |
service_type = '_Beremiz._tcp.local.' |
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
34 |
|
3935
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
35 |
class ZeroConfListenerClass: |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
36 |
def __init__(self, dialog): |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
37 |
self.dialog = weakref.ref(dialog) |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
38 |
self.ZeroConfInstance = Zeroconf() |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
39 |
self.Browser = ServiceBrowser(self.ZeroConfInstance, service_type, self) |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
40 |
|
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
41 |
def clean(self): |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
42 |
if self.Browser is not None: |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
43 |
self.Browser.cancel() |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
44 |
self.Browser = None |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
45 |
if self.ZeroConfInstance is not None: |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
46 |
self.ZeroConfInstance.close() |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
47 |
self.ZeroConfInstance = None |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
48 |
|
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
49 |
def __del__(self): |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
50 |
self.clean() |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
51 |
|
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
52 |
def update_service(self, zeroconf, _type, name): |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
53 |
self.remove_service(zeroconf, _type, name) |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
54 |
self.add_service(zeroconf, _type, name) |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
55 |
|
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
56 |
def add_service(self, zeroconf, _type, name): |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
57 |
info = self.ZeroConfInstance.get_service_info(_type, name) |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
58 |
if info is None: |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
59 |
return |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
60 |
typename = info.properties.get(b"protocol", None).decode() |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
61 |
ip = str(info.parsed_addresses()[0]) |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
62 |
port = info.port |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
63 |
|
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
64 |
wx.CallAfter(self._add_service, typename, ip, port, name) |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
65 |
|
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
66 |
def _add_service(self, typename, ip, port, name): |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
67 |
dialog = self.dialog() |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
68 |
if not dialog: return |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
69 |
dialog._addService(typename, ip, port, name) |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
70 |
|
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
71 |
def remove_service(self, zeroconf, _type, name): |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
72 |
wx.CallAfter(self._remove_service, name) |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
73 |
|
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
74 |
def _remove_service(self, name): |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
75 |
dialog = self.dialog() |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
76 |
if not dialog: return |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
77 |
dialog._removeService(name) |
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
78 |
|
375
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
79 |
class AutoWidthListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin): |
2737
38afed869ff6
Finished fixing Wx IDs abuse. There was still some wasted IDs because of wx.NewId calls in many places where it wasn't needed, and those IDs were not re-used. As a consequence Beremiz was making exception crashing after a few hours of intensive use.
Edouard Tisserant
parents:
2521
diff
changeset
|
80 |
def __init__(self, parent, name, pos=wx.DefaultPosition, |
203 | 81 |
size=wx.DefaultSize, style=0): |
2737
38afed869ff6
Finished fixing Wx IDs abuse. There was still some wasted IDs because of wx.NewId calls in many places where it wasn't needed, and those IDs were not re-used. As a consequence Beremiz was making exception crashing after a few hours of intensive use.
Edouard Tisserant
parents:
2521
diff
changeset
|
82 |
wx.ListCtrl.__init__(self, parent, wx.ID_ANY, pos, size, style, name=name) |
203 | 83 |
listmix.ListCtrlAutoWidthMixin.__init__(self) |
84 |
||
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2482
diff
changeset
|
85 |
|
2332
03a94f862465
'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents:
1881
diff
changeset
|
86 |
class DiscoveryPanel(wx.Panel, listmix.ColumnSorterMixin): |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
87 |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
88 |
def _init_coll_MainSizer_Items(self, parent): |
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2737
diff
changeset
|
89 |
parent.Add(self.staticText1, 0, border=20, flag=wx.TOP | wx.LEFT | wx.RIGHT | wx.GROW) |
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2737
diff
changeset
|
90 |
parent.Add(self.ServicesList, 0, border=20, flag=wx.LEFT | wx.RIGHT | wx.GROW) |
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2737
diff
changeset
|
91 |
parent.Add(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
|
92 |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
93 |
def _init_coll_MainSizer_Growables(self, parent): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
94 |
parent.AddGrowableCol(0) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
95 |
parent.AddGrowableRow(1) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
96 |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
97 |
def _init_coll_ButtonGridSizer_Items(self, parent): |
3303
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2737
diff
changeset
|
98 |
parent.Add(self.RefreshButton, 0, border=0, flag=0) |
0ffb41625592
Preliminary support for WxPython 4.1.0. Needs more testing. Grid selection/focus seems broken, and probably many other bugs hidden in dialogs and editors.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2737
diff
changeset
|
99 |
# parent.Add(self.ByIPCheck, 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
|
100 |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
101 |
def _init_coll_ButtonGridSizer_Growables(self, parent): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
102 |
parent.AddGrowableCol(0) |
1494
00910a8572d9
fix wrong Row number in DiscoveryDialog.py that caused following traceback:
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
814
diff
changeset
|
103 |
parent.AddGrowableRow(0) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
104 |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
105 |
def _init_sizers(self): |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
106 |
self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=3, vgap=10) |
2332
03a94f862465
'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents:
1881
diff
changeset
|
107 |
self.ButtonGridSizer = wx.FlexGridSizer(cols=2, 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
|
108 |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
109 |
self._init_coll_MainSizer_Items(self.MainSizer) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
110 |
self._init_coll_MainSizer_Growables(self.MainSizer) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
111 |
self._init_coll_ButtonGridSizer_Items(self.ButtonGridSizer) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
112 |
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
|
113 |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
114 |
self.SetSizer(self.MainSizer) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
115 |
|
1836
d42b6cf00fa6
fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1830
diff
changeset
|
116 |
def _init_list_ctrl(self): |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
117 |
# 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
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
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
|
124 |
self.ServicesList.InsertColumn(3, _('PORT')) |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
125 |
self.ServicesList.SetColumnWidth(0, 150) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
126 |
self.ServicesList.SetColumnWidth(1, 150) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
127 |
self.ServicesList.SetColumnWidth(2, 150) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
128 |
self.ServicesList.SetColumnWidth(3, 150) |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
129 |
self.ServicesList.SetInitialSize(wx.Size(-1, 300)) |
2737
38afed869ff6
Finished fixing Wx IDs abuse. There was still some wasted IDs because of wx.NewId calls in many places where it wasn't needed, and those IDs were not re-used. As a consequence Beremiz was making exception crashing after a few hours of intensive use.
Edouard Tisserant
parents:
2521
diff
changeset
|
130 |
self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.ServicesList) |
38afed869ff6
Finished fixing Wx IDs abuse. There was still some wasted IDs because of wx.NewId calls in many places where it wasn't needed, and those IDs were not re-used. As a consequence Beremiz was making exception crashing after a few hours of intensive use.
Edouard Tisserant
parents:
2521
diff
changeset
|
131 |
self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated, self.ServicesList) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
132 |
|
1836
d42b6cf00fa6
fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1830
diff
changeset
|
133 |
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
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
|
1768
691083b5682a
clean-up: fix PEP8 E128 continuation line under-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1762
diff
changeset
|
138 |
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
|
139 |
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
|
140 |
pos=wx.Point(0, 0), size=wx.DefaultSize, style=0) |
2477
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
141 |
self.RefreshButton.Bind(wx.EVT_BUTTON, self.OnRefreshButton) |
2332
03a94f862465
'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents:
1881
diff
changeset
|
142 |
|
2478
733d77bf0aa7
Disable MDNS:// scheme support. Also prevent discovery pannel to produce some. For now it seems that that feature is unused, and could be a security issue.
Edouard Tisserant
parents:
2477
diff
changeset
|
143 |
# self.ByIPCheck = wx.CheckBox(self, label=_("Use IP instead of Service Name")) |
733d77bf0aa7
Disable MDNS:// scheme support. Also prevent discovery pannel to produce some. For now it seems that that feature is unused, and could be a security issue.
Edouard Tisserant
parents:
2477
diff
changeset
|
144 |
# self.ByIPCheck.SetValue(True) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
145 |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
146 |
self._init_sizers() |
1696
8043f32de7b8
make all dialog have non-fixed size
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
147 |
self.Fit() |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
148 |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
149 |
def __init__(self, parent): |
2332
03a94f862465
'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents:
1881
diff
changeset
|
150 |
wx.Panel.__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
|
151 |
|
2466
98d28d809488
Fixed Discovery panel in URI Editor dialog : double click works back again, and avoid setting URI to unicode type.
Edouard Tisserant
parents:
2459
diff
changeset
|
152 |
self.parent = parent |
98d28d809488
Fixed Discovery panel in URI Editor dialog : double click works back again, and avoid setting URI to unicode type.
Edouard Tisserant
parents:
2459
diff
changeset
|
153 |
|
1836
d42b6cf00fa6
fix error __init__ method from base class is not called
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1830
diff
changeset
|
154 |
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
|
155 |
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
|
156 |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
157 |
self._init_ctrls(parent) |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
158 |
|
375
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
159 |
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
|
160 |
self.nextItemId = 0 |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
161 |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
162 |
self.URI = None |
2477
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
163 |
|
221 | 164 |
self.RefreshList() |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
165 |
self.LatestSelection = None |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
166 |
|
2477
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
167 |
self.IfacesMonitorState = None |
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
168 |
self.IfacesMonitorTimer = wx.Timer(self) |
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
169 |
self.IfacesMonitorTimer.Start(2000) |
3935
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
170 |
self.ZeroConfListener = None |
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2482
diff
changeset
|
171 |
self.Bind(wx.EVT_TIMER, self.IfacesMonitor, self.IfacesMonitorTimer) |
2477
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
172 |
|
3717
da9ffd572551
IDE: fix segfault when unselecting network discovery in URI editor
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3303
diff
changeset
|
173 |
def _cleanup(self): |
da9ffd572551
IDE: fix segfault when unselecting network discovery in URI editor
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3303
diff
changeset
|
174 |
if self.IfacesMonitorTimer is not None: |
da9ffd572551
IDE: fix segfault when unselecting network discovery in URI editor
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3303
diff
changeset
|
175 |
self.IfacesMonitorTimer.Stop() |
da9ffd572551
IDE: fix segfault when unselecting network discovery in URI editor
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3303
diff
changeset
|
176 |
self.IfacesMonitorTimer = None |
3935
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
177 |
if self.ZeroConfListener is not None: |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
178 |
self.ZeroConfListener.clean() |
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
179 |
self.ZeroConfListener = None |
3717
da9ffd572551
IDE: fix segfault when unselecting network discovery in URI editor
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3303
diff
changeset
|
180 |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
181 |
def __del__(self): |
3717
da9ffd572551
IDE: fix segfault when unselecting network discovery in URI editor
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3303
diff
changeset
|
182 |
self._cleanup() |
da9ffd572551
IDE: fix segfault when unselecting network discovery in URI editor
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3303
diff
changeset
|
183 |
|
da9ffd572551
IDE: fix segfault when unselecting network discovery in URI editor
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3303
diff
changeset
|
184 |
def Destroy(self): |
da9ffd572551
IDE: fix segfault when unselecting network discovery in URI editor
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3303
diff
changeset
|
185 |
self._cleanup() |
da9ffd572551
IDE: fix segfault when unselecting network discovery in URI editor
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3303
diff
changeset
|
186 |
wx.Panel.Destroy(self) |
2477
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
187 |
|
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
188 |
def IfacesMonitor(self, event): |
3876
7d83cd94e3cc
IDE: fix exception showing network discovery
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3752
diff
changeset
|
189 |
NewState = get_all_addresses() |
2477
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
190 |
|
2492
7dd551ac2fa0
check_sources.sh makes me become even less productive
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2482
diff
changeset
|
191 |
if self.IfacesMonitorState != NewState: |
2477
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
192 |
if self.IfacesMonitorState is not None: |
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
193 |
# refresh only if a new address appeared |
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
194 |
for addr in NewState: |
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
195 |
if addr not in self.IfacesMonitorState: |
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
196 |
self.RefreshList() |
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
197 |
break |
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
198 |
self.IfacesMonitorState = NewState |
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
199 |
event.Skip() |
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
200 |
|
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
201 |
def RefreshList(self): |
4866c01e7428
Added support to PYROS in Zeroconf discovery and publish. For now, PYRO://mdnsname._tcp.local. URI are broken, and discovery panel generate IP based URI by default.
Edouard Tisserant
parents:
2466
diff
changeset
|
202 |
self.ServicesList.DeleteAllItems() |
3935
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
203 |
self.ZeroConfListener = ZeroConfListenerClass(self) |
221 | 204 |
|
205 |
def OnRefreshButton(self, event): |
|
206 |
self.RefreshList() |
|
207 |
||
203 | 208 |
# Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py |
209 |
def GetListCtrl(self): |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
210 |
return self.ServicesList |
203 | 211 |
|
212 |
def getColumnText(self, index, col): |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
213 |
item = self.ServicesList.GetItem(index, col) |
203 | 214 |
return item.GetText() |
215 |
||
216 |
def OnItemSelected(self, event): |
|
3935
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
217 |
self.SetURI(event.GetIndex()) |
203 | 218 |
event.Skip() |
219 |
||
220 |
def OnItemActivated(self, event): |
|
3935
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
221 |
self.SetURI(event.GetIndex()) |
2466
98d28d809488
Fixed Discovery panel in URI Editor dialog : double click works back again, and avoid setting URI to unicode type.
Edouard Tisserant
parents:
2459
diff
changeset
|
222 |
self.parent.EndModal(wx.ID_OK) |
203 | 223 |
event.Skip() |
224 |
||
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
225 |
# def SetURI(self, idx): |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
226 |
# connect_type = self.getColumnText(idx, 1) |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
227 |
# connect_address = self.getColumnText(idx, 2) |
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
228 |
# 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
|
229 |
# |
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
230 |
# 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
|
231 |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
232 |
def SetURI(self, idx): |
763
c1104099c151
Now, PYRO:// locations also accept MDNS service names
Edouard Tisserant
parents:
726
diff
changeset
|
233 |
self.LatestSelection = idx |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
234 |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
235 |
def GetURI(self): |
2332
03a94f862465
'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents:
1881
diff
changeset
|
236 |
if self.LatestSelection is not None: |
2478
733d77bf0aa7
Disable MDNS:// scheme support. Also prevent discovery pannel to produce some. For now it seems that that feature is unused, and could be a security issue.
Edouard Tisserant
parents:
2477
diff
changeset
|
237 |
# if self.ByIPCheck.IsChecked(): |
733d77bf0aa7
Disable MDNS:// scheme support. Also prevent discovery pannel to produce some. For now it seems that that feature is unused, and could be a security issue.
Edouard Tisserant
parents:
2477
diff
changeset
|
238 |
svcname, scheme, host, port = \ |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3717
diff
changeset
|
239 |
[self.getColumnText(self.LatestSelection, col) for col in range(4)] |
2478
733d77bf0aa7
Disable MDNS:// scheme support. Also prevent discovery pannel to produce some. For now it seems that that feature is unused, and could be a security issue.
Edouard Tisserant
parents:
2477
diff
changeset
|
240 |
return ("%s://%s:%s#%s" % (scheme, host, port, svcname)) \ |
733d77bf0aa7
Disable MDNS:// scheme support. Also prevent discovery pannel to produce some. For now it seems that that feature is unused, and could be a security issue.
Edouard Tisserant
parents:
2477
diff
changeset
|
241 |
if scheme[-1] == "S" \ |
733d77bf0aa7
Disable MDNS:// scheme support. Also prevent discovery pannel to produce some. For now it seems that that feature is unused, and could be a security issue.
Edouard Tisserant
parents:
2477
diff
changeset
|
242 |
else ("%s://%s:%s" % (scheme, host, port)) |
733d77bf0aa7
Disable MDNS:// scheme support. Also prevent discovery pannel to produce some. For now it seems that that feature is unused, and could be a security issue.
Edouard Tisserant
parents:
2477
diff
changeset
|
243 |
# else: |
733d77bf0aa7
Disable MDNS:// scheme support. Also prevent discovery pannel to produce some. For now it seems that that feature is unused, and could be a security issue.
Edouard Tisserant
parents:
2477
diff
changeset
|
244 |
# svcname = self.getColumnText(self.LatestSelection, 0) |
733d77bf0aa7
Disable MDNS:// scheme support. Also prevent discovery pannel to produce some. For now it seems that that feature is unused, and could be a security issue.
Edouard Tisserant
parents:
2477
diff
changeset
|
245 |
# connect_type = self.getColumnText(self.LatestSelection, 1) |
733d77bf0aa7
Disable MDNS:// scheme support. Also prevent discovery pannel to produce some. For now it seems that that feature is unused, and could be a security issue.
Edouard Tisserant
parents:
2477
diff
changeset
|
246 |
# return str("MDNS://%s" % svcname) |
2332
03a94f862465
'Merged' URI editor dialog and Discovery dialog, also clean up related code
Edouard Tisserant
parents:
1881
diff
changeset
|
247 |
return None |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
248 |
|
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
399
diff
changeset
|
249 |
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
|
250 |
''' |
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
251 |
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
|
252 |
''' |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
253 |
|
375
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
254 |
# loop through the list items looking for the service that went offline |
3750
f62625418bff
automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents:
3717
diff
changeset
|
255 |
for idx in range(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
|
256 |
# this is the unique identifier assigned to the item |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
257 |
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
|
258 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
259 |
# 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
|
260 |
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
|
261 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
262 |
if item_name == name: |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
263 |
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
|
264 |
break |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1696
diff
changeset
|
265 |
|
3935
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
266 |
|
bc51b5a2daa9
IDE: Fix crashing non-thread safe code using Zeroconf
Edouard Tisserant <edouard@beremiz.fr>
parents:
3876
diff
changeset
|
267 |
def _addService(self, 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
|
268 |
''' |
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
269 |
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
|
270 |
''' |
1758
845ca626db09
clean-up: fix PEP8 E222 multiple spaces after operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1756
diff
changeset
|
271 |
svcname = name.split(".")[0] |
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
|
272 |
|
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
273 |
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
|
274 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
275 |
# display the new data in the list |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
276 |
new_item = self.ServicesList.InsertStringItem(num_items, svcname) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
277 |
self.ServicesList.SetStringItem(new_item, 1, "%s" % typename) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
278 |
self.ServicesList.SetStringItem(new_item, 2, "%s" % ip) |
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
279 |
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
|
280 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
281 |
# 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
|
282 |
# 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
|
283 |
# are added or removed) |
392
6617d3fb43e2
Redesign DiscoveryDialog class to conform to others dialogs
laurent
parents:
379
diff
changeset
|
284 |
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
|
285 |
|
375
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
286 |
# 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
|
287 |
# 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
|
288 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
289 |
# "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
|
290 |
# can access it. |
1746
45d6f5fba016
clean-up: fix PEP8 E202 whitespace before ')'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
291 |
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
|
292 |
|
b16bcfe531d7
fix discovery dialog sorting, remove services from the discovery dialog when they go offline
b.taylor@willowglen.ca
parents:
374
diff
changeset
|
293 |
self.nextItemId += 1 |