Skip to content

Commit

Permalink
Merge pull request #339 from genodeftest/less-magic-constants
Browse files Browse the repository at this point in the history
Button events: Use Gdk.BUTTON_* instead of magic numbers
  • Loading branch information
virtuald committed Apr 26, 2017
2 parents 49b3cf6 + be735a7 commit c3014db
Show file tree
Hide file tree
Showing 23 changed files with 58 additions and 53 deletions.
5 changes: 3 additions & 2 deletions plugins/abrepeat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

from gi.repository import Gtk
from gi.repository import Gdk

from xl import event, player, providers
from xl.nls import gettext as _
Expand Down Expand Up @@ -113,7 +114,7 @@ def on_parent_button_press_event(self, widget, event):
"""
Finishes or cancels insertion of markers
"""
if event.button == 1:
if event.button == Gdk.BUTTON_PRIMARY:
if self.move_finish():
if providers.get_provider('playback-markers',
'repeat-end') is None:
Expand All @@ -123,7 +124,7 @@ def on_parent_button_press_event(self, widget, event):
self.move_begin(self.end_marker)

return True
elif event.button == 3:
elif event.button == Gdk.BUTTON_SECONDARY:
if self.move_cancel():
self.clear_markers()

Expand Down
2 changes: 1 addition & 1 deletion plugins/bpm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def on_eventbox_key_press_event(self, widget, event):
@GtkTemplate.Callback
def on_eventbox_button_press_event(self, widget, event):

if event.button == 3:
if event.button == Gdk.BUTTON_SECONDARY:
if self.menu is not None and self.track is not None:
self.menu.popup(event)
return
Expand Down
2 changes: 1 addition & 1 deletion plugins/grouptagger/gt_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def get_selected_categories(self, selected_rows):
return model.get_selected_categories( rows )

def on_mouse_release(self, widget, event):
if event.button == 3:
if event.button == Gdk.BUTTON_SECONDARY:
self.menu.popup(None, None, None, None, event.button, event.time)

def on_popup_menu(self, widget):
Expand Down
2 changes: 1 addition & 1 deletion plugins/jamendo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def button_press(self, widget, event):
if event.type == Gdk.EventType._2BUTTON_PRESS:
self.add_to_playlist()

elif event.button == 3:
elif event.button == Gdk.BUTTON_SECONDARY:
self.menu.popup(event)

#is called by the search thread when it completed
Expand Down
2 changes: 1 addition & 1 deletion plugins/librivox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def add_to_playlist(self, chapters):


def menu_popup(self, treeview, event):
if event.button == 3:
if event.button == Gdk.BUTTON_SECONDARY:
x = int(event.x)
y = int(event.y)
time = event.time
Expand Down
3 changes: 2 additions & 1 deletion plugins/mainmenubutton/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from gi.repository import Atk
from gi.repository import Gtk
from gi.repository import Gdk

from xl.nls import gettext as _
from xl import event, providers
Expand Down Expand Up @@ -121,7 +122,7 @@ def do_button_press_event(self, e):
"""
Pops out the menu upon click
"""
if e.button == 1:
if e.button == Gdk.BUTTON_PRIMARY:
self.set_active(not self.get_active())

return True
Expand Down
12 changes: 6 additions & 6 deletions plugins/minimode/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,22 +1039,22 @@ def do_button_press_event(self, event):
"""
Trigger normal toggle action or seek
"""
if event.button == 1:
if event.button == Gdk.BUTTON_PRIMARY:
PlaylistButtonControl.do_button_press_event(self, event)
elif event.button == 2:
elif event.button == Gdk.BUTTON_MIDDLE:
event = event.copy()
event.button = 1
event.button = Gdk.BUTTON_PRIMARY
x, y = self.translate_coordinates(self.progressbar,
int(event.x), int(event.y))
event.x, event.y = float(x), float(y)
self.progressbar.emit('button-press-event', event)

def do_button_release_event(self, event):
if event.button == 1:
if event.button == Gdk.BUTTON_PRIMARY:
PlaylistButtonControl.do_button_release_event(self, event)
elif event.button == 2:
elif event.button == Gdk.BUTTON_MIDDLE:
event = event.copy()
event.button = 1
event.button = Gdk.BUTTON_PRIMARY
x, y = self.translate_coordinates(self.progressbar,
int(event.x), int(event.y))
event.x, event.y = float(x), float(y)
Expand Down
4 changes: 2 additions & 2 deletions plugins/moodbar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def _on_moodbar_button_press(self, moodbar, event):
:type moodbar: Moodbar
:type event: Gdk.Event
"""
if event.button == 1:
if event.button == Gdk.BUTTON_PRIMARY:
self.seeking = True
self._on_moodbar_motion(moodbar, event)

Expand All @@ -190,7 +190,7 @@ def _on_moodbar_button_release(self, moodbar, event):
:type moodbar: Moodbar
:type event: Gdk.Event
"""
if event.button == 1 and self.seeking:
if event.button == Gdk.BUTTON_PRIMARY and self.seeking:
self.player.set_progress(moodbar.seek_position)
self.seeking = False

Expand Down
6 changes: 3 additions & 3 deletions plugins/osd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,20 +276,20 @@ def do_button_press_event(self, e):
"""
Starts the dragging process
"""
if e.button == 1:
if e.button == Gdk.BUTTON_PRIMARY:
self.drag_origin = Point(e.x, e.y)
self.window.set_cursor(Gdk.Cursor.new(Gdk.CursorType.FLEUR))

return True
elif e.button == 3 and e.state & Gdk.ModifierType.MOD1_MASK:
elif e.button == Gdk.BUTTON_SECONDARY and e.state & Gdk.ModifierType.MOD1_MASK:
self.begin_resize_drag(Gdk.WindowEdge.SOUTH_EAST, 3, int(e.x_root), int(e.y_root), e.time)

def do_button_release_event(self, e):
"""
Finishes the dragging process and
saves the window position
"""
if e.button == 1:
if e.button == Gdk.BUTTON_PRIMARY:
settings.set_option('plugin/osd/position', list(self.get_position()))

self.drag_origin = None
Expand Down
3 changes: 2 additions & 1 deletion plugins/podcasts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

from gi.repository import GLib
from gi.repository import Gtk
from gi.repository import Gdk

from xl import event, common, playlist, providers
from xl import trax
Expand Down Expand Up @@ -97,7 +98,7 @@ def _connect_events(self):
self.tree.connect('button-press-event', self._on_button_press)

def _on_button_press(self, button, event):
if event.button == 3:
if event.button == Gdk.BUTTON_SECONDARY:
self.menu.popup(event)

def _on_refresh(self, *e):
Expand Down
2 changes: 1 addition & 1 deletion plugins/previewdevice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def _on_playpause_button_clicked(self, widget, event):
Called when the play button is clicked
"""

if event.button == 1:
if event.button == Gdk.BUTTON_PRIMARY:
if event.type == Gdk.EventType.BUTTON_PRESS and \
(self.player.is_paused() or self.player.is_playing()):
self.player.toggle_pause()
Expand Down
4 changes: 2 additions & 2 deletions xlgui/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def on_previews_box_button_press_event(self, widget, e):
if path:
self.previews_box.select_path(path)

if e.button == 3:
if e.button == Gdk.BUTTON_SECONDARY:
self.menu.popup(None, None, None, None, 3, e.time)

def on_previews_box_popup_menu(self, menu):
Expand Down Expand Up @@ -685,7 +685,7 @@ def do_button_press_event(self, event):

if event.type == Gdk.EventType._2BUTTON_PRESS:
self.show_cover()
elif event.button == 3:
elif event.button == Gdk.BUTTON_SECONDARY:
self.menu.popup(event)

def do_expose_event(self, event):
Expand Down
4 changes: 2 additions & 2 deletions xlgui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,10 @@ def on_stop_button_press_event(self, widget, event):
"""
Called when the user clicks on the stop button
"""
if event.button == 1:
if event.button == Gdk.BUTTON_PRIMARY:
if event.get_state() & Gdk.ModifierType.SHIFT_MASK:
self.on_spat_clicked()
elif event.button == 3:
elif event.button == Gdk.BUTTON_SECONDARY:
menu = guiutil.Menu()
menu.append(_("Toggle: Stop after Selected Track"),
self.on_spat_clicked,
Expand Down
6 changes: 3 additions & 3 deletions xlgui/panel/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def on_refresh_button_press_event(self, button, event):
"""
Called on mouse activation of the refresh button
"""
if event.button == 3:
if event.button == Gdk.BUTTON_SECONDARY:
menu = guiutil.Menu()
menu.append(_('Rescan Collection'),
xlgui.get_controller().on_rescan_collection,
Expand Down Expand Up @@ -430,7 +430,7 @@ def button_press(self, widget, event):
replace = settings.get_option('playlist/replace_content', False)
self.append_to_playlist(replace=replace)
return False
elif event.button == 2:
elif event.button == Gdk.BUTTON_MIDDLE:
self.append_to_playlist(replace=True)
return False

Expand All @@ -441,7 +441,7 @@ def button_release(self, widget, event):
selection = self.tree.get_selection()
(x, y) = map(int, event.get_coords())
path = self.tree.get_path_at_pos(x, y)
if event.button == 3:
if event.button == Gdk.BUTTON_SECONDARY:
self.menu.popup(event)
if not path:
return False
Expand Down
2 changes: 1 addition & 1 deletion xlgui/panel/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def button_release(self, button, event):
"""
Called when the user clicks on the playlist
"""
if event.button == 3:
if event.button == Gdk.BUTTON_SECONDARY:
selection = self.tree.get_selection()
(x, y) = map(int, event.get_coords())
path = self.tree.get_path_at_pos(x, y)
Expand Down
3 changes: 2 additions & 1 deletion xlgui/panel/flatplaylist.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from gi.repository import GObject
from gi.repository import Gtk
from gi.repository import Gdk

from xl import trax
from xl.nls import gettext as _
Expand Down Expand Up @@ -121,7 +122,7 @@ def button_release(self, button, event):
"""
Called when the user clicks on the playlist
"""
if event.button == 3:
if event.button == Gdk.BUTTON_SECONDARY:
selection = self.tree.get_selection()
(x, y) = map(int, event.get_coords())
path = self.tree.get_path_at_pos(x, y)
Expand Down
2 changes: 1 addition & 1 deletion xlgui/panel/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ def button_release(self, button, event):
Called when a button is pressed, is responsible
for showing the context menu
"""
if event.button == 3:
if event.button == Gdk.BUTTON_SECONDARY:
button_info = self.tree.get_dest_row_at_pos(
int(event.x), int(event.y))
if not button_info:
Expand Down
2 changes: 1 addition & 1 deletion xlgui/panel/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def button_release(self, widget, event):
"""
Called when someone clicks on the tree
"""
if event.button == 3:
if event.button == Gdk.BUTTON_SECONDARY:
(x, y) = map(int, event.get_coords())
path = self.tree.get_path_at_pos(x, y)
if path:
Expand Down
6 changes: 3 additions & 3 deletions xlgui/tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ def on_button_press_event(self, widget, event):
Toggles main window visibility and
pause as well as opens the context menu
"""
if event.button == 1:
if event.button == Gdk.BUTTON_PRIMARY:
self.main.toggle_visible(bringtofront=True)
if event.button == 2:
if event.button == Gdk.BUTTON_MIDDLE:
playback.playpause( player.PLAYER )
if event.button == 3:
if event.button == Gdk.BUTTON_SECONDARY:
self.menu.popup(None, None, self.get_menu_position, self,
event.button, event.time)

Expand Down
4 changes: 2 additions & 2 deletions xlgui/widgets/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def on_button_press(self, button, event):
path = self.get_path_at_pos(x, y)

if path:
if event.button != 3:
if event.button != Gdk.BUTTON_SECONDARY:
if event.type == Gdk.EventType._2BUTTON_PRESS:
try:
return self.container.button_press(button, event)
Expand Down Expand Up @@ -418,7 +418,7 @@ def on_button_release(self, button, event):
"""
Called when a button is released
"""
if event.button != 1 or \
if event.button != Gdk.BUTTON_PRIMARY or \
self.dragging or \
event.get_state() & ModifierType.PRIMARY_SHIFT_MASK:
self.dragging = False
Expand Down
8 changes: 4 additions & 4 deletions xlgui/widgets/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def set_add_tab_on_empty(self, add_tab_on_empty):
self._add_tab_on_empty = add_tab_on_empty

def on_button_press(self, widget, event):
if event.type == Gdk.EventType.BUTTON_PRESS and event.button == 2:
if event.type == Gdk.EventType.BUTTON_PRESS and event.button == Gdk.BUTTON_MIDDLE:
self.add_default_tab()

def on_popup_menu(self, widget):
Expand Down Expand Up @@ -272,11 +272,11 @@ def on_button_press(self, widget, event):
Typically triggers renaming, closing and menu.
"""
if event.button == 1 and event.type == Gdk.EventType._2BUTTON_PRESS:
if event.button == Gdk.BUTTON_PRIMARY and event.type == Gdk.EventType._2BUTTON_PRESS:
self.start_rename()
elif event.button == 2:
elif event.button == Gdk.BUTTON_MIDDLE:
self.close()
elif event.button == 3:
elif event.button == Gdk.BUTTON_SECONDARY:
self.page.tab_menu.popup( None, None, None, None,
event.button, event.time)
return True
Expand Down

0 comments on commit c3014db

Please sign in to comment.