[gnome-music/wip/mschraal/gtk4: 36/69] songwidget: Cleanup & break



commit 2be048e230183ad9add3e851bbe9311571e24221
Author: Marinus Schraal <mschraal gnome org>
Date:   Thu Oct 31 16:11:44 2019 +0100

    songwidget: Cleanup & break

 data/ui/SongWidget.ui            | 101 ++++++++++-----------------------
 gnomemusic/widgets/songwidget.py | 119 +++++++++++++++++++--------------------
 gnomemusic/widgets/starimage.py  |   1 -
 3 files changed, 90 insertions(+), 131 deletions(-)
---
diff --git a/data/ui/SongWidget.ui b/data/ui/SongWidget.ui
index 97627b24..2a05e88f 100644
--- a/data/ui/SongWidget.ui
+++ b/data/ui/SongWidget.ui
@@ -1,27 +1,21 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.20.0 -->
 <interface>
   <requires lib="gtk+" version="3.10"/>
   <template class="SongWidget" parent="GtkBox">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
     <signal name="notify::selected" handler="_on_selection_changed"/>
-<!--<signal name="drag_data_received" handler="_on_drag_data_received"/> -->
     <child>
       <object class="GtkBox" id="box1">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
         <property name="spacing">3</property>
         <property name="margin_top">10</property>
         <property name="margin_bottom">10</property>
         <child>
           <object class="GtkBox" id="_dnd_eventbox">
-            <property name="visible">False</property>
 <!--
             <signal name="drag-begin" handler="_on_drag_begin"/>
             <signal name="drag-end" handler="_on_drag_end"/>
             <signal name="drag_data_get" handler="_on_drag_data_get"/>
 -->
+            <property name="visible">False</property>
             <child>
               <object class="GtkImage">
                 <property name="visible">True</property>
@@ -36,17 +30,12 @@
         <child>
           <object class="GtkBox" id="box3">
             <property name="width_request">48</property>
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="homogeneous">True</property>
+            <property name="homogeneous">1</property>
             <child>
-              <!-- FIXME: Remove this box? -->
               <object class="GtkBox" id="eventbox2">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <child>
                   <object class="GtkImage" id="_play_icon">
-                    <property name="can_focus">False</property>
+                    <property name="visible">0</property>
                     <property name="icon_size">1</property>
                   </object>
                 </child>
@@ -54,17 +43,11 @@
             </child>
             <child>
               <object class="GtkCheckButton" id="_select_button">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="receives_default">False</property>
-                <property name="draw_indicator">True</property>
                 <signal name="toggled" handler="_on_select_button_toggled"/>
               </object>
             </child>
             <child>
               <object class="GtkLabel" id="_number_label">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <property name="halign">end</property>
                 <property name="justify">right</property>
                 <style>
@@ -76,18 +59,14 @@
         </child>
         <child>
           <object class="GtkBox" id="title_box">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
             <property name="margin_top">1</property>
             <property name="margin_bottom">1</property>
-            <property name="hexpand">True</property>
+            <property name="hexpand">1</property>
             <child>
               <object class="GtkLabel" id="_title_label">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <property name="xalign">0</property>
                 <property name="halign">start</property>
-                <property name="hexpand">True</property>
+                <property name="hexpand">1</property>
                 <property name="valign">start</property>
                 <property name="ellipsize">end</property>
                 <property name="max_width_chars">90</property>
@@ -99,18 +78,15 @@
         </child>
         <child>
           <object class="GtkBox" id="_artist_box">
-            <property name="visible">False</property>
-            <property name="can_focus">False</property>
+            <property name="visible">0</property>
             <property name="margin_top">1</property>
             <property name="margin_bottom">1</property>
-            <property name="hexpand">True</property>
+            <property name="hexpand">1</property>
             <child>
               <object class="GtkLabel" id="_artist_label">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <property name="xalign">0</property>
                 <property name="halign">start</property>
-                <property name="hexpand">True</property>
+                <property name="hexpand">1</property>
                 <property name="valign">start</property>
                 <property name="ellipsize">end</property>
                 <property name="max_width_chars">90</property>
@@ -122,18 +98,15 @@
         </child>
         <child>
           <object class="GtkBox" id="_album_duration_box">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
             <property name="margin_top">1</property>
             <property name="margin_bottom">1</property>
-            <property name="hexpand">True</property>
+            <property name="hexpand">1</property>
             <child>
               <object class="GtkLabel" id="_album_label">
-                <property name="visible">False</property>
-                <property name="can_focus">False</property>
+                <property name="visible">0</property>
                 <property name="xalign">0</property>
                 <property name="halign">start</property>
-                <property name="hexpand">True</property>
+                <property name="hexpand">1</property>
                 <property name="valign">start</property>
                 <property name="ellipsize">end</property>
                 <property name="max_width_chars">90</property>
@@ -143,8 +116,6 @@
             </child>
             <child>
               <object class="GtkLabel" id="_duration_label">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
                 <property name="halign">end</property>
                 <property name="valign">center</property>
                 <property name="hexpand">True</property>
@@ -158,42 +129,33 @@
         </child>
         <child>
           <object class="GtkStack" id="_star_stack">
-            <property name="can-focus">False</property>
-            <property name="visible">True</property>
             <child>
-              <object class="GtkBox" id="_star_eventbox">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="halign">end</property>
-                <property name="valign">center</property>
-                <property name="visible_window">True</property>
-                <property name="margin_right">12</property>
-<!--
-                <signal name="button-release-event" handler="_on_star_toggle" swapped="no"/>
-                <signal name="enter-notify-event" handler="_on_star_hover" swapped="no"/>
-                <signal name="leave-notify-event" handler="_on_star_unhover" swapped="no"/>
--->
-                <child>
-                  <object class="StarImage" id="_star_image">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
+              <object class="GtkStackPage">
+                <property name="name">star</property>
+                <property name="child">
+                  <object class="GtkBox" id="_star_eventbox">
+                    <property name="halign">end</property>
                     <property name="valign">center</property>
-                    <property name="margin_start">10</property>
+<!--                    <property name="margin_right">12</property>  -->
+                    <child>
+                      <object class="StarImage" id="_star_image">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="valign">center</property>
+                        <property name="margin_start">10</property>
+                      </object>
+                    </child>
                   </object>
-                </child>
+                </property>
               </object>
-              <packing>
-                <property name="name">star</property>
-              </packing>
             </child>
             <child>
-              <object class="GtkBox">
-                <property name="visible">True</property>
-              </object>
-              <packing>
+              <object class="GtkStackPage">
                 <property name="name">empty</property>
-                <property name="position">1</property>
-              </packing>
+                <property name="child">
+                  <object class="GtkBox"/>
+                </property>
+              </object>
             </child>
           </object>
         </child>
@@ -201,7 +163,6 @@
     </child>
   </template>
   <object class="GtkSizeGroup" id="_size_group">
-    <property name="mode">horizontal</property>
     <widgets>
       <widget name="title_box"/>
       <widget name="_artist_box"/>
diff --git a/gnomemusic/widgets/songwidget.py b/gnomemusic/widgets/songwidget.py
index 4b54069a..41f80dfa 100644
--- a/gnomemusic/widgets/songwidget.py
+++ b/gnomemusic/widgets/songwidget.py
@@ -24,7 +24,6 @@
 
 from enum import IntEnum
 
-import gi
 from gi.repository import Gdk, GObject, Gtk
 
 from gnomemusic import utils
@@ -120,8 +119,7 @@ class SongWidget(Gtk.Box):
 
         self._select_button.set_visible(False)
 
-        self._play_icon.set_from_icon_name(
-            'media-playback-start-symbolic', Gtk.IconSize.SMALL_TOOLBAR)
+        self._play_icon.set_from_icon_name('media-playback-start-symbolic')
 
         self.props.coresong.bind_property(
             'selected', self._select_button, 'active',
@@ -162,70 +160,71 @@ class SongWidget(Gtk.Box):
             self.drag_dest_set(
                 Gtk.DestDefaults.ALL, entries, Gdk.DragAction.MOVE)
 
-    @Gtk.Template.Callback()
-    def _on_selection_changed(self, klass, value):
-        self.emit('selection-changed')
-
-    @Gtk.Template.Callback()
-    def _on_drag_begin(self, klass, context):
-        gdk_window = self.get_window()
-        _, x, y, _ = gdk_window.get_device_position(context.get_device())
-        allocation = self.get_allocation()
-
-        self._drag_widget = Gtk.ListBox()
-        self._drag_widget.set_size_request(allocation.width, allocation.height)
-
-        drag_row = SongWidget(self.props.coresong)
-        self._drag_widget.add(drag_row)
-        self._drag_widget.drag_highlight_row(drag_row.get_parent())
-        self._drag_widget.props.visible = True
-        Gtk.drag_set_icon_widget(context, self._drag_widget, x, y)
-
-    @Gtk.Template.Callback()
-    def _on_drag_end(self, klass, context):
-        self._drag_widget = None
-
-    @Gtk.Template.Callback()
-    def _on_drag_data_get(self, klass, context, selection_data, info, time_):
-        row_position = self.get_parent().get_index()
-        selection_data.set(
-            Gdk.Atom.intern("row_position", False), 0,
-            bytes(str(row_position), encoding="UTF8"))
-
-    @Gtk.Template.Callback()
-    def _on_drag_data_received(
-            self, klass, context, x, y, selection_data, info, time_):
-        source_position = int(str(selection_data.get_data(), "UTF-8"))
-        target_position = self.get_parent().get_index()
-        if source_position == target_position:
-            return
-
-        self.emit("widget-moved", source_position)
-
-    @Gtk.Template.Callback()
-    def _on_select_button_toggled(self, widget):
+    # @Gtk.Template.Callback()
+    # def _on_selection_changed(self, klass, value):
+    #     self.emit('selection-changed')
+
+    # @Gtk.Template.Callback()
+    # def _on_drag_begin(self, klass, context):
+    #     gdk_window = self.get_window()
+    #     _, x, y, _ = gdk_window.get_device_position(context.get_device())
+    #     allocation = self.get_allocation()
+
+    #     self._drag_widget = Gtk.ListBox()
+    #     self._drag_widget.set_size_request(
+    #         allocation.width, allocation.height)
+
+    #     drag_row = SongWidget(self.props.coresong)
+    #     self._drag_widget.add(drag_row)
+    #     self._drag_widget.drag_highlight_row(drag_row.get_parent())
+    #     self._drag_widget.show_all()
+    #     Gtk.drag_set_icon_widget(context, self._drag_widget, x, y)
+
+    # @Gtk.Template.Callback()
+    # def _on_drag_end(self, klass, context):
+    #     self._drag_widget = None
+
+    # @Gtk.Template.Callback()
+    # def _on_drag_data_get(self, klass, context, selection_data, info, time_):
+    #     row_position = self.get_parent().get_index()
+    #     selection_data.set(
+    #         Gdk.Atom.intern("row_position", False), 0,
+    #         bytes(str(row_position), encoding="UTF8"))
+
+    # @Gtk.Template.Callback()
+    # def _on_drag_data_received(
+    #         self, klass, context, x, y, selection_data, info, time_):
+    #     source_position = int(str(selection_data.get_data(), "UTF-8"))
+    #     target_position = self.get_parent().get_index()
+    #     if source_position == target_position:
+    #         return
+
+    #     self.emit("widget-moved", source_position)
+
+    # @Gtk.Template.Callback()
+    # def _on_select_button_toggled(self, widget):
         # This property is used to ignore the second click event
         # (one event in SongWidget and the other one in select_button).
-        self.props.select_click = not self.props.select_click
+    #     self.props.select_click = not self.props.select_click
 
-    @Gtk.Template.Callback()
-    def _on_star_toggle(self, widget, event):
-        (_, button) = event.get_button()
-        if button != Gdk.BUTTON_PRIMARY:
-            return False
+    # @Gtk.Template.Callback()
+    # def _on_star_toggle(self, widget, event):
+    #     (_, button) = event.get_button()
+    #     if button != Gdk.BUTTON_PRIMARY:
+    #         return False
 
-        favorite = not self._star_image.favorite
-        self._star_image.props.favorite = favorite
+    #     favorite = not self._star_image.favorite
+    #     self._star_image.props.favorite = favorite
 
-        return True
+    #     return True
 
-    @Gtk.Template.Callback()
-    def _on_star_hover(self, widget, event):
-        self._star_image.props.hover = True
+    # @Gtk.Template.Callback()
+    # def _on_star_hover(self, widget, event):
+    #     self._star_image.props.hover = True
 
-    @Gtk.Template.Callback()
-    def _on_star_unhover(self, widget, event):
-        self._star_image.props.hover = False
+    # @Gtk.Template.Callback()
+    # def _on_star_unhover(self, widget, event):
+    #     self._star_image.props.hover = False
 
     @GObject.Property(type=bool, default=False)
     def selection_mode(self):
diff --git a/gnomemusic/widgets/starimage.py b/gnomemusic/widgets/starimage.py
index 032bf6e3..0110b1be 100644
--- a/gnomemusic/widgets/starimage.py
+++ b/gnomemusic/widgets/starimage.py
@@ -36,7 +36,6 @@ class StarImage(Gtk.Image):
         self._hover = False
 
         self.get_style_context().add_class("star")
-        self.props.visible = True
 
     @GObject.Property(type=bool, default=False)
     def favorite(self):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]