Primitivus: send_file first draft
- a new dialog for choosing a file is work in progress
This commit is contained in:
parent
cc547e5ec4
commit
7fa8f4d0c2
4 changed files with 112 additions and 3 deletions
|
|
@ -26,6 +26,7 @@ import custom_widgets
|
||||||
import time
|
import time
|
||||||
from tools.jid import JID
|
from tools.jid import JID
|
||||||
from card_game import CardGame
|
from card_game import CardGame
|
||||||
|
from files_management import FileDialog
|
||||||
|
|
||||||
|
|
||||||
class ChatText(urwid.FlowWidget):
|
class ChatText(urwid.FlowWidget):
|
||||||
|
|
@ -131,6 +132,8 @@ class Chat(urwid.WidgetWrap, QuickChat):
|
||||||
if self.type == 'group':
|
if self.type == 'group':
|
||||||
game = _("Game")
|
game = _("Game")
|
||||||
menu.addMenu(game, "Tarot", self.onTarotRequest)
|
menu.addMenu(game, "Tarot", self.onTarotRequest)
|
||||||
|
elif self.type == 'one2one':
|
||||||
|
menu.addMenu(_("Action"), _("Send file"), self.onSendFileRequest)
|
||||||
return menu
|
return menu
|
||||||
|
|
||||||
def setType(self, type):
|
def setType(self, type):
|
||||||
|
|
@ -250,3 +253,8 @@ class Chat(urwid.WidgetWrap, QuickChat):
|
||||||
self.host.showPopUp(custom_widgets.Alert(_("Can't start game"), _("You need to be exactly 4 peoples in the room to start a Tarot game"), ok_cb=self.host.removePopUp))
|
self.host.showPopUp(custom_widgets.Alert(_("Can't start game"), _("You need to be exactly 4 peoples in the room to start a Tarot game"), ok_cb=self.host.removePopUp))
|
||||||
else:
|
else:
|
||||||
self.host.bridge.tarotGameCreate(self.id, list(self.occupants), self.host.profile)
|
self.host.bridge.tarotGameCreate(self.id, list(self.occupants), self.host.profile)
|
||||||
|
|
||||||
|
def onSendFileRequest(self, menu):
|
||||||
|
dialog = FileDialog()
|
||||||
|
self.host.showPopUp(dialog, 80, 80)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -899,7 +899,7 @@ class LabelLine(urwid.LineBox):
|
||||||
top_columns.widget_list[1] = label_widget
|
top_columns.widget_list[1] = label_widget
|
||||||
|
|
||||||
class VerticalSeparator(urwid.WidgetDecoration, urwid.WidgetWrap):
|
class VerticalSeparator(urwid.WidgetDecoration, urwid.WidgetWrap):
|
||||||
def __init__(self, original_widget, left_char = utf8decode("│"), right_char = ''):
|
def __init__(self, original_widget, left_char = u"│", right_char = ''):
|
||||||
"""Draw a separator on left and/or right of original_widget."""
|
"""Draw a separator on left and/or right of original_widget."""
|
||||||
|
|
||||||
widgets = [original_widget]
|
widgets = [original_widget]
|
||||||
|
|
|
||||||
101
frontends/primitivus/files_management.py
Normal file
101
frontends/primitivus/files_management.py
Normal file
|
|
@ -0,0 +1,101 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
Primitivus: a SAT frontend
|
||||||
|
Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import urwid
|
||||||
|
import custom_widgets
|
||||||
|
from tools.jid import JID
|
||||||
|
import os, os.path
|
||||||
|
from xml.dom import minidom
|
||||||
|
from logging import debug, info, error
|
||||||
|
|
||||||
|
class PathEdit(custom_widgets.AdvancedEdit):
|
||||||
|
|
||||||
|
def keypress(self, size, key):
|
||||||
|
if key == 'ctrl w':
|
||||||
|
if self.edit_pos<2:
|
||||||
|
return
|
||||||
|
before = self.edit_text[:self.edit_pos]
|
||||||
|
pos = (before[:-1] if before.endswith('/') else before).rfind("/")+1
|
||||||
|
self.set_edit_text(before[:pos] + self.edit_text[self.edit_pos:])
|
||||||
|
self.set_edit_pos(pos)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
return super(PathEdit, self).keypress(size, key)
|
||||||
|
|
||||||
|
class FileDialog(urwid.WidgetWrap):
|
||||||
|
|
||||||
|
def __init__(self,title=_("Please select a file")):
|
||||||
|
self.__home_path = os.path.expanduser('~')
|
||||||
|
self.path_wid = PathEdit(_('Path: '), os.getcwdu())
|
||||||
|
urwid.connect_signal(self.path_wid, 'change', self.onPathChange)
|
||||||
|
header = urwid.Pile([self.path_wid, urwid.Divider(u'─')])
|
||||||
|
bookm_list = urwid.SimpleListWalker([])
|
||||||
|
self.bookmarks = list(self.getBookmarks())
|
||||||
|
self.bookmarks.sort()
|
||||||
|
for bookmark in self.bookmarks:
|
||||||
|
if bookmark.startswith(self.__home_path):
|
||||||
|
bookmark="~"+bookmark[len(self.__home_path):]
|
||||||
|
book_wid = custom_widgets.ClickableText(bookmark)
|
||||||
|
urwid.connect_signal(book_wid, 'click', self.onBookmarkSelected)
|
||||||
|
bookm_list.append(book_wid)
|
||||||
|
bookm_wid = urwid.Frame(urwid.ListBox(bookm_list), urwid.AttrMap(urwid.Text(_('Bookmarks'),'center'),'title'))
|
||||||
|
self.files_list = urwid.SimpleListWalker([urwid.Text('toto.mkv')])
|
||||||
|
files_wid = urwid.ListBox(self.files_list)
|
||||||
|
center_row = urwid.Columns([('weight',2,bookm_wid),
|
||||||
|
('weight',8,custom_widgets.VerticalSeparator(files_wid))])
|
||||||
|
main_frame = custom_widgets.FocusFrame(center_row, header)
|
||||||
|
decorated = custom_widgets.LabelLine(main_frame, custom_widgets.SurroundedText(title))
|
||||||
|
urwid.WidgetWrap.__init__(self, decorated)
|
||||||
|
|
||||||
|
def getBookmarks(self):
|
||||||
|
gnome_bookm = os.path.expanduser("~/.gtk-bookmarks")
|
||||||
|
kde_bookm = os.path.expanduser("~/.kde/share/apps/kfileplaces/bookmarks.xm")
|
||||||
|
bookmarks = set()
|
||||||
|
try:
|
||||||
|
with open(gnome_bookm) as gnome_fd:
|
||||||
|
for bm in gnome_fd.readlines():
|
||||||
|
if bm.startswith("file:///"):
|
||||||
|
bookmarks.add(bm[7:].replace('\n',''))
|
||||||
|
except IOError:
|
||||||
|
info(_('No Gnome bookmarks file found'))
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
dom = minidom.parse(kde_bookm)
|
||||||
|
for elem in getElementsByTagName('bookmark'):
|
||||||
|
bm = elem.getAttribute("href")
|
||||||
|
if bm.startswith("file:///"):
|
||||||
|
bookmarks.add(bm[7:])
|
||||||
|
except IOError:
|
||||||
|
info(_('No KDE bookmarks file found'))
|
||||||
|
pass
|
||||||
|
|
||||||
|
return bookmarks
|
||||||
|
|
||||||
|
def onBookmarkSelected(self, button):
|
||||||
|
self.path_wid.set_edit_text(os.path.expanduser(button.get_text()))
|
||||||
|
|
||||||
|
def onPathChange(self, edit, text):
|
||||||
|
if os.path.isdir(text):
|
||||||
|
del self.files_list[:]
|
||||||
|
files = os.listdir(text)
|
||||||
|
files.sort()
|
||||||
|
self.files_list.extend([custom_widgets.ClickableText(filename) for filename in files])
|
||||||
|
|
@ -230,10 +230,10 @@ class PrimitivusApp(QuickApp):
|
||||||
#we still have popup to show, we display it
|
#we still have popup to show, we display it
|
||||||
self.showPopUp(next_popup)
|
self.showPopUp(next_popup)
|
||||||
|
|
||||||
def showPopUp(self, pop_up_widget):
|
def showPopUp(self, pop_up_widget, perc_width=40, perc_height=40):
|
||||||
"Show a pop-up window if possible, else put it in queue"
|
"Show a pop-up window if possible, else put it in queue"
|
||||||
if not isinstance(self.loop.widget,urwid.Overlay):
|
if not isinstance(self.loop.widget,urwid.Overlay):
|
||||||
display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', 40), 'middle', ('relative', 40))
|
display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', perc_width), 'middle', ('relative', perc_height))
|
||||||
self.loop.widget = display_widget
|
self.loop.widget = display_widget
|
||||||
else:
|
else:
|
||||||
self.notBar.addPopUp(pop_up_widget)
|
self.notBar.addPopUp(pop_up_widget)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue