44 + def is_rect_on_monitor(self, monitor_number, x, y, w, h):
45 + (m_x, m_y, m_w, m_h) = self.get_monitor_geometry(monitor_number)
46 + return (x >= m_x and x + w <= m_x + m_w and y >= m_y and y + h <= m_y + m_h)
47 +
Instead of passing x,y,w & h as separate parameters, just pass 'rect', and make sure it's a tuple in the function:
def is_rect_on_monitor(self, monitor_number, rect):
"""Returns True if `rect` is _entirely_ on the specified monitor, with no overlap"""
if type(rect) is not tuple:
raise TypeError("rect must be a tuple.")
...if you want you can also check that monitor_number is a valid integer, and that the tuple values are all ints.
Hi,
44 + def is_rect_ on_monitor( self, monitor_number, x, y, w, h): monitor_ geometry( monitor_ number)
45 + (m_x, m_y, m_w, m_h) = self.get_
46 + return (x >= m_x and x + w <= m_x + m_w and y >= m_y and y + h <= m_y + m_h)
47 +
Instead of passing x,y,w & h as separate parameters, just pass 'rect', and make sure it's a tuple in the function: on_monitor( self, monitor_number, rect):
def is_rect_
"""Returns True if `rect` is _entirely_ on the specified monitor, with no overlap"""
if type(rect) is not tuple:
raise TypeError("rect must be a tuple.")
...if you want you can also check that monitor_number is a valid integer, and that the tuple values are all ints.
This:
59 + def get_geometry(self):
60 + return (self.x, self.y, self.width, self.height)
61 +
should be a property, like this:
58 + @property
59 + def geometry(self):
60 + return (self.x, self.y, self.width, self.height)
61 +
this:
84 + screen_geometry = ScreenGeometry() geometry. get_num_ monitors( ) hide_mode' : 0}), hide_mode' : 1}), monitors) : append( ('Monitor %d, Launcher never hide' % (i), {'hud_monitor': i, 'launcher_ hide_mode' : 0})) append( ('Monitor %d, Launcher autohide' % (i), {'hud_monitor': i, 'launcher_ hide_mode' : 1}))
85 + num_monitors = screen_
86 +
87 + if num_monitors == 1:
88 + scenarios = [
89 + ('Single Monitor, Launcher never hide', {'hud_monitor': 0, 'launcher_
90 + ('Single Monitor, Launcher autohide', {'hud_monitor': 0, 'launcher_
91 + ]
92 + else:
93 + scenarios = []
94 + for i in range(num_
95 + scenarios.
96 + scenarios.
is kind of ugly. A better way to do it is how we do it in the launcher tests - use a function to generate the scenarios.
The first two changes I mentioned mean that you can rewrite this:
112 + (x, y, w, h) = self.hud. get_geometry( ) (self.screen_ geometry. is_rect_ on_monitor( self.hud_ monitor, x, y, w, h))
113 + self.assertTrue
like this:
self.assertTrue (self.screen_ geometry. is_rect_ on_monitor( self.hud_ monitor, self.hud.geometry)
The new test:
131 + def test_hud_ dont_change_ launcher_ status( self):
...needs a docstring.
Finally, please use matchers for everything except simple true/false tests, so this:
139 + self.assertEqua l(launcher_ shows_pre, launcher_ shows_post)
becomes:
self.assertThat (launcher_ shows_pre, Equals( launcher_ shows_post) )
Cheers,