Skip to content

Commit

Permalink
Merge pull request #42 from maniotrix/gui
Browse files Browse the repository at this point in the history
importing/exporting channels
  • Loading branch information
cristobalmedinalopez committed Jun 25, 2015
2 parents 706546f + 9ab5e00 commit 014d1ed
Show file tree
Hide file tree
Showing 16 changed files with 229 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,3 +1,3 @@
*.pyc
*~
*.log
*.log*
Empty file added data/channels/sample_data
Empty file.
16 changes: 16 additions & 0 deletions data/channels/sample_data.json
@@ -0,0 +1,16 @@
{
"monitor": {
"splitter_addr": "localhost",
"splitter_port": "4552",
"thumbnail_url": "http:/xyz.com",
"name": "monitor",
"description": "monitor"
},
"monitor1": {
"splitter_addr": "localhost",
"splitter_port": "4552",
"thumbnail_url": "http:/xyz.com",
"name": "monitor",
"description": "monitor"
}
}
3 changes: 1 addition & 2 deletions data/glade/mainwindow.glade
Expand Up @@ -34,12 +34,11 @@
<object class="GtkPaned" id="MainPane">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_BUTTON_PRESS_MASK | GDK_STRUCTURE_MASK</property>
<child>
<object class="GtkBox" id="MainBox">
<property name="name">s</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="events">GDK_BUTTON_PRESS_MASK | GDK_STRUCTURE_MASK</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkMenuBar" id="Menu">
Expand Down
13 changes: 13 additions & 0 deletions src/common/file_util.py
Expand Up @@ -24,4 +24,17 @@ def get_user_interface(dire, fName):
def find_file(dire, fName):
path = os.path.join(os.path.dirname(dire), fName)
return path

@exc_handler
def file_size(path):
f = open(path,"r")
f.seek(0, os.SEEK_END)
size = f.tell()
return size

@exc_handler
def file_del(path):
f = open(path,"w")
del(f)


10 changes: 10 additions & 0 deletions src/common/json_exporter.py
@@ -0,0 +1,10 @@
import json
from common.decorators import exc_handler

class JSON_Exporter():

@exc_handler
def to_JSON(self,path,channels,encoder):
json_file = open(path,"w")
json.dump(channels , json_file, indent = 4 , cls = encoder)
json_file.close()
11 changes: 11 additions & 0 deletions src/common/json_importer.py
@@ -0,0 +1,11 @@
import json
from common.decorators import exc_handler

class JSON_Importer():

@exc_handler
def from_JSON(self,path):
json_file = open(path,"r")
data = json.load(json_file)
json_file.close()
return data
8 changes: 5 additions & 3 deletions src/controller/main_window_controller.py
Expand Up @@ -3,8 +3,7 @@
from common.decorators import exc_handler
from adapter.buffering_adapter import Buffering_Adapter
from adapter.speed_adapter import Speed_Adapter
from gi.repository import GObject
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GdkX11
import common.file_util as file_util
from model.peer_thread import Peer_Thread
Expand Down Expand Up @@ -47,7 +46,7 @@ def start_peer(self):
self.app_window.buffer_status_bar.show()
thread1 = Peer_Thread(1, "Peer Thread")
thread1.start()
print 'thread started'
print('thread started')


@exc_handler
Expand Down Expand Up @@ -154,8 +153,11 @@ def toggle_status_box(self,widget,data=None):

@exc_handler
def _realized(self,widget,data=None):
cursor = Gdk.Cursor.new(Gdk.CursorType.ARROW)
self.vlc_player_instance = self.app_model.get_vlc_player_instance()
self.win_id = widget.get_window().get_xid()
self.toggle_player_type(self.win_id)
widget.get_window().set_cursor(cursor)
print('surface_cursor = ' + str(widget.get_window().get_cursor().__class__ ))
self.app_window.player_surface.connect("configure_event",
self.redraw_surface)
25 changes: 25 additions & 0 deletions src/model/category.py
@@ -0,0 +1,25 @@
#from collections import defaultdict
class Category():

def __init__(self,name):
self.name = name
self.channels = {}

def get_channels(self):
return self.channels

def set_name(self,name):
self.name = name

def get_name(self):
return self.name

def add(self,key,channel):
self.channels[key] = channel

def remove(self,key):
del(self.channels[key])

def get_channel(self,key):
return self.channels[key]

38 changes: 38 additions & 0 deletions src/model/channel.py
@@ -0,0 +1,38 @@
class Channel():

def __init__(self,data):
self.name = data["name"]
self.description = data["description"]
self.thumbnail_url = data["thumbnail_url"]
self.splitter_addr = data["splitter_addr"]
self.splitter_port = data["splitter_port"]

def set_name(self,name):
self.name = name

def get_name(self):
return self.name

def set_thumbnail_url(self,url):
self.thumbnail_url = url

def get_thumbnail_url(self):
return self.thumbnail_url

def set_description(self,description):
self.description = description

def get_description(self):
return self.description

def set_splitter_addr(self,addr):
self.splitter_addr = addr

def get_splitter_addr(self):
return self.splitter_addr

def set_splitter_port(self,port):
self.splitter_port = port

def get_splitter_port(self):
return self.splitter_port
10 changes: 10 additions & 0 deletions src/model/channel_encoder.py
@@ -0,0 +1,10 @@
import json
from channel import Channel

class Channel_Encoder(json.JSONEncoder):

def default(self,obj):
if isinstance(obj, Channel):
return obj.__dict__
else:
return json.JSONEncoder.default(self, obj)
4 changes: 2 additions & 2 deletions src/model/peer_thread.py
Expand Up @@ -21,7 +21,7 @@ def __init__(self, threadID, name):

@exc_handler
def run(self):
print "Starting " + self.name
print("Starting " + self.name)
self.peer_active = True
self.x=peer.Peer()
print "Exiting " + self.name
print("Exiting " + self.name)
2 changes: 1 addition & 1 deletion src/model/vlc_player.py
Expand Up @@ -22,7 +22,7 @@ def __init__(self):
# Creates Vlc Instance
self.vlcInstance = vlc.Instance("--no-xlib")
self.player = self.vlcInstance.media_player_new()
self.em = self.player.event_manager()
self.player.video_set_mouse_input(False)

def _get_media(self,Source):
MEDIA_SOURCE = Source
Expand Down
4 changes: 2 additions & 2 deletions src/p2psp_application_gui.py
Expand Up @@ -18,7 +18,7 @@ def main_app():
App.show()
Gtk.main()
App.quit()
print "Exiting Gtk-Main Thread"
print("Exiting Gtk-Main Thread")

if __name__ == "__main__":
main_app()
94 changes: 94 additions & 0 deletions src/test_import_export_channels.py
@@ -0,0 +1,94 @@
#script tested with python2.7
from model.category import Category
from model.channel import Channel
from common.json_importer import JSON_Importer
from common.json_exporter import JSON_Exporter
from model.channel_encoder import Channel_Encoder
from core._print_ import _print_
import common.file_util as file_util

import unittest
import json

def get_data():

data = {"monitor":
{ "name" : "monitor"
,"thumbnail_url" : "http:/xyz.com"
,"description" : "monitor"
,"splitter_addr" : "localhost"
,"splitter_port" : "4552" }
}
return data

path = file_util.find_file(__file__,
"../data/channels/sample_data.json")

#unittests are sorted according to their name and then run.
#edit tearDown method to retain exported channels file and vice-versa.
class Import_Export_Test(unittest.TestCase):

exported_data = None
imported_data = None

def tearDown(self):
if Import_Export_Test.imported_data is None:
pass
else:
file_util.file_del(path)
#pass

def test_01_delete_channels_data(self):

print("\n")
_print_("deleting existing sample_data...")
file_util.file_del(path)
size = file_util.file_size(path)
self.assertEqual(0,size)

print("----------------------------------------------------------------------")

def test_02_export_channels(self):

Import_Export_Test.exported_data = get_data()

monitor_channel = Channel(Import_Export_Test.exported_data["monitor"])

test_category = Category("test")
test_category.add("monitor",monitor_channel)

Import_Export_Test.exported_data["monitor1"] = get_data()["monitor"]
test_category.add("monitor1",monitor_channel)

exporter = JSON_Exporter()
exporter.to_JSON(path,test_category.get_channels(),Channel_Encoder)
print("\n")
_print_("exporting channels to json file = "
+ path
+ "\n"
+json.dumps(Import_Export_Test.exported_data
,indent = 4 , cls = Channel_Encoder))

size = file_util.file_size(path)
self.assertNotEqual(0,size)

print("----------------------------------------------------------------------")

def test_03_import_channels(self):
importer = JSON_Importer()
Import_Export_Test.imported_data = importer.from_JSON(path)
print("\n")
_print_("importing channels from json file = "
+ path
+ "\n"
+json.dumps(Import_Export_Test.imported_data,indent = 4))

self.assertEqual(Import_Export_Test.exported_data
,Import_Export_Test.imported_data)

print("----------------------------------------------------------------------")


if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(Import_Export_Test)
unittest.TextTestRunner(verbosity=2).run(suite)
1 change: 0 additions & 1 deletion src/view/main_window.py
@@ -1,7 +1,6 @@
import sys
import traceback
try:
from gi.repository import GObject
from gi.repository import Gtk
from gi.repository import Gdk
import common.file_util as file_util
Expand Down

0 comments on commit 014d1ed

Please sign in to comment.