[pessulus/gnome-3-5: 2/2] Very early prototypes
- From: RÅdolfs Mazurs <rudolfsm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pessulus/gnome-3-5: 2/2] Very early prototypes
- Date: Tue, 21 Aug 2012 20:34:25 +0000 (UTC)
commit b7cb57083095ea295c8f8ea4728caba97e37f410
Author: RÅdolfs Mazurs <rudolfsm src gnome org>
Date: Tue Aug 21 23:34:04 2012 +0300
Very early prototypes
src/code.py | 62 +++++++++++++++
src/neue.glade | 226 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/profiles | 2 +
src/vin.vala | 120 ++++++++++++++++++++++++++++++
4 files changed, 410 insertions(+), 0 deletions(-)
---
diff --git a/src/code.py b/src/code.py
new file mode 100755
index 0000000..90b8b88
--- /dev/null
+++ b/src/code.py
@@ -0,0 +1,62 @@
+#!/usr/bin/python
+from gi.repository import Gtk
+import string
+
+def add_profile(button_add, store, tree):
+ treeiter = store.append(["New profile"])
+
+ # Somethig is not right. FIXME later
+ #path = Gtk.TreePath(treeiter)
+ #tree.set_cursor_on_cell (path, None, None, True)
+ #get_string_from_iter(treeiter)
+ flush_model();
+
+def remove_active(button_remove, tree):
+ select = tree.get_selection()
+ model, treeiter = select.get_selected()
+ if treeiter != None:
+ model.remove(treeiter)
+ flush_model();
+
+def changed_active(cell, path, new_text, user_data):
+ select = tree.get_selection()
+ model, treeiter = select.get_selected()
+ model.set(treeiter, 0, new_text)
+ flush_model();
+ #When changing profile name, the user_profile should also be changed
+
+def flush_model():
+ f = open('/home/rudolfs/types', 'w')
+ for row in store:
+ f.write(row[0] + "\n")
+
+# Initialize GUI
+builder = Gtk.Builder()
+builder.add_from_file("neue.glade")
+
+# Get UI objects
+win = builder.get_object("window")
+button_add = builder.get_object("button_add")
+button_remove = builder.get_object("button_remove")
+cellrenderer = builder.get_object("cellrenderertext1")
+cellrenderer.set_property('editable', True)
+
+# Build list
+tree = builder.get_object("treeview")
+store = builder.get_object("tree-model")
+
+try:
+ f = open('/home/rudolfs/types', 'r')
+ for line in f:
+ store.append([string.strip(line)])
+except:
+ pass
+
+win.connect("delete-event", Gtk.main_quit)
+button_add.connect("clicked", add_profile, store, tree)
+button_remove.connect("clicked", remove_active, tree)
+cellrenderer.connect("edited", changed_active, store)
+
+
+win.show_all()
+Gtk.main()
diff --git a/src/neue.glade b/src/neue.glade
new file mode 100644
index 0000000..e5de0dc
--- /dev/null
+++ b/src/neue.glade
@@ -0,0 +1,226 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <object class="GtkListStore" id="tree-model">
+ <columns>
+ <!-- column-name profiles -->
+ <column type="gchararray"/>
+ </columns>
+ </object>
+ <object class="GtkWindow" id="window">
+ <property name="height_request">300</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkBox" id="box1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkBox" id="box2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_left">5</property>
+ <property name="margin_right">5</property>
+ <property name="margin_top">5</property>
+ <property name="margin_bottom">5</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Here you can create, rename
+and delete existing profiles</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow" id="scrolledwindow1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="shadow_type">in</property>
+ <child>
+ <object class="GtkTreeView" id="treeview">
+ <property name="width_request">100</property>
+ <property name="height_request">100</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="model">tree-model</property>
+ <child internal-child="selection">
+ <object class="GtkTreeSelection" id="treeview-selection1"/>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn" id="treeviewcolumn1">
+ <property name="sizing">fixed</property>
+ <property name="title" translatable="yes">Profiles</property>
+ <child>
+ <object class="GtkCellRendererText" id="cellrenderertext1"/>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="box3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_top">5</property>
+ <property name="margin_bottom">5</property>
+ <child>
+ <object class="GtkButton" id="button_add">
+ <property name="label" translatable="yes">Add profile</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_action_appearance">False</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button_remove">
+ <property name="label" translatable="yes">Remove profile</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="margin_left">5</property>
+ <property name="use_action_appearance">False</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkGrid" id="grid1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_top">5</property>
+ <property name="row_spacing">5</property>
+ <property name="column_spacing">5</property>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Is regulated</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Value</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="is_cdrom">
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="on_is_cdrom_toggled" swapped="no"/>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="check_cdrom">
+ <property name="label" translatable="yes">cdrom</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="on_check_cdrom_toggled" object="is_cdrom" swapped="no"/>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button1">
+ <property name="label" translatable="yes">button</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_action_appearance">False</property>
+ <signal name="clicked" handler="on_button1_clicked" swapped="no"/>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/src/profiles b/src/profiles
new file mode 100644
index 0000000..8dc08d4
--- /dev/null
+++ b/src/profiles
@@ -0,0 +1,2 @@
+[groups]
+cdrom=no
diff --git a/src/vin.vala b/src/vin.vala
new file mode 100644
index 0000000..a89c3a9
--- /dev/null
+++ b/src/vin.vala
@@ -0,0 +1,120 @@
+using Gtk;
+
+/*External functions*/
+
+class settings {
+ public char * group_name;
+ public bool managed_cdrom;
+ public bool belongs_cdrom;
+
+ public settings()
+ {
+ managed_cdrom = false;
+ }
+}
+
+void read_config_to_struct (settings sets)
+{
+ var file = File.new_for_path ("profiles");
+ string active_group;
+ string active_type;
+ string [] pair;
+
+ if (!file.query_exists ()) {
+ stderr.printf ("File '%s' doesn't exist.\n", file.get_path ());
+ return;
+ }
+ try {
+ var dis = new DataInputStream (file.read ());
+ string line;
+ while ((line = dis.read_line (null)) != null) {
+ if (line[0] == '[') {//if group item
+ if (line == "[groups]"){
+ active_type = "group";
+ } else if (line == "[gsettings]"){
+ active_type = "gsettings";
+ } else {
+ stderr.printf("Unhandled type\n");
+ }
+ stdout.printf("Control %s\n", line);
+ continue;
+ } else {
+ pair = line.split("=",2);
+ stdout.printf ("Key â%sâ and value â%sâ\n", pair[0], pair[1]);
+ switch (pair[0]){
+ case "group name":
+ active_group = pair[1];
+ active_type = null;
+ break;
+ case "cdrom":
+ sets.managed_cdrom = true;
+ if (pair[1] == "yes")
+ sets.belongs_cdrom = true;
+ else
+ sets.belongs_cdrom = false;
+ stdout.printf("Was here\n");
+ break;
+ }
+ }
+
+ }
+ } catch (Error e) {
+ error ("%s", e.message);
+ }
+ return;
+}
+
+
+public void on_check_cdrom_toggled (CheckButton main, CheckButton secondary ) {
+
+ stdout.printf("Status of secondary is %s\n", (secondary.get_active()?"actice":"inactive"));
+
+ try{
+
+
+ Process.spawn_command_line_async ("touch success");
+ } catch (Error e) {
+ error ("%s", e.message);
+ }
+}
+
+public void on_is_cdrom_toggled (CheckButton baba) {
+// stdout.printf ("Thanks!\n");
+ return;
+}
+
+public void on_button1_clicked (Button dada){
+ dada.label = "hm";
+}
+
+int main (string[] args) {
+ Gtk.init (ref args);
+
+ try {
+ // If the UI contains custom widgets, their types must've been instantiated once
+ // Type type = typeof(Foo.BarEntry);
+ // assert(type != 0);
+ var builder = new Builder ();
+ builder.add_from_file ("neue.glade");
+ builder.connect_signals (null);
+
+ var sets = new settings ();
+
+ read_config_to_struct (sets);
+
+ var check = builder.get_object ("is_cdrom") as CheckButton;
+ check.active = sets.managed_cdrom;
+ var check1 = builder.get_object ("check_cdrom") as CheckButton;
+ check1.active = sets.belongs_cdrom;
+
+
+ var window = builder.get_object ("window") as Window;
+ window.show_all ();
+ Gtk.main ();
+ } catch (Error e) {
+ stderr.printf ("Could not load UI: %s\n", e.message);
+ return 1;
+ }
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]