Jump to content
The Dark Mod Forums

DarkRadiant meets Python


Recommended Posts

- Do we want such functionality at all?

 

I would be perfectly happy to see such functionality provided it was limited to viewing material files; this would be very useful for debugging and testing, for example. My only concern is that once you can view material files, people are going to start asking for a full-blown material file editor, which I certainly don't believe should be part of DarkRadiant (not only is this scope creep, but it opens a whole can of worms relating to editing a file which might be in a PK4 in a non-writable location, having to refresh material shaders etc).

 

I guess a compromise might be to have viewing in DarkRadiant but with a button to open the material file in the user's preferred text editor, if and only if it was in the user-editable mod directory.

 

- Is this GtkSourceView stuff available in Ubuntu as dependency?

 

Yes, in fact it is installed by default since GEdit depends on it.

Link to comment
Share on other sites

I would be perfectly happy to see such functionality provided it was limited to viewing material files;

Yes, I remembered your stance about editing functionality, that's why I was not sure about viewing stuff.

 

Yes, in fact it is installed by default since GEdit depends on it.

And the development headers are also available as package? (I suppose so.)

 

I'll look into getting the stuff ready to be committable to SVN, right now it's a bit "experimental".

Link to comment
Share on other sites

And the development headers are also available as package? (I suppose so.)

I'll look into getting the stuff ready to be committable to SVN, right now it's a bit "experimental".

 

Yes, there is a libgtksourceview-dev package available as well. I will of course have to update the configure script to detect these headers as well, but that is no problem.

Link to comment
Share on other sites

Ok, my first commit using that package is in SVN, so you have a green light for trying to get this to work in Linux. :) Hopefully it won't be too much of a hassle to get this to compile.

 

I also uploaded the syntax/style files for GtkSourceView to the install/ folder, namely to install/sourceviewer. I don't know whether Linux already ships these along with the gtksourceview package, but I definitely need it for Win32 installations.

 

The main files are SourceView.h/.cpp in the gtkutil lib, which has to be updated such that it finds the corresponding GtkSourceView headers.

Link to comment
Share on other sites

Yup, here is a sneak preview of the shader definition inspector. You can access this by right-clicking any shader in the MediaBrowser.

 

darkradiant_shaderdefinition_viewer.jpg

 

The "language" definition is not yet polished, but all shader keywords are recognised already.

Link to comment
Share on other sites

Nice work! I am having two problems, tho:

 

./configure --enable-darkmod-plugins

 

says:

 

Configuration options:
Installation prefix: /usr/local
Sound:			   yes
Darkmod plugins:	 yes
Python scripting:	no
Shader type:		 GLSL

 

So how do I enable python?

 

Also, make under Kubuntu says now:

 

SourceView.cpp:7:52: error: gtksourceview/gtksourcelanguagemanager.h: No such file or directory
SourceView.cpp:8:55: error: gtksourceview/gtksourcestyleschememanager.h: No such file or directory
SourceView.cpp:9:41: error: gtksourceview/gtksourceview.h: No such file or directory
SourceView.cpp: In constructor ‘gtkutil::SourceView::SourceView(const std::string&, bool)’:
SourceView.cpp:26: error: ‘GtkSourceStyleSchemeManager’ was not declared in this scope
SourceView.cpp:26: error: ‘styleSchemeManager’ was not declared in this scope
SourceView.cpp:26: error: ‘gtk_source_style_scheme_manager_get_def
ault’ was not declared in this scope
SourceView.cpp:27: error: ‘gtk_source_style_scheme_manager_set_sea
rch_path’ was not declared in this scope
SourceView.cpp:28: error: ‘gtk_source_style_scheme_manager_force_r
escan’ was not declared in this scope
SourceView.cpp:30: error: ‘gtk_source_language_manager_new’ was not declared in this scope
SourceView.cpp:31: error: ‘gtk_source_language_manager_set_search_
path’ was not declared in this scope
SourceView.cpp:33: error: ‘GtkSourceLanguage’ was not declared in this scope
SourceView.cpp:33: error: ‘lang’ was not declared in this scope
SourceView.cpp:33: error: ‘gtk_source_language_manager_get_languag
e’ was not declared in this scope
SourceView.cpp:41: error: ‘gtk_source_buffer_new_with_language’ was not declared in this scope
SourceView.cpp:42: error: ‘gtk_source_buffer_set_highlight_syntax’ was not declared in this scope
SourceView.cpp:44: error: ‘gtk_source_view_new_with_buffer’ was not declared in this scope
SourceView.cpp:44: error: ‘GTK_SOURCE_VIEW’ was not declared in this scope
SourceView.cpp:47: error: ‘GTK_TEXT_VIEW’ was not declared in this scope
SourceView.cpp:47: error: ‘gtk_text_view_set_wrap_mode’ was not declared in this scope
SourceView.cpp:48: error: ‘gtk_text_view_set_editable’ was not declared in this scope
SourceView.cpp:50: error: ‘gtk_source_view_set_show_line_numbers’ was not declared in this scope
SourceView.cpp:51: error: ‘gtk_source_view_set_auto_indent’ was not declared in this scope
SourceView.cpp:62: error: ‘gtk_source_view_set_tab_width’ was not declared in this scope
SourceView.cpp: In member function ‘void gtkutil::SourceView::setContents(const std::string&)’:
SourceView.cpp:81: error: ‘GTK_TEXT_BUFFER’ was not declared in this scope
SourceView.cpp:81: error: ‘gtk_text_buffer_set_text’ was not declared in this scope
SourceView.cpp: In member function ‘std::string gtkutil::SourceView::getContents()’:
SourceView.cpp:86: error: ‘GtkTextIter’ was not declared in this scope
SourceView.cpp:86: error: expected `;' before ‘start’
SourceView.cpp:87: error: expected `;' before ‘end’
SourceView.cpp:89: error: ‘GTK_TEXT_BUFFER’ was not declared in this scope
SourceView.cpp:89: error: ‘start’ was not declared in this scope
SourceView.cpp:89: error: ‘end’ was not declared in this scope
SourceView.cpp:89: error: ‘gtk_text_buffer_get_bounds’ was not declared in this scope
SourceView.cpp:92: error: ‘gtk_text_buffer_get_text’ was not declared in this scope
SourceView.cpp: In member function ‘void gtkutil::SourceView::clear()’:
SourceView.cpp:103: error: ‘GTK_TEXT_BUFFER’ was not declared in this scope
SourceView.cpp:103: error: ‘gtk_text_buffer_set_text’ was not declared in this scope
make[3]: *** [SourceView.lo] Error 1
make[3]: Leaving directory `/home/te/src/darkradiant/libs/gtkutil'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/te/src/darkradiant/libs'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/te/src/darkradiant'
make: *** [all] Error 2

 

Edit: Nevermind, the latest version 0.9.12 is installed here - must have sneaked in :)

 

Also, as far as I know, I never got again an update for DR via the repository on bloodgate.com - is this not updated anymore?

"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." -- George Bernard Shaw (1856 - 1950)

 

"Remember: If the game lets you do it, it's not cheating." -- Xarax

Link to comment
Share on other sites

Btw, http://darkradiant.sourceforge.net/ links to the wrong wiki page for "Using the repository" (it redirects to the main page)

"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." -- George Bernard Shaw (1856 - 1950)

 

"Remember: If the game lets you do it, it's not cheating." -- Xarax

Link to comment
Share on other sites

Install package libgtksourceview2.0-dev

 

That doesn't enable Python, but it makes the compile go a bit further:

 

mv -f .deps/darkradiant-ModelPropertyEditor.Tpo .deps/darkradiant-ModelPropertyEditor.Po
make[2]: *** No rule to make target `ui/einspector/SoundChooser.cpp', needed by `darkradiant-SoundChooser.o'.  Stop.
make[2]: Leaving directory `/home/te/src/darkradiant/radiant'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/te/src/darkradiant'
make: *** [all] Error 2

"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." -- George Bernard Shaw (1856 - 1950)

 

"Remember: If the game lets you do it, it's not cheating." -- Xarax

Link to comment
Share on other sites

  • 4 months later...

Wanted to try this today. Making a script that shifts textures in a random way to counter repetition of texture patterns on multiple brushes or patches. While making something like down here I realized I didn't even know what python libraries are in DR. Is it possible to add some math and random libraries somehow?

 

# Set the command name so that DarkRadiant recognises this file
__commandName__ = 'shift'

# The actual algorithm called by DarkRadiant 
# is contained in the execute() function

def execute():

import random
s = random.randint(0, 256)
t = random.randint(0, 256)
print(str(s))
print(str(t))
GlobalCommandSystem.execute('texshift" ' + str(s) + ',' + str(t) + '"')

# The variable __executeCommand__ evaluates to true 
# when DarkRadiant executes this command
if __executeCommand__:
execute()

Link to comment
Share on other sites

The import random doesn't work? Do you have Python 2.6 installed on your system? I guess that's needed if you're using "stock" Python libraries.

Yes I did, but reinstalled it today in another folder, now I have Python 2.6 and Dark Radiant in my program files folder. And it's working. I just think it's awesome to have stuff like this, I'm sure people will develop some scripts in time that can replace a need for new features in DR. Thanks very much.

 

To start with that I have a script that translates the texture on selected surfaces in a random way. I used it for stair steps:

 

translates in one direction:

 

# Set the command name so that DarkRadiant recognises this file
__commandName__ = 'shiftup'

# The actual algorithm called by DarkRadiant 
# is contained in the execute() function

def execute():

import random
s = random.randint(0, 256)

for i in range(0, s+1):
GlobalCommandSystem.execute('texshiftup "' + str(s) + '"')

else: 
print("texture translated over" + str(s) )

# The variable __executeCommand__ evaluates to true 
# when DarkRadiant executes this command
if __executeCommand__:
execute()

 

 

translates in both directions (not really tested):

 

# Set the command name so that DarkRadiant recognises this file
__commandName__ = 'shift'

# The actual algorithm called by DarkRadiant 
# is contained in the execute() function

def execute():

import random
s = random.randint(0, 256)
t = random.randint(0, 256)

for i in range(0, s+1):
GlobalCommandSystem.execute('texshiftright "' + str(s) + '"')

else:

for i in range(0, t+1):
GlobalCommandSystem.execute('texshiftup "' + str(t) + '"')

else:

print("texture translated over" + str(s) + " " + str(t))

# The variable __executeCommand__ evaluates to true 
# when DarkRadiant executes this command
if __executeCommand__:
execute()

Link to comment
Share on other sites

Awesome, I didn't expect custom scripts for DarkRadiant so soon. :)

 

I just think it's awesome to have stuff like this, I'm sure people will develop some scripts in time that can replace a need for new features in DR.

That's exactly the reason and intention behind the ScriptingSystem - I thought it would be cool to have a library of custom scripts for DarkRadiant in the end.

 

To start with that I have a script that translates the texture on selected surfaces in a random way. I used it for stair steps:

I'll rename these commands and put them into SVN. I'll also look into some kind of UI integration for these custom scripts, so that users can access them by clicking.

Link to comment
Share on other sites

I'll rename these commands and put them into SVN. I'll also look into some kind of UI integration for these custom scripts, so that users can access them by clicking.

 

I am still pondering of some sort of "scripted generator" (for stairs f.i.) although I still don't know Python and have no time - but anyway, can I ask if there is some sort of "GUI" possible for the scripts, so that they can ask the user for parameters (like how big hoa many stairs etc?)

"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." -- George Bernard Shaw (1856 - 1950)

 

"Remember: If the game lets you do it, it's not cheating." -- Xarax

Link to comment
Share on other sites

No GUIs yet for scripts - what would be possible is to expose the existing functions for "Confirm - Yes No"-style dialogs, but for more fancy stuff there is no interface yet. Though I have some ideas about how to handle that, on the backburner of course, there are just too many things to work on.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recent Status Updates

    • Petike the Taffer

      I've finally managed to log in to The Dark Mod Wiki. I'm back in the saddle and before the holidays start in full, I'll be adding a few new FM articles and doing other updates. Written in Stone is already done.
      · 4 replies
    • nbohr1more

      TDM 15th Anniversary Contest is now active! Please declare your participation: https://forums.thedarkmod.com/index.php?/topic/22413-the-dark-mod-15th-anniversary-contest-entry-thread/
       
      · 0 replies
    • JackFarmer

      @TheUnbeholden
      You cannot receive PMs. Could you please be so kind and check your mailbox if it is full (or maybe you switched off the function)?
      · 1 reply
    • OrbWeaver

      I like the new frob highlight but it would nice if it was less "flickery" while moving over objects (especially barred metal doors).
      · 4 replies
    • nbohr1more

      Please vote in the 15th Anniversary Contest Theme Poll
       
      · 0 replies
×
×
  • Create New...