Skip to content

Commit

Permalink
PathBar widget.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsufeki committed Jun 27, 2013
1 parent f939b86 commit 6590dc6
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 179 deletions.
85 changes: 14 additions & 71 deletions qygmy/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ def __init__(self, main):
self.main = main
self.srv = main.srv
self.setup_ui()
self.setAttribute(Qt.WA_QuitOnClose, False)

def setup_ui(self):
self.ui = Ui_browser()
self.ui.setupUi(self)
self.setup_icons()
self.setup_database()
self.setup_playlists()
self.setup_search()
self.ui.database.setup(self.srv.database)
self.srv.database.current.changed.connect(self.ui.dbpath.set_path)
self.ui.dbpath.clicked.connect(self.srv.database.cd)
self.ui.playlists.setup(self.srv.playlists)
self.srv.playlists.current.changed.connect(self.ui.plpath.set_path)
self.ui.plpath.clicked.connect(self.srv.playlists.cd)
self.ui.search_results.setup(self.srv.search)
self.ui.search_button.setDefaultAction(self.ui.search)
self.srv.state.changed.connect(self.on_state_changed)

try:
Expand All @@ -37,32 +41,13 @@ def setup_icons(self):
('add', 'list-add'),
('remove', 'edit-delete'),
('close', 'window-close'),
('dbroot', 'folder-sound'),
('plroot', 'document-multiple'),
('search', 'edit-find'),
):
getattr(self.ui, action).setIcon(QIcon.fromTheme(icon))
for i, icon in enumerate(['folder-sound', 'document-multiple', 'edit-find']):
self.ui.tabs.setTabIcon(i, QIcon.fromTheme(icon))

def setup_database(self):
self.ui.database.setup(self.srv.database)
self.ui.dbroot_button.setDefaultAction(self.ui.dbroot)
self.ui.db_list = []
self.database_mapper = QSignalMapper(self)
self.database_mapper.mapped.connect(self.on_db_triggered)
self.srv.database.current.changed.connect(self.update_database)

def setup_playlists(self):
self.ui.playlists.setup(self.srv.playlists)
self.ui.plroot_button.setDefaultAction(self.ui.plroot)
self.ui.pl_button.hide()
self.ui.pl_button.setDefaultAction(self.ui.pl)
self.srv.playlists.current.changed.connect(self.update_playlists)

def setup_search(self):
self.ui.search_results.setup(self.srv.search)
self.ui.search_button.setDefaultAction(self.ui.search)
self.ui.dbpath.set_root_icon('folder-sound')
self.ui.plpath.set_root_icon('document-multiple')

@property
def current_view(self):
Expand All @@ -86,60 +71,18 @@ def contextMenuEvent(self, e):

def on_state_changed(self, state):
c = state != 'disconnect'
for act in ('dbroot', 'plroot', 'pl', 'search', 'add', 'addplay',
'replace', 'replaceplay', 'remove', 'rename', 'details'):
for act in ('search', 'add', 'addplay', 'replace', 'replaceplay',
'remove', 'rename', 'details'):
getattr(self.ui, act).setEnabled(c)
for b in self.ui.db_list:
b.defaultAction().setEnabled(c)
self.ui.dbpath.setEnabled(c)
self.ui.plpath.setEnabled(c)
self.ui.what.setEnabled(c)
self.ui.query.setEnabled(c)

def update_database(self, path):
p = path.split('/')
if p == ['']:
p = []
for i in range(len(self.ui.db_list), len(p)):
a = QAction(self)
a.triggered.connect(self.database_mapper.map)
self.database_mapper.setMapping(a, i)
b = QToolButton(self)
b.setDefaultAction(a)
b.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred))
self.ui.db_layout.insertWidget(i+1, b)
self.ui.db_list.append(b)
for i in range(len(p)):
self.ui.db_list[i].defaultAction().setText(p[i])
self.ui.db_list[i].show()
for i in range(len(p), len(self.ui.db_list)):
self.ui.db_list[i].hide()

def update_playlists(self, name):
if name == '':
self.ui.pl_button.hide()
else:
self.ui.pl_button.defaultAction().setText(name)
self.ui.pl_button.show()

@Slot()
def on_close_triggered(self):
self.close()

@Slot()
def on_dbroot_triggered(self):
self.srv.database.cd('')

def on_db_triggered(self, number):
path = '/'.join(self.srv.database.current.value.split('/')[:number+1])
self.srv.database.cd(path)

@Slot()
def on_plroot_triggered(self):
self.srv.playlists.cd('')

@Slot()
def on_pl_triggered(self):
self.srv.playlists.refresh()

@Slot()
def on_search_triggered(self):
self.srv.search.cd((self.ui.what.currentIndex(), self.ui.query.text()))
Expand Down
9 changes: 6 additions & 3 deletions qygmy/qygmy.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,15 @@ def on_state_changed(self, state):
c = state != 'disconnect'
self.ui.connect.setVisible(not c)
self.ui.disconnect.setVisible(c)
self.ui.play.setVisible(state != 'play')
self.ui.pause.setVisible(state == 'play')
for action in ('previous', 'play', 'pause', 'stop', 'next', 'volume',
'add', 'clear', 'repeat', 'shuffle', 'single', 'consume',
'updatedb', 'save', 'randomize', 'details', 'statistics'):
'updatedb', 'save', 'randomize', 'details', 'statistics',
'louder', 'quieter'):
getattr(self.ui, action).setEnabled(c)
self.ui.play.setVisible(state != 'play')
self.ui.pause.setVisible(state == 'play')
self.ui.playback_menu.setEnabled(c)
self.ui.volume_menu.setEnabled(c)
self.on_queue_selection_changed()

@Slot(bool)
Expand Down
151 changes: 46 additions & 105 deletions qygmy/ui/browser.ui
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="vv">
<property name="margin">
<number>2</number>
</property>
<item>
<widget class="ChangeDuringDragTabWidget" name="tabs">
<property name="currentIndex">
Expand All @@ -40,32 +43,18 @@
<string>&amp;Database</string>
</attribute>
<layout class="QVBoxLayout" name="db_v">
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="db_layout">
<item>
<widget class="QToolButton" name="dbroot_button">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="db_label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
<widget class="PathBar" name="dbpath" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="SonglistView" name="database">
Expand Down Expand Up @@ -141,48 +130,18 @@
<string>&amp;Playlists</string>
</attribute>
<layout class="QVBoxLayout" name="pl_v">
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="pl_layout">
<item>
<widget class="QToolButton" name="plroot_button">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="pl_button">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="pl_label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
<widget class="PathBar" name="plpath" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="SonglistView" name="playlists">
Expand Down Expand Up @@ -264,8 +223,23 @@
<string>&amp;Search</string>
</attribute>
<layout class="QVBoxLayout" name="se_v">
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="search_layout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="what">
<property name="toolTip">
Expand Down Expand Up @@ -456,23 +430,6 @@
<bool>false</bool>
</property>
</action>
<action name="dbroot">
<property name="text">
<string>/</string>
</property>
<property name="toolTip">
<string>Root directory</string>
</property>
<property name="shortcut">
<string>Ctrl+R</string>
</property>
<property name="shortcutContext">
<enum>Qt::WindowShortcut</enum>
</property>
<property name="autoRepeat">
<bool>false</bool>
</property>
</action>
<action name="close">
<property name="text">
<string>&amp;Close</string>
Expand All @@ -490,23 +447,6 @@
<bool>false</bool>
</property>
</action>
<action name="plroot">
<property name="text">
<string>Playlists</string>
</property>
<property name="toolTip">
<string>All playlists</string>
</property>
<property name="shortcut">
<string>Ctrl+R</string>
</property>
<property name="shortcutContext">
<enum>Qt::WindowShortcut</enum>
</property>
<property name="autoRepeat">
<bool>false</bool>
</property>
</action>
<action name="search">
<property name="text">
<string>Search</string>
Expand Down Expand Up @@ -543,11 +483,6 @@
<bool>false</bool>
</property>
</action>
<action name="pl">
<property name="autoRepeat">
<bool>false</bool>
</property>
</action>
<action name="details">
<property name="text">
<string>Song &amp;details...</string>
Expand Down Expand Up @@ -605,6 +540,12 @@
<header>..uiutils</header>
<container>1</container>
</customwidget>
<customwidget>
<class>PathBar</class>
<extends>QWidget</extends>
<header>..uiutils</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
Expand Down
3 changes: 3 additions & 0 deletions qygmy/ui/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
</sizepolicy>
</property>
<layout class="QVBoxLayout">
<property name="margin">
<number>2</number>
</property>
<item>
<widget class="ClickableProgressBar" name="progressbar">
<property name="sizePolicy">
Expand Down
Loading

0 comments on commit 6590dc6

Please sign in to comment.