Coverage for src/robotide/preferences/saving.py: 29%
40 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-06 10:40 +0100
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-06 10:40 +0100
1# Copyright 2008-2015 Nokia Networks
2# Copyright 2016- Robot Framework Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
16import builtins 1ab
17import wx 1ab
19from .settings import RideSettings 1ab
20from ..ui.preferences_dialogs import PreferencesPanel, IntegerChoiceEditor, StringChoiceEditor, boolean_editor 1ab
22_ = wx.GetTranslation # To keep linter/code analyser happy 1ab
23builtins.__dict__['_'] = wx.GetTranslation 1ab
26class SavingPreferences(PreferencesPanel): 1ab
27 location = (_('Saving'),) 1ab
29 def __init__(self, settings, *args, **kwargs): 1ab
30 self.location = (_('Saving'),)
31 self.title = _('Saving')
32 self.name = 'Saving'
33 super(SavingPreferences, self).__init__(name_tr=_('Saving'), *args, **kwargs)
34 self._settings = settings
35 self.SetSizer(wx.FlexGridSizer(cols=2))
36 self._gsettings = RideSettings()
37 self.csettings = self._gsettings['General']
38 self.background_color = self.csettings['background']
39 self.foreground_color = self.csettings['foreground']
40 for editor in self._create_editors(settings):
41 self._add_editor(editor)
42 label, selector = boolean_editor(self, settings, 'tasks', _("Is Task?"),
43 _("Default for Tasks or Tests sections."))
44 l_reformat, editor = boolean_editor(self, settings, 'reformat', _('Reformat?'),
45 _('Should it recalculate identation on Save?'))
46 label.SetForegroundColour(self.foreground_color)
47 label.SetBackgroundColour(self.background_color)
48 l_reformat.SetForegroundColour(self.foreground_color)
49 l_reformat.SetBackgroundColour(self.background_color)
50 self.Sizer.AddMany([label, selector])
51 self.Sizer.AddMany([l_reformat, editor])
52 self.Sizer.Layout()
53 self.Update()
55 @staticmethod 1ab
56 def _create_editors(settings): 1ab
57 return [
58 StringChoiceEditor(settings, 'default file format', _('Default file format:'),
59 ('txt', 'tsv', 'html', 'robot', 'resource')
60 ),
61 StringChoiceEditor(settings, 'txt format separator', _('TXT format separator:'),
62 ('pipe', 'space')
63 ),
64 StringChoiceEditor(settings, 'line separator', _('Line separator:'),
65 ('native', 'CRLF', 'LF'),
66 _('Possible values are native (of current OS) CRLF (Windows) and LF (Unixy)')
67 ),
68 IntegerChoiceEditor(settings, 'txt number of spaces', _('Separating spaces'),
69 [str(i) for i in range(2, 11)],
70 _('Number of spaces between cells when saving in txt format')
71 )
72 ]
74 def _add_editor(self, editor): 1ab
75 l_editor = editor.label(self)
76 l_editor.SetForegroundColour(self.foreground_color)
77 l_editor.SetBackgroundColour(self.background_color)
78 self.Sizer.AddMany([l_editor, (editor.chooser(self),)])
79 self.Sizer.AddMany([(editor.help(self), 0, wx.BOTTOM, 10), wx.Window(self)])