Browse Source

Fix WinOS paths issues in MultiDirChooser

pull/900/head
ChenglongMa 1 year ago
parent
commit
9b80e5bb55
3 changed files with 2 additions and 49 deletions
  1. 12
      gooey/gui/components/widgets/core/chooser.py
  2. 37
      gooey/tests/test_chooser_results.py
  3. 2
      requirements.txt

12
gooey/gui/components/widgets/core/chooser.py

@ -136,17 +136,7 @@ class MultiDirChooser(Chooser):
defaultPath=options.get('default_path', os.getcwd()),
agwStyle=MDD.DD_MULTIPLE | MDD.DD_DIR_MUST_EXIST)
def getResult(self, dialog):
paths = dialog.GetPaths()
# Remove volume labels from Windows paths
if 'nt' == os.name:
for i, path in enumerate(paths):
if path:
parts = path.split(os.sep)
vol = parts[0]
drives = re.match(r'.*\((?P<drive>\w:)\)', vol)
paths[i] = os.sep.join([drives.group('drive')] + parts[1:])
return os.pathsep.join(paths)
return os.pathsep.join(dialog.GetPaths())
class DateChooser(Chooser):

37
gooey/tests/test_chooser_results.py

@ -1,37 +0,0 @@
import argparse
import os
import unittest
from gooey.gui.components.widgets.core import chooser
from gooey.tests import *
class MockWxMDD:
def GetPaths(self):
pass
class TestChooserResults(unittest.TestCase):
def test_multiDirChooserGetResult(self):
expected_outputs = [
(None, "", [""]),
# Windows
('nt', "C:", ["OS and System (C:)"]),
('nt', "D:\\A Folder\\Yep Another One",
["Other Stuff (D:)\\A Folder\\Yep Another One"]),
('nt', "A:\\Wow Remember Floppy Drives;E:\\Righto Then",
["Flipflop (A:)\\Wow Remember Floppy Drives",
"Elephants Only (E:)\\Righto Then"])
]
for osname, expected, pathsoutput in expected_outputs:
if not osname or osname == os.name:
chooser.MDD.MultiDirDialog = MockWxMDD
chooser.MDD.MultiDirDialog.GetPaths = lambda self : pathsoutput
result = chooser.MultiDirChooser.getResult(None, MockWxMDD())
print(result)
self.assertEqual(result, expected)
if __name__ == '__main__':
unittest.main()

2
requirements.txt

@ -1,4 +1,4 @@
wxpython>=4.1.0
wxpython>=4.2.1
Pillow>=4.3.0
psutil>=5.4.2
colored>=1.3.93

Loading…
Cancel
Save