Skip to content

Commit

Permalink
Add option to control whether to use the ‘auto’ or ‘equal’ aspect rat…
Browse files Browse the repository at this point in the history
…io in the image viewer.
  • Loading branch information
astrofrog committed Aug 21, 2015
1 parent e869b62 commit 123823a
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 61 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ v0.6 (unreleased)

* Added a GUI plugin manager in the 'Plugins' menu. [#682]

* Added an option to specify whether to use an automatic aspect ratio for image
data or whether to enforce square pixels. [#717]

* Data factories can now be given priorities to determine which ones should
take precedence in ambiguous cases. The ``set_default_factory`` and
``get_default_factory`` functions are now deprecated since it is possible to
Expand Down
17 changes: 13 additions & 4 deletions glue/clients/image_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ def result(*args, **kwargs):


class ImageClient(VizClient):

display_data = CallbackProperty(None)
display_attribute = CallbackProperty(None)
display_aspect = CallbackProperty(None)

def __init__(self, data, artist_container=None):

Expand Down Expand Up @@ -327,14 +329,17 @@ def _update_data_plot(self, relim=False, force=False):

self._view = view
for a in list(self.artists):
if (not isinstance(a, ScatterLayerBase)) and \
a.layer.data is not self.display_data:
if (not isinstance(a, ScatterLayerBase) and
a.layer.data is not self.display_data):
self.artists.remove(a)
else:
a.update(view, transpose)
if isinstance(a, ScatterLayerBase):
a.update(view, transpose)
else:
a.update(view, transpose, aspect=self.display_aspect)
for a in self.artists[self.display_data]:
meth = a.update if not force else a.force_update
meth(view, transpose=transpose)
meth(view, transpose=transpose, aspect=self.display_aspect)

def _update_subset_single(self, s, redraw=False, force=False):
"""
Expand Down Expand Up @@ -464,6 +469,10 @@ def rgb_mode(self, enable=None):
self._redraw()
return result

def update_aspect(self):
self._update_data_plot(relim=True)
self._redraw()

def add_layer(self, layer):
if layer in self.artists:
return self.artists[layer][0]
Expand Down
17 changes: 13 additions & 4 deletions glue/clients/layer_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,11 @@ def _update_clip(self, att):
data = small_view_array(self._override_image)
self.norm.update_clip(data)

def update(self, view, transpose=False):
def update(self, view, transpose=False, aspect=None):

if aspect is None:
aspect = 'equal'

self.clear()
views = view_cascade(self.layer, view)
artists = []
Expand All @@ -470,7 +474,7 @@ def update(self, view, transpose=False):
interpolation='nearest',
origin='lower',
extent=extent, zorder=0))
self._axes.set_aspect('equal', adjustable='datalim')
self._axes.set_aspect(aspect, adjustable='datalim')
self.artists = artists
self._sync_style()

Expand Down Expand Up @@ -541,8 +545,13 @@ def set_norm(self, *args, **kwargs):
self.norm = self.bnorm
self.bnorm = spr(*args, **kwargs)

def update(self, view=None, transpose=False):
def update(self, view=None, transpose=False, aspect=None):

self.clear()

if aspect is None:
aspect = 'equal'

if self.r is None or self.g is None or self.b is None:
return

Expand Down Expand Up @@ -591,7 +600,7 @@ def update(self, view=None, transpose=False):
interpolation='nearest',
origin='lower',
extent=extent, zorder=0))
self._axes.set_aspect('equal', adjustable='datalim')
self._axes.set_aspect(aspect, adjustable='datalim')
self.artists = artists
self._sync_style()

Expand Down
119 changes: 66 additions & 53 deletions glue/qt/ui/imagewidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>299</width>
<height>331</height>
<width>351</width>
<height>279</height>
</rect>
</property>
<property name="baseSize">
Expand Down Expand Up @@ -51,18 +51,15 @@
<number>10</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="QLabel" name="label">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="mono_att_label">
<property name="text">
<string>Data</string>
<string>Attribute</string>
</property>
</widget>
</item>
<item>
<item row="0" column="1">
<widget class="GlueComboBox" name="displayDataCombo">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
Expand All @@ -78,10 +75,56 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="GlueComboBox" name="attributeComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Set which attribute of the data to display</string>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Data</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Aspect</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="aspectCombo"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<layout class="QHBoxLayout" name="monochrome_options">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QRadioButton" name="monochrome">
<property name="text">
Expand All @@ -105,61 +148,31 @@
</attribute>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="monochrome_options">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="QLabel" name="mono_att_label">
<property name="text">
<string>Attribute</string>
</property>
</widget>
</item>
<item>
<widget class="GlueComboBox" name="attributeComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="toolTip">
<string>Set which attribute of the data to display</string>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
</property>
</widget>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="slice_layout"/>
</item>
<item>
<widget class="RGBEdit" name="rgb_options" native="true">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="slice_layout"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>5</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
Expand Down
7 changes: 7 additions & 0 deletions glue/qt/widgets/image_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class ImageWidgetBase(DataViewer):
'Current attribute')
data = CurrentComboProperty('ui.displayDataCombo',
'Current data')
aspect_ratio = CurrentComboProperty('ui.aspectCombo',
'Aspect ratio for image')
rgb_mode = ButtonProperty('ui.rgb',
'RGB Mode?')
rgb_viz = Pointer('ui.rgb_options.rgb_visible')
Expand All @@ -74,6 +76,9 @@ def _setup_widgets(self):
self.ui.slice_layout.addWidget(self.ui.slice)
self._tweak_geometry()

self.ui.aspectCombo.addItem("Square Pixels", userData='equal')
self.ui.aspectCombo.addItem("Automatic", userData='auto')

def make_client(self):
""" Instantiate and return an ImageClient subclass """
raise NotImplementedError()
Expand Down Expand Up @@ -215,10 +220,12 @@ def _connect(self):
# sync window title to data/attribute
add_callback(self.client, 'display_data', nonpartial(self.update_window_title))
add_callback(self.client, 'display_attribute', nonpartial(self.update_window_title))
add_callback(self.client, 'display_aspect', nonpartial(self.client.update_aspect))

# sync data/attribute combos with client properties
connect_current_combo(self.client, 'display_data', self.ui.displayDataCombo)
connect_current_combo(self.client, 'display_attribute', self.ui.attributeComboBox)
connect_current_combo(self.client, 'display_aspect', self.ui.aspectCombo)

@defer_draw
def _update_rgb_console(self, is_monochrome):
Expand Down

0 comments on commit 123823a

Please sign in to comment.