Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mesonium
gajim
Commits
fe68beac
Commit
fe68beac
authored
3 years ago
by
Daniel Brötzmann
Committed by
Philipp Hörist
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
CodeWidget: Add header and styling
parent
3933f457
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gajim/data/style/gajim.css
+14
-0
14 additions, 0 deletions
gajim/data/style/gajim.css
gajim/gtk/conversation/code_widget.py
+69
-14
69 additions, 14 deletions
gajim/gtk/conversation/code_widget.py
with
83 additions
and
14 deletions
gajim/data/style/gajim.css
+
14
−
0
View file @
fe68beac
...
...
@@ -88,6 +88,20 @@ .conversation-nickname {
font-size
:
small
;
font-weight
:
bold
;
}
.code-widget
{
border
:
1px
solid
@
borders
;
border-radius
:
4px
;
}
.code-widget-header
{
background-color
:
alpha
(
@
insensitive_fg_color
,
0.4
);
padding
:
0
6px
;
}
.code-widget-header
label
{
font-size
:
small
;
}
.code-widget-header
button
{
padding
:
0
;
}
.link-button
{
min-height
:
0px
;
}
...
...
This diff is collapsed.
Click to expand it.
gajim/gtk/conversation/code_widget.py
+
69
−
14
View file @
fe68beac
...
...
@@ -12,34 +12,77 @@
# You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
import
logging
import
gi
gi
.
require_version
(
'
GtkSource
'
,
'
4
'
)
from
gi.repository
import
GObject
from
gi.repository
import
Gdk
from
gi.repository
import
Gtk
from
gi.repository
import
GtkSource
from
gajim.common.i18n
import
_
log
=
logging
.
getLogger
(
'
gajim.gui.conversation.code_widget
'
)
class
CodeWidget
(
Gtk
.
Box
):
def
__init__
(
self
,
account
):
Gtk
.
Box
.
__init__
(
self
,
orientation
=
Gtk
.
Orientation
.
VERTICAL
)
self
.
set_vexpand
(
True
)
self
.
get_style_context
().
add_class
(
'
code-widget
'
)
self
.
_account
=
account
header
=
Gtk
.
Box
()
header
.
set_spacing
(
6
)
header
.
get_style_context
().
add_class
(
'
code-widget-header
'
)
self
.
_lang_label
=
Gtk
.
Label
()
header
.
add
(
self
.
_lang_label
)
copy_button
=
Gtk
.
Button
.
new_from_icon_name
(
'
edit-copy-symbolic
'
,
Gtk
.
IconSize
.
MENU
)
copy_button
.
set_tooltip_text
(
_
(
'
Copy code snippet
'
))
copy_button
.
connect
(
'
clicked
'
,
self
.
_on_copy
)
header
.
add
(
copy_button
)
self
.
add
(
header
)
self
.
_textview
=
CodeTextview
()
# self._scrolled = Gtk.ScrolledWindow()
# self._scrolled.set_policy(Gtk.PolicyType.AUTOMATIC,
# Gtk.PolicyType.AUTOMATIC)
# self._scrolled.set_hexpand(True)
# self._scrolled.set_vexpand(True)
# self._scrolled.set_propagate_natural_height(True)
# self._scrolled.set_max_content_height(400)
# self._scrolled.add(self._textview)
self
.
_scrolled
=
Gtk
.
ScrolledWindow
()
self
.
_scrolled
.
set_policy
(
Gtk
.
PolicyType
.
AUTOMATIC
,
Gtk
.
PolicyType
.
AUTOMATIC
)
self
.
_scrolled
.
set_hexpand
(
True
)
self
.
_scrolled
.
set_vexpand
(
True
)
self
.
_scrolled
.
set_propagate_natural_height
(
True
)
self
.
_scrolled
.
set_max_content_height
(
400
)
self
.
_scrolled
.
add
(
self
.
_textview
)
self
.
add
(
self
.
_scrolled
)
self
.
add
(
self
.
_textview
)
def
_on_copy
(
self
,
_button
):
text
=
self
.
_textview
.
get_code
()
clipboard
=
Gtk
.
Clipboard
.
get
(
Gdk
.
SELECTION_CLIPBOARD
)
clipboard
.
set_text
(
text
,
-
1
)
def
add_content
(
self
,
block
):
self
.
_textview
.
print_code
(
block
)
code
,
lang
=
self
.
_prepare_code
(
block
.
text
)
lang_name
=
self
.
_textview
.
set_language
(
lang
)
if
lang
is
None
:
self
.
_lang_label
.
set_text
(
_
(
'
Code snippet
'
))
else
:
self
.
_lang_label
.
set_text
(
_
(
'
Code snippet (%s)
'
)
%
lang_name
)
self
.
_textview
.
print_code
(
code
)
@staticmethod
def
_prepare_code
(
text
):
code_start
=
text
.
partition
(
'
\n
'
)[
0
]
lang
=
None
if
len
(
code_start
)
>
3
:
lang
=
code_start
[
3
:]
code
=
text
.
partition
(
'
\n
'
)[
2
][:
-
4
]
return
code
,
lang
class
CodeTextview
(
GtkSource
.
View
):
...
...
@@ -51,9 +94,21 @@ def __init__(self):
self
.
_source_manager
=
GtkSource
.
LanguageManager
.
get_default
()
def
print_code
(
self
,
block
):
def
set_language
(
self
,
language_string
):
if
language_string
is
None
:
lang
=
self
.
_source_manager
.
get_language
(
'
python3
'
)
else
:
lang
=
self
.
_source_manager
.
get_language
(
language_string
)
log
.
debug
(
'
Code snippet lang: %s
'
,
lang
.
get_name
())
self
.
get_buffer
().
set_language
(
lang
)
return
lang
.
get_name
()
def
get_code
(
self
):
buffer_
=
self
.
get_buffer
()
lang
=
self
.
_source_manager
.
get_language
(
'
python3
'
)
buffer_
.
set_language
(
lang
)
start
,
end
=
buffer_
.
get_bounds
()
return
buffer_
.
get_text
(
start
,
end
,
False
)
def
print_code
(
self
,
code
):
self
.
set_show_line_numbers
(
True
)
buffer_
.
insert
(
buffer_
.
get_start_iter
(),
block
.
text
)
buffer_
=
self
.
get_buffer
()
buffer_
.
insert
(
buffer_
.
get_start_iter
(),
code
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment