Esempio n. 1
0
    def __init__(self, tree_view):
        CellRendererIcon.__init__(self, tree_view)

        self.props.width = style.GRID_CELL_SIZE
        self.props.height = style.GRID_CELL_SIZE
        self.props.size = style.SMALL_ICON_SIZE
        self.props.icon_name = 'emblem-favorite'
        self.props.mode = Gtk.CellRendererMode.ACTIVATABLE
        client = GConf.Client.get_default()
        prelit_color = XoColor(client.get_string('/desktop/sugar/user/color'))
        self.props.prelit_stroke_color = prelit_color.get_stroke_color()
        self.props.prelit_fill_color = prelit_color.get_fill_color()
Esempio n. 2
0
    def __init__(self, tree_view):
        CellRendererIcon.__init__(self, tree_view)

        self.props.width = style.GRID_CELL_SIZE
        self.props.height = style.GRID_CELL_SIZE
        self.props.size = style.SMALL_ICON_SIZE
        self.props.icon_name = 'emblem-favorite'
        self.props.mode = Gtk.CellRendererMode.ACTIVATABLE
        client = GConf.Client.get_default()
        prelit_color = XoColor(client.get_string('/desktop/sugar/user/color'))
        self.props.prelit_stroke_color = prelit_color.get_stroke_color()
        self.props.prelit_fill_color = prelit_color.get_fill_color()
Esempio n. 3
0
    def __init__(self, tree_view):
        CellRendererIcon.__init__(self, tree_view)

        self.props.width = style.GRID_CELL_SIZE
        self.props.height = style.GRID_CELL_SIZE
        self.props.size = style.STANDARD_ICON_SIZE
        self.props.stroke_color = style.COLOR_BUTTON_GREY.get_svg()
        self.props.fill_color = style.COLOR_TRANSPARENT.get_svg()
        self.props.mode = Gtk.CellRendererMode.ACTIVATABLE

        client = GConf.Client.get_default()
        prelit_color = XoColor(client.get_string("/desktop/sugar/user/color"))
        self.props.prelit_stroke_color = prelit_color.get_stroke_color()
        self.props.prelit_fill_color = prelit_color.get_fill_color()

        self._tree_view = tree_view
Esempio n. 4
0
    def __init__(self, tree_view):
        CellRendererIcon.__init__(self, tree_view)

        self.props.width = style.GRID_CELL_SIZE
        self.props.height = style.GRID_CELL_SIZE
        self.props.size = style.STANDARD_ICON_SIZE
        self.props.stroke_color = style.COLOR_BUTTON_GREY.get_svg()
        self.props.fill_color = style.COLOR_TRANSPARENT.get_svg()
        self.props.mode = Gtk.CellRendererMode.ACTIVATABLE

        client = GConf.Client.get_default()
        prelit_color = XoColor(client.get_string('/desktop/sugar/user/color'))
        self.props.prelit_stroke_color = prelit_color.get_stroke_color()
        self.props.prelit_fill_color = prelit_color.get_fill_color()

        self._tree_view = tree_view
class ProgressToolButton(ToolButton):
    '''
    This button is just like a normal tool button, except that the
    icon can dynamically fill based on a progress number.
    '''

    __gtype_name__ = 'SugarProgressToolButton'

    def __init__(self, **kwargs):
        self._xo_color = XoColor('insensitive')
        self._icon_name = None
        self._direction = 'vertical'
        self._progress = 0.0

        ToolButton.__init__(self, **kwargs)
        # GObject should do this, but something down the ToolButton chain of
        # parents is not passing the kwargs to GObject
        if 'xo_color' in kwargs:
            self.props.xo_color = kwargs['xo_color']
        if 'icon_name' in kwargs:
            self.props.icon_name = kwargs['icon_name']
        if 'direction' in kwargs:
            self.props.direction = kwargs['direction']
        self._updated()

    @GObject.property
    def xo_color(self):
        '''
        This property defines the stroke and fill of the icon, and is
        the type :class:`sugar3.graphics.xocolor.XoColor`
        '''
        return self._xo_color

    @xo_color.setter
    def xo_color(self, new):
        self._xo_color = new
        self._updated()

    @GObject.property
    def icon_name(self):
        '''
        Icon name (same as with a :class:`sugar3.graphics.icon.Icon`), as the
        type :class:`str`
        '''
        return self._icon_name

    @icon_name.setter
    def icon_name(self, new):
        self._icon_name = new
        self._updated()

    @GObject.property
    def direction(self):
        '''
        Direction for the icon to fill as it progresses, filling either,
        * :class:`Gtk.Orientation.VERTICAL` - bottom to top
        * :class:`Gtk.Orientation.HORIZONTAL` - user's text direction
        '''
        if self._direction == 'vertical':
            return Gtk.Orientation.VERTICAL
        else:
            return Gtk.Orientation.HORIZONTAL

    @direction.setter
    def direction(self, new):
        if new == Gtk.Orientation.VERTICAL:
            self._direction = 'vertical'
        else:
            self._direction = 'horizontal'
        self._updated()

    def _updated(self):
        self._icon = ProgressIcon(
            self._icon_name,
            style.STANDARD_ICON_SIZE,
            self._xo_color.get_stroke_color(),
            self._xo_color.get_fill_color(),
            self._direction)
        self._icon.update(self._progress)
        self.set_icon_widget(self._icon)
        self._icon.show()

    def update(self, progress):
        '''
        Redraw the icon with a different percentage filled in

        Args:
            progress (float): a value from 0.0 to 1.0, where 1.0 fully
                fills the icon and 0.0 results in only the stroke being
                visible
        '''
        self._progress = progress
        self._icon.update(progress)
        self.queue_draw()
Esempio n. 6
0
    def __init__(self, activity):
        GObject.GObject.__init__(self)

        self.activity = activity

        self.instrumentDB = InstrumentDB.getRef()
        self.noteDB = NoteDB.NoteDB()

        #-- initial settings ----------------------------------
        self.tempo = Config.PLAYER_TEMPO
        self.beatDuration = 60.0 / self.tempo
        self.ticksPerSecond = Config.TICKS_PER_BEAT * self.tempo / 60.0
        self.volume = 0.5

        self.csnd = new_csound_client()
        for i in range(0, 9):
            self.csnd.setTrackVolume(100, i)
        # csnd expects a range 0-100 for now
        self.csnd.setMasterVolume(self.volume * 100)
        self.csnd.setTempo(self.tempo)

        self.muted = False

        #-- Drawing -------------------------------------------
        def darken(hex):
            hexToDec = {"0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6,
                        "7": 7, "8": 8, "9": 9, "A": 10, "B": 11, "C": 12,
                        "D": 13, "E": 14, "F": 15, "a": 10, "b": 11, "c": 12,
                        "d": 13, "e": 14, "f": 15}
            r = int(0.7 * (16 * hexToDec[hex[1]] + hexToDec[hex[2]]))
            g = int(0.7 * (16 * hexToDec[hex[3]] + hexToDec[hex[4]]))
            b = int(0.7 * (16 * hexToDec[hex[5]] + hexToDec[hex[6]]))
            return r * 256, g * 256, b * 256

        def lighten(hex):
            hexToDec = {"0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6,
                        "7": 7, "8": 8, "9": 9, "A": 10, "B": 11, "C": 12,
                        "D": 13, "E": 14, "F": 15, "a": 10, "b": 11, "c": 12,
                        "d": 13, "e": 14, "f": 15}
            r = 255 - int(0.7 * (255 - (
                        16 * hexToDec[hex[1]] + hexToDec[hex[2]])))
            g = 255 - int(0.7 * (255 - (
                        16 * hexToDec[hex[3]] + hexToDec[hex[4]])))
            b = 255 - int(0.7 * (255 - (
                        16 * hexToDec[hex[5]] + hexToDec[hex[6]])))
            return r * 256, g * 256, b * 256

        xoColor = profile.get_color()
        if not xoColor:
            xoColorKey = ("#8D8D8D,#FFDDEA")
            xoColor = XoColor(xoColorKey)

        # colors in Config and in XoColor are strings,
        # the colors in style are style.Color, transform all to Gdk.Color
        self.colors = {"bg": CairoUtil.get_gdk_color(Config.PANEL_BCK_COLOR),
               "black": style.COLOR_BLACK.get_gdk_color(),
               #"Picker_Bg": colormap.alloc_color("#404040"),
               #"Picker_Bg_Inactive": colormap.alloc_color("#808080"),
               "Picker_Bg": style.COLOR_TOOLBAR_GREY.get_gdk_color(),
               "Picker_Bg_Inactive": style.COLOR_BUTTON_GREY.get_gdk_color(),
               "Picker_Fg": style.COLOR_WHITE.get_gdk_color(),
               "Border_Active": \
                        CairoUtil.get_gdk_color(xoColor.get_stroke_color()),
               "Border_Inactive": CairoUtil.get_gdk_color("#8D8D8D"),
               "Border_Highlight": CairoUtil.get_gdk_color("#FFFFFF"),
               "Bg_Active": CairoUtil.get_gdk_color(xoColor.get_fill_color()),
               "Bg_Inactive": CairoUtil.get_gdk_color("#DBDBDB"),
               "Preview_Note_Fill": CairoUtil.get_gdk_color(Config.BG_COLOR),
               "Preview_Note_Border": CairoUtil.get_gdk_color(Config.FG_COLOR),
               "Preview_Note_Selected": style.COLOR_WHITE.get_gdk_color(),
                # TODO: lighten here can be removed, check if is used in other
                # places
               "Note_Fill_Active": Gdk.Color(*lighten("#590000")),
               # base "Border_Active"
               "Note_Fill_Inactive": Gdk.Color(*lighten("#8D8D8D")),
               # base "Border_Inactive"
               "Beat_Line": CairoUtil.get_gdk_color("#959595")}
        self.colors["Note_Border_Active"] = self.colors["Border_Active"]
        self.colors["Note_Border_Inactive"] = self.colors["Border_Inactive"]

        self.sampleNoteHeight = 7

        self.sampleBg = cairo.ImageSurface.create_from_png(
                imagefile('sampleBG.png'))
        self.loopPitchOffset = 4
        self.loopTickOffset = 13
        self.pitchPerPixel = float(Config.NUMBER_OF_POSSIBLE_PITCHES - 1) / \
            (Block.Loop.HEIGHT - 2 * self.loopPitchOffset - \
                 self.sampleNoteHeight)
        self.pixelsPerPitch = float(Block.Loop.HEIGHT - \
            2 * self.loopPitchOffset - self.sampleNoteHeight) / \
            (Config.MAXIMUM_PITCH - Config.MINIMUM_PITCH)
        self.pixelsPerTick = Block.Loop.BEAT / float(Config.TICKS_PER_BEAT)
        self.ticksPerPixel = 1.0 / self.pixelsPerTick

        #-- Instruments ---------------------------------------
        self.instrumentImage = {}
        self.instrumentImageActive = {}
        for inst in self.instrumentDB.getSet("All"):
            if not inst.kitStage:
                self.prepareInstrumentImage(inst.instrumentId, inst.img)
            self.csnd.load_instrument(inst.name)

        #-- Loop Images ---------------------------------------
        self.loopImage = {}  # get filled in through updateLoopImage
        self.loopImageActive = {}

        #-- Key Images ----------------------------------------
        self.keyImage = {}
        self.keyImageActive = {}
        # use hardware key codes to work on any keyboard layout (hopefully)
        self.valid_shortcuts = {18: "9", 19: "0", 20: "-", 21: "=",
                                32: "O", 33: "P", 34: "[", 35: "]",
                                47: ";", 48: "'", 51: "\\",
                                60: ".", 61: "/",
                                None: " "}
        for key in self.valid_shortcuts.keys():
            self.prepareKeyImage(key)

        #-- Toolbars ------------------------------------------

        self.jamToolbar = JamToolbar(self)
        jam_toolbar_button = ToolbarButton(label=_('Jam'),
                                           page=self.jamToolbar,
                                           icon_name='voltemp')
        self.jamToolbar.show()
        jam_toolbar_button.show()
        self.activity.toolbar_box.toolbar.insert(jam_toolbar_button, -1)

        self.beatToolbar = BeatToolbar(self)
        beat_toolbar_button = ToolbarButton(label=_('Beat'),
                                                page=self.beatToolbar,
                                                icon_name='heart')
        self.beatToolbar.show()
        beat_toolbar_button.show()
        self.activity.toolbar_box.toolbar.insert(beat_toolbar_button, -1)

        self.desktopToolbar = DesktopToolbar(self)
        desktop_toolbar_button = ToolbarButton(label=_('Desktop'),
                                              page=self.desktopToolbar,
                                              icon_name='jam-presets-list')
        self.desktopToolbar.show()
        desktop_toolbar_button.show()
        self.activity.toolbar_box.toolbar.insert(desktop_toolbar_button, -1)

        if Config.FEATURES_MIC or Config.FEATURES_NEWSOUNDS:
            self.recordToolbar = RecordToolbar(self)
            record_toolbar_button = ToolbarButton(label=_('Record'),
                                                  page=self.recordToolbar,
                                                  icon_name='microphone')
            self.recordToolbar.show()
            record_toolbar_button.show()
            self.activity.toolbar_box.toolbar.insert(record_toolbar_button, -1)

        separator = Gtk.SeparatorToolItem()
        separator.props.draw = True
        separator.set_expand(False)
        self.activity.toolbar_box.toolbar.insert(separator, -1)
        separator.show()

        common_playback_buttons(self.activity.toolbar_box.toolbar, self)

        #-- GUI -----------------------------------------------
        if True:  # GUI
            self.modify_bg(Gtk.StateType.NORMAL, self.colors["bg"])

            self.GUI = {}
            self.GUI["mainVBox"] = Gtk.VBox()
            self.add(self.GUI["mainVBox"])

            #-- Desktop -------------------------------------------
            self.desktop = self.GUI["desktop"] = Desktop(self)
            self.GUI["mainVBox"].pack_start(self.GUI["desktop"], True, True, 0)

            #-- Bank ----------------------------------------------
            separator = Gtk.Label(label=" ")
            separator.set_size_request(-1, style.TOOLBOX_SEPARATOR_HEIGHT)
            self.GUI["mainVBox"].pack_start(separator, False, True, 0)
            self.GUI["notebook"] = Gtk.Notebook()
            self.GUI["notebook"].set_scrollable(True)
            self.GUI["notebook"].modify_bg(Gtk.StateType.NORMAL,
                                           self.colors["Picker_Bg"])
            self.GUI["notebook"].modify_bg(Gtk.StateType.ACTIVE,
                                           self.colors["Picker_Bg_Inactive"])
            # TODO gtk3 no available anymore?
            #self.GUI["notebook"].props.tab_vborder = style.TOOLBOX_TAB_VBORDER
            #self.GUI["notebook"].props.tab_hborder = style.TOOLBOX_TAB_HBORDER
            self.GUI["notebook"].set_size_request(-1, scale(160))
            self.GUI["notebook"].connect("switch-page", self.setPicker)
            self.GUI["mainVBox"].pack_start(self.GUI["notebook"], False,
                    False, 0)
            self.pickers = {}
            self.pickerScroll = {}
            for type in [Picker.Instrument, Picker.Drum, Picker.Loop]:
                self.pickers[type] = type(self)

            def prepareLabel(name):
                label = Gtk.Label(label=Tooltips.categories.get(name) or name)
                label.set_alignment(0.0, 0.5)
                label.modify_fg(Gtk.StateType.NORMAL, self.colors["Picker_Fg"])
                label.modify_fg(Gtk.StateType.ACTIVE, self.colors["Picker_Fg"])
                return label

            self.GUI["notebook"].append_page(self.pickers[Picker.Drum],
                                             prepareLabel(_("Drum Kits")))
            self.GUI["notebook"].append_page(self.pickers[Picker.Loop],
                                             prepareLabel(_("Loops")))

            sets = self.instrumentDB.getLabels()[:]
            sets.sort()
            for set in sets:
                page = Gtk.HBox()
                page.set = set
                self.GUI["notebook"].append_page(page, prepareLabel(set))

            self.show_all()

            self.GUI["notebook"].set_current_page(0)

        #-- Keyboard ------------------------------------------
        self.key_dict = {}
        self.nextTrack = 2
        self.keyboardListener = None
        self.recordingNote = None

        self.keyMap = {}

        # default instrument
        self._updateInstrument(
            self.instrumentDB.instNamed["kalimba"].instrumentId, 0.5)
        self.instrumentStack = []

        # metronome
        page = NoteDB.Page(1, local=False)
        self.metronomePage = self.noteDB.addPage(-1, page)
        self.metronome = False

        #-- Drums ---------------------------------------------
        self.drumLoopId = None
        # use dummy values for now
        self.drumFillin = Fillin(
            2, 100, self.instrumentDB.instNamed["drum1kit"].instrumentId, 0, 1)

        #-- Desktops ------------------------------------------
        self.curDesktop = None
        # copy preset desktops
        path = Config.FILES_DIR + "/Desktops/"
        filelist = os.listdir(path)
        for file in filelist:
            shutil.copyfile(path + file, Config.TMP_DIR + '/' + file)

        #-- Network -------------------------------------------
        self.network = Net.Network()
        self.network.addWatcher(self.networkStatusWatcher)
        self.network.connectMessage(Net.HT_SYNC_REPLY,
                                    self.processHT_SYNC_REPLY)
        self.network.connectMessage(Net.HT_TEMPO_UPDATE,
                                    self.processHT_TEMPO_UPDATE)
        self.network.connectMessage(Net.PR_SYNC_QUERY,
                                    self.processPR_SYNC_QUERY)
        self.network.connectMessage(Net.PR_TEMPO_QUERY,
                                    self.processPR_TEMPO_QUERY)
        self.network.connectMessage(Net.PR_REQUEST_TEMPO_CHANGE,
                                    self.processPR_REQUEST_TEMPO_CHANGE)

        # sync
        self.syncQueryStart = {}
        self.syncTimeout = None
        self.heartbeatLoop = self.csnd.loopCreate()
        self.syncBeats = 4
        self.syncTicks = self.syncBeats * Config.TICKS_PER_BEAT
        self.offsetTicks = 0  # offset from the true heartbeat
        self.csnd.loopSetNumTicks(self.syncTicks * HEARTBEAT_BUFFER,
                                  self.heartbeatLoop)
        self.heartbeatStart = time.time()
        self.csnd.loopStart(self.heartbeatLoop)
        self.curBeat = 0
        self.beatWheelTimeout = GObject.timeout_add(100, self.updateBeatWheel)

        # data packing classes
        self.packer = xdrlib.Packer()
        self.unpacker = xdrlib.Unpacker("")

        # handle forced networking
        if self.network.isHost():
            self.updateSync()
            self.syncTimeout = GObject.timeout_add(1000, self.updateSync)
        elif self.network.isPeer():
            self.sendTempoQuery()
            self.syncTimeout = GObject.timeout_add(1000, self.updateSync)

        self.activity.connect("shared", self.shared)

        if self.activity.shared_activity:  # PEER
            self.activity.shared_activity.connect("buddy-joined",
                                                   self.buddy_joined)
            self.activity.shared_activity.connect("buddy-left",
                                                   self.buddy_left)
            self.activity.connect("joined", self.joined)
            self.network.setMode(Net.MD_WAIT)

        #-- Final Set Up --------------------------------------
        self.setVolume(self.volume)
        self.setTempo(self.tempo)
        #self.activity.toolbar_box.set_current_toolbar(1)  # JamToolbar
        self.setDesktop(0, True)
class ProgressToolButton(ToolButton):

    '''
    This button is just like a normal tool button, except that the
    icon can dynamically fill based on a progress number.
    '''

    __gtype_name__ = 'SugarProgressToolButton'

    def __init__(self, **kwargs):
        self._xo_color = XoColor('insensitive')
        self._icon_name = None
        self._direction = 'vertical'
        self._progress = 0.0

        ToolButton.__init__(self, **kwargs)
        # GObject should do this, but something down the ToolButton chain of
        # parents is not passing the kwargs to GObject
        if 'xo_color' in kwargs:
            self.props.xo_color = kwargs['xo_color']
        if 'icon_name' in kwargs:
            self.props.icon_name = kwargs['icon_name']
        if 'direction' in kwargs:
            self.props.direction = kwargs['direction']
        self._updated()

    @GObject.property
    def xo_color(self):
        '''
        This property defines the stroke and fill of the icon, and is
        the type :class:`sugar3.graphics.xocolor.XoColor`
        '''
        return self._xo_color

    @xo_color.setter
    def xo_color(self, new):
        self._xo_color = new
        self._updated()

    @GObject.property
    def icon_name(self):
        '''
        Icon name (same as with a :class:`sugar3.graphics.icon.Icon`), as the
        type :class:`str`
        '''
        return self._icon_name

    @icon_name.setter
    def icon_name(self, new):
        self._icon_name = new
        self._updated()

    @GObject.property
    def direction(self):
        '''
        Direction for the icon to fill as it progresses, filling either,
        * :class:`Gtk.Orientation.VERTICAL` - bottom to top
        * :class:`Gtk.Orientation.HORIZONTAL` - user's text direction
        '''
        if self._direction == 'vertical':
            return Gtk.Orientation.VERTICAL
        else:
            return Gtk.Orientation.HORIZONTAL

    @direction.setter
    def direction(self, new):
        if new == Gtk.Orientation.VERTICAL:
            self._direction = 'vertical'
        else:
            self._direction = 'horizontal'
        self._updated()

    def _updated(self):
        self._icon = ProgressIcon(
            self._icon_name,
            style.STANDARD_ICON_SIZE,
            self._xo_color.get_stroke_color(),
            self._xo_color.get_fill_color(),
            self._direction)
        self._icon.update(self._progress)
        self.set_icon_widget(self._icon)
        self._icon.show()

    def update(self, progress):
        '''
        Redraw the icon with a different percentage filled in

        Args:
            progress (float): a value from 0.0 to 1.0, where 1.0 fully
                fills the icon and 0.0 results in only the stroke being
                visible
        '''
        self._progress = progress
        self._icon.update(progress)
        self.queue_draw()
Esempio n. 8
0
class BookmarkView(Gtk.EventBox):

    __gsignals__ = {
        'bookmark-changed':
        (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE, ([])),
    }

    def __init__(self):
        Gtk.EventBox.__init__(self)
        self._box = Gtk.VButtonBox()
        self._box.set_layout(Gtk.ButtonBoxStyle.START)
        self._box.set_margin_top(style.GRID_CELL_SIZE / 2)
        self.add(self._box)
        self._box.show()

        self._bookmark_icon = None
        self._bookmark_manager = None
        self._is_showing_local_bookmark = False
        self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
        self.connect('draw', self.__draw_cb)
        self.connect('event', self.__event_cb)

    def __draw_cb(self, widget, ctx):
        width = style.GRID_CELL_SIZE
        height = style.GRID_CELL_SIZE * (len(self._bookmarks) + 1)

        ctx.rectangle(0, 0, width, height)
        ctx.set_source_rgba(*self._fill_color.get_rgba())
        ctx.paint()

        ctx.new_path()
        ctx.move_to(0, 0)
        ctx.line_to(width, 0)
        ctx.line_to(width, height)
        ctx.line_to(width / 2, height - width / 2)
        ctx.line_to(0, height)
        ctx.close_path()
        ctx.set_source_rgba(*self._stroke_color.get_rgba())
        ctx.fill()

    def _add_bookmark_icon(self, bookmark):
        self._xo_color = XoColor(str(bookmark.color))
        self._fill_color = style.Color(self._xo_color.get_fill_color())
        self._stroke_color = style.Color(self._xo_color.get_stroke_color())
        self._bookmark_icon = Icon(icon_name='emblem-favorite',
                                   xo_color=self._xo_color,
                                   pixel_size=style.STANDARD_ICON_SIZE)
        self._bookmark_icon.set_valign(Gtk.Align.START)

        self._box.props.has_tooltip = True
        self.__box_query_tooltip_cb_id = self._box.connect(
            'query_tooltip', self.__bookmark_query_tooltip_cb)

        self._box.pack_start(self._bookmark_icon, False, False, 0)
        self._bookmark_icon.show_all()

        if bookmark.is_local():
            self._is_showing_local_bookmark = True

    def __bookmark_query_tooltip_cb(self, widget, x, y, keyboard_mode, tip):
        vbox = Gtk.VBox()
        for bookmark in self._bookmarks:

            tooltip_header = bookmark.get_note_title()
            tooltip_body = bookmark.get_note_body()
            time = timestamp_to_elapsed_string(bookmark.timestamp)
            # TRANS: This goes like Bookmark added by User 5 days ago
            # TRANS: (the elapsed string gets translated automatically)
            tooltip_footer = (_('Bookmark added by %(user)s %(time)s') % {
                'user': bookmark.nick.decode('utf-8'),
                'time': time.decode('utf-8')
            })

            l = Gtk.Label('<big>%s</big>' % tooltip_header)
            l.set_use_markup(True)
            l.set_width_chars(40)
            l.set_line_wrap(True)
            vbox.pack_start(l, False, False, 0)
            l.show()

            l = Gtk.Label('%s' % tooltip_body)
            l.set_use_markup(True)
            l.set_alignment(0, 0)
            l.set_padding(2, 6)
            l.set_width_chars(40)
            l.set_line_wrap(True)
            l.set_justify(Gtk.Justification.FILL)
            vbox.pack_start(l, True, True, 0)
            l.show()

            l = Gtk.Label('<small><i>%s</i></small>' % tooltip_footer)
            l.set_use_markup(True)
            l.set_width_chars(40)
            l.set_line_wrap(True)
            vbox.pack_start(l, False, False, 0)
            l.show()

        tip.set_custom(vbox)
        return True

    def __event_cb(self, widget, event):
        if event.type == Gdk.EventType.BUTTON_PRESS:
            # TODO: show the first bookmark
            dialog = BookmarkEditDialog(self.get_toplevel().get_window(),
                                        _("Add notes for bookmark: "),
                                        self._bookmarks, self._page, self)
            dialog.show_all()

        return False

    def _clear_bookmarks(self):
        for bookmark_icon in self._box.get_children():
            bookmark_icon.destroy()
            self._bookmark_icon = None
            self._is_showing_local_bookmark = False

    def set_bookmarkmanager(self, bookmark_manager):
        self._bookmark_manager = bookmark_manager

    def get_bookmarkmanager(self):
        return (self._bookmark_manager)

    def update_for_page(self, page):
        self._page = page
        self._clear_bookmarks()
        if self._bookmark_manager is None:
            return

        self._bookmarks = self._bookmark_manager.get_bookmarks_for_page(page)

        if self._bookmarks:
            self.show()
        else:
            self.hide()

        for bookmark in self._bookmarks:
            self._add_bookmark_icon(bookmark)

        self.set_size_request(
            style.GRID_CELL_SIZE,
            style.GRID_CELL_SIZE * (len(self._bookmarks) + 1))

        self.notify_bookmark_change()

    def notify_bookmark_change(self):
        self.queue_draw()
        self.emit('bookmark-changed')

    def add_bookmark(self, page):
        bookmark_title = (_("%s's bookmark") % profile.get_nick_name())
        bookmark_content = (_("Bookmark for page %d") % (int(page) + 1))
        dialog = BookmarkAddDialog(parent_xid=self.get_toplevel().get_window(),
                                   dialog_title=_("Add notes for bookmark: "),
                                   bookmark_title=bookmark_title,
                                   bookmark_content=bookmark_content,
                                   page=page,
                                   sidebarinstance=self)
        dialog.show_all()

    def _real_add_bookmark(self, page, content):
        self._bookmark_manager.add_bookmark(page, str(content))
        self.update_for_page(page)

    def del_bookmark(self, page):
        self._bookmark_manager.del_bookmark(page)
        self.update_for_page(page)

    def is_showing_local_bookmark(self):
        return self._is_showing_local_bookmark
Esempio n. 9
0
class JournalManager(GObject.GObject):

    __gsignals__ = {'updated': (GObject.SignalFlags.RUN_FIRST, None, ([]))}

    def __init__(self, activity_root):
        GObject.GObject.__init__(self)
        self._instance_path = activity_root + '/instance/'
        self._shared_items = []
        try:
            self.nick_name = profile.get_nick_name()
        except:
            logging.exception('Can' 't get nick_name')
            self.nick_name = ''
        try:
            self.xo_color = profile.get_color()
        except:
            logging.exception('Can' 't get xo_color')
            self.xo_color = XoColor()

        # write json files
        owner_info_file_path = self._instance_path + 'owner_info.json'
        owner_info_file = open(owner_info_file_path, 'w')
        owner_info_file.write(self.get_journal_owner_info())
        owner_info_file.close()

        self._update_temporary_files()

    def set_shared_items(self, shared_items):
        self._shared_items = shared_items
        self._update_temporary_files()

    def _update_temporary_files(self):
        selected_file_path = os.path.join(self._instance_path, 'selected.json')
        selected_file = open(selected_file_path, 'w')
        selected_file.write(self._prepare_shared_items())
        selected_file.close()
        self.emit('updated')

    def get_shared_items(self):
        return self._shared_items

    def append_to_shared_items(self, item):
        self._shared_items.append(item)
        self._update_temporary_files()

    def get_journal_owner_info(self):
        info = {}
        info['nick_name'] = self.nick_name
        info['stroke_color'] = self.xo_color.get_stroke_color()
        info['fill_color'] = self.xo_color.get_fill_color()
        logging.error('INFO %s', info)
        return json.dumps(info)

    def add_downloader(self, object_id, name, icon):
        """
        Add to the metadata downloaded_by field, the information
        about who downloaded one object
        """
        dsobj = datastore.get(object_id)
        downloaded_by = []
        if 'downloaded_by' in dsobj.metadata:
            downloaded_by = json.loads(dsobj.metadata['downloaded_by'])
        # add the user data
        user_data = {}
        user_data['from'] = name
        user_data['icon'] = icon
        downloaded_by.append(user_data)
        dsobj.metadata['downloaded_by'] = json.dumps(downloaded_by)
        datastore.write(dsobj)
        self._update_temporary_files()

    def create_object(self, file_path, metadata, preview_content):
        new_dsobject = datastore.create()
        #Set the file_path in the datastore.
        new_dsobject.set_file_path(file_path)

        for key in metadata.keys():
            new_dsobject.metadata[key] = metadata[key]

        if preview_content is not None and preview_content != '':
            new_dsobject.metadata['preview'] = \
                dbus.ByteArray(preview_content)
        datastore.write(new_dsobject)
        if self._shared_items == ['*']:
            # mark as favorite
            new_dsobject.metadata['keep'] = '1'
            self._update_temporary_files()
        else:
            self.append_to_shared_items(new_dsobject.object_id)
        return False

    def _prepare_shared_items(self):
        results = []
        if not self._shared_items:
            return json.dumps(results)

        if self._shared_items == ['*']:
            dsobjects, _nobjects = datastore.find({'keep': '1'})
        else:
            dsobjects = []
            for object_id in self._shared_items:
                dsobjects.append(datastore.get(object_id))

        for dsobj in dsobjects:
            title = ''
            desc = ''
            comment = []
            shared_by = {}
            downloaded_by = []
            object_id = dsobj.object_id
            if hasattr(dsobj, 'metadata'):
                if 'title' in dsobj.metadata:
                    title = dsobj.metadata['title']
                if 'description' in dsobj.metadata:
                    desc = dsobj.metadata['description']
                if 'comments' in dsobj.metadata:
                    try:
                        comment = json.loads(dsobj.metadata['comments'])
                    except:
                        comment = []
                if 'shared_by' in dsobj.metadata:
                    shared_by = json.loads(dsobj.metadata['shared_by'])
                if 'downloaded_by' in dsobj.metadata:
                    downloaded_by = json.loads(dsobj.metadata['downloaded_by'])
            else:
                logging.debug('dsobj has no metadata')

            utils.package_ds_object(dsobj, self._instance_path)

            results.append({
                'title': str(title),
                'desc': str(desc),
                'comment': comment,
                'id': str(object_id),
                'shared_by': shared_by,
                'downloaded_by': downloaded_by
            })
        logging.error(results)
        return json.dumps(results)
Esempio n. 10
0
class BookmarkView(Gtk.EventBox):

    __gsignals__ = {
        'bookmark-changed': (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE,
                             ([])),
    }

    def __init__(self):
        Gtk.EventBox.__init__(self)
        self._box = Gtk.VButtonBox()
        self._box.set_layout(Gtk.ButtonBoxStyle.START)
        self._box.set_margin_top(style.GRID_CELL_SIZE / 2)
        self.add(self._box)
        self._box.show()

        self._bookmark_icon = None
        self._bookmark_manager = None
        self._is_showing_local_bookmark = False
        self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
        self.connect('draw', self.__draw_cb)
        self.connect('event', self.__event_cb)

    def __draw_cb(self, widget, ctx):
        width = style.GRID_CELL_SIZE
        height = style.GRID_CELL_SIZE * (len(self._bookmarks) + 1)

        ctx.rectangle(0, 0, width, height)
        ctx.set_source_rgba(*self._fill_color.get_rgba())
        ctx.paint()

        ctx.new_path()
        ctx.move_to(0, 0)
        ctx.line_to(width, 0)
        ctx.line_to(width, height)
        ctx.line_to(width / 2, height - width / 2)
        ctx.line_to(0, height)
        ctx.close_path()
        ctx.set_source_rgba(*self._stroke_color.get_rgba())
        ctx.fill()

    def _add_bookmark_icon(self, bookmark):
        self._xo_color = XoColor(str(bookmark.color))
        self._fill_color = style.Color(self._xo_color.get_fill_color())
        self._stroke_color = style.Color(self._xo_color.get_stroke_color())
        self._bookmark_icon = Icon(icon_name='emblem-favorite',
                                   xo_color=self._xo_color,
                                   pixel_size=style.STANDARD_ICON_SIZE)
        self._bookmark_icon.set_valign(Gtk.Align.START)

        self._box.props.has_tooltip = True
        self.__box_query_tooltip_cb_id = self._box.connect(
            'query_tooltip', self.__bookmark_query_tooltip_cb)

        self._box.pack_start(self._bookmark_icon, False, False, 0)
        self._bookmark_icon.show_all()

        if bookmark.is_local():
            self._is_showing_local_bookmark = True

    def __bookmark_query_tooltip_cb(self, widget, x, y, keyboard_mode, tip):
        vbox = Gtk.VBox()
        for bookmark in self._bookmarks:

            tooltip_header = bookmark.get_note_title()
            tooltip_body = bookmark.get_note_body()
            time = timestamp_to_elapsed_string(bookmark.timestamp)
            # TRANS: This goes like Bookmark added by User 5 days ago
            # TRANS: (the elapsed string gets translated automatically)
            tooltip_footer = (
                _('Bookmark added by %(user)s %(time)s')
                % {'user': bookmark.nick.decode('utf-8'),
                   'time': time.decode('utf-8')})

            l = Gtk.Label('<big>%s</big>' % tooltip_header)
            l.set_use_markup(True)
            l.set_width_chars(40)
            l.set_line_wrap(True)
            vbox.pack_start(l, False, False, 0)
            l.show()

            l = Gtk.Label('%s' % tooltip_body)
            l.set_use_markup(True)
            l.set_alignment(0, 0)
            l.set_padding(2, 6)
            l.set_width_chars(40)
            l.set_line_wrap(True)
            l.set_justify(Gtk.Justification.FILL)
            vbox.pack_start(l, True, True, 0)
            l.show()

            l = Gtk.Label('<small><i>%s</i></small>' % tooltip_footer)
            l.set_use_markup(True)
            l.set_width_chars(40)
            l.set_line_wrap(True)
            vbox.pack_start(l, False, False, 0)
            l.show()

        tip.set_custom(vbox)
        return True

    def __event_cb(self, widget, event):
        if event.type == Gdk.EventType.BUTTON_PRESS:
            # TODO: show the first bookmark
            dialog = BookmarkEditDialog(
                self.get_toplevel().get_window(),
                _("Add notes for bookmark: "),
                self._bookmarks, self._page, self)
            dialog.show_all()

        return False

    def _clear_bookmarks(self):
        for bookmark_icon in self._box.get_children():
            bookmark_icon.destroy()
            self._bookmark_icon = None
            self._is_showing_local_bookmark = False

    def set_bookmarkmanager(self, bookmark_manager):
        self._bookmark_manager = bookmark_manager

    def get_bookmarkmanager(self):
        return (self._bookmark_manager)

    def update_for_page(self, page):
        self._page = page
        self._clear_bookmarks()
        if self._bookmark_manager is None:
            return

        self._bookmarks = self._bookmark_manager.get_bookmarks_for_page(page)

        if self._bookmarks:
            self.show()
        else:
            self.hide()

        for bookmark in self._bookmarks:
            self._add_bookmark_icon(bookmark)

        self.set_size_request(
            style.GRID_CELL_SIZE,
            style.GRID_CELL_SIZE * (len(self._bookmarks) + 1))

        self.notify_bookmark_change()

    def notify_bookmark_change(self):
        self.queue_draw()
        self.emit('bookmark-changed')

    def add_bookmark(self, page):
        bookmark_title = (_("%s's bookmark") % profile.get_nick_name())
        bookmark_content = (_("Bookmark for page %d") % (int(page) + 1))
        dialog = BookmarkAddDialog(
            parent_xid=self.get_toplevel().get_window(),
            dialog_title=_("Add notes for bookmark: "),
            bookmark_title=bookmark_title,
            bookmark_content=bookmark_content, page=page,
            sidebarinstance=self)
        dialog.show_all()

    def _real_add_bookmark(self, page, content):
        self._bookmark_manager.add_bookmark(page, unicode(content))
        self.update_for_page(page)

    def del_bookmark(self, page):
        self._bookmark_manager.del_bookmark(page)
        self.update_for_page(page)

    def is_showing_local_bookmark(self):
        return self._is_showing_local_bookmark
Esempio n. 11
0
    def __init__(self, activity):
        GObject.GObject.__init__(self)

        self.activity = activity

        self.instrumentDB = InstrumentDB.getRef()
        self.noteDB = NoteDB.NoteDB()

        #-- initial settings ----------------------------------
        self.tempo = Config.PLAYER_TEMPO
        self.beatDuration = 60.0 / self.tempo
        self.ticksPerSecond = Config.TICKS_PER_BEAT * self.tempo / 60.0
        self.volume = 0.5

        self.csnd = new_csound_client()
        for i in range(0, 9):
            self.csnd.setTrackVolume(100, i)
        # csnd expects a range 0-100 for now
        self.csnd.setMasterVolume(self.volume * 100)
        self.csnd.setTempo(self.tempo)

        self.muted = False

        #-- Drawing -------------------------------------------
        def darken(hex):
            hexToDec = {
                "0": 0,
                "1": 1,
                "2": 2,
                "3": 3,
                "4": 4,
                "5": 5,
                "6": 6,
                "7": 7,
                "8": 8,
                "9": 9,
                "A": 10,
                "B": 11,
                "C": 12,
                "D": 13,
                "E": 14,
                "F": 15,
                "a": 10,
                "b": 11,
                "c": 12,
                "d": 13,
                "e": 14,
                "f": 15
            }
            r = int(0.7 * (16 * hexToDec[hex[1]] + hexToDec[hex[2]]))
            g = int(0.7 * (16 * hexToDec[hex[3]] + hexToDec[hex[4]]))
            b = int(0.7 * (16 * hexToDec[hex[5]] + hexToDec[hex[6]]))
            return r * 256, g * 256, b * 256

        def lighten(hex):
            hexToDec = {
                "0": 0,
                "1": 1,
                "2": 2,
                "3": 3,
                "4": 4,
                "5": 5,
                "6": 6,
                "7": 7,
                "8": 8,
                "9": 9,
                "A": 10,
                "B": 11,
                "C": 12,
                "D": 13,
                "E": 14,
                "F": 15,
                "a": 10,
                "b": 11,
                "c": 12,
                "d": 13,
                "e": 14,
                "f": 15
            }
            r = 255 - int(0.7 * (255 -
                                 (16 * hexToDec[hex[1]] + hexToDec[hex[2]])))
            g = 255 - int(0.7 * (255 -
                                 (16 * hexToDec[hex[3]] + hexToDec[hex[4]])))
            b = 255 - int(0.7 * (255 -
                                 (16 * hexToDec[hex[5]] + hexToDec[hex[6]])))
            return r * 256, g * 256, b * 256

        xoColor = profile.get_color()
        if not xoColor:
            xoColorKey = ("#8D8D8D,#FFDDEA")
            xoColor = XoColor(xoColorKey)

        # colors in Config and in XoColor are strings,
        # the colors in style are style.Color, transform all to Gdk.Color
        self.colors = {"bg": CairoUtil.get_gdk_color(Config.PANEL_BCK_COLOR),
               "black": style.COLOR_BLACK.get_gdk_color(),
               #"Picker_Bg": colormap.alloc_color("#404040"),
               #"Picker_Bg_Inactive": colormap.alloc_color("#808080"),
               "Picker_Bg": style.COLOR_TOOLBAR_GREY.get_gdk_color(),
               "Picker_Bg_Inactive": style.COLOR_BUTTON_GREY.get_gdk_color(),
               "Picker_Fg": style.COLOR_WHITE.get_gdk_color(),
               "Border_Active": \
                        CairoUtil.get_gdk_color(xoColor.get_stroke_color()),
               "Border_Inactive": CairoUtil.get_gdk_color("#8D8D8D"),
               "Border_Highlight": CairoUtil.get_gdk_color("#FFFFFF"),
               "Bg_Active": CairoUtil.get_gdk_color(xoColor.get_fill_color()),
               "Bg_Inactive": CairoUtil.get_gdk_color("#DBDBDB"),
               "Preview_Note_Fill": CairoUtil.get_gdk_color(Config.BG_COLOR),
               "Preview_Note_Border": CairoUtil.get_gdk_color(Config.FG_COLOR),
               "Preview_Note_Selected": style.COLOR_WHITE.get_gdk_color(),
                # TODO: lighten here can be removed, check if is used in other
                # places
               "Note_Fill_Active": Gdk.Color(*lighten("#590000")),
               # base "Border_Active"
               "Note_Fill_Inactive": Gdk.Color(*lighten("#8D8D8D")),
               # base "Border_Inactive"
               "Beat_Line": CairoUtil.get_gdk_color("#959595")}
        self.colors["Note_Border_Active"] = self.colors["Border_Active"]
        self.colors["Note_Border_Inactive"] = self.colors["Border_Inactive"]

        self.sampleNoteHeight = 7

        self.sampleBg = cairo.ImageSurface.create_from_png(
            imagefile('sampleBG.png'))
        self.loopPitchOffset = 4
        self.loopTickOffset = 13
        self.pitchPerPixel = float(Config.NUMBER_OF_POSSIBLE_PITCHES - 1) / \
            (Block.Loop.HEIGHT - 2 * self.loopPitchOffset - \
                 self.sampleNoteHeight)
        self.pixelsPerPitch = float(Block.Loop.HEIGHT - \
            2 * self.loopPitchOffset - self.sampleNoteHeight) / \
            (Config.MAXIMUM_PITCH - Config.MINIMUM_PITCH)
        self.pixelsPerTick = Block.Loop.BEAT / float(Config.TICKS_PER_BEAT)
        self.ticksPerPixel = 1.0 / self.pixelsPerTick

        #-- Instruments ---------------------------------------
        self.instrumentImage = {}
        self.instrumentImageActive = {}
        for inst in self.instrumentDB.getSet("All"):
            if not inst.kitStage:
                self.prepareInstrumentImage(inst.instrumentId, inst.img)
            self.csnd.load_instrument(inst.name)

        #-- Loop Images ---------------------------------------
        self.loopImage = {}  # get filled in through updateLoopImage
        self.loopImageActive = {}

        #-- Key Images ----------------------------------------
        self.keyImage = {}
        self.keyImageActive = {}
        # use hardware key codes to work on any keyboard layout (hopefully)
        self.valid_shortcuts = {
            18: "9",
            19: "0",
            20: "-",
            21: "=",
            32: "O",
            33: "P",
            34: "[",
            35: "]",
            47: ";",
            48: "'",
            51: "\\",
            60: ".",
            61: "/",
            None: " "
        }
        for key in self.valid_shortcuts.keys():
            self.prepareKeyImage(key)

        #-- Toolbars ------------------------------------------

        self.jamToolbar = JamToolbar(self)
        jam_toolbar_button = ToolbarButton(label=_('Jam'),
                                           page=self.jamToolbar,
                                           icon_name='voltemp')
        self.jamToolbar.show()
        jam_toolbar_button.show()
        self.activity.toolbar_box.toolbar.insert(jam_toolbar_button, -1)

        self.beatToolbar = BeatToolbar(self)
        beat_toolbar_button = ToolbarButton(label=_('Beat'),
                                            page=self.beatToolbar,
                                            icon_name='heart')
        self.beatToolbar.show()
        beat_toolbar_button.show()
        self.activity.toolbar_box.toolbar.insert(beat_toolbar_button, -1)

        self.desktopToolbar = DesktopToolbar(self)
        desktop_toolbar_button = ToolbarButton(label=_('Desktop'),
                                               page=self.desktopToolbar,
                                               icon_name='jam-presets-list')
        self.desktopToolbar.show()
        desktop_toolbar_button.show()
        self.activity.toolbar_box.toolbar.insert(desktop_toolbar_button, -1)

        if Config.FEATURES_MIC or Config.FEATURES_NEWSOUNDS:
            self.recordToolbar = RecordToolbar(self)
            record_toolbar_button = ToolbarButton(label=_('Record'),
                                                  page=self.recordToolbar,
                                                  icon_name='microphone')
            self.recordToolbar.show()
            record_toolbar_button.show()
            self.activity.toolbar_box.toolbar.insert(record_toolbar_button, -1)

        separator = Gtk.SeparatorToolItem()
        separator.props.draw = True
        separator.set_expand(False)
        self.activity.toolbar_box.toolbar.insert(separator, -1)
        separator.show()

        common_playback_buttons(self.activity.toolbar_box.toolbar, self)

        #-- GUI -----------------------------------------------
        if True:  # GUI
            self.modify_bg(Gtk.StateType.NORMAL, self.colors["bg"])

            self.GUI = {}
            self.GUI["mainVBox"] = Gtk.VBox()
            self.add(self.GUI["mainVBox"])

            #-- Desktop -------------------------------------------
            self.desktop = self.GUI["desktop"] = Desktop(self)
            self.GUI["mainVBox"].pack_start(self.GUI["desktop"], True, True, 0)

            #-- Bank ----------------------------------------------
            separator = Gtk.Label(label=" ")
            separator.set_size_request(-1, style.TOOLBOX_SEPARATOR_HEIGHT)
            self.GUI["mainVBox"].pack_start(separator, False, True, 0)
            self.GUI["notebook"] = Gtk.Notebook()
            self.GUI["notebook"].set_scrollable(True)
            self.GUI["notebook"].modify_bg(Gtk.StateType.NORMAL,
                                           self.colors["Picker_Bg"])
            self.GUI["notebook"].modify_bg(Gtk.StateType.ACTIVE,
                                           self.colors["Picker_Bg_Inactive"])
            # TODO gtk3 no available anymore?
            #self.GUI["notebook"].props.tab_vborder = style.TOOLBOX_TAB_VBORDER
            #self.GUI["notebook"].props.tab_hborder = style.TOOLBOX_TAB_HBORDER
            self.GUI["notebook"].set_size_request(-1, scale(160))
            self.GUI["notebook"].connect("switch-page", self.setPicker)
            self.GUI["mainVBox"].pack_start(self.GUI["notebook"], False, False,
                                            0)
            self.pickers = {}
            self.pickerScroll = {}
            for type in [Picker.Instrument, Picker.Drum, Picker.Loop]:
                self.pickers[type] = type(self)

            def prepareLabel(name):
                label = Gtk.Label(label=Tooltips.categories.get(name) or name)
                label.set_alignment(0.0, 0.5)
                label.modify_fg(Gtk.StateType.NORMAL, self.colors["Picker_Fg"])
                label.modify_fg(Gtk.StateType.ACTIVE, self.colors["Picker_Fg"])
                return label

            self.GUI["notebook"].append_page(self.pickers[Picker.Drum],
                                             prepareLabel(_("Drum Kits")))
            self.GUI["notebook"].append_page(self.pickers[Picker.Loop],
                                             prepareLabel(_("Loops")))

            sets = self.instrumentDB.getLabels()[:]
            sets.sort()
            for set in sets:
                page = Gtk.HBox()
                page.set = set
                self.GUI["notebook"].append_page(page, prepareLabel(set))

            self.show_all()

            self.GUI["notebook"].set_current_page(0)

        #-- Keyboard ------------------------------------------
        self.key_dict = {}
        self.nextTrack = 2
        self.keyboardListener = None
        self.recordingNote = None

        self.keyMap = {}

        # default instrument
        self._updateInstrument(
            self.instrumentDB.instNamed["kalimba"].instrumentId, 0.5)
        self.instrumentStack = []

        # metronome
        page = NoteDB.Page(1, local=False)
        self.metronomePage = self.noteDB.addPage(-1, page)
        self.metronome = False

        #-- Drums ---------------------------------------------
        self.drumLoopId = None
        # use dummy values for now
        self.drumFillin = Fillin(
            2, 100, self.instrumentDB.instNamed["drum1kit"].instrumentId, 0, 1)

        #-- Desktops ------------------------------------------
        self.curDesktop = None
        # copy preset desktops
        path = Config.FILES_DIR + "/Desktops/"
        filelist = os.listdir(path)
        for file in filelist:
            shutil.copyfile(path + file, Config.TMP_DIR + '/' + file)

        #-- Network -------------------------------------------
        self.network = Net.Network()
        self.network.addWatcher(self.networkStatusWatcher)
        self.network.connectMessage(Net.HT_SYNC_REPLY,
                                    self.processHT_SYNC_REPLY)
        self.network.connectMessage(Net.HT_TEMPO_UPDATE,
                                    self.processHT_TEMPO_UPDATE)
        self.network.connectMessage(Net.PR_SYNC_QUERY,
                                    self.processPR_SYNC_QUERY)
        self.network.connectMessage(Net.PR_TEMPO_QUERY,
                                    self.processPR_TEMPO_QUERY)
        self.network.connectMessage(Net.PR_REQUEST_TEMPO_CHANGE,
                                    self.processPR_REQUEST_TEMPO_CHANGE)

        # sync
        self.syncQueryStart = {}
        self.syncTimeout = None
        self.heartbeatLoop = self.csnd.loopCreate()
        self.syncBeats = 4
        self.syncTicks = self.syncBeats * Config.TICKS_PER_BEAT
        self.offsetTicks = 0  # offset from the true heartbeat
        self.csnd.loopSetNumTicks(self.syncTicks * HEARTBEAT_BUFFER,
                                  self.heartbeatLoop)
        self.heartbeatStart = time.time()
        self.csnd.loopStart(self.heartbeatLoop)
        self.curBeat = 0
        self.beatWheelTimeout = GObject.timeout_add(100, self.updateBeatWheel)

        # data packing classes
        self.packer = xdrlib.Packer()
        self.unpacker = xdrlib.Unpacker("")

        # handle forced networking
        if self.network.isHost():
            self.updateSync()
            self.syncTimeout = GObject.timeout_add(1000, self.updateSync)
        elif self.network.isPeer():
            self.sendTempoQuery()
            self.syncTimeout = GObject.timeout_add(1000, self.updateSync)

        self.activity.connect("shared", self.shared)

        if self.activity.shared_activity:  # PEER
            self.activity.shared_activity.connect("buddy-joined",
                                                  self.buddy_joined)
            self.activity.shared_activity.connect("buddy-left",
                                                  self.buddy_left)
            self.activity.connect("joined", self.joined)
            self.network.setMode(Net.MD_WAIT)

        #-- Final Set Up --------------------------------------
        self.setVolume(self.volume)
        self.setTempo(self.tempo)
        #self.activity.toolbar_box.set_current_toolbar(1)  # JamToolbar
        self.setDesktop(0, True)