Browse Source

implemented current texture to be displayed in the "set texture" form

Natenom/support-murmur-13-1446181288462
Michael Ziegler 16 years ago
parent
commit
787e0ff1d3
  1. 28
      pyweb/mumble/models.py
  2. 7
      pyweb/mumble/urls.py
  3. 18
      pyweb/mumble/views.py
  4. 6
      template/mumble/mumble.htm

28
pyweb/mumble/models.py

@ -14,9 +14,9 @@
* GNU General Public License for more details. * GNU General Public License for more details.
""" """
from PIL import Image
from struct import pack
from zlib import compress
from PIL import Image
from struct import pack, unpack
from zlib import compress, decompress
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import models from django.db import models
@ -223,6 +223,28 @@ class MumbleUser( models.Model ):
bus.setACL( *acl.pack() ); bus.setACL( *acl.pack() );
return value; return value;
def getTexture( self ):
murmur = self.server.getDbusObject();
texture = murmur.getTexture( dbus.Int32( self.mumbleid ) );
if len(texture) == 0:
raise ValueError( "No Texture has been set." );
# this returns a list of bytes.
# first 4 bytes: Length of uncompressed string, rest: compressed data
orig_len = ( texture[0] << 24 ) | ( texture[1] << 16 ) | ( texture[2] << 8 ) | ( texture[3] );
# convert rest to string and run decompress
bytestr = "";
for byte in texture[4:]:
bytestr += pack( "B", int(byte) );
decompressed = decompress( bytestr );
# iterate over 4 byte chunks of the string
imgdata = "";
for idx in range( 0, orig_len, 4 ):
# read 4 bytes = BGRA and convert to RGBA
bgra = unpack( "4B", decompressed[idx:idx+4] );
imgdata += pack( "4B", bgra[2], bgra[1], bgra[0], bgra[3] );
# return an 600x60 RGBA image object created from the data
return Image.fromstring( "RGBA", ( 600, 60 ), imgdata );
def setTexture( self, infile ): def setTexture( self, infile ):
# open image, convert to RGBA, and resize to 600x60 # open image, convert to RGBA, and resize to 600x60
img = Image.open( infile ).convert( "RGBA" ).transform( ( 600, 60 ), Image.EXTENT, ( 0, 0, 600, 60 ) ); img = Image.open( infile ).convert( "RGBA" ).transform( ( 600, 60 ), Image.EXTENT, ( 0, 0, 600, 60 ) );

7
pyweb/mumble/urls.py

@ -17,7 +17,8 @@
from django.conf.urls.defaults import * from django.conf.urls.defaults import *
urlpatterns = patterns( urlpatterns = patterns(
'',
( r'(?P<server>\d+)', 'mumble.views.show' ),
( r'$', 'mumble.views.mumbles' ),
'mumble.views',
( r'(?P<server>\d+)/texture.jpg', 'showTexture' ),
( r'(?P<server>\d+)', 'show' ),
( r'$', 'mumbles' ),
) )

18
pyweb/mumble/views.py

@ -14,9 +14,11 @@
* GNU General Public License for more details. * GNU General Public License for more details.
""" """
from StringIO import StringIO
from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404 from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404
from django.template import RequestContext from django.template import RequestContext
from django.http import HttpResponseRedirect
from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
@ -124,6 +126,20 @@ def show( request, server ):
); );
def showTexture( request, server ):
if request.user.is_authenticated():
srv = Mumble.objects.get( id=int(server) );
user = MumbleUser.objects.get( server=srv, owner=request.user );
try:
img = user.getTexture();
except ValueError:
raise Http404();
else:
buffer = StringIO();
img.save( buffer, "JPEG" );
return HttpResponse( buffer.getvalue(), "image/jpeg" );
raise Http404();
def showContent( server, user = None ): def showContent( server, user = None ):
"Renders and returns the channel list for the given Server ID." "Renders and returns the channel list for the given Server ID."
from django.template import Context, loader from django.template import Context, loader

6
template/mumble/mumble.htm

@ -40,7 +40,11 @@
{% if Registered %} {% if Registered %}
<div id="mumble_texture"> <div id="mumble_texture">
<h2>User Texture</h2> <h2>User Texture</h2>
You can upload an image that you would like to use as your user texture here.<br />
<p>
You can upload an image that you would like to use as your user texture here.<br />
Your current texture is:<br />
<img src="/mumble/{{DBaseObject.id}}/texture.jpg" alt="user texture" /><br />
</p>
<form action="" method="post" enctype="multipart/form-data"> <form action="" method="post" enctype="multipart/form-data">
<table> <table>
{{ TextureForm }} {{ TextureForm }}

Loading…
Cancel
Save