Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2010-09-14 20:25:32 (GMT)
committer Walter Bender <walter@sugarlabs.org>2010-09-14 20:25:32 (GMT)
commit5b8809d563b2748908598c8c5490974ef7ae2069 (patch)
tree97cb4ac68b257f67dc4e03be4ffaca7bea5dae93
parent7eb8ccb9183c547d1ba419bd7ecb34053a5ba5b1 (diff)
separate customization for slide and stator
-rw-r--r--NEWS4
-rw-r--r--SlideruleActivity.py151
-rw-r--r--activity/activity.info2
-rw-r--r--constants.py3
-rw-r--r--window.py93
5 files changed, 162 insertions, 91 deletions
diff --git a/NEWS b/NEWS
index 022b6b7..1ee4847 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+17
+
+* custom slide *and* custom stator
+
16
* customizable slide
diff --git a/SlideruleActivity.py b/SlideruleActivity.py
index b5ca8c0..0732834 100644
--- a/SlideruleActivity.py
+++ b/SlideruleActivity.py
@@ -46,7 +46,7 @@ import logging
_logger = logging.getLogger('sliderule-activity')
from window import SlideRule
-from constants import SWIDTH
+from constants import SWIDTH, SLIDE, STATOR
_FA = _('square/square root')
_FC = _('multiply/divide')
@@ -187,18 +187,22 @@ class SlideruleActivity(activity.Activity):
self.metadata['slide'])
# custom slide settings
- if 'min' in self.metadata:
- self._min_entry.set_text(self.metadata['min'])
- if 'max' in self.metadata:
- self._max_entry.set_text(self.metadata['max'])
- if 'step' in self.metadata:
- self._step_entry.set_text(self.metadata['step'])
- if 'label' in self.metadata:
- self._label_function.set_text(self.metadata['label'])
- if 'offset' in self.metadata:
- self._offset_function.set_text(self.metadata['offset'])
- if 'calculate' in self.metadata:
- self._calculate_function.set_text(self.metadata['calculate'])
+ for i in range(2):
+ if 'min' + str(i) in self.metadata:
+ self._domain_min[i].set_text(self.metadata['min' + str(i)])
+ if 'max' + str(i) in self.metadata:
+ self._domain_max[i].set_text(self.metadata['max' + str(i)])
+ if 'step' + str(i) in self.metadata:
+ self._step_size[i].set_text(self.metadata['step' + str(i)])
+ if 'label' + str(i) in self.metadata:
+ self._label_function[i].set_text(
+ self.metadata['label' + str(i)])
+ if 'offset' + str(i) in self.metadata:
+ self._offset_function[i].set_text(
+ self.metadata['offset' + str(i)])
+ if 'calculate' + str(i) in self.metadata:
+ self._calculate_function[i].set_text(
+ self.metadata['calculate' + str(i)])
function = self._predefined_function()
if function is not None:
@@ -219,12 +223,16 @@ class SlideruleActivity(activity.Activity):
self.metadata[slide.name] = str(slide.spr.get_xy()[0])
self.metadata['D'] = str(self.sr.name_to_stator('D').spr.get_xy()[0])
self.metadata['R'] = str(self.sr.reticule.spr.get_xy()[0])
- self.metadata['min'] = self._min_entry.get_text()
- self.metadata['max'] = self._max_entry.get_text()
- self.metadata['step'] = self._step_entry.get_text()
- self.metadata['label'] = self._label_function.get_text()
- self.metadata['offset'] = self._offset_function.get_text()
- self.metadata['calculate'] = self._calculate_function.get_text()
+ for i in range(2):
+ self.metadata['min' + str(i)] = self._domain_min[i].get_text()
+ self.metadata['max' + str(i)] = self._domain_max[i].get_text()
+ self.metadata['step' + str(i)] = self._step_size[i].get_text()
+ self.metadata['label' + str(i)] = \
+ self._label_function[i].get_text()
+ self.metadata['offset' + str(i)] = \
+ self._offset_function[i].get_text()
+ self.metadata['calculate' + str(i)] = \
+ self._calculate_function[i].get_text()
def _hide_all(self):
self._hide_top()
@@ -421,14 +429,21 @@ class SlideruleActivity(activity.Activity):
self.sr.update_slide_labels()
self.sr.update_results_label()
- def _custom_cb(self, arg=None):
- """ Create custom slide and stator from parameters in entry widgets """
- self.sr.make_custom_slide(self._offset_function.get_text(),
- self._label_function.get_text(),
- self._calculate_function.get_text(),
- self._min_entry.get_text(),
- self._max_entry.get_text(),
- self._step_entry.get_text())
+ def _custom_slide_cb(self, arg=None):
+ """ Create custom slide from parameters in entry widgets """
+ self._customize(SLIDE)
+
+ def _custom_stator_cb(self, arg=None):
+ """ Create custom stator from parameters in entry widgets """
+ self._customize(STATOR)
+
+ def _customize(self, slide):
+ self.sr.make_custom_slide(self._offset_function[slide].get_text(),
+ self._label_function[slide].get_text(),
+ self._calculate_function[slide].get_text(),
+ self._domain_min[slide].get_text(),
+ self._domain_max[slide].get_text(),
+ self._step_size[slide].get_text(), slide)
def _dummy_cb(self, arg=None):
return
@@ -437,7 +452,8 @@ class SlideruleActivity(activity.Activity):
""" Setup the toolbars.. """
project_toolbar = gtk.Toolbar()
- custom_toolbar = gtk.Toolbar()
+ custom_slide_toolbar = gtk.Toolbar()
+ custom_stator_toolbar = gtk.Toolbar()
# no sharing
self.max_participants = 1
@@ -457,11 +473,19 @@ class SlideruleActivity(activity.Activity):
toolbox.toolbar.insert(project_toolbar_button, -1)
project_toolbar_button.show()
- custom_toolbar_button = ToolbarButton(page=custom_toolbar,
- icon_name='view-source')
- custom_toolbar.show()
- toolbox.toolbar.insert(custom_toolbar_button, -1)
- custom_toolbar_button.show()
+ custom_slide_toolbar_button = ToolbarButton(
+ page=custom_slide_toolbar,
+ icon_name='custom-slide')
+ custom_slide_toolbar.show()
+ toolbox.toolbar.insert(custom_slide_toolbar_button, -1)
+ custom_slide_toolbar_button.show()
+
+ custom_stator_toolbar_button = ToolbarButton(
+ page=custom_stator_toolbar,
+ icon_name='custom-stator')
+ custom_stator_toolbar.show()
+ toolbox.toolbar.insert(custom_stator_toolbar_button, -1)
+ custom_stator_toolbar_button.show()
self.set_toolbar_box(toolbox)
toolbox.show()
@@ -472,7 +496,8 @@ class SlideruleActivity(activity.Activity):
toolbox = activity.ActivityToolbox(self)
self.set_toolbox(toolbox)
toolbox.add_toolbar(_('Project'), project_toolbar)
- toolbox.add_toolbar(_('Custom'), custom_toolbar)
+ toolbox.add_toolbar(_('Custom slide'), custom_slide_toolbar)
+ toolbox.add_toolbar(_('Custom stator'), custom_stator_toolbar)
toolbox.show()
toolbox.set_current_toolbar(1)
toolbar = project_toolbar
@@ -499,20 +524,50 @@ class SlideruleActivity(activity.Activity):
self.realign_button = _button_factory('realign', _('realign slides'),
self.realign_cb, project_toolbar)
- self._offset_function = _entry_factory('log(x, 10)',
- custom_toolbar, _('position function'))
- self._label_function = _entry_factory('x', custom_toolbar,
- _('label function'), max=6)
- self._calculate_function = _entry_factory('pow(10, x)', custom_toolbar,
- _('results function'))
- self._min_entry = _entry_factory('1', custom_toolbar, _('minimum'),
- max=6)
- self._max_entry = _entry_factory('10', custom_toolbar, _('maximum'),
- max=6)
- self._step_entry = _entry_factory('1', custom_toolbar, _('step'),
- max=6)
- self.custom = _button_factory("view-source", _('custom'),
- self._custom_cb, custom_toolbar)
+ self._offset_function = []
+ self._label_function = []
+ self._calculate_function = []
+ self._domain_min = []
+ self._domain_max = []
+ self._step_size = []
+ self.custom = []
+
+ self._offset_function.append(_entry_factory('log(x, 10)',
+ custom_slide_toolbar,
+ _('position function')))
+ self._label_function.append(_entry_factory('x', custom_slide_toolbar,
+ _('label function'), max=6))
+ self._calculate_function.append(_entry_factory('pow(10, x)',
+ custom_slide_toolbar,
+ _('results function')))
+ self._domain_min.append(_entry_factory('1', custom_slide_toolbar,
+ _('domain minimum'), max=6))
+ self._domain_max.append(_entry_factory('10', custom_slide_toolbar,
+ _('domain maximum'), max=6))
+ self._step_size.append(_entry_factory('1', custom_slide_toolbar,
+ _('step size'), max=6))
+ self.custom.append(_button_factory("custom-slide",
+ _('create custom slide'),
+ self._custom_slide_cb,
+ custom_slide_toolbar))
+ self._offset_function.append(_entry_factory('log(x, 10)',
+ custom_stator_toolbar,
+ _('position function')))
+ self._label_function.append(_entry_factory('x', custom_stator_toolbar,
+ _('label function'), max=6))
+ self._calculate_function.append(_entry_factory('pow(10, x)',
+ custom_stator_toolbar,
+ _('results function')))
+ self._domain_min.append(_entry_factory('1', custom_stator_toolbar,
+ _('domain minimum'), max=6))
+ self._domain_max.append(_entry_factory('10', custom_stator_toolbar,
+ _('domain maximum'), max=6))
+ self._step_size.append(_entry_factory('1', custom_stator_toolbar,
+ _('step size'), max=6))
+ self.custom.append(_button_factory("custom-stator",
+ _('create custom stator'),
+ self._custom_stator_cb,
+ custom_stator_toolbar))
if have_toolbox:
_separator_factory(toolbox.toolbar, False, True)
diff --git a/activity/activity.info b/activity/activity.info
index 23f20ef..b9ed396 100644
--- a/activity/activity.info
+++ b/activity/activity.info
@@ -1,6 +1,6 @@
[Activity]
name = Sliderule
-activity_version = 16
+activity_version = 17
license = GPLv3
bundle_id = org.sugarlabs.SlideruleActivity
exec = sugar-activity SlideruleActivity.SlideruleActivity
diff --git a/constants.py b/constants.py
index 5596d03..6b01ba8 100644
--- a/constants.py
+++ b/constants.py
@@ -26,3 +26,6 @@ LEFT = 0
RIGHT = 1
TOP = 0
BOTTOM = 1
+
+SLIDE = 0
+STATOR = 1
diff --git a/window.py b/window.py
index 0ed73b0..ee82bd7 100644
--- a/window.py
+++ b/window.py
@@ -26,7 +26,7 @@ except:
GRID_CELL_SIZE = 0
from constants import SHEIGHT, SWIDTH, SCALE, OFFSET, LEFT, RIGHT, TOP, \
- BOTTOM, SCREENOFFSET
+ BOTTOM, SCREENOFFSET, SLIDE, STATOR
from sprite_factory import Slide, Stator, Reticule, CustomSlide, CustomStator
from sprites import Sprites
from genslides import C_slide, D_stator, CI_slide, DI_stator, A_slide, \
@@ -166,8 +166,8 @@ class SlideRule():
'S':[S_slide, self._calc_S], 'T':[T_slide, self._calc_T],
'L':[L_slide, self._calc_L],
'LLn':[LLn_slide, self._calc_LLn],
- # 'LL0':[LL0_slide, self._calc_LL0],
'Log':[Log_slide, self._calc_Log]}
+ # 'LL0':[LL0_slide, self._calc_LL0],
STATORS = {'D':[D_stator, self._calc_D, self._calc_D_result],
'DI':[DI_stator, self._calc_DI, self._calc_DI_result],
@@ -177,8 +177,8 @@ class SlideRule():
'T2':[T_stator, self._calc_T2, self._calc_T2_result],
'L2':[L_stator, self._calc_L2, self._calc_L2_result],
'LLn2':[LLn_stator, self._calc_LLn2, self._calc_LLn2_result],
- # 'LL02':[LL0_stator, self._calc_LL02, self._calc_LL02_result],
'Log2':[Log_stator, self._calc_Log2, self._calc_Log2_result]}
+ # 'LL02':[LL0_stator, self._calc_LL02, self._calc_LL02_result],
self.path = path
self.activity = parent
@@ -224,7 +224,8 @@ class SlideRule():
SCREENOFFSET + 2 * SHEIGHT,
STATORS[stator][0], STATORS[stator][1], STATORS[stator][2]))
- self.make_custom_slide('log(x, 10)', 'x', 'exp(x)', 1, 10, 1)
+ self.make_custom_slide('log(x, 10)', 'x', 'exp(x)', 1, 10, 1, SLIDE)
+ self.make_custom_slide('log(x, 10)', 'x', 'exp(x)', 1, 10, 1, STATOR)
self.reticule = Reticule(self.sprites, self.path, 'reticule',
150, SCREENOFFSET + SHEIGHT, 100, 2 * SHEIGHT)
@@ -358,7 +359,7 @@ class SlideRule():
return stator
def make_custom_slide(self, offset_text, label_text, calculate_text,
- min_text, max_text, step_text):
+ min_text, max_text, step_text, slide):
""" Create custom slide and stator from text entered on toolbar. """
try:
min_value = float(min_text)
@@ -430,45 +431,53 @@ class SlideRule():
traceback.print_exc()
return None
- custom_slide = CustomSlide(self.sprites, self.path, 'custom',
- 0, SCREENOFFSET + SHEIGHT, Custom_slide,
- self._calc_custom, custom_offset_function,
- custom_label_function, min_value, max_value,
- step_value)
- custom_stator = CustomStator(self.sprites, 'custom2',
- 0, SCREENOFFSET + SHEIGHT, Custom_stator,
- self._calc_custom2,
- self._calc_custom2_result,
- custom_offset_function,
- custom_label_function, min_value,
- max_value, step_value)
-
- if self.name_to_slide('custom').name == 'custom':
- i = self.slides.index(self.name_to_slide('custom'))
- active = False
- if self.active_slide == self.slides[i]:
- active = True
- self.slides[i].hide()
- self.slides[i] = custom_slide
- if active:
- self.active_slide = self.slides[i]
- self.parent.set_slide()
- else:
- self.slides.append(custom_slide)
- if self.name_to_stator('custom2').name == 'custom2':
- i = self.stators.index(self.name_to_stator('custom2'))
- active = False
- if self.active_stator == self.stators[i]:
- active = True
- self.stators[i].hide()
- self.stators[i] = custom_stator
- if active:
- self.active_stator = self.stators[i]
- self.parent.set_stator()
+ if slide == SLIDE:
+ custom_slide = CustomSlide(self.sprites, self.path, 'custom',
+ 0, SCREENOFFSET + SHEIGHT, Custom_slide,
+ self._calc_custom,
+ custom_offset_function,
+ custom_label_function,
+ min_value, max_value, step_value)
+ if self.name_to_slide('custom').name == 'custom':
+ i = self.slides.index(self.name_to_slide('custom'))
+ active = False
+ if self.active_slide == self.slides[i]:
+ active = True
+ self.slides[i].hide()
+ self.slides[i] = custom_slide
+ if active:
+ self.active_slide = self.slides[i]
+ self.parent.set_slide()
+ else:
+ self.slides.append(custom_slide)
+
+ self.active_slide = self.name_to_slide('custom')
+
else:
- self.stators.append(custom_stator)
+ custom_stator = CustomStator(self.sprites, 'custom2',
+ 0, SCREENOFFSET + 2* SHEIGHT,
+ Custom_stator,
+ self._calc_custom2,
+ self._calc_custom2_result,
+ custom_offset_function,
+ custom_label_function,
+ min_value, max_value, step_value)
+
+ if self.name_to_stator('custom2').name == 'custom2':
+ i = self.stators.index(self.name_to_stator('custom2'))
+ active = False
+ if self.active_stator == self.stators[i]:
+ active = True
+ self.stators[i].hide()
+ self.stators[i] = custom_stator
+ if active:
+ self.active_stator = self.stators[i]
+ self.parent.set_stator()
+ else:
+ self.stators.append(custom_stator)
+
+ self.active_stator = self.name_to_stator('custom2')
- self.active_slide = self.name_to_slide('custom')
if hasattr(self.parent, 'sr'):
self.parent.show_u()