Skip to content

Commit

Permalink
More mature connection handling. Main Dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
jsarasin committed May 4, 2016
1 parent c780faf commit 732b4e5
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 18 deletions.
34 changes: 31 additions & 3 deletions catchat.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,46 @@
import cc_chatdialog
import cc_http
import cc_configurator
from cc_configurator import get_cc_config

from cc_main_window import cc_main_window

from cc_connector import cc_connector_http

import urllib
import os

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Pango, Gdk, GObject


builder = None
config = None
connections = []

def connect_services():
global config
global connections

config = get_cc_config()


for item in range(0, len(config['services'])):
name = config['services'][item]['display-name']
type = config['services'][item]['server-type']
username = config['services'][item]['username']
password = config['services'][item]['password']
print "Connecting to '" + name + "'"

if type == "url":
url = config['services'][item]['server-url']
new_server = cc_connector_http.cc_connector_http(url, username, password)
connections.append(new_server)

new_server.connect()


def start_program():
builder = Gtk.Builder()
connect_services()

main_window = cc_main_window(builder)

Expand All @@ -22,3 +49,4 @@ def start_program():

if __name__ == "__main__":
start_program()

2 changes: 1 addition & 1 deletion cc_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{
'display-name' :'Main Server',
'server-type' :'url',
'server-url' :'http://azenguard.com/CatChat/',
'server-url' :'http://107.150.59.253/',
'username' :'james',
'password' :'computer'
}
Expand Down
12 changes: 12 additions & 0 deletions cc_connector/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class ConnectionStatus(object):
DISCONNECTED = 0
CONNECTED = 1
ERROR = 2


class cc_connector_base(object):
my_id = None
connection_status = ConnectionStatus.DISCONNECTED
username = None
password = None

30 changes: 30 additions & 0 deletions cc_connector/cc_connector_http.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import requests
import json
import datetime
import hashlib

from cc_connector import cc_connector_base, ConnectionStatus


class cc_connector_http(cc_connector_base):
server_url = None
http_session = None
handling_request_callback = False


def __init__(self, server_url, username, password):
self.server_url = server_url
self.username = username
self.password = password
self.connection_status = ConnectionStatus.DISCONNECTED

def connect(self):
if self.connection_status != ConnectionStatus.DISCONNECTED:
raise(ValueError("Already connected to " + self.server_url))

self.http_session = requests.Session()

datas = {'username':self.username, 'password':self.password}

r = self.http_session.post(self.server_url + 'login.php', data = datas)

2 changes: 1 addition & 1 deletion cc_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class cc_http(object):
server_url = 'http://azenguard.com/CatChat/'
server_url = 'http://107.150.59.253/'
username='james'
password='computer'
userid=0
Expand Down
7 changes: 6 additions & 1 deletion cc_main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self, builder):
self.window.connect("delete-event", Gtk.main_quit)

self.window.show_all()
self.UpdateGUI()

# Load other dialogs
self.configure_services_dialog = cc_configure_services(builder)
Expand Down Expand Up @@ -53,9 +54,13 @@ def onDisconnectServices(self, action):
self.toggle_connect_disconnect_action_items(False)

def onToggleShowDebugArea(self, menu_item):
self.builder.get_object('debug_box').set_visible(menu_item.get_active())
self.UpdateGUI()

def onConfigureServices(self, action):
self.configure_services_dialog.open_window()

def UpdateGUI(self):
show_debug_bar = self.builder.get_object('menu_toggle_show_debug_area').get_active()
self.builder.get_object('debug_box').set_visible(show_debug_bar)


32 changes: 20 additions & 12 deletions glade/main_window.glade
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,20 @@
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
</object>
<object class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
</object>
<object class="GtkImage" id="image3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
<property name="stock">gtk-convert</property>
</object>
<object class="GtkImage" id="image4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
<property name="icon_name">utilities-terminal</property>
</object>
<object class="GtkImage" id="image5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
<property name="stock">gtk-quit</property>
</object>
<object class="GtkWindow" id="main_window">
<property name="width_request">400</property>
Expand Down Expand Up @@ -182,13 +177,12 @@
</child>
<child>
<object class="GtkImageMenuItem" id="menu_disconnect">
<property name="label" translatable="yes">Disconnect</property>
<property name="label">gtk-disconnect</property>
<property name="use_action_appearance">True</property>
<property name="related_action">action_disconnect</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="image">image2</property>
<property name="use_stock">False</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
Expand Down Expand Up @@ -255,6 +249,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Show Debug Toolbar</property>
<property name="active">True</property>
<signal name="toggled" handler="onToggleShowDebugArea" swapped="no"/>
</object>
</child>
Expand Down Expand Up @@ -320,6 +315,7 @@
<object class="GtkComboBoxText" id="comboboxtext1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="active">0</property>
<items>
<item translatable="yes">Online</item>
<item translatable="yes">Invisible</item>
Expand All @@ -341,8 +337,20 @@
</child>
<child>
<object class="GtkBox" id="debug_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="icon_name">utilities-terminal</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
Expand Down
Binary file added images/terminal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 732b4e5

Please sign in to comment.