Skip to content
Snippets Groups Projects
Commit 77df9d06 authored by Sébastien Helleu's avatar Sébastien Helleu
Browse files

Code refactoring, fix setup.py

All changes:
- full PEP8 compliance
- move sources from src/qweechat/ to qweechat/
- move data from data/icons/ to qweechat/data/icons/
- sources validated with PEP8
- use setuptools in setup.py, fix path of data files
parent 42f35412
No related branches found
No related tags found
No related merge requests found
Showing
with 200 additions and 53 deletions
# Ignored files for Git
 
*.pyc
*.pyo
MANIFEST
build/*
dist/*
*.pyc
qweechat.egg-info/*
src/qweechat.egg-info/*
Loading
Loading
@@ -27,35 +27,10 @@ Following packages are *required*:
* Python 2.x >= 2.6
* PySide (recommended, packages: python.pyside.*) or PyQt4 (python-qt4)
 
=== Run without install
Extract files from archive and run qweechat.py:
----
$ tar xvzf qweechat-x.y.tar.gz
$ cd qweechat-x.y
$ python src/qweechat/qweechat.py
----
=== Run with install
Extract files from archive and install using script 'setup.py':
----
$ tar xvzf qweechat-x.y.tar.gz
$ cd qweechat-x.y
----
To install in your home:
----
$ python setup.py install --home=~/qweechat
----
To install in system directories (as root):
=== Install via source distribution
 
----
# python setup.py install
$ python setup.py install
----
 
== WeeChat setup
Loading
Loading
File moved
File moved
Loading
Loading
@@ -21,6 +21,7 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
 
from pkg_resources import resource_filename
import qt_compat
QtCore = qt_compat.import_module('QtCore')
QtGui = qt_compat.import_module('QtGui')
Loading
Loading
@@ -85,7 +86,10 @@ class BufferListWidget(GenericListWidget):
 
 
class BufferWidget(QtGui.QWidget):
"""Widget with (from top to bottom): title, chat + nicklist (optional) + prompt/input."""
"""
Widget with (from top to bottom):
title, chat + nicklist (optional) + prompt/input.
"""
 
def __init__(self, display_nicklist=False):
QtGui.QWidget.__init__(self)
Loading
Loading
@@ -96,7 +100,8 @@ class BufferWidget(QtGui.QWidget):
 
# splitter with chat + nicklist
self.chat_nicklist = QtGui.QSplitter()
self.chat_nicklist.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
self.chat_nicklist.setSizePolicy(QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding)
self.chat = ChatTextEdit(debug=False)
self.chat_nicklist.addWidget(self.chat)
self.nicklist = GenericListWidget()
Loading
Loading
@@ -148,7 +153,8 @@ class Buffer(QtCore.QObject):
QtCore.QObject.__init__(self)
self.data = data
self.nicklist = {}
self.widget = BufferWidget(display_nicklist=self.data.get('nicklist', 0))
self.widget = BufferWidget(display_nicklist=self.data.get('nicklist',
0))
self.update_title()
self.update_prompt()
self.widget.input.textSent.connect(self.input_text_sent)
Loading
Loading
@@ -160,7 +166,8 @@ class Buffer(QtCore.QObject):
def update_title(self):
"""Update title."""
try:
self.widget.set_title(color.remove(self.data['title'].decode('utf-8')))
self.widget.set_title(
color.remove(self.data['title'].decode('utf-8')))
except:
self.widget.set_title(None)
 
Loading
Loading
@@ -179,12 +186,14 @@ class Buffer(QtCore.QObject):
def nicklist_add_item(self, parent, group, prefix, name, visible):
"""Add a group/nick in nicklist."""
if group:
self.nicklist[name] = { 'visible': visible,
'nicks': [] }
self.nicklist[name] = {
'visible': visible,
'nicks': []
}
else:
self.nicklist[parent]['nicks'].append({ 'prefix': prefix,
'name': name,
'visible': visible })
self.nicklist[parent]['nicks'].append({'prefix': prefix,
'name': name,
'visible': visible})
 
def nicklist_remove_item(self, parent, group, name):
"""Remove a group/nick from nicklist."""
Loading
Loading
@@ -193,7 +202,10 @@ class Buffer(QtCore.QObject):
del self.nicklist[name]
else:
if parent in self.nicklist:
self.nicklist[parent]['nicks'] = [nick for nick in self.nicklist[parent]['nicks'] if nick['name'] != name]
self.nicklist[parent]['nicks'] = [
nick for nick in self.nicklist[parent]['nicks']
if nick['name'] != name
]
 
def nicklist_update_item(self, parent, group, prefix, name, visible):
"""Update a group/nick in nicklist."""
Loading
Loading
@@ -212,11 +224,15 @@ class Buffer(QtCore.QObject):
"""Refresh nicklist."""
self.widget.nicklist.clear()
for group in sorted(self.nicklist):
for nick in sorted(self.nicklist[group]['nicks'], key=lambda n:n['name']):
prefix_color = { '': '', ' ': '', '+': 'yellow' }
for nick in sorted(self.nicklist[group]['nicks'],
key=lambda n: n['name']):
prefix_color = {'': '', ' ': '', '+': 'yellow'}
color = prefix_color.get(nick['prefix'], 'green')
if color:
icon = QtGui.QIcon('data/icons/bullet_%s_8x8.png' % color)
icon = QtGui.QIcon(
resource_filename(__name__,
'data/icons/bullet_%s_8x8.png' %
color))
else:
pixmap = QtGui.QPixmap(8, 8)
pixmap.fill()
Loading
Loading
Loading
Loading
@@ -40,13 +40,27 @@ class ChatTextEdit(QtGui.QTextEdit):
self.setFontFamily('monospace')
self._textcolor = self.textColor()
self._bgcolor = QtGui.QColor('#FFFFFF')
self._setcolorcode = { 'F': (self.setTextColor, self._textcolor),
'B': (self.setTextBackgroundColor, self._bgcolor) }
self._setfont = { '*': self.setFontWeight,
'_': self.setFontUnderline,
'/': self.setFontItalic }
self._fontvalues = { False: { '*': QtGui.QFont.Normal, '_': False, '/': False },
True: { '*': QtGui.QFont.Bold, '_': True, '/': True } }
self._setcolorcode = {
'F': (self.setTextColor, self._textcolor),
'B': (self.setTextBackgroundColor, self._bgcolor)
}
self._setfont = {
'*': self.setFontWeight,
'_': self.setFontUnderline,
'/': self.setFontItalic
}
self._fontvalues = {
False: {
'*': QtGui.QFont.Normal,
'_': False,
'/': False
},
True: {
'*': QtGui.QFont.Bold,
'_': True,
'/': True
}
}
self._color = color.Color(config.color_options(), self.debug)
 
def display(self, time, prefix, text, forcecolor=None):
Loading
Loading
@@ -93,17 +107,22 @@ class ChatTextEdit(QtGui.QTextEdit):
# reset attributes and color
if code == 'r':
self._reset_attributes()
self._setcolorcode[action][0](self._setcolorcode[action][1])
self._setcolorcode[action][0](
self._setcolorcode[action][1])
else:
# set attributes + color
while code.startswith(('*', '!', '/', '_', '|', 'r')):
while code.startswith(('*', '!', '/', '_', '|',
'r')):
if code[0] == 'r':
self._reset_attributes()
elif code[0] in self._setfont:
self._set_attribute(code[0], not self._font[code[0]])
self._set_attribute(
code[0],
not self._font[code[0]])
code = code[1:]
if code:
self._setcolorcode[action][0](QtGui.QColor(code))
self._setcolorcode[action][0](
QtGui.QColor(code))
item = item[pos+1:]
if len(item) > 0:
self.insertPlainText(item)
Loading
Loading
Loading
Loading
@@ -21,8 +21,8 @@
# along with QWeeChat. If not, see <http://www.gnu.org/licenses/>.
#
 
import os, ConfigParser
import weechat.color as color
import ConfigParser
import os
 
CONFIG_DIR = '%s/.qweechat' % os.getenv('HOME')
CONFIG_FILENAME = '%s/qweechat.conf' % CONFIG_DIR
Loading
Loading
@@ -40,51 +40,52 @@ CONFIG_DEFAULT_OPTIONS = (('relay.server', ''),
('look.statusbar', 'off'))
 
# Default colors for WeeChat color options (option name, #rgb value)
CONFIG_DEFAULT_COLOR_OPTIONS = (('separator', '#000066'), # 0
('chat', '#000000'), # 1
('chat_time', '#999999'), # 2
('chat_time_delimiters', '#000000'), # 3
('chat_prefix_error', '#FF6633'), # 4
('chat_prefix_network', '#990099'), # 5
('chat_prefix_action', '#000000'), # 6
('chat_prefix_join', '#00CC00'), # 7
('chat_prefix_quit', '#CC0000'), # 8
('chat_prefix_more', '#CC00FF'), # 9
('chat_prefix_suffix', '#330099'), # 10
('chat_buffer', '#000000'), # 11
('chat_server', '#000000'), # 12
('chat_channel', '#000000'), # 13
('chat_nick', '#000000'), # 14
('chat_nick_self', '*#000000'), # 15
('chat_nick_other', '#000000'), # 16
('', '#000000'), # 17 (nick1 -- obsolete)
('', '#000000'), # 18 (nick2 -- obsolete)
('', '#000000'), # 19 (nick3 -- obsolete)
('', '#000000'), # 20 (nick4 -- obsolete)
('', '#000000'), # 21 (nick5 -- obsolete)
('', '#000000'), # 22 (nick6 -- obsolete)
('', '#000000'), # 23 (nick7 -- obsolete)
('', '#000000'), # 24 (nick8 -- obsolete)
('', '#000000'), # 25 (nick9 -- obsolete)
('', '#000000'), # 26 (nick10 -- obsolete)
('chat_host', '#666666'), # 27
('chat_delimiters', '#9999FF'), # 28
('chat_highlight', '#3399CC'), # 29
('chat_read_marker', '#000000'), # 30
('chat_text_found', '#000000'), # 31
('chat_value', '#000000'), # 32
('chat_prefix_buffer', '#000000'), # 33
('chat_tags', '#000000'), # 34
('chat_inactive_window', '#000000'), # 35
('chat_inactive_buffer', '#000000'), # 36
('chat_prefix_buffer_inactive_buffer', '#000000'), # 37
('chat_nick_offline', '#000000'), # 38
('chat_nick_offline_highlight', '#000000'), # 39
('chat_nick_prefix', '#000000'), # 40
('chat_nick_suffix', '#000000'), # 41
('emphasis', '#000000'), # 42
('chat_day_change', '#000000'), #43
)
CONFIG_DEFAULT_COLOR_OPTIONS = (
('separator', '#000066'), # 0
('chat', '#000000'), # 1
('chat_time', '#999999'), # 2
('chat_time_delimiters', '#000000'), # 3
('chat_prefix_error', '#FF6633'), # 4
('chat_prefix_network', '#990099'), # 5
('chat_prefix_action', '#000000'), # 6
('chat_prefix_join', '#00CC00'), # 7
('chat_prefix_quit', '#CC0000'), # 8
('chat_prefix_more', '#CC00FF'), # 9
('chat_prefix_suffix', '#330099'), # 10
('chat_buffer', '#000000'), # 11
('chat_server', '#000000'), # 12
('chat_channel', '#000000'), # 13
('chat_nick', '#000000'), # 14
('chat_nick_self', '*#000000'), # 15
('chat_nick_other', '#000000'), # 16
('', '#000000'), # 17 (nick1 -- obsolete)
('', '#000000'), # 18 (nick2 -- obsolete)
('', '#000000'), # 19 (nick3 -- obsolete)
('', '#000000'), # 20 (nick4 -- obsolete)
('', '#000000'), # 21 (nick5 -- obsolete)
('', '#000000'), # 22 (nick6 -- obsolete)
('', '#000000'), # 23 (nick7 -- obsolete)
('', '#000000'), # 24 (nick8 -- obsolete)
('', '#000000'), # 25 (nick9 -- obsolete)
('', '#000000'), # 26 (nick10 -- obsolete)
('chat_host', '#666666'), # 27
('chat_delimiters', '#9999FF'), # 28
('chat_highlight', '#3399CC'), # 29
('chat_read_marker', '#000000'), # 30
('chat_text_found', '#000000'), # 31
('chat_value', '#000000'), # 32
('chat_prefix_buffer', '#000000'), # 33
('chat_tags', '#000000'), # 34
('chat_inactive_window', '#000000'), # 35
('chat_inactive_buffer', '#000000'), # 36
('chat_prefix_buffer_inactive_buffer', '#000000'), # 37
('chat_nick_offline', '#000000'), # 38
('chat_nick_offline_highlight', '#000000'), # 39
('chat_nick_prefix', '#000000'), # 40
('chat_nick_suffix', '#000000'), # 41
('emphasis', '#000000'), # 42
('chat_day_change', '#000000'), # 43
)
config_color_options = []
 
 
Loading
Loading
@@ -118,6 +119,7 @@ def read():
 
return config
 
def write(config):
"""Write config file."""
if not os.path.exists(CONFIG_DIR):
Loading
Loading
@@ -125,6 +127,7 @@ def write(config):
with open(CONFIG_FILENAME, 'wb') as cfg:
config.write(cfg)
 
def color_options():
global config_color_options
return config_color_options
Loading
Loading
@@ -57,7 +57,8 @@ class ConnectionDialog(QtGui.QDialog):
self.fields['ssl'] = ssl
 
self.dialog_buttons = QtGui.QDialogButtonBox()
self.dialog_buttons.setStandardButtons(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel)
self.dialog_buttons.setStandardButtons(
QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel)
self.dialog_buttons.rejected.connect(self.close)
 
grid.addWidget(self.dialog_buttons, 4, 0, 1, 2)
Loading
Loading
File moved
File moved
File moved
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment