Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrinux committed Sep 3, 2018
1 parent 414c1da commit 1cebe08
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
30 changes: 20 additions & 10 deletions py3status/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,7 @@ def create_output_modules(self):
output_modules[name]['type'] = 'py3status'
output_modules[name]['color'] = self.mappings_color.get(name)
output_modules[name]['max_size'] = self.mappings_max_size.get(name)
output_modules[name]['short_format'] = self.mappings_short_format.get(name)
# i3status modules
for name in i3modules:
if name not in output_modules:
Expand All @@ -899,6 +900,7 @@ def create_output_modules(self):
output_modules[name]['type'] = 'i3status'
output_modules[name]['color'] = self.mappings_color.get(name)
output_modules[name]['max_size'] = self.mappings_max_size.get(name)
output_modules[name]['short_format'] = self.mappings_short_format.get(name)

self.output_modules = output_modules

Expand All @@ -921,9 +923,15 @@ def create_mappings(self, config):
max_size = None
mappings[name] = max_size

short_format = self.get_config_attribute(name, 'short_format')
if hasattr(max_size, 'none_setting'):
short_format = None
mappings[name] = short_format

# Store mappings for later use.
self.mappings_max_size = mappings
self.mappings_color = mappings
self.mappings_short_format = mappings

def process_module_output(self, module):
"""
Expand All @@ -934,6 +942,7 @@ def process_module_output(self, module):
outputs = module['module'].get_latest()
color = module['color']
max_size = module['max_size']
short_format = module['short_format']

for output in outputs:
if color:
Expand All @@ -942,16 +951,17 @@ def process_module_output(self, module):
output['color'] = color

if 'short_text' not in output:
full_text = output['full_text']
if int(max_size) >= 1:
short = full_text[:max_size] if len(full_text) > int(max_size) else full_text
short = short + '..' if len(short + '..') < len(full_text) else short
output['short_text'] = short
elif max_size is True:
size = int((len(full_text) + 1) / 2)
short = full_text[:size]
short = short + '..' if len(short + '..') < len(full_text) else short
output['short_text'] = short
if not short_format and output['full_text']:
full_text = output['full_text']
if max_size and int(max_size) >= 1:
short = full_text[:max_size] if len(full_text) > int(max_size) else full_text
short = short + '..' if len(short + '..') < len(full_text) else short
output['short_text'] = short
elif max_size and isinstance(max_size, str):
size = int((len(full_text) + 1) / 2)
short = full_text[:size]
short = short + '..' if len(short + '..') < len(full_text) else short
output['short_text'] = short

# Create the json string output.
return ','.join([dumps(x) for x in outputs])
Expand Down
8 changes: 3 additions & 5 deletions py3status/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,19 +649,17 @@ def deprecation_log(item):
if not hasattr(self.module_class, 'py3'):
setattr(self.module_class, 'py3', Py3(self))

# allow_urgent
# get the value form the config or use the module default if
# get the value from the config or use the module default if
# supplied.
fn = self._py3_wrapper.get_config_attribute

# allow_urgent
param = fn(self.module_full_name, 'allow_urgent')
if hasattr(param, 'none_setting'):
param = True
self.allow_urgent = param

# max_size
# get the value form the config or use the module default if
# supplied.
fn = self._py3_wrapper.get_config_attribute
param = fn(self.module_full_name, 'max_size')
if hasattr(param, 'none_setting'):
param = True
Expand Down
3 changes: 2 additions & 1 deletion py3status/modules/wwan.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ def wwan(self):

response = {
'cached_until': self.py3.time_in(self.cache_timeout),
'full_text': self.py3.safe_format(self.format, wwan_data)
'full_text': self.py3.safe_format(self.format, wwan_data),
'short_text': self.py3.safe_format(self.short_format, wwan_data)
}
if urgent:
response['urgent'] = True
Expand Down
4 changes: 4 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

[testenv]
deps =
coverage
pytest
pytest-flake8

commands =
pytest --flake8
coverage erase
coverage run --omit=**/__init__.py --source=modules -m py.test
coverage report

[flake8]
max-line-length = 99
Expand Down

0 comments on commit 1cebe08

Please sign in to comment.